refinerycms-pages 2.1.5 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/refinery/admin/page_parts_controller.rb +6 -1
  3. data/app/controllers/refinery/admin/pages_controller.rb +53 -45
  4. data/app/controllers/refinery/pages/admin/preview_controller.rb +12 -3
  5. data/app/controllers/refinery/pages_controller.rb +12 -12
  6. data/app/helpers/refinery/admin/pages_helper.rb +5 -4
  7. data/app/helpers/refinery/pages/content_pages_helper.rb +6 -1
  8. data/app/models/refinery/page.rb +115 -141
  9. data/app/models/refinery/page_part.rb +32 -7
  10. data/app/presenters/refinery/pages/content_presenter.rb +7 -5
  11. data/app/presenters/refinery/pages/menu_presenter.rb +41 -15
  12. data/app/presenters/refinery/pages/page_part_section_presenter.rb +1 -7
  13. data/app/presenters/refinery/pages/section_presenter.rb +2 -6
  14. data/app/views/refinery/admin/pages/_actions.html.erb +4 -13
  15. data/app/views/refinery/admin/pages/_form.html.erb +7 -10
  16. data/app/views/refinery/admin/pages/_form_advanced_options.html.erb +5 -3
  17. data/app/views/refinery/admin/pages/_form_extra_fields_for_more_options.html.erb +1 -0
  18. data/app/views/refinery/admin/pages/_form_new_page_parts.html.erb +8 -0
  19. data/app/views/refinery/admin/pages/_form_page_parts.html.erb +10 -21
  20. data/app/views/refinery/admin/pages/_page.html.erb +31 -31
  21. data/app/views/refinery/admin/pages/_page_part_field.html.erb +2 -1
  22. data/app/views/refinery/admin/pages/_records.html.erb +3 -3
  23. data/app/views/refinery/admin/pages/_save_and_continue_callback.html.erb +1 -0
  24. data/app/views/refinery/admin/pages/index.html.erb +2 -4
  25. data/app/views/refinery/admin/pages_dialogs/link_to.html.erb +1 -1
  26. data/config/locales/bg.yml +1 -2
  27. data/config/locales/ca.yml +85 -0
  28. data/config/locales/cs.yml +13 -3
  29. data/config/locales/da.yml +1 -2
  30. data/config/locales/de.yml +0 -1
  31. data/config/locales/el.yml +41 -29
  32. data/config/locales/en.yml +2 -2
  33. data/config/locales/es.yml +2 -4
  34. data/config/locales/fi.yml +1 -4
  35. data/config/locales/fr.yml +2 -2
  36. data/config/locales/hu.yml +1 -2
  37. data/config/locales/it.yml +15 -16
  38. data/config/locales/ja.yml +1 -3
  39. data/config/locales/ko.yml +1 -4
  40. data/config/locales/lt.yml +1 -3
  41. data/config/locales/lv.yml +0 -2
  42. data/config/locales/nb.yml +1 -4
  43. data/config/locales/nl.yml +1 -2
  44. data/config/locales/pl.yml +1 -13
  45. data/config/locales/pt-BR.yml +1 -3
  46. data/config/locales/pt.yml +1 -2
  47. data/config/locales/rs.yml +1 -3
  48. data/config/locales/ru.yml +8 -5
  49. data/config/locales/sk.yml +1 -2
  50. data/config/locales/sl.yml +1 -3
  51. data/config/locales/sv.yml +1 -3
  52. data/config/locales/tr.yml +1 -2
  53. data/config/locales/uk.yml +1 -5
  54. data/config/locales/vi.yml +1 -3
  55. data/config/locales/zh-CN.yml +1 -4
  56. data/config/locales/zh-TW.yml +1 -3
  57. data/config/routes.rb +16 -16
  58. data/db/migrate/20100913234708_create_refinerycms_pages_schema.rb +28 -11
  59. data/db/migrate/20140105190324_add_custom_slug_to_refinery_pages.rb +20 -0
  60. data/db/migrate/20150130044643_add_slug_to_refinery_page_parts.rb +6 -0
  61. data/db/migrate/20150720155305_update_slug_and_title_in_refinery_page_parts.rb +13 -0
  62. data/db/seeds.rb +42 -36
  63. data/lib/generators/refinery/pages/templates/config/initializers/refinery/pages.rb.erb +12 -0
  64. data/lib/refinery/pages.rb +4 -3
  65. data/lib/refinery/pages/admin/instance_methods.rb +3 -3
  66. data/lib/refinery/pages/configuration.rb +7 -1
  67. data/lib/refinery/pages/engine.rb +19 -18
  68. data/lib/refinery/pages/finder.rb +179 -0
  69. data/lib/refinery/pages/instance_methods.rb +3 -14
  70. data/lib/refinery/pages/tab.rb +2 -2
  71. data/lib/refinery/pages/types.rb +1 -1
  72. data/lib/refinery/pages/url.rb +15 -3
  73. data/license.md +1 -1
  74. data/refinerycms-pages.gemspec +8 -5
  75. data/spec/controllers/refinery/admin/pages_controller_spec.rb +53 -0
  76. data/spec/controllers/refinery/pages_controller_spec.rb +1 -1
  77. data/spec/factories/pages.rb +1 -1
  78. data/spec/features/refinery/admin/pages_spec.rb +274 -290
  79. data/spec/features/refinery/pages_spec.rb +123 -138
  80. data/spec/helpers/refinery/pages/admin/pages_helper_spec.rb +15 -11
  81. data/spec/helpers/refinery/pages/content_pages_helper_spec.rb +11 -11
  82. data/spec/lib/generators/refinery/pages/pages_generator_spec.rb +1 -1
  83. data/spec/lib/pages_spec.rb +2 -2
  84. data/spec/lib/refinery/pages/tab_spec.rb +9 -9
  85. data/spec/lib/refinery/pages/url_spec.rb +12 -12
  86. data/spec/models/refinery/page_finder_spec.rb +72 -0
  87. data/spec/models/refinery/page_menu_spec.rb +107 -0
  88. data/spec/models/refinery/page_meta_data_spec.rb +49 -0
  89. data/spec/models/refinery/page_part_spec.rb +67 -0
  90. data/spec/models/refinery/page_spec.rb +16 -534
  91. data/spec/models/refinery/page_url_spec.rb +320 -0
  92. data/spec/presenters/refinery/pages/content_page_presenter_spec.rb +9 -9
  93. data/spec/presenters/refinery/pages/content_presenter_spec.rb +20 -20
  94. data/spec/presenters/refinery/pages/menu_presenter_spec.rb +44 -6
  95. data/spec/presenters/refinery/pages/page_part_section_presenter_spec.rb +12 -12
  96. data/spec/presenters/refinery/pages/section_presenter_spec.rb +22 -22
  97. data/spec/presenters/refinery/pages/title_section_presenter_spec.rb +4 -4
  98. data/spec/support/refinery/pages/caching_helpers.rb +2 -2
  99. metadata +55 -25
  100. data/app/helpers/refinery/admin/page_parts_helper.rb +0 -6
  101. data/app/helpers/refinery/admin/pages_dialogs_helper.rb +0 -6
  102. data/app/sweepers/refinery/pages/page_sweeper.rb +0 -29
  103. data/lib/refinery/pages/caching.rb +0 -60
  104. data/spec/lib/refinery/pages/caching_spec.rb +0 -90
  105. data/spec/support/refinery/pages/caching.rb +0 -19
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module Refinery
5
+ describe Page do
6
+ let(:page_title) { 'RSpec is great for testing too' }
7
+ let(:page) { subject.class.new(:title => page_title, :deletable => true)}
8
+
9
+ context 'responds to' do
10
+ it 'meta_description' do
11
+ page.respond_to?(:meta_description)
12
+ end
13
+
14
+ it 'browser_title' do
15
+ page.respond_to?(:browser_title)
16
+ end
17
+ end
18
+
19
+ context 'allows us to assign to' do
20
+ it 'meta_description' do
21
+ page.meta_description = 'This is my description of the page for search results.'
22
+ expect(page.meta_description).to eq('This is my description of the page for search results.')
23
+ end
24
+
25
+ it 'browser_title' do
26
+ page.browser_title = 'An awesome browser title for SEO'
27
+ expect(page.browser_title).to eq('An awesome browser title for SEO')
28
+ end
29
+ end
30
+
31
+ context 'allows us to update' do
32
+ it 'meta_description' do
33
+ page.meta_description = 'This is my description of the page for search results.'
34
+ page.save
35
+
36
+ page.reload
37
+ expect(page.meta_description).to eq('This is my description of the page for search results.')
38
+ end
39
+
40
+ it 'browser_title' do
41
+ page.browser_title = 'An awesome browser title for SEO'
42
+ page.save
43
+
44
+ page.reload
45
+ expect(page.browser_title).to eq('An awesome browser title for SEO')
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module Refinery
5
+ describe Page do
6
+ let(:page_title) { 'RSpec is great for testing too' }
7
+ let(:page) { subject.class.new(:title => page_title, :deletable => true)}
8
+
9
+ before do
10
+ page.parts.new(:title => 'body', :slug => 'body', :content => "I'm the first page part for this page.", :position => 0)
11
+ page.parts.new(:title => 'side body', :slug => 'side_body', :content => 'Closely followed by the second page part.', :position => 1)
12
+ end
13
+
14
+ it 'return the content when using content_for' do
15
+ expect(page.content_for(:body)).to eq("<p>I'm the first page part for this page.</p>")
16
+ expect(page.content_for('BoDY')).to eq("<p>I'm the first page part for this page.</p>")
17
+ end
18
+
19
+ it 'requires a unique slug' do
20
+ page.save
21
+ page.parts.create(:title => 'body', :slug => 'body')
22
+ duplicate_title_part = page.parts.create(:title => 'body', :slug => 'body')
23
+
24
+ expect(duplicate_title_part.errors[:slug]).to be_present
25
+ end
26
+
27
+ it 'only requires a unique slug on the same page' do
28
+ part_one = Page.create(:title => 'first page', :slug => 'first_page').parts.create(:title => 'body', :slug => 'body')
29
+ part_two = Page.create(:title => 'second page', :slug => 'second_page').parts.create(:title => 'body', :slug => 'body')
30
+
31
+ expect(part_two.errors[:slug]).to be_empty
32
+ end
33
+
34
+ context 'when using content_for?' do
35
+
36
+ it 'return true when page part has content' do
37
+ expect(page.content_for?(:body)).to be_truthy
38
+ end
39
+
40
+ it 'return false when page part does not exist' do
41
+ page.parts = []
42
+ expect(page.content_for?(:body)).to be_falsey
43
+ end
44
+
45
+ it 'return false when page part does not have any content' do
46
+ page.parts.first.content = ''
47
+ expect(page.content_for?(:body)).to be_falsey
48
+ end
49
+
50
+ end
51
+
52
+ it 'reposition correctly' do
53
+ page.save
54
+
55
+ page.parts.first.update_columns position: 6
56
+ page.parts.last.update_columns position: 4
57
+
58
+ expect(page.parts.first.position).to eq(6)
59
+ expect(page.parts.last.position).to eq(4)
60
+
61
+ page.reposition_parts!
62
+
63
+ expect(page.parts.first.position).to eq(0)
64
+ expect(page.parts.last.position).to eq(1)
65
+ end
66
+ end
67
+ end
@@ -2,37 +2,13 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  module Refinery
5
- describe Page do
5
+ describe Page, :type => :model do
6
6
  let(:page_title) { 'RSpec is great for testing too' }
