Skip to content

Commit

Permalink
Fix updating the public_on date on persisted pages
Browse files Browse the repository at this point in the history
When updating a page's `public_on` date, we need to save the associated
public page as well. This commit accomplishes that.

Prior to this commit, we would set the `public_on` date on the public
version, but not persist it.
  • Loading branch information
mamhoff committed Apr 21, 2022
1 parent f83cbd6 commit 26e92bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,11 @@ def public_on=(time)
# Need to reset the public version on the instance so we do not need to reload
self.public_version = nil
elsif public_version
public_version.public_on = time
if persisted?
public_version.update!(public_on: time)
else
public_version.public_on = time
end
elsif time.present?
versions.build(public_on: time)
end
Expand Down
11 changes: 10 additions & 1 deletion spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@ def copy_children_to(new_parent)
end

describe "#public_on=" do
let(:time) { Time.now }
let(:time) { 1.hour.ago }

subject { page.public_on = time }

Expand All @@ -1409,6 +1409,15 @@ def copy_children_to(new_parent)
expect(page.public_version.public_on).to be_within(1.second).of(time)
end

context "when the page is persisted" do
let(:page) { create(:alchemy_page, :public) }

it "sets public_on on the public version" do
page.update(public_on: time)
expect(page.reload.public_version.public_on).to be_within(1.second).of(time)
end
end

context "and the time is nil" do
let(:page) { build(:alchemy_page, :public) }
let(:time) { nil }
Expand Down

0 comments on commit 26e92bc

Please sign in to comment.