kuhsaft 2.2.6 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -0
  3. data/Rakefile +6 -5
  4. data/app/assets/javascripts/ckeditor/plugins/adv_link/LICENSE.txt +674 -0
  5. data/app/assets/javascripts/ckeditor/plugins/adv_link/README.md +62 -0
  6. data/app/assets/javascripts/ckeditor/plugins/adv_link/dialogs/anchor.js.coffee +81 -0
  7. data/app/assets/javascripts/ckeditor/plugins/adv_link/dialogs/link.js.coffee +1353 -0
  8. data/app/assets/javascripts/ckeditor/plugins/adv_link/images/anchor.png +0 -0
  9. data/app/assets/javascripts/ckeditor/plugins/adv_link/images/hidpi/anchor.png +0 -0
  10. data/app/assets/javascripts/ckeditor/plugins/adv_link/lang/de.js +68 -0
  11. data/app/assets/javascripts/ckeditor/plugins/adv_link/lang/en.js +68 -0
  12. data/app/assets/javascripts/ckeditor/plugins/adv_link/plugin.js.coffee +282 -0
  13. data/app/assets/javascripts/kuhsaft/cms/application.js.coffee.erb +42 -4
  14. data/app/assets/stylesheets/kuhsaft/application.css.sass +0 -3
  15. data/app/assets/stylesheets/kuhsaft/cms/application.css.sass +26 -11
  16. data/app/controllers/kuhsaft/api/pages_controller.rb +14 -0
  17. data/app/controllers/kuhsaft/cms/admin_controller.rb +1 -1
  18. data/app/controllers/kuhsaft/cms/assets_controller.rb +7 -7
  19. data/app/controllers/kuhsaft/cms/bricks_controller.rb +15 -4
  20. data/app/controllers/kuhsaft/cms/pages_controller.rb +8 -15
  21. data/app/controllers/kuhsaft/pages_controller.rb +16 -6
  22. data/app/controllers/kuhsaft/sitemaps_controller.rb +13 -0
  23. data/app/helpers/cms_helper.rb +4 -4
  24. data/app/helpers/kuhsaft/admin_helper.rb +0 -1
  25. data/app/helpers/kuhsaft/cms/admin_helper.rb +1 -2
  26. data/app/helpers/kuhsaft/cms/pages_helper.rb +2 -7
  27. data/app/helpers/pages_helper.rb +8 -37
  28. data/app/helpers/sitemaps_helper.rb +12 -0
  29. data/app/models/kuhsaft/accordion_item_brick.rb +1 -1
  30. data/app/models/kuhsaft/anchor_brick.rb +1 -1
  31. data/app/models/kuhsaft/asset.rb +26 -23
  32. data/app/models/kuhsaft/asset_brick.rb +2 -1
  33. data/app/models/kuhsaft/brick.rb +38 -16
  34. data/app/models/kuhsaft/brick_type.rb +2 -2
  35. data/app/models/kuhsaft/brick_type_filter.rb +0 -2
  36. data/app/models/kuhsaft/column_brick.rb +0 -1
  37. data/app/models/kuhsaft/image_brick.rb +2 -2
  38. data/app/models/kuhsaft/image_size.rb +0 -1
  39. data/app/models/kuhsaft/link_brick.rb +1 -1
  40. data/app/models/kuhsaft/page.rb +111 -107
  41. data/app/models/kuhsaft/page_type.rb +1 -1
  42. data/app/models/kuhsaft/partition.rb +12 -12
  43. data/app/models/kuhsaft/placeholder_brick.rb +8 -0
  44. data/app/models/kuhsaft/publish_state.rb +9 -10
  45. data/app/models/kuhsaft/slider_brick.rb +0 -2
  46. data/app/models/kuhsaft/text_brick.rb +1 -1
  47. data/app/models/kuhsaft/two_column_brick.rb +0 -1
  48. data/app/models/kuhsaft/video_brick.rb +1 -2
  49. data/app/uploaders/kuhsaft/asset_brick_asset_uploader.rb +39 -38
  50. data/app/uploaders/kuhsaft/asset_uploader.rb +43 -43
  51. data/app/uploaders/kuhsaft/image_brick_image_uploader.rb +7 -34
  52. data/app/views/kuhsaft/asset_bricks/asset_brick/_edit.html.haml +3 -2
  53. data/app/views/kuhsaft/cms/admin/_brick_type_dropdown.html.haml +2 -2
  54. data/app/views/kuhsaft/cms/bricks/_brick_item.html.haml +17 -10
  55. data/app/views/kuhsaft/cms/bricks/_new.html.haml +34 -0
  56. data/app/views/kuhsaft/cms/bricks/create.js.haml +6 -0
  57. data/app/views/kuhsaft/cms/bricks/destroy.js.haml +4 -0
  58. data/app/views/kuhsaft/cms/bricks/new.js.haml +11 -0
  59. data/app/views/kuhsaft/cms/pages/_branch.html.haml +2 -2
  60. data/app/views/kuhsaft/cms/pages/_form.html.haml +29 -18
  61. data/app/views/kuhsaft/image_bricks/_image_brick.html.haml +9 -7
  62. data/app/views/kuhsaft/image_bricks/image_brick/_edit.html.haml +3 -0
  63. data/app/views/kuhsaft/pages/show.html.haml +1 -9
  64. data/app/views/kuhsaft/placeholder_bricks/_placeholder_brick.html.haml +1 -1
  65. data/app/views/kuhsaft/sitemaps/index.xml.haml +9 -0
  66. data/app/views/kuhsaft/video_bricks/_video_brick.html.haml +4 -4
  67. data/app/views/layouts/kuhsaft/cms/application.html.haml +4 -3
  68. data/config/initializers/simple_form.rb +4 -4
  69. data/config/initializers/simple_form_bootstrap.rb +14 -14
  70. data/config/locales/de.yml +203 -0
  71. data/config/locales/en.yml +282 -0
  72. data/config/locales/kuhsaft.de.yml +14 -0
  73. data/config/locales/kuhsaft.en.yml +60 -0
  74. data/config/locales/models/kuhsaft/image_brick/de.yml +1 -0
  75. data/config/locales/models/kuhsaft/image_brick/en.yml +16 -0
  76. data/config/locales/models/kuhsaft/text_brick/de.yml +3 -0
  77. data/config/locales/models/kuhsaft/text_brick/en.yml +16 -0
  78. data/config/locales/models/kuhsaft/video_brick/en.yml +15 -0
  79. data/config/locales/views/kuhsaft/cms/pages/de.yml +3 -0
  80. data/config/locales/views/kuhsaft/cms/video_bricks/de.yml +1 -1
  81. data/config/routes.rb +18 -9
  82. data/db/migrate/10_add_redirect_url_to_kuhsaft_pages.rb +1 -1
  83. data/db/migrate/11_update_url_and_redirect_url_value.rb +4 -4
  84. data/db/migrate/13_add_page_title_to_pages.rb +1 -1
  85. data/db/migrate/15_add_alt_text_to_bricks.rb +5 -0
  86. data/db/migrate/16_update_default_value_for_page_type.rb +9 -0
  87. data/db/migrate/17_set_page_type_to_content_for_empty_fields.rb +7 -0
  88. data/lib/generators/kuhsaft/assets/install_generator.rb +1 -2
  89. data/lib/generators/kuhsaft/translations/add_generator.rb +19 -4
  90. data/lib/kuhsaft.rb +1 -0
  91. data/lib/kuhsaft/brick_list.rb +6 -8
  92. data/lib/kuhsaft/engine.rb +5 -1
  93. data/lib/kuhsaft/orderable.rb +22 -19
  94. data/lib/kuhsaft/partial_extractor.rb +1 -1
  95. data/lib/kuhsaft/searchable.rb +8 -11
  96. data/lib/kuhsaft/translatable.rb +35 -19
  97. data/lib/kuhsaft/version.rb +1 -1
  98. data/lib/tasks/kuhsaft_tasks.rake +12 -0
  99. data/lib/templates/kuhsaft/assets/ck-config.js.coffee +7 -0
  100. data/lib/templates/kuhsaft/translations/add_translation.html.erb +4 -10
  101. data/spec/controllers/kuhsaft/api/pages_controller_spec.rb +70 -0
  102. data/spec/controllers/kuhsaft/pages_controller_spec.rb +18 -14
  103. data/spec/controllers/kuhsaft/sitemaps_controller_spec.rb +13 -0
  104. data/spec/dummy/app/assets/javascripts/kuhsaft/cms/ck-config.js.coffee +7 -0
  105. data/spec/dummy/config/application.rb +2 -1
  106. data/spec/dummy/config/database.yml +1 -1
  107. data/spec/factories.rb +3 -3
  108. data/spec/features/cms_pages_spec.rb +13 -13
  109. data/spec/features/search_spec.rb +16 -18
  110. data/spec/helpers/kuhsaft/cms/pages_helper_spec.rb +2 -1
  111. data/spec/kuhsaft_spec.rb +1 -1
  112. data/spec/lib/brick_list_spec.rb +1 -1
  113. data/spec/lib/page_tree_spec.rb +10 -6
  114. data/spec/lib/searchable_spec.rb +4 -4
  115. data/spec/lib/translatable_spec.rb +114 -44
  116. data/spec/models/anchor_brick_spec.rb +1 -1
  117. data/spec/models/asset_spec.rb +1 -1
  118. data/spec/models/brick_spec.rb +1 -1
  119. data/spec/models/page_spec.rb +48 -37
  120. data/spec/models/publish_state_spec.rb +9 -9
  121. data/spec/spec_helper.rb +43 -21
  122. data/spec/support/kuhsaft_spec_helper.rb +2 -2
  123. data/spec/support/write_expectation.rb +57 -0
  124. data/spec/views/kuhsaft/sitemaps/index.xml.haml_spec.rb +67 -0
  125. metadata +119 -4
