seiten 1.1.0 → 1.2.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.
@@ -2,12 +2,13 @@ require 'test_helper'
2
2
 
3
3
  class Seiten::HTML::HelpersTest < ActiveSupport::TestCase
4
4
 
5
+ # Its own navigation: pages added to a shared one would show up in other tests.
5
6
  def navigation
6
- @navigation ||= Seiten::Navigation.find_by(id: 'application.en')
7
+ @navigation ||= Seiten::Navigation.new(name: :helpers_test, locale: :en).tap { |navigation| Seiten.navigations << navigation }
7
8
  end
8
9
 
9
- def current_page
10
- @current_page ||= navigation.pages.find(1)
10
+ teardown do
11
+ Seiten.navigations -= [@navigation] if @navigation
11
12
  end
12
13
 
13
14
  def helpers
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ class Seiten::I18nNavigationTest < ActiveSupport::TestCase
4
+ def navigation(locale)
5
+ Seiten::Navigation.find_by(name: 'guide', locale: locale)
6
+ end
7
+
8
+ def page(locale, key)
9
+ navigation(locale).pages.find_by(key: key)
10
+ end
11
+
12
+ test 'one structure file gives a navigation in every available locale' do
13
+ assert_equal ['de', 'en'], Seiten::Navigation.where(name: 'guide').map(&:locale).sort
14
+ end
15
+
16
+ test 'titles and slugs come from I18n, nested like the pages' do
17
+ assert_equal 'Account verwalten', page('de', 'account.manage').title
18
+ assert_equal 'dein-account/account-verwalten', page('de', 'account.manage').slug
19
+ assert_equal 'your-account/account-security', page('en', 'account.security').slug, 'a translated slug replaces the title'
20
+ assert_equal '', page('en', 'start').slug, 'url in the structure applies to every locale'
21
+ assert_equal page('en', 'account'), page('en', 'account.manage').parent
22
+ end
23
+
24
+ test 'pages with the same key translate each other' do
25
+ assert_equal page('en', 'account.manage'), page('de', 'account.manage').translation(:en)
26
+ assert_equal({ 'de' => page('de', 'billing'), 'en' => page('en', 'billing') }, page('en', 'billing').translations)
27
+ end
28
+
29
+ test 'navigations are built again with reloaded translations' do
30
+ I18n.backend.store_translations(:en, navigations: { guide: { billing: { title: 'Invoices' } } })
31
+ Seiten.reset_i18n_navigations!
32
+
33
+ assert_equal 'invoices', page('en', 'billing').slug
34
+ ensure
35
+ I18n.backend.store_translations(:en, navigations: { guide: { billing: { title: 'Billing' } } })
36
+ Seiten.reset_i18n_navigations!
37
+ end
38
+
39
+ test 'a page needs a key and a title or slug' do
40
+ assert_raises(Seiten::Errors::PageError) { Seiten.send(:i18n_pages, [{ 'title' => 'Untitled' }], :en, ['navigations', 'guide']) }
41
+ assert_raises(Seiten::Errors::PageError) { Seiten.send(:i18n_pages, [{ 'key' => 'missing' }], :en, ['navigations', 'guide']) }
42
+ end
43
+
44
+ test 'navigations of one locale per file keep working' do
45
+ assert_equal 'Produkte', Seiten::Navigation.find_by(name: 'application', locale: 'de').pages.find_by(slug: 'produkte').title
46
+ end
47
+ end
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.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Puglisi
@@ -149,8 +149,11 @@ files:
149
149
  - test/dummy/config/initializers/session_store.rb
150
150
  - test/dummy/config/initializers/wrap_parameters.rb
151
151
  - test/dummy/config/locales/en.yml
152
+ - test/dummy/config/locales/guide.de.yml
153
+ - test/dummy/config/locales/guide.en.yml
152
154
  - test/dummy/config/navigations/application.de.yml
153
155
  - test/dummy/config/navigations/application.en.yml
156
+ - test/dummy/config/navigations/guide.yml
154
157
  - test/dummy/config/navigations/help.en.yml
155
158
  - test/dummy/config/routes.rb
156
159
  - test/dummy/config/secrets.yml
@@ -169,6 +172,7 @@ files:
169
172
  - test/lib/seiten/html/breadcrumb_test.rb
170
173
  - test/lib/seiten/html/helpers_test.rb
171
174
  - test/lib/seiten/html/navigation_test.rb
175
+ - test/lib/seiten/i18n_navigation_test.rb
172
176
  - test/lib/seiten/navigation_test.rb
173
177
  - test/lib/seiten/page_collection_builder_test.rb
174
178
  - test/lib/seiten/page_collection_test.rb
@@ -251,8 +255,11 @@ test_files:
251
255
  - test/dummy/config/initializers/session_store.rb
252
256
  - test/dummy/config/initializers/wrap_parameters.rb
253
257
  - test/dummy/config/locales/en.yml
258
+ - test/dummy/config/locales/guide.de.yml
259
+ - test/dummy/config/locales/guide.en.yml
254
260
  - test/dummy/config/navigations/application.de.yml
255
261
  - test/dummy/config/navigations/application.en.yml
262
+ - test/dummy/config/navigations/guide.yml
256
263
  - test/dummy/config/navigations/help.en.yml
257
264
  - test/dummy/config/routes.rb
258
265
  - test/dummy/config/secrets.yml
@@ -271,6 +278,7 @@ test_files:
271
278
  - test/lib/seiten/html/breadcrumb_test.rb
272
279
  - test/lib/seiten/html/helpers_test.rb
273
280
  - test/lib/seiten/html/navigation_test.rb
281
+ - test/lib/seiten/i18n_navigation_test.rb
274
282
  - test/lib/seiten/navigation_test.rb
275
283
  - test/lib/seiten/page_collection_builder_test.rb
276
284
  - test/lib/seiten/page_collection_test.rb