7
- let(:child_title) { 'The child page' }
8
-
9
- # For when we do not need the page persisted.
10
7
  let(:page) { subject.class.new(:title => page_title, :deletable => true)}
11
- let(:child) { page.children.new(:title => child_title) }
12
-
13
- # For when we need the page persisted.
14
- let(:created_page) { subject.class.create!(:title => page_title, :deletable => true) }
15
- let(:created_child) { created_page.children.create!(:title => child_title) }
16
8
 
17
9
  def page_cannot_be_destroyed
18
- page.should_receive(:puts_destroy_help)
19
- page.destroy.should == false
20
- end
21
-
22
- def turn_off_marketable_urls
23
- Pages.stub(:marketable_urls).and_return(false)
24
- end
25
-
26
- def turn_on_marketable_urls
27
- Pages.stub(:marketable_urls).and_return(true)
28
- end
29
-
30
- def turn_off_slug_scoping
31
- Pages.stub(:scope_slug_by_parent).and_return(false)
32
- end
33
-
34
- def turn_on_slug_scoping
35
- Pages.stub(:scope_slug_by_parent).and_return(true)
10
+ expect(page).to receive(:puts_destroy_help)
11
+ expect(page.destroy).to eq(false)
36
12
  end
37
13
 
38
14
  context 'cannot be deleted under certain rules' do