@@ -33,7 +33,8 @@ describe Kuhsaft::Cms::PagesHelper do
33
33
  end
34
34
 
35
35
  it 'has a redirect page' do
36
- @page = create(:page, title: 'Page 1', slug: 'page1', page_type: Kuhsaft::PageType::REDIRECT, redirect_url: 'en/references')
36
+ @page = create(:page, title: 'Page 1', slug: 'page1',
37
+ page_type: Kuhsaft::PageType::REDIRECT, redirect_url: 'en/references')
37
38
  expect(helper.hide_content_tab?(@page)).to be_true
38
39
  end
39
40
 
data/spec/kuhsaft_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Kuhsaft do
4
- it "should be valid" do
4
+ it 'should be valid' do
5
5
  Kuhsaft.should be_a(Module)
6
6
  end
7
7
  end
@@ -13,7 +13,7 @@ describe Kuhsaft::BrickList do
13
13
  describe '#collect_fulltext' do
14
14
  context 'with bricks' do
15
15
  it 'collects its childs fulltext' do
16
- brick.stub_chain(:bricks, :localized).and_return([mock_model(Kuhsaft::Brick, :collect_fulltext => 'hallo')])
16
+ brick.stub_chain(:bricks, :localized).and_return([mock_model(Kuhsaft::Brick, collect_fulltext: 'hallo')])
17
17
  brick.collect_fulltext.should == 'hallo'
