From a896b0a9e6bfe264c3ba5621038f0a13d327cff9 Mon Sep 17 00:00:00 2001 From: Rob Zolkos Date: Mon, 9 Mar 2026 13:59:57 -0400 Subject: [PATCH] Touch board when publication is created or destroyed (#2674) Publishing or unpublishing a board didn't bust the `json.cache! board` fragment cache because `Board::Publication` didn't touch its parent board. The board's `updated_at` stayed stale, so subsequent GET requests continued serving cached JSON without `public_url`. --- app/models/board/publication.rb | 2 +- test/models/board/publishable_test.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/models/board/publication.rb b/app/models/board/publication.rb index bd480eecc..20dcc40da 100644 --- a/app/models/board/publication.rb +++ b/app/models/board/publication.rb @@ -1,6 +1,6 @@ class Board::Publication < ApplicationRecord belongs_to :account, default: -> { board.account } - belongs_to :board + belongs_to :board, touch: true has_secure_token :key end diff --git a/test/models/board/publishable_test.rb b/test/models/board/publishable_test.rb index e05f19bd2..8feadfd73 100644 --- a/test/models/board/publishable_test.rb +++ b/test/models/board/publishable_test.rb @@ -42,6 +42,20 @@ class Board::PublishableTest < ActiveSupport::TestCase end end + test "touch board when publication is created" do + assert_changes -> { boards(:writebook).reload.updated_at } do + boards(:writebook).publish + end + end + + test "touch board when publication is destroyed" do + boards(:writebook).publish + + assert_changes -> { boards(:writebook).reload.updated_at } do + boards(:writebook).unpublish + end + end + test "publish doesn't create duplicate publications" do boards(:writebook).publish original_publication = boards(:writebook).publication