Skip to content

Commit

Permalink
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.
  • Loading branch information
mamhoff committed May 14, 2024
1 parent 62fa05b commit 7383a02
Show file tree
Hide file tree
Showing 3 changed files with 11 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
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion spec/models/alchemy/page/publisher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, public_on: yesterday, page: page)
end

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

it "updates public version's updated_at timestamp" do
# Need to do this here, because the nested element touches the version on creation.
public_version.update_columns(updated_at: yesterday)
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
Expand Down
4 changes: 2 additions & 2 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7383a02

Please sign in to comment.