18
18
  end
19
19
  end
@@ -6,8 +6,12 @@ require_relative '../../app/models/kuhsaft/page'
6
6
 
7
7
  module Kuhsaft
8
8
  describe PageTree do
9
- let(:page_tree) { {"0"=>{"id"=>"1", "children"=>{"0"=>{"id"=>"2"}}},
10
- "1"=>{"id"=>"3"}}}
9
+ let(:page_tree) do
10
+ {
11
+ '0' => { 'id' => '1', 'children' => { '0' => { 'id' => '2' } } },
12
+ '1' => { 'id' => '3' }
13
+ }
14
+ end
11
15
 
12
16
  before :each do
13
17
  @page1 = FactoryGirl.create(:page, id: 1, position: 10)
@@ -18,15 +22,15 @@ module Kuhsaft
18
22
  describe 'update' do
19
23
  it 'sets the correct position of the root nodes' do
20
24
  PageTree.update(page_tree)
21
- @page1.reload.position.should == 0
22
- @page2.reload.position.should == 0
23
- @page3.reload.position.should == 1
25
+ expect(@page1.reload.position).to eq(0)
26
+ expect(@page2.reload.position).to eq(0)
27
+ expect(@page3.reload.position).to eq(1)
24
28
  end
25
29
 
26
30
  it 'sets the correct parent attribute for the nodes' do
