Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Touch page version's updated at when updating
Browse files Browse the repository at this point in the history
Without this, the previous commit will not do what we expect. If we
don´t update the page version's updated at, it will not serve as a good
cache invalidator.
mamhoff committed May 13, 2024
1 parent 62fa05b commit 38e4c42
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/models/alchemy/page/publisher.rb
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ def publish!(public_on:)
end
end
end
version.update(updated_at: public_on)
page.update(published_at: public_on)
end
end
7 changes: 6 additions & 1 deletion spec/models/alchemy/page/publisher_spec.rb
Original file line number Diff line number Diff line change
@@ -55,8 +55,9 @@
end

context "with published version existing" do
let(:yesterday) { Date.yesterday.to_time }
let!(:public_version) do
create(:alchemy_page_version, :with_elements, element_count: 3, public_on: Date.yesterday.to_time, page: page)
create(:alchemy_page_version, :with_elements, element_count: 3, updated_at: yesterday, public_on: yesterday, page: page)
end

let!(:nested_element) do
@@ -67,6 +68,10 @@
expect { publish }.to_not change(page.public_version, :public_on)
end

it "updates public version's updated_at timestamp" do
expect { publish }.to change(page.public_version, :updated_at)
end

it "does not create another public version" do
expect { publish }.to_not change(page.versions, :count)
end
4 changes: 2 additions & 2 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
@@ -711,13 +711,13 @@ module Alchemy
end

around do |example|
travel_to(Time.parse("2019-01-01 12:00:00")) do
travel_to(Time.parse("2019-01-01 12:00:00 UTC")) do
example.run
end
end

it "returns a cache version string" do
expect(page.cache_version).to eq("2018-12-31 11:00:00 UTC")
expect(page.cache_version).to eq("2018-12-31 12:00:00 UTC")
end
end

0 comments on commit 38e4c42

Please sign in to comment.