Skip to content

Commit 16c56dc

Browse files
committed
Add cache invalidation tests for tag updates
1 parent dedd285 commit 16c56dc

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

test/controllers/cards_controller_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,27 @@ class CardsControllerTest < ActionDispatch::IntegrationTest
319319
assert_equal [ tag.title ], @response.parsed_body["tags"]
320320
end
321321

322+
test "update as JSON with description and tag_ids busts the card cache key" do
323+
card = cards(:logo)
324+
original_cache_key = card.cache_key_with_version
325+
tag = tags(:mobile)
326+
327+
travel 1.minute do
328+
put card_path(card, format: :json), params: {
329+
card: {
330+
description: "Updated description",
331+
tag_ids: [ tag.id ]
332+
}
333+
}
334+
end
335+
336+
assert_response :success
337+
assert_not_equal original_cache_key, card.reload.cache_key_with_version
338+
assert_equal "Updated description", card.description.to_plain_text.strip
339+
assert_equal [ tag ], card.tags
340+
assert_equal [ tag.title ], @response.parsed_body["tags"]
341+
end
342+
322343
test "delete as JSON" do
323344
card = cards(:logo)
324345

test/models/card/taggable_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,17 @@ class Card::TaggableTest < ActiveSupport::TestCase
2525

2626
assert_not_equal cards(:logo).tags.last, cards(:paycheck).tags.last
2727
end
28+
29+
test "updating just tag_ids touches the card and board" do
30+
board = @card.board
31+
card_updated_at = @card.updated_at
32+
board_updated_at = board.updated_at
33+
34+
travel 1.minute do
35+
@card.update!(tag_ids: [ tags(:web).id, tags(:mobile).id ])
36+
end
37+
38+
assert @card.reload.updated_at > card_updated_at
39+
assert board.reload.updated_at > board_updated_at
40+
end
2841
end

0 commit comments

Comments
 (0)