27
31
  PageTree.update(page_tree)
28
32
  @page1.reload.parent_id.should be_nil
29
- @page2.reload.parent_id.should == 1
33
+ expect(@page2.reload.parent_id).to eq(1)
30
34
  @page3.reload.parent_id.should be nil
31
35
  end
32
36
  end
@@ -4,11 +4,11 @@ describe Kuhsaft::Searchable do
4
4
 
5
5
  context 'with missing includes' do
6
6
  it 'raises exteption when class does not include Kuhsaft::Bricklist' do
7
- expect {
7
+ expect do
8
8
  class Foo
9
9
  include Kuhsaft::Searchable
10
10
  end
11
- }.to raise_error(/needs Kuhsaft::BrickList to be included/)
11
+ end.to raise_error(/needs Kuhsaft::BrickList to be included/)
12
12
  end
13
13
  end
14
14
 
@@ -19,12 +19,12 @@ describe Kuhsaft::Searchable do
19
19
 
20
20
  context 'without postgresql' do
21
21
  it 'initializes scope' do
22
- ActiveRecord::Base.connection.instance_values.should_not == 'postgresql'
22
+ expect(ActiveRecord::Base.connection.instance_values).not_to eq('postgresql')
23
23
  SearchableDemo.should_receive :scope
24
24
  SearchableDemo.class_eval do
25
25
  include Kuhsaft::Searchable
26
26
  end
27
27
  end
28
28
  end
29
- end
29
+ end
30
30
  end
@@ -11,74 +11,144 @@ describe Kuhsaft::Translatable do
11
11
  Demo.new
12
12
  end
13
13
 
14
- before do
15
- I18n.available_locales = [:en, :de]
16
- I18n.locale = :en
17
- end
14
+ describe 'normal locale' do
15
+ before do
16
+ I18n.locale = :en
17
+ end
18
18
 
19
- after do
20
- I18n.available_locales = [:en]
21
- I18n.locale = :en
22
- end
19
+ describe '.translate' do
20
+ it 'defines a getter for each attribute' do
21
+ expect(model).to respond_to(:name)
22
+ end
23
23
 
24
- describe '.translate' do
25
- it 'defines a getter for each attribute' do
26
- model.should respond_to(:name)
24
+ it 'defines a setter for each attributes' do
25
+ expect(model).to respond_to(:name=)
26
+ end
27
27
  end
28
28
 
29
- it 'defines a setter for each attributes' do
30
- model.should respond_to(:name=)
29
+ describe '.locale_attr' do
30
+ it 'returns a suffixed attribute name' do
31
+ expect(Demo.locale_attr('text')).to eq('text_en')
32
+ end
31
33
  end
32
- end
33
34
 
34
- describe '.locale_attr' do
35
- it 'returns a suffixed attribute name' do
36
- Demo.locale_attr('text').should == 'text_en'
35
+ describe '#locale_attr' do
36
+ it 'returns a suffixed attribute name' do
37
+ expect(model.locale_attr('text')).to eq('text_en')
38
+ end
37
39
  end
38
- end
39
40
 
40
- describe '#locale_attr' do
41
- it 'returns a suffixed attribute name' do
42
- model.locale_attr('text').should == 'text_en'
41
+ describe 'translated attributes' do
42
+ it 'delegates the getter to the suffixed attribute' do
43
+ model.should_receive(:name_en).and_return('John')
44
+ model.name.should == 'John'
45
+ end
46
+
47
+ it 'delegates the setter to the suffixed attribute' do
48
+ model.should_receive(:name_en=).with('Johnny')
49
+ model.name = 'Johnny'
50
+ end
51
+
52
+ context 'dynamic methods' do
53
+ it 'delegates boolean accessors' do
54
+ model.should_receive(:name_en?)
55
+ model.name?
56
+ end
57
+
58
+ it 'delegates simple dynamic finders' do
59
+ Demo.should_receive(:find_by_name_en).with('Max')
60
+ Demo.find_by_name('Max')
61
+ end
62
+ end
63
+
64
+ context 'when changing the locale' do
65
+ before do
66
+ I18n.locale = :de
67
+ end
68
+
69
+ it 'delegates the getter to current locale' do
70
+ model.should_receive(:name_de).and_return('Johannes')
71
+ model.name.should == 'Johannes'
72
+ end
73
+
74
+ it 'delegates the getter to current locale' do
75
+ model.should_receive(:name_de=).with('Johannes')
76
+ model.name = 'Johannes'
77
+ end
78
+ end
43
79
  end
