-
-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow ancestry to be set in custom pages (#1261)
* Allow ancestry to be set in custom pages * Add basic testing around Spina::Account * Update documentation for custom_pages
- Loading branch information
1 parent
25f9dd8
commit b45196b
Showing
3 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,31 @@ | ||
# Custom pages | ||
|
||
You can define custom pages for your theme that will be generated when bootstrapping your website. You can define whether or not they're deletable. By default Spina creates a custom page named Homepage which is not deletable. | ||
You can define custom pages for your theme that will be generated when bootstrapping your website. | ||
You can define whether or not they're deletable. By default Spina creates a custom page named Homepage which is not deletable. | ||
You can define nested pages by passing the name of a custom page as the parent. | ||
|
||
You define custom pages in your theme's config file: | ||
|
||
``` | ||
::Spina::Theme.register do |theme| | ||
# ... | ||
theme.custom_pages = [ | ||
{ | ||
name: "homepage", | ||
title: "Homepage", | ||
deletable: false, | ||
view_template: "homepage" | ||
}, | ||
{ | ||
name: "articles", | ||
title: "Articles", | ||
deletable: false, | ||
view_template: "articles", | ||
parent: "homepage" | ||
} | ||
] | ||
# ... | ||
end | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require "test_helper" | ||
|
||
module Spina | ||
class AccountTest < ActiveSupport::TestCase | ||
def setup | ||
@account = FactoryBot.create :account | ||
@theme = Spina::Theme.find_by_name(@account.theme) | ||
end | ||
|
||
test "after_save callback to bootstrap_navigations creates navigations" do | ||
@theme.navigations << {name: "navigation", label: "Navigation"} | ||
@account.save | ||
navigation = Spina::Navigation.find_by(name: "navigation") | ||
|
||
assert navigation | ||
end | ||
|
||
test "after_save callback to bootstrap_pages creates custom pages" do | ||
@theme.custom_pages << {name: "page", title: "Page", deletable: true, view_template: "page_template"} | ||
@account.save | ||
page = Spina::Page.find_by(name: "page") | ||
|
||
assert page | ||
end | ||
|
||
test "after_save callback to bootstrap_pages creates nested pages" do | ||
parent_page = FactoryBot.create :parent_page | ||
@theme.custom_pages << {name: "child", title: "Child", deletable: true, view_template: "child_page", parent: parent_page.name} | ||
@account.save | ||
child_page = Spina::Page.find_by(name: "child") | ||
|
||
assert_equal child_page.parent, parent_page | ||
end | ||
|
||
test "after_save callback to bootstrap_pages deactivates pages with unused templates" do | ||
@theme.custom_pages << {name: "page", title: "Page", deletable: true, active: true, view_template: "invalid_template"} | ||
@account.save | ||
page = Spina::Page.find_by(name: "page") | ||
|
||
assert_not page.active | ||
end | ||
|
||
test "after_save callback to bootstrap_pages activates pages with used templates" do | ||
@theme.view_templates << {name: "valid_template", title: "Template"} | ||
@theme.custom_pages << {name: "page", title: "Page", deletable: true, active: false, view_template: "valid_template"} | ||
@account.save | ||
page = Spina::Page.find_by(name: "page") | ||
|
||
assert page.active | ||
end | ||
|
||
test "after_save callback to bootstrap_resources creates resources" do | ||
@theme.resources << {name: "resource", label: "Resource", view_template: "resource_template", slug: "resource"} | ||
@account.save | ||
resource = Spina::Resource.find_by(name: "resource") | ||
|
||
assert resource | ||
end | ||
end | ||
end |