Skip to content

Commit

Permalink
Merge pull request #2241 from dbwinger/global-page-copy
Browse files Browse the repository at this point in the history
Handle copying/pasting global pages
  • Loading branch information
tvdeyen authored Feb 28, 2022
2 parents bc4ff7f + ac96c94 commit 4353d51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ def copy(source, differences = {})

def copy_and_paste(source, new_parent, new_name)
page = copy(source, {
parent_id: new_parent.id,
language: new_parent.language,
parent: new_parent,
language: new_parent&.language,
name: new_name,
title: new_name,
})
Expand Down
17 changes: 16 additions & 1 deletion spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ class AnotherUrlPathClass; end

it "should copy the source page with the given name to the new parent" do
expect(Page).to receive(:copy).with(source, {
parent_id: new_parent.id,
parent: new_parent,
language: new_parent.language,
name: page_name,
title: page_name,
Expand All @@ -1184,6 +1184,21 @@ class AnotherUrlPathClass; end
subject
end
end

context "if the source page has no parent (global page)" do
let(:source) { build_stubbed(:alchemy_page, layoutpage: true, parent_id: nil) }
let(:new_parent) { nil }

it "copies the source page with the given name" do
expect(Page).to receive(:copy).with(source, {
parent: nil,
language: nil,
name: page_name,
title: page_name,
})
subject
end
end
end

context "previous and next." do
Expand Down

0 comments on commit 4353d51

Please sign in to comment.