44
80
  end
45
81
 
46
- describe 'translated attributes' do
47
- it 'delegates the getter to the suffixed attribute' do
48
- model.should_receive(:name_en).and_return('John')
49
- model.name.should == 'John'
82
+ describe 'country specific locale' do
83
+ before do
84
+ I18n.available_locales = [:de, 'de-CH']
85
+ I18n.locale = 'de-CH'
50
86
  end
51
87
 
52
- it 'delegates the setter to the suffixed attribute' do
53
- model.should_receive(:name_en=).with('Johnny')
54
- model.name = 'Johnny'
88
+ after do
89
+ I18n.available_locales = [:en]
90
+ I18n.locale = :en
55
91
  end
56
92
 
57
- context 'dynamic methods' do
58
- it 'delegates boolean accessors' do
59
- model.should_receive(:name_en?)
60
- model.name?
93
+ describe '.translate' do
94
+ it 'defines a getter for each attribute' do
95
+ expect(model).to respond_to(:name)
61
96
  end
62
97
 
63
- it 'delegates simple dynamic finders' do
64
- Demo.should_receive(:find_by_name_en).with('Max')
65
- Demo.find_by_name('Max')
98
+ it 'defines a setter for each attributes' do
99
+ expect(model).to respond_to(:name=)
66
100
  end
67
101
  end
68
102
 
69
- context 'when changing the locale' do
70
- before do
71
- I18n.locale = :de
103
+ describe '.locale_attr' do
104
+ it 'returns a suffixed attribute name' do
105
+ expect(Demo.locale_attr('text')).to eq('text_de_ch')
72
106
  end
107
+ end
108
+
109
+ describe '#locale_attr' do
110
+ it 'returns a suffixed attribute name' do
111
+ expect(Demo.locale_attr('text')).to eq('text_de_ch')
112
+ end
113
+ end
73
114
 
74
- it 'delegates the getter to current locale' do
75
- model.should_receive(:name_de).and_return('Johannes')
76
- model.name.should == 'Johannes'
115
+ describe 'translated attributes' do
116
+ it 'delegates the getter to the suffixed attribute' do
117
+ model.should_receive(:name_de_ch).and_return('John')
118
+ model.name.should == 'John'
77
119
  end
78
120
 
79
- it 'delegates the getter to current locale' do
80
- model.should_receive(:name_de=).with('Johannes')
81
- model.name = 'Johannes'
121
+ it 'delegates the setter to the suffixed attribute' do
122
+ model.should_receive(:name_de_ch=).with('Johnny')
123
+ model.name = 'Johnny'
124
+ end
125
+
126
+ context 'dynamic methods' do
127
+ it 'delegates boolean accessors' do
128
+ model.should_receive(:name_de_ch?)
129
+ model.name?
130
+ end
131
+
132
+ it 'delegates simple dynamic finders' do
133
+ Demo.should_receive(:find_by_name_de_ch).with('Max')
134
+ Demo.find_by_name('Max')
135
+ end
136
+ end
137
+
138
+ context 'when changing the locale' do
139
+ before do
140
+ I18n.locale = :de
141
+ end
142
+
143
+ it 'delegates the getter to current locale' do
144
+ model.should_receive(:name_de).and_return('Johannes')
145
+ model.name.should == 'Johannes'
146
+ end
147
+
148
+ it 'delegates the getter to current locale' do
149
+ model.should_receive(:name_de=).with('Johannes')
150
+ model.name = 'Johannes'
151
+ end
82
152
  end
83
153
  end
84
154
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Kuhsaft::AnchorBrick do
4
4
 
5
5
  let :anchor_brick do
6
- Kuhsaft::AnchorBrick.new(:caption => 'test-anchor')
6
+ Kuhsaft::AnchorBrick.new(caption: 'test-anchor')
7
7
  end
8
8
 
9
9
  describe '#bricks' do
