seiten 1.2.0 → 1.3.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 +4 -4
- data/lib/seiten/navigation.rb +10 -0
- data/lib/seiten/routes_helper.rb +79 -4
- data/lib/seiten/version.rb +1 -1
- data/lib/seiten.rb +5 -0
- data/test/dummy/app/controllers/guide/pages_controller.rb +5 -0
- data/test/dummy/config/locales/guide.de.yml +1 -0
- data/test/dummy/config/locales/guide.en.yml +1 -0
- data/test/dummy/config/routes.rb +2 -0
- data/test/dummy/log/development.log +0 -0
- data/test/dummy/log/test.log +8048 -0
- data/test/integration/localized_routes_test.rb +71 -0
- data/test/lib/seiten/i18n_navigation_test.rb +10 -0
- metadata +7 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class Seiten::LocalizedRoutesTest < ActionDispatch::IntegrationTest
|
|
4
|
+
def route_set(&)
|
|
5
|
+
ActionDispatch::Routing::RouteSet.new.tap do |routes|
|
|
6
|
+
routes.default_url_options[:host] = 'example.com'
|
|
7
|
+
routes.draw(&)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def draw(&)
|
|
12
|
+
route_set(&).routes.map { |route| [route.name, route.path.spec.to_s, route.defaults.except(:action, :slug)] }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
test 'routes a navigation of one file under each locale and its slug, to its pages controller' do
|
|
16
|
+
get '/de/anleitung/dein-account/account-verwalten'
|
|
17
|
+
assert_equal 'guide.de account.manage', response.body
|
|
18
|
+
|
|
19
|
+
get '/en/guide'
|
|
20
|
+
assert_equal 'guide.en start', response.body
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test 'names the routes after the navigation and the locale' do
|
|
24
|
+
assert_equal '/de/anleitung/rechnungen', guide_page_de_path(slug: 'rechnungen')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test 'to, as and path replace the defaults' do
|
|
28
|
+
assert_equal [['docs_de', '/de/doku(/*slug)', { controller: 'docs', navigation_id: 'guide', locale: 'de' }],
|
|
29
|
+
['docs_en', '/en/doku(/*slug)', { controller: 'docs', navigation_id: 'guide', locale: 'en' }]],
|
|
30
|
+
draw { seiten :guide, to: 'docs#show', as: :docs, path: 'doku' }.sort
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
test 'localized: false draws one catch-all route' do
|
|
34
|
+
assert_equal [['seiten_guide_page', '/(*slug)(.:format)', { controller: 'seiten/pages', navigation_id: 'guide' }]],
|
|
35
|
+
draw { seiten :guide, localized: false }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
test 'navigations of one file per locale get one catch-all route unless localized' do
|
|
39
|
+
assert_equal 1, draw { seiten :application }.size
|
|
40
|
+
assert_equal ['/de(/*slug)', '/en(/*slug)'], draw { seiten :application, localized: true }.map(&:second).sort
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
test 'links a page by its key in the current or the given locale' do
|
|
44
|
+
I18n.with_locale(:de) { assert_equal '/de/anleitung/dein-account/account-verwalten', guide_page_path('account.manage') }
|
|
45
|
+
assert_equal '/en/guide/your-account/account-security', guide_page_path('account.security', locale: :en)
|
|
46
|
+
assert_equal 'http://example.com/de/anleitung/rechnungen?page=2#top', guide_page_url('billing', locale: 'de', host: 'example.com', page: 2, anchor: 'top')
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
test 'links the navigation root without a key' do
|
|
50
|
+
assert_equal '/en/guide', guide_page_path
|
|
51
|
+
assert_equal '/de/anleitung', guide_page_path(locale: :de)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
test 'page helpers are named after the navigation and the key' do
|
|
55
|
+
assert_equal '/en/guide/your-account/manage-your-account', guide_account_manage_path
|
|
56
|
+
assert_equal 'http://example.com/de/anleitung/rechnungen#top', guide_billing_url(locale: :de, host: 'example.com', anchor: 'top')
|
|
57
|
+
assert_equal '/en/guide', guide_start_path
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
test 'prefix: false names the page helpers after the key only' do
|
|
61
|
+
helpers = route_set { seiten :guide, prefix: false }.url_helpers
|
|
62
|
+
|
|
63
|
+
assert_equal '/en/guide/your-account/manage-your-account', helpers.account_manage_path
|
|
64
|
+
assert_respond_to helpers, :guide_page_path
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
test 'raises for an unknown page or locale' do
|
|
68
|
+
assert_raises(ArgumentError) { guide_page_path('account.missing') }
|
|
69
|
+
assert_raises(ArgumentError) { guide_page_path('billing', locale: :fr) }
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -36,6 +36,16 @@ class Seiten::I18nNavigationTest < ActiveSupport::TestCase
|
|
|
36
36
|
Seiten.reset_i18n_navigations!
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
test 'the navigation has a title and a slug from I18n, like its pages' do
|
|
40
|
+
assert_equal 'Anleitung', navigation('de').title
|
|
41
|
+
assert_equal 'anleitung', navigation('de').slug
|
|
42
|
+
|
|
43
|
+
I18n.backend.store_translations(:en, navigations: { guide: { slug: 'docs' } })
|
|
44
|
+
assert_equal 'docs', navigation('en').slug
|
|
45
|
+
ensure
|
|
46
|
+
I18n.backend.store_translations(:en, navigations: { guide: { slug: nil } })
|
|
47
|
+
end
|
|
48
|
+
|
|
39
49
|
test 'a page needs a key and a title or slug' do
|
|
40
50
|
assert_raises(Seiten::Errors::PageError) { Seiten.send(:i18n_pages, [{ 'title' => 'Untitled' }], :en, ['navigations', 'guide']) }
|
|
41
51
|
assert_raises(Seiten::Errors::PageError) { Seiten.send(:i18n_pages, [{ 'key' => 'missing' }], :en, ['navigations', 'guide']) }
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: seiten
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Puglisi
|
|
@@ -104,6 +104,7 @@ files:
|
|
|
104
104
|
- test/dummy/README.rdoc
|
|
105
105
|
- test/dummy/Rakefile
|
|
106
106
|
- test/dummy/app/controllers/application_controller.rb
|
|
107
|
+
- test/dummy/app/controllers/guide/pages_controller.rb
|
|
107
108
|
- test/dummy/app/controllers/pages_controller.rb
|
|
108
109
|
- test/dummy/app/controllers/posts_controller.rb
|
|
109
110
|
- test/dummy/app/helpers/application_helper.rb
|
|
@@ -157,6 +158,7 @@ files:
|
|
|
157
158
|
- test/dummy/config/navigations/help.en.yml
|
|
158
159
|
- test/dummy/config/routes.rb
|
|
159
160
|
- test/dummy/config/secrets.yml
|
|
161
|
+
- test/dummy/log/development.log
|
|
160
162
|
- test/dummy/log/test.log
|
|
161
163
|
- test/dummy/public/404.html
|
|
162
164
|
- test/dummy/public/422.html
|
|
@@ -167,6 +169,7 @@ files:
|
|
|
167
169
|
- test/fixtures/breadcrumb.html
|
|
168
170
|
- test/fixtures/navigation.html
|
|
169
171
|
- test/integration/layout_test.rb
|
|
172
|
+
- test/integration/localized_routes_test.rb
|
|
170
173
|
- test/integration/navigation_test.rb
|
|
171
174
|
- test/lib/seiten/helpers/frontend_test.rb
|
|
172
175
|
- test/lib/seiten/html/breadcrumb_test.rb
|
|
@@ -210,6 +213,7 @@ test_files:
|
|
|
210
213
|
- test/dummy/README.rdoc
|
|
211
214
|
- test/dummy/Rakefile
|
|
212
215
|
- test/dummy/app/controllers/application_controller.rb
|
|
216
|
+
- test/dummy/app/controllers/guide/pages_controller.rb
|
|
213
217
|
- test/dummy/app/controllers/pages_controller.rb
|
|
214
218
|
- test/dummy/app/controllers/posts_controller.rb
|
|
215
219
|
- test/dummy/app/helpers/application_helper.rb
|
|
@@ -263,6 +267,7 @@ test_files:
|
|
|
263
267
|
- test/dummy/config/navigations/help.en.yml
|
|
264
268
|
- test/dummy/config/routes.rb
|
|
265
269
|
- test/dummy/config/secrets.yml
|
|
270
|
+
- test/dummy/log/development.log
|
|
266
271
|
- test/dummy/log/test.log
|
|
267
272
|
- test/dummy/public/404.html
|
|
268
273
|
- test/dummy/public/422.html
|
|
@@ -273,6 +278,7 @@ test_files:
|
|
|
273
278
|
- test/fixtures/breadcrumb.html
|
|
274
279
|
- test/fixtures/navigation.html
|
|
275
280
|
- test/integration/layout_test.rb
|
|
281
|
+
- test/integration/localized_routes_test.rb
|
|
276
282
|
- test/integration/navigation_test.rb
|
|
277
283
|
- test/lib/seiten/helpers/frontend_test.rb
|
|
278
284
|
- test/lib/seiten/html/breadcrumb_test.rb
|