seiten 0.0.8 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +1 -0
- data/app/controllers/seiten/pages_controller.rb +2 -18
- data/config/initializers/seiten.rb +1 -1
- data/lib/seiten/errors/base_error.rb +4 -0
- data/lib/seiten/errors/page_error.rb +4 -0
- data/lib/seiten/errors/routing_error.rb +4 -0
- data/lib/seiten/helpers/backend.rb +23 -0
- data/lib/seiten/helpers/current.rb +33 -0
- data/lib/seiten/helpers/frontend.rb +19 -0
- data/lib/seiten/html/breadcrumb.rb +41 -0
- data/lib/seiten/html/helpers.rb +32 -0
- data/lib/seiten/html/navigation.rb +39 -0
- data/lib/seiten/navigation.rb +43 -0
- data/lib/seiten/page.rb +71 -50
- data/lib/seiten/page_collection.rb +54 -0
- data/lib/seiten/page_collection_builder.rb +63 -0
- data/lib/seiten/railtie.rb +7 -0
- data/lib/seiten/routes_helper.rb +16 -11
- data/lib/seiten/slug_builder.rb +32 -0
- data/lib/seiten/version.rb +1 -1
- data/lib/seiten.rb +63 -12
- data/test/controllers/helper_methods_test.rb +25 -0
- data/test/controllers/pages_controller_test.rb +9 -0
- data/test/controllers/posts_controller_test.rb +12 -0
- data/test/controllers/seiten/pages_controller_test.rb +39 -0
- data/test/dummy/app/controllers/application_controller.rb +10 -0
- data/test/dummy/app/controllers/pages_controller.rb +1 -1
- data/test/dummy/app/controllers/posts_controller.rb +10 -0
- data/test/dummy/app/helpers/application_helper.rb +1 -0
- data/test/dummy/app/pages/{de → application/de}/produkte.html.erb +0 -0
- data/test/dummy/app/pages/{en/about/our-team/switzerland.html.erb → application/en/about/our-team/italy.html.erb} +0 -0
- data/test/dummy/app/pages/{en/about/works.html.erb → application/en/about/our-team/switzerland.html.erb} +0 -0
- data/test/dummy/app/pages/application/en/about/our-team.html.erb +2 -0
- data/test/dummy/app/pages/application/en/about/partners.html.erb +1 -0
- data/test/dummy/app/pages/{en/contact.html.erb → application/en/about/works.html.erb} +0 -0
- data/test/dummy/app/pages/{en/about/our-team/italy.html.erb → application/en/about.html.erb} +0 -0
- data/test/dummy/app/pages/{en/products/logo-design.html.erb → application/en/contact.html.erb} +0 -0
- data/test/dummy/app/pages/{en → application/en}/home.html.erb +0 -0
- data/test/dummy/app/pages/{en/products/web-development.html.erb → application/en/products/hire-us.html.erb} +0 -0
- data/test/dummy/{db/test.sqlite3 → app/pages/application/en/products/logo-design.html.erb} +0 -0
- data/test/dummy/app/pages/application/en/products/web-development.html.erb +0 -0
- data/test/dummy/app/pages/{en → application/en}/products.html.erb +0 -0
- data/test/dummy/app/pages/{localization.html.erb → application/localization.html.erb} +0 -0
- data/test/dummy/app/pages/help/en/home.html.erb +0 -0
- data/test/dummy/app/pages/help/en/logging-in.html.erb +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +1 -1
- data/test/dummy/app/views/layouts/home.html.erb +1 -1
- data/test/dummy/app/views/pages/secret.html.erb +1 -1
- data/test/dummy/app/views/posts/index.html.erb +1 -0
- data/test/dummy/config/application.rb +4 -41
- data/test/dummy/config/boot.rb +2 -9
- data/test/dummy/config/cable.yml +9 -0
- data/test/dummy/config/environments/development.rb +26 -21
- data/test/dummy/config/environments/production.rb +3 -0
- data/test/dummy/config/environments/test.rb +15 -19
- data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +6 -5
- data/test/dummy/config/initializers/mime_types.rb +0 -1
- data/test/dummy/config/initializers/new_framework_defaults.rb +20 -0
- data/test/dummy/config/initializers/session_store.rb +1 -6
- data/test/dummy/config/initializers/wrap_parameters.rb +5 -5
- data/test/dummy/config/{navigation/de.yml → navigations/application.de.yml} +5 -5
- data/test/dummy/config/{navigation/en.yml → navigations/application.en.yml} +15 -7
- data/test/dummy/config/navigations/help.en.yml +17 -0
- data/test/dummy/config/routes.rb +6 -3
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/log/development.log +1716 -4559
- data/test/dummy/log/test.log +43833 -16254
- data/test/fixtures/breadcrumb.html +1 -0
- data/test/fixtures/navigation.html +1 -0
- data/test/integration/layout_test.rb +10 -11
- data/test/integration/navigation_test.rb +50 -50
- data/test/lib/seiten/helpers/frontend_test.rb +37 -0
- data/test/lib/seiten/html/breadcrumb_test.rb +29 -0
- data/test/lib/seiten/html/helpers_test.rb +55 -0
- data/test/lib/seiten/html/navigation_test.rb +29 -0
- data/test/lib/seiten/navigation_test.rb +45 -0
- data/test/lib/seiten/page_collection_builder_test.rb +141 -0
- data/test/lib/seiten/page_collection_test.rb +59 -0
- data/test/lib/seiten/page_test.rb +188 -0
- data/test/lib/seiten/slug_builder_test.rb +47 -0
- data/test/lib/seiten_test.rb +16 -0
- data/test/test_helper.rb +2 -8
- metadata +134 -78
- data/app/helpers/seiten_helper.rb +0 -46
- data/lib/seiten/controllers/helpers.rb +0 -16
- data/lib/seiten/page_store.rb +0 -165
- data/test/dummy/app/assets/javascripts/application.js +0 -15
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/pages/en/about/our-team.html.erb +0 -2
- data/test/dummy/app/pages/en/about/partners.html.erb +0 -1
- data/test/dummy/config/navigation.yml +0 -37
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/integration/i18n_test.rb +0 -31
- data/test/integration/redirect_test.rb +0 -15
- data/test/page_store_test.rb +0 -28
- data/test/page_test.rb +0 -104
- data/test/seiten_test.rb +0 -11
@@ -0,0 +1 @@
|
|
1
|
+
<ul class="breadcrumb"><li class="breadcrumb__item"><a href="/our-team">About</a></li><li class="breadcrumb__item"><span class="breadcrumb__separator">></span><a href="/about/our-team">Our Team</a></li><li class="breadcrumb__item breadcrumb__item--current"><span class="breadcrumb__separator">></span><a href="/about/our-team/switzerland">Switzerland</a></li></ul>
|
@@ -0,0 +1 @@
|
|
1
|
+
<ul class="navigation"><li class="navigation__item navigation__item--active navigation__item--current test-class" data-behaviour="hello"><a href="/">Home</a></li><li class="navigation__item"><a href="/blog">Blog</a></li><li class="navigation__item navigation__item--parent"><a href="/products">Products</a><ul class="navigation__nodes"><li class="navigation__item"><a href="/products/logo-design">Logo Design</a></li><li class="navigation__item"><a href="/products/web-development">Web Development</a></li><li class="navigation__item"><a href="/contact">Hire us</a></li></ul></li><li class="navigation__item navigation__item--parent"><a href="/our-team">About</a><ul class="navigation__nodes"><li class="navigation__item navigation__item--parent"><a href="/about/our-team">Our Team</a></li><li class="navigation__item"><a href="/about/works">Works</a></li><li class="navigation__item navigation__item--parent"><a href="/about/partners">Partners</a></li></ul></li><li class="navigation__item"><a href="/contact">Contact</a></li><li class="navigation__item"><a href="/localization">I18n</a></li></ul>
|
@@ -1,26 +1,25 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class LayoutTest < ActionDispatch::IntegrationTest
|
4
|
-
|
5
4
|
def test_returns_default_layout
|
6
|
-
|
7
|
-
|
5
|
+
get '/about/works'
|
6
|
+
assert_select 'p', 'Default Layout'
|
8
7
|
end
|
9
8
|
|
10
9
|
def test_returns_home_layout
|
11
|
-
|
12
|
-
|
10
|
+
get '/'
|
11
|
+
assert_select 'p', 'Home Layout'
|
13
12
|
end
|
14
13
|
|
15
14
|
def test_returns_inherited_layout
|
16
|
-
|
17
|
-
|
15
|
+
get '/products/logo-design'
|
16
|
+
assert_select 'p', 'Products Layout'
|
18
17
|
end
|
19
18
|
|
20
19
|
def test_returns_no_inherited_layout
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
get '/about/our-team/switzerland'
|
21
|
+
assert_select 'p', 'Default Layout'
|
22
|
+
get '/contact'
|
23
|
+
assert_select 'p', 'Default Layout'
|
25
24
|
end
|
26
25
|
end
|
@@ -1,69 +1,69 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class NavigationTest < ActionDispatch::IntegrationTest
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
assert has_content?("Products")
|
9
|
-
assert has_content?("Logo Design")
|
10
|
-
assert has_content?("Web Development")
|
11
|
-
assert has_content?("Hire us")
|
12
|
-
assert has_content?("About")
|
13
|
-
assert has_content?("Our Team")
|
14
|
-
assert has_content?("Works")
|
15
|
-
assert has_content?("Partners")
|
16
|
-
assert has_content?("Contact")
|
4
|
+
def test_should_ignore_active_storage_routes
|
5
|
+
assert_raise ActionController::RoutingError do
|
6
|
+
get '/rails/active_storage/test'
|
7
|
+
end
|
17
8
|
end
|
18
9
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
assert !has_content?("Kreatify")
|
10
|
+
def test_should_raise_seiten_routing_error
|
11
|
+
assert_raise Seiten::Errors::RoutingError do
|
12
|
+
get '/non-existing-route'
|
13
|
+
end
|
24
14
|
end
|
25
15
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
16
|
+
def test_returns_2_level_deep_navigation
|
17
|
+
get '/'
|
18
|
+
assert_select 'a', 'Home'
|
19
|
+
assert_select 'a', 'Products'
|
20
|
+
assert_select 'a', 'Logo Design'
|
21
|
+
assert_select 'a', 'Web Development'
|
22
|
+
assert_select 'a', 'Hire us'
|
23
|
+
assert_select 'a', 'About'
|
24
|
+
assert_select 'a', 'Our Team'
|
25
|
+
assert_select 'a', 'Works'
|
26
|
+
assert_select 'a', 'Partners'
|
27
|
+
assert_select 'a', 'Contact'
|
28
|
+
assert_select 'a', { count: 0, text: 'Daniel Puglisi' }
|
29
|
+
assert_select 'a', { count: 0, text: 'Codegestalt' }
|
30
|
+
assert_select 'a', { count: 0, text: 'Kreatify' }
|
31
|
+
assert_select '.navigation__item--active', count: 1
|
32
|
+
assert_select 'title', 'My awesome Web Agency'
|
31
33
|
end
|
32
34
|
|
33
35
|
def test_returns_sub_navigation
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
get '/about/partners'
|
37
|
+
assert_select 'a', 'Daniel Puglisi'
|
38
|
+
assert_select 'a', 'Codegestalt'
|
39
|
+
assert_select 'a', 'Kreatify'
|
40
|
+
assert_select '.navigation__item--active', count: 2
|
41
|
+
assert_select 'title', 'Partners'
|
38
42
|
end
|
39
43
|
|
40
44
|
def test_returns_breadcrumb_navigation
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
visit "/about/our-team/switzerland"
|
49
|
-
find(".breadcrumb a", text: "Our Team").click
|
50
|
-
assert_equal "/about/our-team", current_path
|
45
|
+
get '/about/our-team/switzerland'
|
46
|
+
assert_select '.breadcrumb a', 'About'
|
47
|
+
assert_select '.breadcrumb a', 'Our Team'
|
48
|
+
assert_select '.breadcrumb a', 'Switzerland'
|
49
|
+
assert_select '.navigation__item--active', count: 2
|
50
|
+
assert_select '.breadcrumb__item--current', count: 1
|
51
|
+
assert_select 'title', 'Switzerland'
|
51
52
|
end
|
52
53
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
def test_returns_external_links
|
60
|
-
visit "/about/partners"
|
61
|
-
assert has_xpath?("//a[@href='http://danielpuglisi.com']")
|
54
|
+
def test_returns_page_with_navigation_which_is_not_defined_in_navigation_config
|
55
|
+
get '/secret'
|
56
|
+
assert_response :success
|
57
|
+
assert_select 'p', 'pages#secret'
|
58
|
+
assert_select '.navigation__item--active', count: 0
|
59
|
+
assert_select 'title', nil
|
62
60
|
end
|
63
61
|
|
64
|
-
def
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
def test_returns_current_page_of_custom_controller
|
63
|
+
get '/blog'
|
64
|
+
assert_select 'title', 'Blog'
|
65
|
+
assert_select 'p', 'posts#index'
|
66
|
+
assert_select '.navigation__item--active', count: 1
|
67
|
+
assert_select '.navigation__item--active a', text: 'Blog'
|
68
68
|
end
|
69
69
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Seiten::Helpers::FrontendTest < ActionView::TestCase
|
4
|
+
include Seiten::Helpers::Frontend
|
5
|
+
|
6
|
+
def navigation
|
7
|
+
@navigation ||= Seiten::Navigation.find_by(id: 'application.en')
|
8
|
+
end
|
9
|
+
|
10
|
+
def current_navigation
|
11
|
+
@current_navigation ||= navigation
|
12
|
+
end
|
13
|
+
|
14
|
+
def current_page
|
15
|
+
@current_page
|
16
|
+
end
|
17
|
+
|
18
|
+
test '#link_to_seiten_page' do
|
19
|
+
page = current_navigation.pages.find_by(slug: 'about/our-team')
|
20
|
+
|
21
|
+
assert_equal '<a href="/about/our-team">Our Team</a>', link_to_seiten_page(page)
|
22
|
+
end
|
23
|
+
|
24
|
+
test '#seiten_navigation' do
|
25
|
+
@current_page = current_navigation.pages.find_by(slug: '')
|
26
|
+
html = File.read(File.join(FIXTURES_DIR, 'navigation.html')).strip
|
27
|
+
|
28
|
+
assert_equal html, seiten_navigation
|
29
|
+
end
|
30
|
+
|
31
|
+
test '#seiten_breadcrumb' do
|
32
|
+
@current_page = current_navigation.pages.find_by(slug: 'about/our-team/switzerland')
|
33
|
+
html = File.read(File.join(FIXTURES_DIR, 'breadcrumb.html')).strip
|
34
|
+
|
35
|
+
assert_equal html, seiten_breadcrumb
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Seiten::HTML::BreadcrumbTest < ActiveSupport::TestCase
|
4
|
+
def context
|
5
|
+
controller = ApplicationController.new
|
6
|
+
controller.view_context.tap do |context|
|
7
|
+
context.instance_eval do
|
8
|
+
def url_options
|
9
|
+
{ host: 'localhost:3000' }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def navigation
|
16
|
+
@navigation ||= Seiten::Navigation.find_by(id: 'application.en')
|
17
|
+
end
|
18
|
+
|
19
|
+
def current_page
|
20
|
+
@current_page ||= navigation.pages.find_by(slug: 'about/our-team/switzerland')
|
21
|
+
end
|
22
|
+
|
23
|
+
test '::new' do
|
24
|
+
nav = Seiten::HTML::Breadcrumb.new(context, page: current_page)
|
25
|
+
html = File.read(File.join(FIXTURES_DIR, 'breadcrumb.html')).strip
|
26
|
+
|
27
|
+
assert_equal html, nav.body
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Seiten::HTML::HelpersTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def navigation
|
6
|
+
@navigation ||= Seiten::Navigation.find_by(id: 'application.en')
|
7
|
+
end
|
8
|
+
|
9
|
+
def current_page
|
10
|
+
@current_page ||= navigation.pages.find(1)
|
11
|
+
end
|
12
|
+
|
13
|
+
def helpers
|
14
|
+
Seiten::HTML::Helpers
|
15
|
+
end
|
16
|
+
|
17
|
+
test '#build_page_modifiers' do
|
18
|
+
page_1 = navigation.pages.new(id: 99)
|
19
|
+
page_2 = navigation.pages.new(id: 200, parent_id: 99)
|
20
|
+
assert_equal [:parent], helpers.build_page_modifiers(page_1, nil)
|
21
|
+
assert_equal [], helpers.build_page_modifiers(page_2, nil)
|
22
|
+
|
23
|
+
assert_equal [:parent, :active, :current], helpers.build_page_modifiers(page_1, page_1)
|
24
|
+
assert_equal [], helpers.build_page_modifiers(page_2, page_1)
|
25
|
+
|
26
|
+
assert_equal [:parent, :active, :expanded], helpers.build_page_modifiers(page_1, page_2)
|
27
|
+
assert_equal [:active, :current], helpers.build_page_modifiers(page_2, page_2)
|
28
|
+
end
|
29
|
+
|
30
|
+
test '#build_classes' do
|
31
|
+
class_options = Seiten.config[:html][:navigation].dup
|
32
|
+
modifier_options = Seiten.config[:html][:modifier].dup
|
33
|
+
|
34
|
+
assert_equal 'navigation', helpers.build_classes(class_options: class_options, modifier_options: modifier_options)
|
35
|
+
assert_equal 'navigation__item', helpers.build_classes(:item, class_options: class_options, modifier_options: modifier_options)
|
36
|
+
assert_equal 'navigation__item navigation__item--active', helpers.build_classes(:item, modifiers: [:active], class_options: class_options, modifier_options: modifier_options)
|
37
|
+
assert_equal 'navigation__item navigation__item--active navigation__item--parent', helpers.build_classes(:item, modifiers: [:active, :parent], class_options: class_options, modifier_options: modifier_options)
|
38
|
+
assert_equal 'navigation__nodes navigation__nodes--active navigation__nodes--parent', helpers.build_classes(:nodes, modifiers: [:active, :parent], class_options: class_options, modifier_options: modifier_options)
|
39
|
+
|
40
|
+
# Works with custom html class config
|
41
|
+
class_options[:base] = 'navbar'
|
42
|
+
class_options[:item] = 'navbar-item'
|
43
|
+
class_options[:nodes] = 'navbar-dropdown'
|
44
|
+
modifier_options[:base] = 'is'
|
45
|
+
modifier_options[:separator] = '-'
|
46
|
+
assert_equal 'navbar', helpers.build_classes(class_options: class_options, modifier_options: modifier_options)
|
47
|
+
assert_equal 'navbar-item', helpers.build_classes(:item, class_options: class_options, modifier_options: modifier_options)
|
48
|
+
assert_equal 'navbar-item is-active', helpers.build_classes(:item, modifiers: [:active], class_options: class_options, modifier_options: modifier_options)
|
49
|
+
assert_equal 'navbar-item is-active is-parent', helpers.build_classes(:item, modifiers: [:active, :parent], class_options: class_options, modifier_options: modifier_options)
|
50
|
+
assert_equal 'navbar-dropdown is-active is-parent', helpers.build_classes(:nodes, modifiers: [:active, :parent], class_options: class_options, modifier_options: modifier_options)
|
51
|
+
|
52
|
+
# Merges extension-class
|
53
|
+
assert_equal 'navbar-item is-active is-parent extension-class', helpers.build_classes(:item, modifiers: [:active, :parent], merge: 'extension-class', class_options: class_options, modifier_options: modifier_options)
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Seiten::HTML::NavigationTest < ActiveSupport::TestCase
|
4
|
+
def context
|
5
|
+
controller = ApplicationController.new
|
6
|
+
controller.view_context.tap do |context|
|
7
|
+
context.instance_eval do
|
8
|
+
def url_options
|
9
|
+
{ host: 'localhost:3000' }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def navigation
|
16
|
+
@navigation ||= Seiten::Navigation.find_by(id: 'application.en')
|
17
|
+
end
|
18
|
+
|
19
|
+
def current_page
|
20
|
+
@current_page ||= navigation.pages.find_by(slug: '')
|
21
|
+
end
|
22
|
+
|
23
|
+
test '::new' do
|
24
|
+
nav = Seiten::HTML::Navigation.new(context, navigation: navigation, current_page: current_page)
|
25
|
+
html = File.read(File.join(FIXTURES_DIR, 'navigation.html')).strip
|
26
|
+
|
27
|
+
assert_equal html, nav.body
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Seiten::NavigationTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def navigation
|
6
|
+
@navigation ||= Seiten::Navigation.new(
|
7
|
+
name: 'test',
|
8
|
+
locale: 'en'
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
test '::find_by' do
|
13
|
+
assert_equal 'application.en', Seiten::Navigation.find_by(name: 'application', locale: 'en').id
|
14
|
+
assert_equal 'application.de', Seiten::Navigation.find_by(name: 'application', locale: 'de').id
|
15
|
+
assert_equal 'application.en', Seiten::Navigation.find_by(locale: 'en').id
|
16
|
+
assert_equal 'application.de', Seiten::Navigation.find_by(locale: 'de').id
|
17
|
+
end
|
18
|
+
|
19
|
+
test '::where' do
|
20
|
+
assert_equal ['application.de', 'application.en'], Seiten::Navigation.where(name: 'application').map(&:id).sort
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
test '#id' do
|
25
|
+
nav = Seiten::Navigation.new(name: 'site', locale: 'en')
|
26
|
+
assert_equal 'site.en', nav.id
|
27
|
+
end
|
28
|
+
|
29
|
+
test '#pages' do
|
30
|
+
nav = Seiten::Navigation.new(name: 'test', locale: 'en')
|
31
|
+
pages = Seiten::PageCollection.new
|
32
|
+
nav.page_collection = pages
|
33
|
+
|
34
|
+
assert_equal pages, nav.pages
|
35
|
+
end
|
36
|
+
|
37
|
+
test '#pages=' do
|
38
|
+
page = Seiten::Page.new
|
39
|
+
|
40
|
+
navigation.pages = [page]
|
41
|
+
|
42
|
+
assert_equal page.navigation_id, navigation.id
|
43
|
+
assert_equal [page], navigation.pages.all
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Seiten::PageCollectionBuilderTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def page_collection
|
6
|
+
@page_collection ||= Seiten::PageCollection.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def options
|
10
|
+
@options ||= Hash[:pages, []]
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'should build root page' do
|
14
|
+
options[:pages] << { "title" => "Home", "root" => true }
|
15
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
16
|
+
|
17
|
+
assert_equal "Home", page_collection.find_by(slug: '').title
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'should build page with a defined url' do
|
21
|
+
options[:pages] << { "title" => "About us", "url" => 'about' }
|
22
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
23
|
+
|
24
|
+
assert_equal "About us", page_collection.find_by(slug: 'about').title
|
25
|
+
end
|
26
|
+
|
27
|
+
test 'should build a child page with a defined url' do
|
28
|
+
options[:pages] << { "title" => "About us", "nodes" => [{ "title" => "Team", "url" => "/team" }] }
|
29
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
30
|
+
|
31
|
+
assert_equal "Team", page_collection.find_by(slug: 'team').title
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'should build page without an url' do
|
35
|
+
options[:pages] << { "title" => "About us", "url" => false }
|
36
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
37
|
+
|
38
|
+
assert_equal "About us", page_collection.where(slug: nil).first.title
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'should build child page' do
|
42
|
+
options[:pages] << { "title" => "About us", "nodes" => [{ "title" => "Team" }] }
|
43
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
44
|
+
|
45
|
+
assert_equal "About us", page_collection.find_by(slug: 'about-us').title
|
46
|
+
assert_equal "Team", page_collection.find_by(slug: 'about-us/team').title
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'should build child page of child page' do
|
50
|
+
options[:pages] << { "title" => "About us", "nodes" => [{ "title" => "Team", "nodes" => [{ "title" => "Management" }] }] }
|
51
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
52
|
+
|
53
|
+
parent = page_collection.find_by(slug: 'about-us')
|
54
|
+
child_1 = page_collection.find_by(slug: 'about-us/team')
|
55
|
+
child_2 = page_collection.find_by(slug: 'about-us/team/management')
|
56
|
+
|
57
|
+
assert_equal "About us", parent.title
|
58
|
+
assert_equal "Team", child_1.title
|
59
|
+
assert_equal "Management", child_2.title
|
60
|
+
|
61
|
+
assert_nil parent.parent_id
|
62
|
+
assert_equal parent.id, child_1.parent_id
|
63
|
+
assert_equal child_1.id, child_2.parent_id
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'should build child page without parent url' do
|
67
|
+
options[:pages] << { "title" => "About us", "url" => false, "nodes" => [{ "title" => "Team" }] }
|
68
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
69
|
+
|
70
|
+
assert_equal "About us", page_collection.where(slug: nil).first.title
|
71
|
+
assert_equal "Team", page_collection.find_by(slug: 'team').title
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'should build a page that refers to its first child' do
|
75
|
+
options[:pages] << { "title" => "About us", "refer" => true, "nodes" => [{ "title" => "Team" }] }
|
76
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
77
|
+
|
78
|
+
assert_equal "/team", page_collection.where(slug: nil).first.refer
|
79
|
+
end
|
80
|
+
|
81
|
+
test 'should build a referer page with an absolute path' do
|
82
|
+
options[:pages] << { "title" => "About us", "refer" => "/team" }
|
83
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
84
|
+
|
85
|
+
assert_equal "/team", page_collection.where(slug: nil).first.refer
|
86
|
+
end
|
87
|
+
|
88
|
+
test 'should build a referer page with an external path' do
|
89
|
+
options[:pages] << { "title" => "About us", "refer" => "https://codegestalt.com" }
|
90
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
91
|
+
|
92
|
+
assert_equal "https://codegestalt.com", page_collection.where(slug: nil).first.refer
|
93
|
+
end
|
94
|
+
|
95
|
+
test 'should build a page with default layout' do
|
96
|
+
options[:pages] << { "title" => "About us" }
|
97
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
98
|
+
|
99
|
+
assert_equal "application", page_collection.find_by(slug: 'about-us').layout
|
100
|
+
end
|
101
|
+
|
102
|
+
test 'should build a page with a layout' do
|
103
|
+
options[:pages] << { "title" => "About us", "layout" => "team", "nodes" => [{ "title" => "Team" }] }
|
104
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
105
|
+
|
106
|
+
assert_equal "team", page_collection.find_by(slug: 'about-us').layout
|
107
|
+
assert_equal "team", page_collection.find_by(slug: 'about-us/team').layout
|
108
|
+
end
|
109
|
+
|
110
|
+
test 'should build a page with an inherited layout' do
|
111
|
+
options[:pages] << { "title" => "About us", "layout" => { "name" => "team", "inherit" => true }, "nodes" => [{ "title" => "Team" }] }
|
112
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
113
|
+
|
114
|
+
assert_equal "team", page_collection.find_by(slug: 'about-us').layout
|
115
|
+
assert_equal "team", page_collection.find_by(slug: 'about-us/team').layout
|
116
|
+
end
|
117
|
+
|
118
|
+
test 'should build a page without inheriting the layout' do
|
119
|
+
options[:pages] << { "title" => "About us", "layout" => { "name" => "team", "inherit" => false }, "nodes" => [{ "title" => "Team" }] }
|
120
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
121
|
+
|
122
|
+
assert_equal "team", page_collection.find_by(slug: 'about-us').layout
|
123
|
+
assert_equal "application", page_collection.find_by(slug: 'about-us/team').layout
|
124
|
+
end
|
125
|
+
|
126
|
+
test 'should raise page refer exception' do
|
127
|
+
options[:pages] << { "title" => 'Refer', "refer" => 'home' }
|
128
|
+
err = assert_raises Seiten::Errors::PageError do
|
129
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
130
|
+
end
|
131
|
+
assert_match "The `refer` option must be `true` or an absolute or external path", err.message
|
132
|
+
end
|
133
|
+
|
134
|
+
test 'should raise page url exception' do
|
135
|
+
options[:pages] << { "title" => 'External path', "url" => 'https://codegestalt.com' }
|
136
|
+
err = assert_raises Seiten::Errors::PageError do
|
137
|
+
Seiten::PageCollectionBuilder.call(page_collection, options)
|
138
|
+
end
|
139
|
+
assert_match "The `url` option can not be an external path. Use the `refer` option to link to external resources.", err.message
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Seiten::PageCollectionTest < ActiveSupport::TestCase
|
4
|
+
def navigation
|
5
|
+
@navigation ||= Seiten::Navigation.new(name: :test, locale: :en)
|
6
|
+
end
|
7
|
+
|
8
|
+
def page_collection
|
9
|
+
@page_collection ||= Seiten::PageCollection.new(
|
10
|
+
navigation_id: 'test.en',
|
11
|
+
pages: [
|
12
|
+
Seiten::Page.new(navigation_id: 'test.en', id: 1),
|
13
|
+
Seiten::Page.new(navigation_id: 'test.en', id: 2, parent_id: 1),
|
14
|
+
Seiten::Page.new(navigation_id: 'test.en', id: 3, parent_id: 1),
|
15
|
+
Seiten::Page.new(navigation_id: 'test.en', id: 4),
|
16
|
+
Seiten::Page.new(navigation_id: 'test.en', id: 5)
|
17
|
+
]
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
setup do
|
22
|
+
Seiten.navigations << navigation
|
23
|
+
end
|
24
|
+
|
25
|
+
teardown do
|
26
|
+
Seiten.navigations = Seiten.navigations - [navigation]
|
27
|
+
end
|
28
|
+
|
29
|
+
test '#navigation' do
|
30
|
+
assert_equal navigation, page_collection.navigation
|
31
|
+
end
|
32
|
+
|
33
|
+
test '#all' do
|
34
|
+
assert_equal [1,2,3,4,5], page_collection.all.map(&:id)
|
35
|
+
end
|
36
|
+
|
37
|
+
test '#find' do
|
38
|
+
assert_equal 3, page_collection.find(3).id
|
39
|
+
end
|
40
|
+
|
41
|
+
test '#find_by' do
|
42
|
+
assert_equal 2, page_collection.find_by(id: 2).id
|
43
|
+
assert_equal 3, page_collection.find_by(id: 3, parent_id: 1).id
|
44
|
+
assert_nil page_collection.find_by(id: 2, parent_id: 2)
|
45
|
+
end
|
46
|
+
|
47
|
+
test '#where' do
|
48
|
+
assert_equal [1], page_collection.where(id: 1).map(&:id)
|
49
|
+
assert_equal [2,3], page_collection.where(parent_id: 1).map(&:id)
|
50
|
+
assert_equal [], page_collection.where(parent_id: 2)
|
51
|
+
end
|
52
|
+
|
53
|
+
test '#new' do
|
54
|
+
page = page_collection.new(id: 6)
|
55
|
+
assert_equal 6, page.id
|
56
|
+
assert_equal 'test.en', page.navigation_id
|
57
|
+
assert_equal [1,2,3,4,5,6], page_collection.all.map(&:id)
|
58
|
+
end
|
59
|
+
end
|