@@ -54,519 +30,25 @@ module Refinery
54
30
  it 'unless you really want it to! >:]' do
55
31
  page.deletable = false
56
32
  page_cannot_be_destroyed
57
- page.destroy!.should be
58
- end
59
- end
60
-
61
- context 'page urls' do
62
- let(:page_path) { 'rspec-is-great-for-testing-too' }
63
- let(:child_path) { 'the-child-page' }
64
- it 'return a full path' do
65
- page.path.should == page_title
66
- end
67
-
68
- it 'and all of its parent page titles, reversed' do
69
- created_child.path.should == [page_title, child_title].join(' - ')
70
- end
71
-
72
- it 'or normally ;-)' do
73
- created_child.path(:reversed => false).should == [child_title, page_title].join(' - ')
74
- end
75
-
76
- it 'returns its url' do
77
- page.link_url = '/contact'
78
- page.url.should == '/contact'
79
- end
80
-
81
- it 'returns its path with marketable urls' do
82
- created_page.url[:id].should be_nil
83
- created_page.url[:path].should == [page_path]
84
- end
85
-
86
- it 'returns its path underneath its parent with marketable urls' do
87
- created_child.url[:id].should be_nil
88
- created_child.url[:path].should == [created_page.url[:path].first, child_path]
89
- end
90
-
91
- it 'no path parameter without marketable urls' do
92
- turn_off_marketable_urls
93
- created_page.url[:path].should be_nil
94
- created_page.url[:id].should == page_path
95
- turn_on_marketable_urls
96
- end
97
-
98
- it "doesn't mention its parent without marketable urls" do
99
- turn_off_marketable_urls
100
- created_child.url[:id].should == child_path
101
- created_child.url[:path].should be_nil
102
- turn_on_marketable_urls
103
- end
104
-
105
- it 'returns its path with slug set by menu_title' do
106
- page.menu_title = 'RSpec is great'
107
- page.save
108
- page.reload
109
-
110
- page.url[:id].should be_nil
111
- page.url[:path].should == ['rspec-is-great']
112
- end
113
- end
114
-
115
- context 'canonicals' do
116
- before do
117
- Refinery::I18n.stub(:default_frontend_locale).and_return(:en)
118
- Refinery::I18n.stub(:frontend_locales).and_return([I18n.default_frontend_locale, :ru])
119
- Refinery::I18n.stub(:current_frontend_locale).and_return(I18n.default_frontend_locale)
120
-
121
- page.save
122
- end
123
- let(:page_title) { 'team' }
124
- let(:child_title) { 'about' }
125
- let(:ru_page_title) { 'Новости' }
126
-
127
- describe '#canonical' do
128
- let!(:default_canonical) {
129
- Globalize.with_locale(Refinery::I18n.default_frontend_locale) {
130
- page.canonical
131
- }
132
- }
133
-
134
- specify 'page returns itself' do
135
- page.canonical.should == page.url
136
- end
137
-
138
- specify 'default canonical matches page#canonical' do
139
- default_canonical.should == page.canonical
140
- end
141
-
142
- specify 'translated page returns master page' do
143
- Globalize.with_locale(:ru) do
144
- page.title = ru_page_title
145
- page.save
146
-
147
- page.canonical.should == default_canonical
148
- end
149
- end
150
- end
151
-
152
- describe '#canonical_slug' do
153
- let!(:default_canonical_slug) {
154
- Globalize.with_locale(Refinery::I18n.default_frontend_locale) {
155
- page.canonical_slug
156
- }
157
- }
158
- specify 'page returns its own slug' do
159
- page.canonical_slug.should == page.slug
160
- end
161
-
162
- specify 'default canonical_slug matches page#canonical' do
163
- default_canonical_slug.should == page.canonical_slug
164
- end
165
-
166
- specify "translated page returns master page's slug'" do
167
- Globalize.with_locale(:ru) do
168
- page.title = ru_page_title
169
- page.save
170
-
171
- page.canonical_slug.should == default_canonical_slug
172
- end
173
- end
174
- end
175
- end
176
-
177
- context 'custom slugs' do
178
- let(:custom_page_slug) { 'custom-page-slug' }
179
- let(:custom_child_slug) { 'custom-child-slug' }
180
- let(:custom_route) { '/products/my-product' }
181
- let(:page_with_custom_slug) {
182
- subject.class.new(:title => page_title, :custom_slug => custom_page_slug)
183
- }
184
- let(:child_with_custom_slug) {
185
- page.children.new(:title => child_title, :custom_slug => custom_child_slug)
186
- }
187
- let(:page_with_custom_route) {
188
- subject.class.new(:title => page_title, :custom_slug => custom_route)
189
- }
190
-
191
- after(:each) do
192
- Refinery::I18n.stub(:current_frontend_locale).and_return(I18n.default_frontend_locale)
193
- Refinery::I18n.stub(:current_locale).and_return(I18n.default_locale)
194
- end
195
-
196
- it 'returns its path with custom slug' do
197
- page_with_custom_slug.save
198
- page_with_custom_slug.url[:id].should be_nil
199
- page_with_custom_slug.url[:path].should == [custom_page_slug]
200
- end
201
-
202
- it 'allows a custom route when slug scoping is off' do
203
- turn_off_slug_scoping
204
- page_with_custom_route.save
205
- page_with_custom_route.url[:id].should be_nil
206
- page_with_custom_route.url[:path].should == [custom_route]
207
- turn_on_slug_scoping
208
- end
209
-
210
- it 'allows slashes in custom routes but slugs everything in between' do
211
- turn_off_slug_scoping
212
- page_needing_a_slugging = subject.class.new(:title => page_title, :custom_slug => 'products/category/sub category/my product is cool!')
213
- page_needing_a_slugging.save
214
- page_needing_a_slugging.url[:id].should be_nil
215
- page_needing_a_slugging.url[:path].should == ['products/category/sub-category/my-product-is-cool']
216
- turn_on_slug_scoping
217
- end
218
-
219
- it 'returns its path underneath its parent with custom urls' do
220
- child_with_custom_slug.save
221
- page.save
222
-
223
- child_with_custom_slug.url[:id].should be_nil
224
- child_with_custom_slug.url[:path].should == [page.url[:path].first, custom_child_slug]
225
- end
226
-
227
- it 'does not return a path underneath its parent when scoping is off' do
228
- turn_off_slug_scoping
229
- child_with_custom_slug.save
230
- page.save
231
-
232
- child_with_custom_slug.url[:id].should be_nil
233
- child_with_custom_slug.url[:path].should == [custom_child_slug]
234
- turn_on_slug_scoping
235
- end
236
-
237
- it "doesn't allow slashes in slug" do
238
- page_with_slashes_in_slug = subject.class.new(:title => page_title, :custom_slug => '/products/category')
239
- page_with_slashes_in_slug.save
240
- page_with_slashes_in_slug.url[:path].should == ['productscategory']
241
- end
242
-
243
- it "allow slashes in slug when slug scoping is off" do
244
- turn_off_slug_scoping
245
- page_with_slashes_in_slug = subject.class.new(:title => page_title, :custom_slug => 'products/category/subcategory')
246
- page_with_slashes_in_slug.save
247
- page_with_slashes_in_slug.url[:path].should == ['products/category/subcategory']
248
- turn_on_slug_scoping
249
- end
250
-
251
- it "strips leading and trailing slashes in slug when slug scoping is off" do
252
- turn_off_slug_scoping
253
- page_with_slashes_in_slug = subject.class.new(:title => page_title, :custom_slug => '/products/category/subcategory/')
254
- page_with_slashes_in_slug.save
255
- page_with_slashes_in_slug.url[:path].should == ['products/category/subcategory']
256
- turn_on_slug_scoping
257
- end
258
-
259
- it 'returns its path with custom slug when using different locale' do
260
- Refinery::I18n.stub(:current_frontend_locale).and_return(:ru)
261
- Refinery::I18n.stub(:current_locale).and_return(:ru)
262
- page_with_custom_slug.custom_slug = "#{custom_page_slug}-ru"
263
- page_with_custom_slug.save
264
- page_with_custom_slug.reload
265
-
266
- page_with_custom_slug.url[:id].should be_nil
267
- page_with_custom_slug.url[:path].should == ["#{custom_page_slug}-ru"]
33
+ expect(page.destroy!).to be
268
34
  end