@@ -24,7 +24,7 @@ describe Kuhsaft::Asset do
24
24
  uploader.should respond_to(:thumb)
25
25
  end
26
26
 
27
- it "makes the image readable only to the owner and not executable" do
27
+ it 'makes the image readable only to the owner and not executable' do
28
28
  pending 'how and where do we ensure permissions?'
29
29
  uploader.should have_permissions(0600)
30
30
  end
@@ -98,7 +98,7 @@ describe Kuhsaft::Brick do
98
98
 
99
99
  context 'with the parenthesis option given' do
100
100
  brick = Kuhsaft::TextBrick.new
101
- brick.backend_label(:parenthesis => true).should == '(Text)'
101
+ brick.backend_label(parenthesis: true).should == '(Text)'
102
102
  end
103
103
  end
104
104
 
@@ -5,9 +5,7 @@ describe Kuhsaft::Page do
5
5
 
6
6
  describe '.search' do
7
7
  before do
8
- create :page
9
- create :page
10
- create :page
8
+ 3.times { create :page }
11
9
  end
12
10
 
13
11
  it 'should find any containing the search term' do
@@ -70,33 +68,32 @@ describe Kuhsaft::Page do
70
68
 
71
69
  describe '#published' do
72
70
  it 'returns only published pages' do
73
- p1, p2, p3 = 3.times.map { create(:page) }
71
+ _p1, p2, _p3 = 3.times.map { create(:page) }
74
72
  p2.update_attribute :published, Kuhsaft::PublishState::UNPUBLISHED
75
73
  Kuhsaft::Page.published.should be_all { |p| p.published?.should be_true }
76
74
  end
77
75
  end
78
76
 
79
77
  describe '#content_page' do
80
- it 'returns only content pages ("" or nil)' do
78
+ it 'returns only content pages' do
81
79
  p1, p2, p3 = 3.times.map { create(:page) }
82
80
  p2.update_attribute :page_type, Kuhsaft::PageType::REDIRECT
83
- p3.update_attribute :page_type, nil
84
81
  Kuhsaft::Page.content_page.should == [p1, p3]
85
82
  end
86
83
  end
87
84
 
88
- describe "#state_class" do
85
+ describe '#state_class' do
89
86
 
90
87
  let(:page) { Kuhsaft::Page.new }
91
88
 
92
89
  it 'returns publsihed as string when page is published' do
93
- page.published == Kuhsaft::PublishState::PUBLISHED
94
- page.state_class == 'published'
90
+ page.published = Kuhsaft::PublishState::PUBLISHED
91
+ expect(page.state_class).to eq 'published'
95
92
  end
96
93
 
97
94
  it 'returns unpublsihed as string when page is unpublished' do
98
- page.published == Kuhsaft::PublishState::UNPUBLISHED
99
- page.state_class == 'unpublished'
95
+ page.published = Kuhsaft::PublishState::UNPUBLISHED
96
+ expect(page.state_class).to eq 'unpublished'
100
97
  end
101
98
  end
102
99
 
@@ -114,11 +111,11 @@ describe Kuhsaft::Page do
114
111
  end
115
112
 
116
113
  let :child_page do
117
- create(:page, :parent => page)
114
+ create(:page, parent: page)
118
115
  end
119
116
 
120
117
  let :child_child_page do
121
- create(:page, :parent => child_page)
118
+ create(:page, parent: child_page)
122
119
  end
123
120
 
124
121
  context 'on the topmost level' do
@@ -146,7 +143,7 @@ describe Kuhsaft::Page do
146
143
  end
147
144
 
148
145
  let :child_page do
149
- create(:page, :parent => page)
146
+ create(:page, parent: page)
150
147
  end
151
148
 
152
149
  it 'has a list of parent pages' do
@@ -162,7 +159,7 @@ describe Kuhsaft::Page do
162
159
  context 'when it has no content' do
163
160
  it 'should return the link of it\'s first child' do
164
161
  page = create(:page)
165
- child = create(:page, :parent => page)
162
+ child = create(:page, parent: page)
166
163
  page.body = nil
167
164
  page.save
168
165
  page.link.should == child.link
@@ -190,7 +187,7 @@ describe Kuhsaft::Page do
190
187
 
