Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.1] Fix page seeder #2482

Merged
merged 2 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/alchemy/seeder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ def page_seeds_file
end

def page_yml
@_page_yml ||= YAML.load_file(page_seeds_file)
@_page_yml ||= YAML.safe_load(
page_seeds_file.read,
permitted_classes: [Date],
aliases: true
)
end

def contentpages
Expand All @@ -99,7 +103,9 @@ def user_seeds_file

def create_page(draft, attributes = {})
children = draft.delete("children") || []
page = Alchemy::Page.create!(draft.merge(attributes))
page = Alchemy::Page.new(draft.merge(attributes))
page.versions.build
page.save!
log "Created page: #{page.name}"
children.each do |child|
create_page(child, parent: page, language: page.language)
Expand Down
7 changes: 7 additions & 0 deletions spec/features/page_seeder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
expect(Alchemy::Page.find_by(name: "Footer")).to be_present
end

it "public pages have two page versions" do
seed
home_page = Alchemy::Page.find_by(name: "Home")
expect(home_page.public_version).to be_present
expect(home_page.draft_version).to be_present
end

context "when more then one content root page is present" do
let(:seeds_file) do
"spec/fixtures/pages_with_two_roots.yml"
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/pages.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---

- name: Index
page_layout: index
children:
- name: Home
public_on: 2015-01-01
page_layout: standard
- name: About
page_layout: about
Expand Down