269
35
 
270
- it 'returns path underneath its parent with custom urls when using different locale' do
271
- Refinery::I18n.stub(:current_frontend_locale).and_return(:ru)
272
- Refinery::I18n.stub(:current_locale).and_return(:ru)
273
- child_with_custom_slug.custom_slug = "#{custom_child_slug}-ru"
274
- child_with_custom_slug.save
275
- child_with_custom_slug.reload
276
-
277
- child_with_custom_slug.url[:id].should be_nil
278
- child_with_custom_slug.url[:path].should == [page.url[:path].first, "#{custom_child_slug}-ru"]
279
- end
280
-
281
- context "given a page with a custom_slug exists" do
282
- before do
283
- FactoryGirl.create(:page, :custom_slug => custom_page_slug)
284
- end
285
-
286
- it "fails validation when a new record uses that custom_slug" do
287
- new_page = Page.new :custom_slug => custom_page_slug
288
- new_page.valid?
289
-
290
- new_page.errors[:custom_slug].should_not be_empty
291
- end
292
- end
293
- end
294
-
295
- context 'content sections (page parts)' do
296
- before do
297
- page.parts.new(:title => 'body', :content => "I'm the first page part for this page.", :position => 0)
298
- page.parts.new(:title => 'side body', :content => 'Closely followed by the second page part.', :position => 1)
299
- end
300
-
301
- it 'return the content when using content_for' do
302
- page.content_for(:body).should == "<p>I'm the first page part for this page.</p>"
303
- page.content_for('BoDY').should == "<p>I'm the first page part for this page.</p>"
304
- end
305
-
306
- it 'requires a unique title' do
307
- page.save
308
- page.parts.create(:title => 'body')
309
- duplicate_title_part = page.parts.create(:title => 'body')
310
-
311
- duplicate_title_part.errors[:title].should be_present
312
- end
313
-
314
- it 'only requires a unique title on the same page' do
315
- part_one = Page.create(:title => 'first page').parts.create(:title => 'body')
316
- part_two = Page.create(:title => 'second page').parts.create(:title => 'body')
317
-
318
- part_two.errors[:title].should be_empty
319
- end
320
-
321
- context 'when using content_for?' do
322
-
323
- it 'return true when page part has content' do
324
- page.content_for?(:body).should be_true
325
- end
326
-
327
- it 'return false when page part does not exist' do
328
- page.parts = []
329
- page.content_for?(:body).should be_false
330
- end
331
-
332
- it 'return false when page part does not have any content' do
333
- page.parts.first.content = ''
334
- page.content_for?(:body).should be_false
335
- end
336
-
337
- end
338
-
339
- it 'reposition correctly' do
340
- page.save
341
-
342
- page.parts.first.update_attributes :position => 6
343
- page.parts.last.update_attributes :position => 4
344
-
345
- page.parts.first.position.should == 6
346
- page.parts.last.position.should == 4
347
-
348
- page.reposition_parts!
349
-
350
- page.parts.first.position.should == 0
351
- page.parts.last.position.should == 1
36
+ it "even if you really want it to AND it's saved! >:]" do
37
+ page.update_attribute(:deletable, false)
38
+ page_cannot_be_destroyed
39
+ expect(page.destroy!).to be
352
40
  end
