From 329d257f1a4b795027cd0f07fb0d24ed288bb7de Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 19 Aug 2021 12:15:46 +0200 Subject: [PATCH] Touch page if page version gets updated Crucial for page caching --- app/models/alchemy/page_version.rb | 2 +- spec/models/alchemy/page_version_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/alchemy/page_version.rb b/app/models/alchemy/page_version.rb index a565bdec4a..e17c5cf10a 100644 --- a/app/models/alchemy/page_version.rb +++ b/app/models/alchemy/page_version.rb @@ -2,7 +2,7 @@ module Alchemy class PageVersion < BaseRecord - belongs_to :page, class_name: "Alchemy::Page", inverse_of: :versions + belongs_to :page, class_name: "Alchemy::Page", inverse_of: :versions, touch: true has_many :elements, -> { order(:position) }, class_name: "Alchemy::Element", diff --git a/spec/models/alchemy/page_version_spec.rb b/spec/models/alchemy/page_version_spec.rb index 9a71364f45..53f27f3ce4 100644 --- a/spec/models/alchemy/page_version_spec.rb +++ b/spec/models/alchemy/page_version_spec.rb @@ -70,6 +70,16 @@ end end + describe "when saved" do + let(:page_version) { build(:alchemy_page_version) } + let(:page) { page_version.page } + + it "touches the page" do + expect(page).to receive(:touch) + page_version.save + end + end + describe "#public?" do subject { page_version.public? }