191
188
  describe '#preceding_sibling' do
192
189
  it 'finds the predecing sibling' do
193
- page1 = create :page
190
+ _page1 = create :page
194
191
  page2 = create :page
195
192
  page3 = create :page
196
193
  page3.preceding_sibling.id.should == page2.id
@@ -199,7 +196,7 @@ describe Kuhsaft::Page do
199
196
 
200
197
  describe '#succeeding_sibling' do
201
198
  it 'finds the succeeding sibling' do
202
- page1 = create :page
199
+ _page1 = create :page
203
200
  page2 = create :page
204
201
  page3 = create :page
205
202
  page2.succeeding_sibling.id.should == page3.id
@@ -209,14 +206,14 @@ describe Kuhsaft::Page do
209
206
  describe '#reposition' do
210
207
  it 'repositions before a page, specified by id' do
211
208
  page1 = create :page
212
- page2 = create :page
209
+ _page2 = create :page
213
210
  page3 = create :page
214
211
  page3.reposition page1.id
215
212
  page3.preceding_sibling.id.should == page1.id
216
213
  end
217
214
 
218
215
  it 'repositions before all siblings, specified by nil' do
219
- page1 = create :page
216
+ _page1 = create :page
220
217
  page2 = create :page
221
218
  page2.reposition nil
222
219
  page2.position.should == 1
@@ -252,30 +249,30 @@ describe Kuhsaft::Page do
252
249
  describe '#url' do
253
250
  context 'when it is a normal page' do
254
251
  it 'returns the concatenated slug of the whole child/parent tree' do
255
- page = create(:page, :slug => 'parent-slug', :page_type => '')
256
- child = create(:page, :slug => 'child-slug', :page_type => '', :parent => page)
252
+ page = create(:page, slug: 'parent-slug')
253
+ child = create(:page, slug: 'child-slug', parent: page)
257
254
  child.url.should == 'en/parent-slug/child-slug'
258
255
  end
259
256
  end
260
257
 
261
258
  context 'when it is a navigation? page' do
262
259
  it 'returns without the parent page slug' do
263
- page = create(:page, :slug => 'parent-slug', :page_type => Kuhsaft::PageType::NAVIGATION)
264
- child = create(:page, :slug => 'child-slug', :page_type => '', :parent => page)
260
+ page = create(:page, slug: 'parent-slug', page_type: Kuhsaft::PageType::NAVIGATION)
261
+ child = create(:page, slug: 'child-slug', parent: page)
265
262
  child.url.should == 'en/child-slug'
266
263
  end
267
264
  end
268
265
 
269
266
  context 'when it is a redirect? page' do
270
267
  it 'returns the absolute url' do
271
- page = create(:page, :page_type => Kuhsaft::PageType::REDIRECT, :redirect_url => 'en/references', :slug => 'news')
268
+ page = create(:page, page_type: Kuhsaft::PageType::REDIRECT, redirect_url: 'en/references', slug: 'news')
272
269
  page.link.should eq('/en/news')
273
270
  end
274
271
  end
275
272
 
276
273
  context 'when url part is empty' do
277
274
  it 'strips the trailing slash' do
278
- page = create(:page, :page_type => Kuhsaft::PageType::NAVIGATION)
275
+ page = create(:page, page_type: Kuhsaft::PageType::NAVIGATION)
279
276
  page.link.should eq('/en')
280
277
  end
281
278
  end
@@ -284,13 +281,13 @@ describe Kuhsaft::Page do
284
281
  describe '#navigation?' do
285
282
  context 'when the page_type is navigation' do
286
283
  it 'returns true if the page_type is PageType::NAVIGATION' do
287
- Kuhsaft::Page.new(:page_type => Kuhsaft::PageType::NAVIGATION).navigation?.should be_true
284
+ Kuhsaft::Page.new(page_type: Kuhsaft::PageType::NAVIGATION).navigation?.should be_true
288
285
  end
289
286
  end
290
287
 
291
288
  context 'when the page_type is anything else' do
292
289
  it 'returns false' do
293
- Kuhsaft::Page.new(:page_type => Kuhsaft::PageType::REDIRECT).navigation?.should be_false
290
+ Kuhsaft::Page.new(page_type: Kuhsaft::PageType::REDIRECT).navigation?.should be_false
294
291
  end
