seiten 0.0.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -1,16 +0,0 @@
|
|
1
|
-
module Seiten
|
2
|
-
module Controllers
|
3
|
-
# Those helpers are convenience methods added to ApplicationController.
|
4
|
-
module Helpers
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
helper_method :current_page
|
9
|
-
end
|
10
|
-
|
11
|
-
def current_page
|
12
|
-
@current_page ||= Seiten::Page.find_by_slug(params[:page])
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/lib/seiten/page_store.rb
DELETED
@@ -1,165 +0,0 @@
|
|
1
|
-
module Seiten
|
2
|
-
|
3
|
-
class PageStore
|
4
|
-
|
5
|
-
attr_accessor :storage_type, :storage_file, :storage_language, :storage_directory, :pages
|
6
|
-
|
7
|
-
def initialize(options={})
|
8
|
-
@storage_type = options[:storage_type] || Seiten.config[:default_storage_type]
|
9
|
-
@storage_directory = options[:storage_directory] || File.join(Rails.root, Seiten.config[:default_storage_directory])
|
10
|
-
@storage_language = (options[:storage_language] || I18n.locale).to_sym
|
11
|
-
@storage_file = options[:storage_file] || load_storage_file
|
12
|
-
@pages = load_pages
|
13
|
-
end
|
14
|
-
|
15
|
-
@storages = []
|
16
|
-
|
17
|
-
class << self
|
18
|
-
|
19
|
-
def storages
|
20
|
-
@storages
|
21
|
-
end
|
22
|
-
|
23
|
-
def storages=(storages)
|
24
|
-
@storages = storages
|
25
|
-
end
|
26
|
-
|
27
|
-
def current
|
28
|
-
Seiten.config[:current_page_store]
|
29
|
-
end
|
30
|
-
|
31
|
-
def set_current_page_store(options={})
|
32
|
-
Seiten.config[:current_page_store] = find_by(options) if options
|
33
|
-
end
|
34
|
-
|
35
|
-
def find_by(options={})
|
36
|
-
tmp_storages = storages
|
37
|
-
options.each do |option|
|
38
|
-
tmp_storages = tmp_storages.select { |storage| storage.send(option[0]) == option[1] }
|
39
|
-
end
|
40
|
-
tmp_storages.first
|
41
|
-
end
|
42
|
-
|
43
|
-
def initialize_page_stores
|
44
|
-
# Check if config/navigation exists?
|
45
|
-
# If true: Initialize localized navigation page stores with locale language and directory
|
46
|
-
# If false: Initialize the default storage file
|
47
|
-
if File.directory?(File.join(Rails.root, Seiten.config[:default_storage_file]))
|
48
|
-
Dir[File.join(Rails.root, Seiten.config[:default_storage_file], "*.yml")].each do |file|
|
49
|
-
locale = File.basename(file, '.yml')
|
50
|
-
Seiten::PageStore.storages << Seiten::PageStore.new(storage_language: locale, storage_directory: File.join(Rails.root, "app", "pages", locale))
|
51
|
-
end
|
52
|
-
else
|
53
|
-
Seiten::PageStore.storages << Seiten::PageStore.new(storage_language: default_locale)
|
54
|
-
end
|
55
|
-
set_current_page_store(storage_language: default_locale)
|
56
|
-
end
|
57
|
-
|
58
|
-
# NOTE: Haven't found out what's the problem, but Rails has some weird I18n behaviour on initialization.
|
59
|
-
# This method returns I18n.default_locale if config.i18n.default_locale is not set.
|
60
|
-
def default_locale
|
61
|
-
Rails.application.config.i18n.default_locale || I18n.default_locale
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
def load_storage_file
|
67
|
-
if File.exists?(File.join(Rails.root, Seiten.config[:default_storage_file], "#{storage_language}.yml"))
|
68
|
-
File.join(Rails.root, Seiten.config[:default_storage_file], "#{storage_language}.yml")
|
69
|
-
else
|
70
|
-
File.join(Rails.root, "#{Seiten.config[:default_storage_file]}.yml")
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def file_path(options={})
|
75
|
-
File.join(storage_directory, options[:filename])
|
76
|
-
end
|
77
|
-
|
78
|
-
def build_link(page, prefix_url="")
|
79
|
-
|
80
|
-
# if url is nil parameterize title otherwise just use url
|
81
|
-
slug = page["url"].nil? ? page["title"].parameterize : page["url"]
|
82
|
-
|
83
|
-
# prepend prefix_url if slug is not root or external url
|
84
|
-
unless slug[0] == "/" || !!(slug.match(/^https?:\/\/.+/)) || !prefix_url.present?
|
85
|
-
slug = "#{prefix_url}/#{slug}"
|
86
|
-
end
|
87
|
-
|
88
|
-
# return nil if page slug is /
|
89
|
-
if slug == "/" || page["root"] == true
|
90
|
-
slug = nil
|
91
|
-
end
|
92
|
-
|
93
|
-
# remove leading slash if present
|
94
|
-
if slug
|
95
|
-
slug = slug[1..-1] if slug[0] == "/"
|
96
|
-
end
|
97
|
-
|
98
|
-
slug
|
99
|
-
end
|
100
|
-
|
101
|
-
def load_pages(options={})
|
102
|
-
|
103
|
-
pages = options[:pages]
|
104
|
-
parent_id = options[:parent_id] # || nil
|
105
|
-
layout = options[:layout]
|
106
|
-
prefix_url = options[:prefix_url] || ""
|
107
|
-
|
108
|
-
# Setting default values
|
109
|
-
if storage_type == :yaml
|
110
|
-
pages ||= YAML.load_file(storage_file)
|
111
|
-
end
|
112
|
-
|
113
|
-
@id ||= 1
|
114
|
-
@navigation ||= []
|
115
|
-
|
116
|
-
pages.each_index do |i|
|
117
|
-
|
118
|
-
# Load page and set parent_id and generated page id
|
119
|
-
page = pages[i]
|
120
|
-
page["id"] = @id
|
121
|
-
page["parent_id"] = parent_id
|
122
|
-
page["layout"] ||= layout
|
123
|
-
|
124
|
-
# Increment generated id
|
125
|
-
@id += 1
|
126
|
-
|
127
|
-
# Build link
|
128
|
-
page["slug"] = build_link(page, prefix_url)
|
129
|
-
|
130
|
-
# Set layout
|
131
|
-
if page["layout"]
|
132
|
-
if page["layout"].is_a?(String)
|
133
|
-
inherited_layout = page["layout"]
|
134
|
-
elsif page["layout"].is_a?(Hash)
|
135
|
-
if page["layout"]["inherit"]
|
136
|
-
inherited_layout = page["layout"]
|
137
|
-
else
|
138
|
-
inherited_layout = nil
|
139
|
-
end
|
140
|
-
page["layout"] = page["layout"]["name"]
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
# Set redirect
|
145
|
-
if page["redirect"]
|
146
|
-
if page["redirect"].is_a?(TrueClass)
|
147
|
-
page["redirect"] = build_link(page["nodes"].first, page["slug"])
|
148
|
-
else
|
149
|
-
page["redirect"] = page["redirect"][1..-1] if page["redirect"][0] == "/"
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
# Load children
|
154
|
-
if page["nodes"]
|
155
|
-
load_pages(pages: page["nodes"], parent_id: page["id"], prefix_url: page["slug"], layout: inherited_layout, external: page["external"])
|
156
|
-
end
|
157
|
-
|
158
|
-
page_params = page.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
159
|
-
@navigation << Page.new(page_params)
|
160
|
-
end
|
161
|
-
|
162
|
-
@navigation
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// the compiled file.
|
9
|
-
//
|
10
|
-
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
-
// GO AFTER THE REQUIRES BELOW.
|
12
|
-
//
|
13
|
-
//= require jquery
|
14
|
-
//= require jquery_ujs
|
15
|
-
//= require_tree .
|
@@ -1,13 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
-
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
-
*
|
11
|
-
*= require_self
|
12
|
-
*= require_tree .
|
13
|
-
*/
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= seiten_navigation parent_id: Seiten::Page.find_by_slug("about/partners").id %>
|
@@ -1,37 +0,0 @@
|
|
1
|
-
- title: "Home"
|
2
|
-
root: true
|
3
|
-
layout: "home"
|
4
|
-
|
5
|
-
- title: "Products"
|
6
|
-
layout:
|
7
|
-
name: "products"
|
8
|
-
inherit: true
|
9
|
-
nodes:
|
10
|
-
- title: "Logo Design"
|
11
|
-
- title: "Web Development"
|
12
|
-
- title: "Hire us"
|
13
|
-
redirect: "/contact" # links to Contact page
|
14
|
-
|
15
|
-
- title: "About"
|
16
|
-
redirect: true # redirects /about to /about/our-team
|
17
|
-
nodes:
|
18
|
-
- title: "Our Team"
|
19
|
-
layout:
|
20
|
-
name: "team"
|
21
|
-
inherit: false
|
22
|
-
nodes:
|
23
|
-
- title: "Switzerland"
|
24
|
-
- title: "Italy"
|
25
|
-
- title: "Works"
|
26
|
-
- title: "Partners"
|
27
|
-
nodes:
|
28
|
-
- title: "Daniel Puglisi"
|
29
|
-
url: "http://danielpuglisi.com"
|
30
|
-
- title: "Codegestalt"
|
31
|
-
url: "http://codegestalt.com"
|
32
|
-
- title: "Kreatify"
|
33
|
-
url: "http://kreatify.com"
|
34
|
-
|
35
|
-
- title: "Contact"
|
36
|
-
- title: "I18n"
|
37
|
-
url: "/localization"
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class I18nTest < ActionDispatch::IntegrationTest
|
4
|
-
|
5
|
-
def test_returns_products_page_in_en_directory
|
6
|
-
Seiten::PageStore.set_current_page_store(storage_language: :en)
|
7
|
-
visit "/products"
|
8
|
-
assert has_content?("This is the products page")
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_returns_products_page_in_de_directory
|
12
|
-
Seiten::PageStore.set_current_page_store(storage_language: :de)
|
13
|
-
visit "/produkte"
|
14
|
-
assert has_content?("Das ist die Produkte Seite")
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_loads_de_navigation
|
18
|
-
I18n.locale = :de
|
19
|
-
assert_equal File.join(Rails.root, "config", "navigation", "de.yml"), Seiten::PageStore.new.storage_file
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_loads_en_navigation
|
23
|
-
I18n.locale = :en
|
24
|
-
assert_equal File.join(Rails.root, "config", "navigation", "en.yml"), Seiten::PageStore.new.storage_file
|
25
|
-
end
|
26
|
-
|
27
|
-
# def test_loads_navigation_without_locale_if_not_found
|
28
|
-
# I18n.locale = :fr
|
29
|
-
# assert_equal File.join(Rails.root, "config", "navigation.yml"), Seiten::PageStore.new.storage_file
|
30
|
-
# end
|
31
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class RedirectTest < ActionDispatch::IntegrationTest
|
4
|
-
|
5
|
-
def test_redirects_to_specified_page
|
6
|
-
visit "/"
|
7
|
-
click_link "Hire us"
|
8
|
-
assert_equal "/contact", current_path
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_redirects_to_first_child_page
|
12
|
-
visit "/about"
|
13
|
-
assert_equal "/about/our-team", current_path
|
14
|
-
end
|
15
|
-
end
|
data/test/page_store_test.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class PageStoreTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def test_returns_storages
|
6
|
-
assert_equal 2, Seiten::PageStore.storages.count
|
7
|
-
end
|
8
|
-
|
9
|
-
# TODO: Split into two tests
|
10
|
-
def test_sets_and_returns_current_page_store
|
11
|
-
page_store = Seiten::PageStore.find_by(storage_language: :de)
|
12
|
-
Seiten::PageStore.set_current_page_store(storage_language: :de)
|
13
|
-
assert_equal page_store, Seiten::PageStore.current
|
14
|
-
Seiten::PageStore.set_current_page_store(storage_language: :en)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_find_by_with_one_argument
|
18
|
-
page_store = Seiten::PageStore.find_by(storage_language: :de)
|
19
|
-
assert_equal File.join(Rails.root, "config", "navigation", "de.yml"), page_store.storage_file
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_find_by_with_multiple_arguments
|
23
|
-
page_store = Seiten::PageStore.find_by(storage_language: :de, storage_file: File.join(Rails.root, "config", "navigation", "de.yml"))
|
24
|
-
assert_equal File.join(Rails.root, "config", "navigation", "de.yml"), page_store.storage_file
|
25
|
-
end
|
26
|
-
|
27
|
-
# TODO: Write more tests
|
28
|
-
end
|
data/test/page_test.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class PageTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def test_returns_correct_number_of_page_objects
|
6
|
-
pages = Seiten::Page.all
|
7
|
-
assert_equal 16, pages.count
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_returns_page_title
|
11
|
-
assert_equal "Home", Seiten::Page.find(1).title
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_returns_nil_for_root_page_slug
|
15
|
-
assert_equal nil, Seiten::Page.find(1).slug
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_returns_page_slug
|
19
|
-
assert_equal "about/our-team", Seiten::Page.find(7).slug
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_returns_page_layout
|
23
|
-
assert_equal "home", Seiten::Page.find(1).layout
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_returns_external?
|
27
|
-
assert_equal true, Seiten::Page.find(13).external?
|
28
|
-
assert_equal false, Seiten::Page.find(4).external?
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_returns_parent_page
|
32
|
-
page = Seiten::Page.find(3)
|
33
|
-
assert_equal Seiten::Page.find(2).title, page.parent.title
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_returns_true_if_page_has_a_parent
|
37
|
-
page = Seiten::Page.find(3)
|
38
|
-
assert_equal true, page.parent?
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_returns_false_if_page_has_no_parent
|
42
|
-
page = Seiten::Page.find(1)
|
43
|
-
assert_equal false, page.parent?
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_returns_branch_root_page
|
47
|
-
page = Seiten::Page.find(13)
|
48
|
-
assert_equal Seiten::Page.find(6), page.branch_root
|
49
|
-
page = Seiten::Page.find(3)
|
50
|
-
assert_equal Seiten::Page.find(2), page.branch_root
|
51
|
-
page = Seiten::Page.find(1)
|
52
|
-
assert_equal Seiten::Page.find(1), page.branch_root
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_returns_children_pages
|
56
|
-
page = Seiten::Page.find(2)
|
57
|
-
assert_equal ["Logo Design", "Web Development", "Hire us"], page.children.map(&:title)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_returns_true_if_page_is_child_of_parent
|
61
|
-
child = Seiten::Page.find(3)
|
62
|
-
assert_equal true, Seiten::Page.find(2).parent_of?(child)
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_returns_true_if_page_child_is_deeply_nested
|
66
|
-
child = Seiten::Page.find_by_slug("about/our-team")
|
67
|
-
assert_equal true, Seiten::Page.find_by_slug("about").parent_of?(child)
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_returns_false_if_page_is_not_child_of_parent
|
71
|
-
wrong_child = Seiten::Page.find(1)
|
72
|
-
assert_equal false, Seiten::Page.find(2).parent_of?(wrong_child)
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_returns_true_for_active_page
|
76
|
-
active_page = Seiten::Page.find(1)
|
77
|
-
assert_equal true, active_page.active?(active_page)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_returns_true_for_parent_of_active_page
|
81
|
-
active_page = Seiten::Page.find(3)
|
82
|
-
assert_equal true, Seiten::Page.find(2).active?(active_page)
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_returns_false_for_not_active_page
|
86
|
-
active_page = Seiten::Page.find(1)
|
87
|
-
assert_equal false, active_page.active?(Seiten::Page.find(2))
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_finds_page_by_slug
|
91
|
-
page = Seiten::Page.find_by_slug("products/logo-design")
|
92
|
-
assert_equal "Logo Design", page.title
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_returns_nil_for_active_method_when_current_page_is_nil
|
96
|
-
assert_equal nil, Seiten::Page.find(1).active?(nil)
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_returns_metadata
|
100
|
-
page = Seiten::Page.find_by_slug("products/logo-design")
|
101
|
-
assert_equal({ header_image: "logo.jpg", description: "Our logo design is awesome." }, page.metadata)
|
102
|
-
assert_equal "logo.jpg", page.metadata[:header_image]
|
103
|
-
end
|
104
|
-
end
|
data/test/seiten_test.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class SeitenTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
def test_returns_page_storage_path
|
6
|
-
Seiten::PageStore.set_current_page_store(storage_language: :en)
|
7
|
-
assert_equal File.join(Rails.root, "app/pages/en/home.html.erb"), Seiten::PageStore.current.file_path(filename: "home.html.erb")
|
8
|
-
Seiten::PageStore.set_current_page_store(storage_language: :de)
|
9
|
-
assert_equal File.join(Rails.root, "app/pages/de/kontakt.html.erb"), Seiten::PageStore.current.file_path(filename: "kontakt.html.erb")
|
10
|
-
end
|
11
|
-
end
|