Skip to content

Commit

Permalink
Fix page re-publishing for page with nested elements (#2043)
Browse files Browse the repository at this point in the history
If a page has a published page version with nested elements
the nested elements got deleted before the parent has been deleted.

Using the not_nested scope here to cascade from top to bottom.
  • Loading branch information
tvdeyen authored Mar 3, 2021
1 parent d05a757 commit 8af3092
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/alchemy/page/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(page)
def publish!(public_on:)
Page.transaction do
version = public_version(public_on)
version.elements.destroy_all
version.elements.not_nested.destroy_all

# We must not use .find_each here to not mess up the order of elements
page.draft_version.elements.not_nested.available.each do |element|
Expand Down
4 changes: 4 additions & 0 deletions spec/models/alchemy/page/publisher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
create(:alchemy_page_version, :with_elements, element_count: 3, public_on: Date.yesterday.to_time, page: page)
end

let!(:nested_element) do
create(:alchemy_element, page_version: public_version, parent_element: public_version.elements.first)
end

it "does not change current public versions public on date" do
expect { publish }.to_not change(page.public_version, :public_on)
end
Expand Down

0 comments on commit 8af3092

Please sign in to comment.