From 506f74144ba21afe551c5689cb12d0a96e1cfc24 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Mon, 24 Mar 2025 16:41:45 -0400 Subject: [PATCH] Touch Account when adding or removing a Tag so we can properly cache the tags partial using account as part of the key. --- app/models/tag.rb | 2 +- test/models/tag_test.rb | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index a9fd6adba..51e27c30f 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,7 +1,7 @@ class Tag < ApplicationRecord include Filterable - belongs_to :account, default: -> { Current.account } + belongs_to :account, default: -> { Current.account }, touch: true has_many :taggings, dependent: :destroy has_many :bubbles, through: :taggings diff --git a/test/models/tag_test.rb b/test/models/tag_test.rb index 1846cdbcb..554056941 100644 --- a/test/models/tag_test.rb +++ b/test/models/tag_test.rb @@ -1,7 +1,15 @@ require "test_helper" class TagTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + test "creating or deleting a tag touches the account, so tags dialog fragment cache is invalidated" do + account = accounts("37s") + + assert_changes -> { account.reload.updated_at } do + account.tags.create!(title: "ReleaseBlocker") + end + + assert_changes -> { account.reload.updated_at } do + account.tags.find_by(title: "ReleaseBlocker").destroy + end + end end