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
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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
|
||||
Reference in New Issue
Block a user