Skip to content

Commit d58ea11

Browse files
committed
Set public_until instead of clearing public_on when unpublishing elements
Previously, setting `public = false` on an element cleared its `public_on` timestamp, turning it into a draft. Now it sets `public_until` to the current time, preserving the publication history while marking the element as expired. Setting `public = true` now also always refreshes `public_on` and clears any `public_until` value. (cherry picked from commit 73a290c)
1 parent 1dfaea1 commit d58ea11

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

app/models/alchemy/element.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,10 @@ def store_page(page)
234234
def public=(value)
235235
@public_on_explicitely_set = true
236236
if ActiveModel::Type::Boolean.new.cast(value)
237-
self.public_on ||= Time.current
237+
self.public_on = Time.current
238+
self.public_until = nil
238239
else
239-
self.public_on = nil
240+
self.public_until = Time.current
240241
end
241242
end
242243

spec/models/alchemy/page/publisher_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
shared_context "with elements" do
2929
let(:page) do
3030
create(:alchemy_page, autogenerate_elements: true).tap do |page|
31-
page.draft_version.elements.first.update!(public: false)
31+
page.draft_version.elements.first.update!(public_until: 1.minute.ago)
3232
end
3333
end
3434
end

0 commit comments

Comments
 (0)