353
41
  end
354
42
 
355
43
  context 'draft pages' do
356
44
  it 'not live when set to draft' do
357
45
  page.draft = true
358
- page.live?.should_not be
46
+ expect(page.live?).not_to be
359
47
  end
360
48
 
361
49
  it 'live when not set to draft' do
362
50
  page.draft = false
363
- page.live?.should be
364
- end
365
- end
366
-
367
- context "should add url suffix" do
368
- let(:reserved_word) { subject.class.friendly_id_config.reserved_words.last }
369
- let(:page_with_reserved_title) {
370
- subject.class.create!(:title => reserved_word, :deletable => true)
371
- }
372
- let(:child_with_reserved_title_parent) {
373
- page_with_reserved_title.children.create(:title => 'reserved title child page')
374
- }
375
-
376
- before { turn_on_marketable_urls }
377
-
378
- it 'when title is set to a reserved word' do
379
- page_with_reserved_title.url[:path].should == ["#{reserved_word}-page"]
380
- end
381
-
382
- it "when parent page title is set to a reserved word" do
383
- child_with_reserved_title_parent.url[:path].should == ["#{reserved_word}-page", 'reserved-title-child-page']
384
- end
385
- end
386
-
387
- context 'meta data' do
388
- context 'responds to' do
389
- it 'meta_description' do
390
- page.respond_to?(:meta_description)
391
- end
392
-
393
- it 'browser_title' do
394
- page.respond_to?(:browser_title)
395
- end
396
- end
397
-
398
- context 'allows us to assign to' do
399
- it 'meta_description' do
400
- page.meta_description = 'This is my description of the page for search results.'
401
- page.meta_description.should == 'This is my description of the page for search results.'
402
- end
403
-
404
- it 'browser_title' do
405
- page.browser_title = 'An awesome browser title for SEO'
406
- page.browser_title.should == 'An awesome browser title for SEO'
407
- end
408
- end
409
-
410
- context 'allows us to update' do
411
- it 'meta_description' do
412
- page.meta_description = 'This is my description of the page for search results.'
413
- page.save
414
-
415
- page.reload
416
- page.meta_description.should == 'This is my description of the page for search results.'
417
- end
418
-
419
- it 'browser_title' do
420
- page.browser_title = 'An awesome browser title for SEO'
421
- page.save
422
-
423
- page.reload
424
- page.browser_title.should == 'An awesome browser title for SEO'
425
- end
426
- end
427
-
428
- end
429
-
430
- describe "#to_refinery_menu_item" do
431
- let(:page) do
432
- Page.new(
433
- :id => 5,
434
- :parent_id => 8,
435
- :menu_match => "^/foo$"
436
-
437
- # Page does not allow setting lft and rgt, so stub them.
438
- ).tap do |p|
439
- p[:lft] = 6
440
- p[:rgt] = 7
441
- end
442
- end
443
-
444
- subject { page.to_refinery_menu_item }
445
-
446
- shared_examples_for("Refinery menu item hash") do
447
- [ [:id, 5],
448
- [:lft, 6],
449
- [:rgt, 7],
450
- [:parent_id, 8],
451
- [:menu_match, "^/foo$"]
452
- ].each do |attr, value|
453
- it "returns the correct :#{attr}" do
454
- subject[attr].should eq(value)
455
- end
456
- end
457
-
458
- it "returns the correct :url" do
459
- subject[:url].should be_a(Hash) # guard against nil
460
- subject[:url].should eq(page.url)
461
- end
462
- end
463
-
464
- context "with #menu_title" do
465
- before do
466
- page[:menu_title] = "Menu Title"
467
- end
468
-
469
- it_should_behave_like "Refinery menu item hash"
470
-
471
- it "returns the menu_title for :title" do
472
- subject[:title].should eq("Menu Title")
473
- end
474
- end
475
-
476
- context "with #title" do
477
- before do
478
- page[:title] = "Title"
479
- end
480
-
481
- it_should_behave_like "Refinery menu item hash"
482
-
483
- it "returns the title for :title" do
484
- subject[:title].should eq("Title")
485
- end
486
- end
487
- end
488
-
489
- describe "#in_menu?" do
490
- context "when live? and show_in_menu? returns true" do
491
- it "returns true" do
492
- page.stub(:live?).and_return(true)
493
- page.stub(:show_in_menu?).and_return(true)
494
- page.in_menu?.should be_true
495
- end
496
- end
497
-
498
- context "when live? or show_in_menu? doesn't return true" do
499
- it "returns false" do
500
- page.stub(:live?).and_return(true)
501
- page.stub(:show_in_menu?).and_return(false)
502
- page.in_menu?.should be_false
503
-
504
- page.stub(:live?).and_return(false)
505
- page.stub(:show_in_menu?).and_return(true)
506
- page.in_menu?.should be_false
507
- end
508
- end
509
- end
510
-
511
- describe "#not_in_menu?" do
512
- context "when in_menu? returns true" do
513
- it "returns false" do
514
- page.stub(:in_menu?).and_return(true)
515
- page.not_in_menu?.should be_false
516
- end
517
- end
518
-
519
- context "when in_menu? returns false" do
520
- it "returns true" do
521
- page.stub(:in_menu?).and_return(false)
522
- page.not_in_menu?.should be_true
523
- end
524
- end
525
- end
526
-
527
- describe '.find_by_path' do
528
- let(:page_title) { 'team' }
529
- let(:child_title) { 'about' }
530
- let(:created_root_about) { subject.class.create!(:title => child_title, :deletable => true) }
531
-
532
- before do
533
- # Ensure pages are created.
534
- created_child
535
- created_root_about
536
- end
537
-
538
- it "should return (root) about page when looking for '/about'" do
539
- Page.find_by_path('/about').should == created_root_about
540
- end
541
-
542
- it "should return child about page when looking for '/team/about'" do
543
- Page.find_by_path('/team/about').should == created_child
544
- end
545
- end
546
-
547
- describe ".find_by_path_or_id" do
548
- let!(:market) { FactoryGirl.create(:page, :title => "market") }
549
- let(:path) { "market" }
550
- let(:id) { market.id }
551
-
552
- context "when path param is present" do
553
- context "when path is friendly_id" do
554
- it "finds page using path" do
555
- Page.find_by_path_or_id(path, "").should eq(market)
556
- end
557
- end
558
-
559
- context "when path is not friendly_id" do
560
- it "finds page using id" do
561
- Page.find_by_path_or_id(id, "").should eq(market)
562
- end
563
- end
564
- end
565
-
566
- context "when id param is present" do
567
- it "finds page using id" do
568
- Page.find_by_path_or_id("", id).should eq(market)
569
- end
51
+ expect(page.live?).to be
570
52
  end
