Testing Tag Management Controller Integration in Maybe Finance
This test suite validates the TagsController functionality in a Ruby on Rails application using Minitest. It covers essential CRUD operations for tag management, including listing, creating, editing, and updating tags within a family-based user context.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
maybe-finance/maybe
test/controllers/tags_controller_test.rb
require "test_helper"
class TagsControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in @user = users(:family_admin)
end
test "should get index" do
get tags_url
assert_response :success
@user.family.tags.each do |tag|
assert_select "#" + dom_id(tag), count: 1
end
end
test "should get new" do
get new_tag_url
assert_response :success
end
test "should create tag" do
assert_difference("Tag.count") do
post tags_url, params: { tag: { name: "Test Tag" } }
end
assert_redirected_to tags_url
assert_equal "Tag created", flash[:notice]
end
test "should get edit" do
get edit_tag_url(tags.first)
assert_response :success
end
test "should update tag" do
patch tag_url(tags.first), params: { tag: { name: "Test Tag" } }
assert_redirected_to tags_url
assert_equal "Tag updated", flash[:notice]
end
end