Files
fizzy/test/controllers/cards/self_assignments_controller_test.rb
T
Mike Dalessio 2527f07365 Fix "M" hotkey using stale user from fragment cache
Add a SelfAssignmentsController to resolve the current user at request
time, avoiding the use of an incorrect user id baked into a cached URL.

ref: #2211 originally added the "M" hotkey
ref: https://app.fizzy.do/5986089/cards/3722
2026-01-16 13:41:33 -05:00

45 lines
1.1 KiB
Ruby

require "test_helper"
class Cards::SelfAssignmentsControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in_as :kevin
end
test "create assigns to current user" do
card = cards(:layout)
assert_not card.assigned_to?(users(:kevin))
post card_self_assignment_path(card), as: :turbo_stream
assert_response :success
assert_meta_replaced(card)
assert card.reload.assigned_to?(users(:kevin))
end
test "create toggles off when already assigned" do
card = cards(:logo)
assert card.assigned_to?(users(:kevin))
post card_self_assignment_path(card), as: :turbo_stream
assert_response :success
assert_meta_replaced(card)
assert_not card.reload.assigned_to?(users(:kevin))
end
test "create as JSON" do
card = cards(:layout)
assert_not card.assigned_to?(users(:kevin))
post card_self_assignment_path(card), as: :json
assert_response :no_content
assert card.reload.assigned_to?(users(:kevin))
end
private
def assert_meta_replaced(card)
assert_turbo_stream action: :replace, target: dom_id(card, :meta)
end
end