571
53
  end
572
54
 
@@ -575,20 +57,20 @@ module Refinery
575
57
  page.deletable = true
576
58
  page.link_url = ""
577
59
  page.menu_match = ""
578
- page.stub(:puts_destroy_help).and_return('')
60
+ allow(page).to receive(:puts_destroy_help).and_return('')
579
61
  page
580
62
  end
581
63
 
582
64
  context "when deletable is true and link_url, and menu_match is blank" do
583
65
  it "returns true" do
584
- deletable_page.deletable?.should be_true
66
+ expect(deletable_page.deletable?).to be_truthy
585
67
  end
586
68
  end
587
69
 
588
70
  context "when deletable is false and link_url, and menu_match is blank" do
589
71
  it "returns false" do
590
72
  deletable_page.deletable = false
591
- deletable_page.deletable?.should be_false
73
+ expect(deletable_page.deletable?).to be_falsey
592
74
  end
593
75
  end
594
76
 
@@ -596,10 +78,10 @@ module Refinery
596
78
  it "returns false" do
597
79
  deletable_page.deletable = false
598
80
  deletable_page.link_url = "text"
599
- deletable_page.deletable?.should be_false
81
+ expect(deletable_page.deletable?).to be_falsey
600
82
 
601
83
  deletable_page.menu_match = "text"
602
- deletable_page.deletable?.should be_false
84
+ expect(deletable_page.deletable?).to be_falsey
603
85
  end
604
86
  end
605
87
  end
@@ -613,7 +95,7 @@ module Refinery
613
95
  end
614
96
 
615
97
  it "shows message" do
616
- page.should_receive(:puts_destroy_help)
98
+ expect(page).to receive(:puts_destroy_help)
617
99
 
618
100
  page.destroy
619
101
  end