295
292
  end
296
293
  end
@@ -298,17 +295,31 @@ describe Kuhsaft::Page do
298
295
  describe '#redirect?' do
299
296
  context 'when the page_type is a redirect' do
300
297
  it 'returns true' do
301
- Kuhsaft::Page.new(:page_type => Kuhsaft::PageType::REDIRECT).redirect?.should be_true
298
+ Kuhsaft::Page.new(page_type: Kuhsaft::PageType::REDIRECT).redirect?.should be_true
302
299
  end
303
300
  end
304
301
 
305
302
  context 'when the page type is anything else' do
306
303
  it 'returns false' do
307
- Kuhsaft::Page.new(:page_type => Kuhsaft::PageType::NAVIGATION).redirect?.should be_false
304
+ Kuhsaft::Page.new(page_type: Kuhsaft::PageType::NAVIGATION).redirect?.should be_false
308
305
  end
309
306
  end
310
307
  end
311
308
 
309
+ describe 'page types' do
310
+ it 'returns content by default' do
311
+ expect(Kuhsaft::Page.new.page_type).to eq('content')
312
+ end
313
+
314
+ it 'returns navigation if set' do
315
+ expect(Kuhsaft::Page.new(page_type: Kuhsaft::PageType::NAVIGATION).page_type).to eq('navigation')
316
+ end
317
+
318
+ it 'returns redirect if set' do
319
+ expect(Kuhsaft::Page.new(page_type: Kuhsaft::PageType::REDIRECT).page_type).to eq('redirect')
320
+ end
321
+ end
322
+
312
323
  describe '#translated?' do
313
324
  it 'returns true when page is translated' do
314
325
  @page = create(:page, title: 'Page 1', slug: 'page1')
@@ -325,8 +336,8 @@ describe Kuhsaft::Page do
325
336
 
326
337
  describe '#fulltext' do
327
338
  let :page do
328
- p = create(:page, :keywords => 'key words', :description => 'descrip tion', :title => 'my title')
329
- p.bricks << Kuhsaft::TextBrick.new(:locale => I18n.locale, :text => 'oh la la')
339
+ p = create(:page, keywords: 'key words', description: 'descrip tion', title: 'my title')
340
+ p.bricks << Kuhsaft::TextBrick.new(locale: I18n.locale, text: 'oh la la')
330
341
  p.save
331
342
  p
332
343
  end
@@ -349,7 +360,7 @@ describe Kuhsaft::Page do
349
360
 
350
361
  describe '#before_validation' do
351
362
  it 'generates url automatically' do
352
- page = Kuhsaft::Page.new :slug => 'slug'
363
+ page = Kuhsaft::Page.new slug: 'slug'
353
364
  page.url.should be_nil
354
365
  page.valid?
355
366
  page.url.should be_present
@@ -358,7 +369,7 @@ describe Kuhsaft::Page do
358
369
 
359
370
  describe '#url_without_locale' do
360
371
  let :page do
361
- create(:page, :slug => 'page')
372
+ create(:page, slug: 'page')
362
373
  end
363
374
 
364
375
  context 'without parent' do
@@ -373,11 +384,11 @@ describe Kuhsaft::Page do
373
384
 
374
385
  context 'when parent is navigation' do
375
386
  let :parent do
376
- create(:page, :page_type => Kuhsaft::PageType::NAVIGATION)
387
+ create(:page, page_type: Kuhsaft::PageType::NAVIGATION)
377
388
  end
378
389
 
379
390
  let :child do
380
- create(:page, :slug => 'child', :parent => parent)
391
+ create(:page, slug: 'child', parent: parent)
381
392
  end
382
393
 
383
394
  it 'returns url without leading /' do
@@ -391,11 +402,11 @@ describe Kuhsaft::Page do
391
402
 
392
403
  context 'when parent is normal page' do
393
404
  let :parent do
394
- create(:page, :slug => 'parent')
405
+ create(:page, slug: 'parent')
395
406
  end
396
407
 
397
408
  let :child do
398
- create(:page, :slug => 'child', :parent => parent)
409
+ create(:page, slug: 'child', parent: parent)
399
410
  end
400
411
 
401
412
  it 'returns url without leading /' do