refinerycms-page-menus 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.gitignore +2 -0
  2. data/app/controllers/refinery/admin/page_menus_controller.rb +9 -0
  3. data/app/controllers/refinery/admin/page_positions_controller.rb +51 -0
  4. data/app/models/refinery/page_menu.rb +31 -0
  5. data/app/models/refinery/page_position.rb +37 -0
  6. data/app/views/refinery/admin/page_menus/_form.html.erb +41 -0
  7. data/app/views/refinery/admin/page_menus/edit.html.erb +1 -0
  8. data/app/views/refinery/admin/page_positions/_actions.html.erb +45 -0
  9. data/app/views/refinery/admin/page_positions/_page_position.html.erb +49 -0
  10. data/app/views/refinery/admin/page_positions/_records.html.erb +14 -0
  11. data/app/views/refinery/admin/page_positions/_sortable_list.html.erb +4 -0
  12. data/app/views/refinery/admin/page_positions/index.html.erb +11 -0
  13. data/app/views/refinery/admin/pages/_actions.html.erb +40 -0
  14. data/app/views/refinery/admin/pages/_list_actions.html.erb +28 -0
  15. data/app/views/refinery/admin/pages/_list_page.html.erb +46 -0
  16. data/app/views/refinery/admin/pages/_list_records.html.erb +16 -0
  17. data/app/views/refinery/admin/pages/list.html.erb +8 -0
  18. data/app/views/refinery/admin/pages_shared/_submenu.html.erb +65 -0
  19. data/config/locales/da.yml +32 -0
  20. data/config/locales/en.yml +93 -0
  21. data/config/routes.rb +14 -0
  22. data/db/migrate/20120406121839_create_page_menus.rb +31 -0
  23. data/db/migrate/20120411133453_add_permatitle_to_page_menus.rb +9 -0
  24. data/db/migrate/20120411134419_add_menu_match_to_page_positions.rb +6 -0
  25. data/lib/generators/refinery/page_menus/page_menus_generator.rb +14 -0
  26. data/lib/generators/refinery/page_menus/templates/config/initializers/refinery/page_menus.rb.erb +3 -0
  27. data/lib/refinery/page_menus.rb +31 -0
  28. data/lib/refinery/page_menus/configuration.rb +10 -0
  29. data/lib/refinery/page_menus/controller_extension.rb +44 -0
  30. data/lib/refinery/page_menus/engine.rb +35 -0
  31. data/lib/refinery/page_menus/instance_methods.rb +16 -0
  32. data/lib/refinery/page_menus/model_extension.rb +14 -0
  33. data/lib/refinerycms-page-menus.rb +1 -0
  34. data/license.md +21 -0
  35. data/readme.md +1 -0
  36. data/refinerycms-page-menus.gemspec +25 -0
  37. data/spec/factories/pages.rb +5 -0
  38. data/spec/helpers/refinery/pages/content_pages_helper_spec.rb +44 -0
  39. data/spec/lib/generators/refinery/pages/pages_generator_spec.rb +29 -0
  40. data/spec/lib/pages/content_page_presenter_spec.rb +43 -0
  41. data/spec/lib/pages/content_presenter_spec.rb +111 -0
  42. data/spec/lib/pages/page_part_section_presenter_spec.rb +35 -0
  43. data/spec/lib/pages/section_presenter_spec.rb +86 -0
  44. data/spec/lib/pages/title_section_presenter_spec.rb +21 -0
  45. data/spec/lib/pages_spec.rb +26 -0
  46. data/spec/models/refinery/page_spec.rb +415 -0
  47. data/spec/requests/refinery/admin/pages_spec.rb +613 -0
  48. data/spec/requests/refinery/pages_spec.rb +302 -0
  49. metadata +127 -0
@@ -0,0 +1,415 @@
1
+ require 'spec_helper'
2
+
3
+ module Refinery
4
+ describe Page do
5
+
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
+ 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
+
17
+ def page_cannot_be_destroyed
18
+ page.destroy.should == false
19
+ end
20
+
21
+ def turn_off_marketable_urls
22
+ Refinery::Pages.stub(:marketable_urls).and_return(false)
23
+ end
24
+
25
+ def turn_on_marketable_urls
26
+ Refinery::Pages.stub(:marketable_urls).and_return(true)
27
+ end
28
+
29
+ context 'cannot be deleted under certain rules' do
30
+ it 'if link_url is present' do
31
+ page.link_url = '/plugin-name'
32
+ page_cannot_be_destroyed
33
+ end
34
+
35
+ it 'if refinery team deems it so' do
36
+ page.deletable = false
37
+ page_cannot_be_destroyed
38
+ end
39
+
40
+ it 'if menu_match is present' do
41
+ page.menu_match = "^/#{page_title}*$"
42
+ page_cannot_be_destroyed
43
+ end
44
+
45
+ it 'unless you really want it to! >:]' do
46
+ page.deletable = false
47
+ page_cannot_be_destroyed
48
+ page.destroy!.should be
49
+ end
50
+ end
51
+
52
+ context 'page urls' do
53
+ let(:page_path) { 'rspec-is-great-for-testing-too' }
54
+ let(:child_path) { 'the-child-page' }
55
+ it 'return a full path' do
56
+ page.path.should == page_title
57
+ end
58
+
59
+ it 'and all of its parent page titles, reversed' do
60
+ created_child.path.should == [page_title, child_title].join(' - ')
61
+ end
62
+
63
+ it 'or normally ;-)' do
64
+ created_child.path(:reversed => false).should == [child_title, page_title].join(' - ')
65
+ end
66
+
67
+ it 'returns its url' do
68
+ page.link_url = '/contact'
69
+ page.url.should == '/contact'
70
+ end
71
+
72
+ it 'returns its path with marketable urls' do
73
+ created_page.url[:id].should be_nil
74
+ created_page.url[:path].should == [page_path]
75
+ end
76
+
77
+ it 'returns its path underneath its parent with marketable urls' do
78
+ created_child.url[:id].should be_nil
79
+ created_child.url[:path].should == [created_page.url[:path].first, child_path]
80
+ end
81
+
82
+ it 'no path parameter without marketable urls' do
83
+ turn_off_marketable_urls
84
+ created_page.url[:path].should be_nil
85
+ created_page.url[:id].should == page_path
86
+ turn_on_marketable_urls
87
+ end
88
+
89
+ it "doesn't mention its parent without marketable urls" do
90
+ turn_off_marketable_urls
91
+ created_child.url[:id].should == child_path
92
+ created_child.url[:path].should be_nil
93
+ turn_on_marketable_urls
94
+ end
95
+
96
+ it 'returns its path with slug set by menu_title' do
97
+ page.menu_title = 'RSpec is great'
98
+ page.save
99
+ page.reload
100
+
101
+ page.url[:id].should be_nil
102
+ page.url[:path].should == ['rspec-is-great']
103
+ end
104
+ end
105
+
106
+ context 'custom slugs' do
107
+ let(:custom_page_slug) { 'custom-page-slug' }
108
+ let(:custom_child_slug) { 'custom-child-slug' }
109
+ let(:page_with_custom_slug) {
110
+ subject.class.new(:title => page_title, :custom_slug => custom_page_slug)
111
+ }
112
+ let(:child_with_custom_slug) {
113
+ page.children.new(:title => child_title, :custom_slug => custom_child_slug)
114
+ }
115
+
116
+ after(:each) do
117
+ ::Refinery::I18n.stub(:current_frontend_locale).and_return(Refinery::I18n.default_frontend_locale)
118
+ ::Refinery::I18n.current_locale = Refinery::I18n.default_locale
119
+ end
120
+
121
+ it 'returns its path with custom slug' do
122
+ page_with_custom_slug.save
123
+ page_with_custom_slug.url[:id].should be_nil
124
+ page_with_custom_slug.url[:path].should == [custom_page_slug]
125
+ end
126
+
127
+ it 'returns its path underneath its parent with custom urls' do
128
+ child_with_custom_slug.save
129
+ page.save
130
+
131
+ child_with_custom_slug.url[:id].should be_nil
132
+ child_with_custom_slug.url[:path].should == [page.url[:path].first, custom_child_slug]
133
+ end
134
+
135
+ it 'returns its path with custom slug when using different locale' do
136
+ ::Refinery::I18n.stub(:current_frontend_locale).and_return(:ru)
137
+ ::Refinery::I18n.current_locale = :ru
138
+ page_with_custom_slug.custom_slug = "#{custom_page_slug}-ru"
139
+ page_with_custom_slug.save
140
+ page_with_custom_slug.reload
141
+
142
+ page_with_custom_slug.url[:id].should be_nil
143
+ page_with_custom_slug.url[:path].should == ["#{custom_page_slug}-ru"]
144
+ end
145
+
146
+ it 'returns path underneath its parent with custom urls when using different locale' do
147
+ ::Refinery::I18n.stub(:current_frontend_locale).and_return(:ru)
148
+ ::Refinery::I18n.current_locale = :ru
149
+ child_with_custom_slug.custom_slug = "#{custom_child_slug}-ru"
150
+ child_with_custom_slug.save
151
+ child_with_custom_slug.reload
152
+
153
+ child_with_custom_slug.url[:id].should be_nil
154
+ child_with_custom_slug.url[:path].should == [page.url[:path].first, "#{custom_child_slug}-ru"]
155
+ end
156
+
157
+ end
158
+
159
+ context 'home page' do
160
+ it 'responds as the home page' do
161
+ page.link_url = '/'
162
+ page.home?.should == true
163
+ end
164
+
165
+ it 'responds as a normal page when not set to home page' do
166
+ page.home?.should == false
167
+ end
168
+ end
169
+
170
+ context 'content sections (page parts)' do
171
+ before do
172
+ page.parts.new(:title => 'body', :content => "I'm the first page part for this page.", :position => 0)
173
+ page.parts.new(:title => 'side body', :content => 'Closely followed by the second page part.', :position => 1)
174
+ end
175
+
176
+ it 'return the content when using content_for' do
177
+ page.content_for(:body).should == "<p>I'm the first page part for this page.</p>"
178
+ page.content_for('BoDY').should == "<p>I'm the first page part for this page.</p>"
179
+ end
180
+
181
+ it 'return all page part content' do
182
+ page.all_page_part_content.should == "<p>I'm the first page part for this page.</p> <p>Closely followed by the second page part.</p>"
183
+ end
184
+
185
+ it 'reposition correctly' do
186
+ page.save
187
+
188
+ page.parts.first.update_attribute(:position, 6)
189
+ page.parts.last.update_attribute(:position, 4)
190
+
191
+ page.parts.first.position.should == 6
192
+ page.parts.last.position.should == 4
193
+
194
+ page.reposition_parts!
195
+
196
+ page.parts.first.position.should == 0
197
+ page.parts.last.position.should == 1
198
+ end
199
+ end
200
+
201
+ context 'draft pages' do
202
+ it 'not live when set to draft' do
203
+ page.draft = true
204
+ page.live?.should_not be
205
+ end
206
+
207
+ it 'live when not set to draft' do
208
+ page.draft = false
209
+ page.live?.should be
210
+ end
211
+ end
212
+
213
+ context "should add url suffix" do
214
+ let(:reserved_word) { subject.class.friendly_id_config.reserved_words.last }
215
+ let(:page_with_reserved_title) {
216
+ subject.class.create!(:title => reserved_word, :deletable => true)
217
+ }
218
+ let(:child_with_reserved_title_parent) {
219
+ page_with_reserved_title.children.create(:title => 'reserved title child page')
220
+ }
221
+
222
+ before { turn_on_marketable_urls }
223
+
224
+ it 'when title is set to a reserved word' do
225
+ page_with_reserved_title.url[:path].should == ["#{reserved_word}-page"]
226
+ end
227
+
228
+ it "when parent page title is set to a reserved word" do
229
+ child_with_reserved_title_parent.url[:path].should == ["#{reserved_word}-page", 'reserved-title-child-page']
230
+ end
231
+ end
232
+
233
+ context 'meta data' do
234
+ context 'responds to' do
235
+ it 'meta_keywords' do
236
+ page.respond_to?(:meta_keywords)
237
+ end
238
+
239
+ it 'meta_description' do
240
+ page.respond_to?(:meta_description)
241
+ end
242
+
243
+ it 'browser_title' do
244
+ page.respond_to?(:browser_title)
245
+ end
246
+ end
247
+
248
+ context 'allows us to assign to' do
249
+ it 'meta_keywords' do
250
+ page.meta_keywords = 'Some, great, keywords'
251
+ page.meta_keywords.should == 'Some, great, keywords'
252
+ end
253
+
254
+ it 'meta_description' do
255
+ page.meta_description = 'This is my description of the page for search results.'
256
+ page.meta_description.should == 'This is my description of the page for search results.'
257
+ end
258
+
259
+ it 'browser_title' do
260
+ page.browser_title = 'An awesome browser title for SEO'
261
+ page.browser_title.should == 'An awesome browser title for SEO'
262
+ end
263
+ end
264
+
265
+ context 'allows us to update' do
266
+ it 'meta_keywords' do
267
+ page.meta_keywords = 'Some, great, keywords'
268
+ page.save
269
+
270
+ page.reload
271
+ page.meta_keywords.should == 'Some, great, keywords'
272
+ end
273
+
274
+ it 'meta_description' do
275
+ page.meta_description = 'This is my description of the page for search results.'
276
+ page.save
277
+
278
+ page.reload
279
+ page.meta_description.should == 'This is my description of the page for search results.'
280
+ end
281
+
282
+ it 'browser_title' do
283
+ page.browser_title = 'An awesome browser title for SEO'
284
+ page.save
285
+
286
+ page.reload
287
+ page.browser_title.should == 'An awesome browser title for SEO'
288
+ end
289
+ end
290
+
291
+ end
292
+
293
+ describe "#to_refinery_menu_item" do
294
+ let(:page) do
295
+ Refinery::Page.new(
296
+ :id => 5,
297
+ :parent_id => 8,
298
+ :menu_match => "^/foo$"
299
+
300
+ # Refinery::Page does not allow setting lft and rgt, so stub them.
301
+ ).tap do |p|
302
+ p[:lft] = 6
303
+ p[:rgt] = 7
304
+ end
305
+ end
306
+
307
+ subject { page.to_refinery_menu_item }
308
+
309
+ shared_examples_for("Refinery menu item hash") do
310
+ [ [:id, 5],
311
+ [:lft, 6],
312
+ [:rgt, 7],
313
+ [:parent_id, 8],
314
+ [:menu_match, "^/foo$"]
315
+ ].each do |attr, value|
316
+ it "returns the correct :#{attr}" do
317
+ subject[attr].should eq(value)
318
+ end
319
+ end
320
+
321
+ it "returns the correct :url" do
322
+ subject[:url].should be_a(Hash) # guard against nil
323
+ subject[:url].should eq(page.url)
324
+ end
325
+ end
326
+
327
+ context "with #page_menu_title" do
328
+ before do
329
+ page.page_menu_title = "Page Menu Title"
330
+ end
331
+
332
+ it_should_behave_like "Refinery menu item hash"
333
+
334
+ it "returns the page_menu_title for :title" do
335
+ subject[:title].should eq("Page Menu Title")
336
+ end
337
+ end
338
+
339
+ context "with #page_title" do
340
+ before do
341
+ page.page_title = "Page Title"
342
+ end
343
+
344
+ it_should_behave_like "Refinery menu item hash"
345
+
346
+ it "returns the page_title for :title" do
347
+ subject[:title].should eq("Page Title")
348
+ end
349
+ end
350
+
351
+ context "with #menu_title" do
352
+ before do
353
+ page[:menu_title] = "Menu Title"
354
+ end
355
+
356
+ it_should_behave_like "Refinery menu item hash"
357
+
358
+ it "returns the menu_title for :title" do
359
+ subject[:title].should eq("Menu Title")
360
+ end
361
+ end
362
+
363
+ context "with #title" do
364
+ before do
365
+ page[:title] = "Title"
366
+ end
367
+
368
+ it_should_behave_like "Refinery menu item hash"
369
+
370
+ it "returns the title for :title" do
371
+ subject[:title].should eq("Title")
372
+ end
373
+ end
374
+ end
375
+
376
+ describe ".in_menu?" do
377
+ context "when live? and show_in_menu? returns true" do
378
+ it "returns true" do
379
+ page.stub(:live?).and_return(true)
380
+ page.stub(:show_in_menu?).and_return(true)
381
+ page.in_menu?.should be_true
382
+ end
383
+ end
384
+
385
+ context "when live? or show_in_menu? doesn't return true" do
386
+ it "returns false" do
387
+ page.stub(:live?).and_return(true)
388
+ page.stub(:show_in_menu?).and_return(false)
389
+ page.in_menu?.should be_false
390
+
391
+ page.stub(:live?).and_return(false)
392
+ page.stub(:show_in_menu?).and_return(true)
393
+ page.in_menu?.should be_false
394
+ end
395
+ end
396
+ end
397
+
398
+ describe ".not_in_menu?" do
399
+ context "when in_menu? returns true" do
400
+ it "returns false" do
401
+ page.stub(:in_menu?).and_return(true)
402
+ page.not_in_menu?.should be_false
403
+ end
404
+ end
405
+
406
+ context "when in_menu? returns false" do
407
+ it "returns true" do
408
+ page.stub(:in_menu?).and_return(false)
409
+ page.not_in_menu?.should be_true
410
+ end
411
+ end
412
+ end
413
+
414
+ end
415
+ end
@@ -0,0 +1,613 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ def new_window_should_have_content(content)
5
+ new_window = page.driver.browser.window_handles.last
6
+ page.within_window new_window do
7
+ page.should have_content(content)
8
+ end
9
+ end
10
+
11
+ module Refinery
12
+ module Admin
13
+ describe "Pages" do
14
+ login_refinery_user
15
+
16
+ context "when no pages" do
17
+ it "invites to create one" do
18
+ visit refinery.admin_pages_path
19
+ page.should have_content(%q{There are no pages yet. Click "Add new page" to add your first page.})
20
+ end
21
+ end
22
+
23
+ describe "action links" do
24
+ it "shows add new page link" do
25
+ visit refinery.admin_pages_path
26
+
27
+ within "#actions" do
28
+ page.should have_content("Add new page")
29
+ page.should have_selector("a[href='/refinery/pages/new']")
30
+ end
31
+ end
32
+
33
+ context "when no pages" do
34
+ it "doesn't show reorder pages link" do
35
+ visit refinery.admin_pages_path
36
+
37
+ within "#actions" do
38
+ page.should have_no_content("Reorder pages")
39
+ page.should have_no_selector("a[href='/refinery/pages']")
40
+ end
41
+ end
42
+ end
43
+
44
+ context "when some pages exist" do
45
+ before(:each) { 2.times { FactoryGirl.create(:page) } }
46
+
47
+ it "shows reorder pages link" do
48
+ visit refinery.admin_pages_path
49
+
50
+ within "#actions" do
51
+ page.should have_content("Reorder pages")
52
+ page.should have_selector("a[href='/refinery/pages']")
53
+ end
54
+ end
55
+ end
56
+
57
+ context "when sub pages exist" do
58
+ let(:company) { FactoryGirl.create(:page, :title => "Our Company") }
59
+ let(:team) { FactoryGirl.create(:page, :parent => company, :title => 'Our Team') }
60
+ let(:locations) { FactoryGirl.create(:page, :parent => company, :title => 'Our Locations')}
61
+ let(:location) { FactoryGirl.create(:page, :parent => locations, :title => 'New York') }
62
+
63
+ context "with auto expand option turned off" do
64
+ before do
65
+ Refinery::Pages.auto_expand_admin_tree = false
66
+
67
+ # Pre load pages
68
+ location
69
+ team
70
+
71
+ visit refinery.admin_pages_path
72
+ end
73
+
74
+ it "show parent page" do
75
+
76
+ page.should have_content(company.title)
77
+ end
78
+
79
+ it "doesn't show children" do
80
+ page.should_not have_content(team.title)
81
+ page.should_not have_content(locations.title)
82
+ end
83
+
84
+ it "expands children", :js => true do
85
+ find(".toggle").click
86
+
87
+ page.should have_content(team.title)
88
+ page.should have_content(locations.title)
89
+ end
90
+
91
+ it "expands children when nested mutliple levels deep", :js => true do
92
+ find("#page_#{company.id} .toggle").click
93
+ find("#page_#{locations.id} .toggle").click
94
+
95
+ page.should have_content("New York")
96
+ end
97
+ end
98
+
99
+ context "with auto expand option turned on" do
100
+ before do
101
+ Refinery::Pages.auto_expand_admin_tree = true
102
+
103
+ # Pre load pages
104
+ location
105
+ team
106
+
107
+ visit refinery.admin_pages_path
108
+ end
109
+
110
+ it "shows children" do
111
+ page.should have_content(team.title)
112
+ page.should have_content(locations.title)
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ describe "new/create" do
119
+ it "allows to create page" do
120
+ visit refinery.admin_pages_path
121
+
122
+ click_link "Add new page"
123
+
124
+ fill_in "Title", :with => "My first page"
125
+ click_button "Save"
126
+
127
+ page.should have_content("'My first page' was successfully added.")
128
+
129
+ page.body.should =~ /Remove this page forever/
130
+ page.body.should =~ /Edit this page/
131
+ page.body.should =~ %r{/refinery/pages/my-first-page/edit}
132
+ page.body.should =~ /Add a new child page/
133
+ page.body.should =~ %r{/refinery/pages/new\?parent_id=}
134
+ page.body.should =~ /View this page live/
135
+ page.body.should =~ %r{/pages/my-first-page}
136
+
137
+ Refinery::Page.count.should == 1
138
+ end
139
+
140
+ it "includes menu title field" do
141
+ visit refinery.new_admin_page_path
142
+
143
+ fill_in "Title", :with => "My first page"
144
+ fill_in "Menu title", :with => "The first page"
145
+
146
+ click_button "Save"
147
+
148
+ page.should have_content("'My first page' was successfully added.")
149
+ page.body.should =~ %r{/pages/the-first-page}
150
+ end
151
+ end
152
+
153
+ describe "edit/update" do
154
+ before(:each) { FactoryGirl.create(:page, :title => "Update me") }
155
+
156
+ it "updates page" do
157
+ visit refinery.admin_pages_path
158
+
159
+ page.should have_content("Update me")
160
+
161
+ click_link "Edit this page"
162
+
163
+ fill_in "Title", :with => "Updated"
164
+ click_button "Save"
165
+
166
+ page.should have_content("'Updated' was successfully updated.")
167
+ end
168
+ end
169
+
170
+ describe 'Previewing' do
171
+ context "an existing page" do
172
+ before(:each) { FactoryGirl.create(:page, :title => 'Preview me') }
173
+
174
+ it 'will show the preview changes in a new window', :js => true do
175
+ visit refinery.admin_pages_path
176
+
177
+ find('a[tooltip^=Edit]').click
178
+ fill_in "Title", :with => "Some changes I'm unsure what they will look like"
179
+ click_button "Preview"
180
+
181
+ new_window_should_have_content("Some changes I'm unsure what they will look like")
182
+ end
183
+
184
+ it 'will not save the preview changes', :js => true do
185
+ visit refinery.admin_pages_path
186
+
187
+ find('a[tooltip^=Edit]').click
188
+ fill_in "Title", :with => "Some changes I'm unsure what they will look like"
189
+ click_button "Preview"
190
+
191
+ new_window_should_have_content("Some changes I'm unsure what they will look like")
192
+
193
+ Page.by_title("Some changes I'm unsure what they will look like").should be_empty
194
+ end
195
+
196
+ end
197
+
198
+ context 'a brand new page' do
199
+ it "will not save when just previewing", :js => true do
200
+ visit refinery.admin_pages_path
201
+
202
+ click_link "Add new page"
203
+ fill_in "Title", :with => "My first page"
204
+ click_button "Preview"
205
+
206
+ new_window_should_have_content("My first page")
207
+
208
+ Page.count.should == 0
209
+ end
210
+ end
211
+
212
+ context 'a nested page' do
213
+ let!(:parent_page) { FactoryGirl.create(:page, :title => "Our Parent Page") }
214
+ let!(:nested_page) { FactoryGirl.create(:page, :parent => @parent, :title => 'Preview Me') }
215
+
216
+ it "works like an un-nested page", :js => true do
217
+ visit refinery.admin_pages_path
218
+
219
+ within "#page_#{nested_page.id}" do
220
+ find('a[tooltip^=Edit]').click
221
+ end
222
+
223
+ fill_in "Title", :with => "Some changes I'm unsure what they will look like"
224
+ click_button "Preview"
225
+
226
+ new_window_should_have_content("Some changes I'm unsure what they will look like")
227
+ end
228
+ end
229
+ end
230
+
231
+ describe "destroy" do
232
+ context "when page can be deleted" do
233
+ before(:each) { FactoryGirl.create(:page, :title => "Delete me") }
234
+
235
+ it "will show delete button" do
236
+ visit refinery.admin_pages_path
237
+
238
+ click_link "Remove this page forever"
239
+
240
+ page.should have_content("'Delete me' was successfully removed.")
241
+
242
+ Refinery::Page.count.should == 0
243
+ end
244
+ end
245
+
246
+ context "when page can't be deleted" do
247
+ before(:each) { FactoryGirl.create(:page, :title => "Indestructible", :deletable => false) }
248
+
249
+ it "wont show delete button" do
250
+ visit refinery.admin_pages_path
251
+
252
+ page.should have_no_content("Remove this page forever")
253
+ page.should have_no_selector("a[href='/refinery/pages/indestructible']")
254
+ end
255
+ end
256
+ end
257
+
258
+ context "duplicate page titles" do
259
+ before(:each) { FactoryGirl.create(:page, :title => "I was here first") }
260
+
261
+ it "will append nr to url path" do
262
+ visit refinery.new_admin_page_path
263
+
264
+ fill_in "Title", :with => "I was here first"
265
+ click_button "Save"
266
+
267
+ Refinery::Page.last.url[:path].should == ["i-was-here-first--2"]
268
+ end
269
+ end
270
+
271
+ context "with translations" do
272
+ before(:each) do
273
+ Refinery::I18n.stub(:frontend_locales).and_return([:en, :ru])
274
+
275
+ # Create a home page in both locales (needed to test menus)
276
+ home_page = FactoryGirl.create(:page, :title => 'Home',
277
+ :link_url => '/',
278
+ :menu_match => "^/$")
279
+ Globalize.locale = :ru
280
+ home_page.title = 'Домашняя страница'
281
+ home_page.save
282
+ Globalize.locale = :en
283
+ end
284
+
285
+ describe "add a page with title for default locale" do
286
+ before do
287
+ visit refinery.admin_pages_path
288
+ click_link "Add new page"
289
+ fill_in "Title", :with => "News"
290
+ click_button "Save"
291
+ end
292
+
293
+ it "succeeds" do
294
+ page.should have_content("'News' was successfully added.")
295
+ Refinery::Page.count.should == 2
296
+ end
297
+
298
+ it "shows locale flag for page" do
299
+ p = ::Refinery::Page.by_slug('news').first
300
+ within "#page_#{p.id}" do
301
+ page.should have_css("img[src='/assets/refinery/icons/flags/en.png']")
302
+ end
303
+ end
304
+
305
+ it "shows title in the admin menu" do
306
+ p = ::Refinery::Page.by_slug('news').first
307
+ within "#page_#{p.id}" do
308
+ page.should have_content('News')
309
+ page.find_link('Edit this page')[:href].should include('news')
310
+ end
311
+ end
312
+
313
+ it "shows in frontend menu for 'en' locale" do
314
+ visit "/"
315
+
316
+ within "#menu" do
317
+ page.should have_content('News')
318
+ page.should have_css('a', :href => 'news')
319
+ end
320
+ end
321
+
322
+ it "doesn't show in frontend menu for 'ru' locale" do
323
+ visit "/ru"
324
+
325
+ within "#menu" do
326
+ # we should only have the home page in the menu
327
+ page.should have_css('li', :count => 1)
328
+ end
329
+ end
330
+ end
331
+
332
+ describe "add a page with title for both locales" do
333
+ let(:en_page_title) { 'News' }
334
+ let(:en_page_slug) { 'news' }
335
+ let(:ru_page_title) { 'Новости' }
336
+ let(:ru_page_slug) { 'новости' }
337
+ let(:ru_page_slug_encoded) { '%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8' }
338
+ let!(:news_page) do
339
+ Refinery::I18n.stub(:frontend_locales).and_return([:en, :ru])
340
+
341
+ _page = Globalize.with_locale(:en) {
342
+ FactoryGirl.create(:page, :title => en_page_title)
343
+ }
344
+ Globalize.with_locale(:ru) do
345
+ _page.title = ru_page_title
346
+ _page.save
347
+ end
348
+
349
+ _page
350
+ end
351
+
352
+ it "succeeds" do
353
+ news_page.destroy!
354
+ visit refinery.admin_pages_path
355
+
356
+ click_link "Add new page"
357
+ within "#switch_locale_picker" do
358
+ click_link "Ru"
359
+ end
360
+ fill_in "Title", :with => ru_page_title
361
+ click_button "Save"
362
+
363
+ within "#page_#{Page.last.id}" do
364
+ click_link "Application_edit"
365
+ end
366
+ within "#switch_locale_picker" do
367
+ click_link "En"
368
+ end
369
+ fill_in "Title", :with => en_page_title
370
+ click_button "Save"
371
+
372
+ page.should have_content("'#{en_page_title}' was successfully updated.")
373
+ Refinery::Page.count.should == 2
374
+ end
375
+
376
+ it "shows both locale flags for page" do
377
+ visit refinery.admin_pages_path
378
+
379
+ within "#page_#{news_page.id}" do
380
+ page.should have_css("img[src='/assets/refinery/icons/flags/en.png']")
381
+ page.should have_css("img[src='/assets/refinery/icons/flags/ru.png']")
382
+ end
383
+ end
384
+
385
+ it "shows title in admin menu in current admin locale" do
386
+ visit refinery.admin_pages_path
387
+
388
+ within "#page_#{news_page.id}" do
389
+ page.should have_content(en_page_title)
390
+ end
391
+ end
392
+
393
+ it "uses the slug from the default locale in admin" do
394
+ visit refinery.admin_pages_path
395
+
396
+ within "#page_#{news_page.id}" do
397
+ page.find_link('Edit this page')[:href].should include(en_page_slug)
398
+ end
399
+ end
400
+
401
+ it "shows correct language and slugs for default locale" do
402
+ visit "/"
403
+
404
+ within "#menu" do
405
+ page.find_link(news_page.title)[:href].should include(en_page_slug)
406
+ end
407
+ end
408
+
409
+ it "shows correct language and slugs for second locale" do
410
+ visit "/ru"
411
+
412
+ within "#menu" do
413
+ page.find_link(ru_page_title)[:href].should include(ru_page_slug_encoded)
414
+ end
415
+ end
416
+ end
417
+
418
+ describe "add a page with title only for secondary locale" do
419
+ let(:ru_page) {
420
+ Globalize.with_locale(:ru) {
421
+ FactoryGirl.create(:page, :title => ru_page_title)
422
+ }
423
+ }
424
+ let(:ru_page_id) { ru_page.id }
425
+ let(:ru_page_title) { 'Новости' }
426
+ let(:ru_page_slug) { 'новости' }
427
+
428
+ before(:each) do
429
+ ru_page
430
+ visit refinery.admin_pages_path
431
+ end
432
+
433
+ it "succeeds" do
434
+ ru_page.destroy!
435
+ click_link "Add new page"
436
+ within "#switch_locale_picker" do
437
+ click_link "Ru"
438
+ end
439
+ fill_in "Title", :with => ru_page_title
440
+ click_button "Save"
441
+
442
+ page.should have_content("'#{ru_page_title}' was successfully added.")
443
+ Refinery::Page.count.should == 2
444
+ end
445
+
446
+ it "shows locale flag for page" do
447
+ within "#page_#{ru_page_id}" do
448
+ page.should have_css("img[src='/assets/refinery/icons/flags/ru.png']")
449
+ end
450
+ end
451
+
452
+ it "doesn't show locale flag for primary locale" do
453
+ within "#page_#{ru_page_id}" do
454
+ page.should_not have_css("img[src='/assets/refinery/icons/flags/en.png']")
455
+ end
456
+ end
457
+
458
+ it "shows title in the admin menu" do
459
+ within "#page_#{ru_page_id}" do
460
+ page.should have_content(ru_page_title)
461
+ end
462
+ end
463
+
464
+ it "uses id instead of slug in admin" do
465
+ within "#page_#{ru_page_id}" do
466
+ page.find_link('Edit this page')[:href].should include(ru_page_id.to_s)
467
+ end
468
+ end
469
+
470
+ it "shows in frontend menu for 'ru' locale" do
471
+ visit "/ru"
472
+
473
+ within "#menu" do
474
+ page.should have_content(ru_page_title)
475
+ page.should have_css('a', :href => ru_page_slug)
476
+ end
477
+ end
478
+
479
+ it "won't show in frontend menu for 'en' locale" do
480
+ visit "/"
481
+
482
+ within "#menu" do
483
+ # we should only have the home page in the menu
484
+ page.should have_css('li', :count => 1)
485
+ end
486
+ end
487
+ end
488
+ end
489
+
490
+ describe "new page part", :js => true do
491
+ before do
492
+ Refinery::Pages.stub(:new_page_parts).and_return(true)
493
+ end
494
+
495
+ it "adds new page part" do
496
+ visit refinery.new_admin_page_path
497
+ click_link "add_page_part"
498
+
499
+ within "#new_page_part_dialog" do
500
+ fill_in "new_page_part_title", :with => "testy"
501
+ click_button "Save"
502
+ end
503
+
504
+ within "#page_parts" do
505
+ page.should have_content("testy")
506
+ end
507
+ end
508
+ end
509
+ end
510
+
511
+ describe "TranslatePages" do
512
+ login_refinery_translator
513
+
514
+ describe "add page to main locale" do
515
+ it "doesn't succeed" do
516
+ visit refinery.admin_pages_path
517
+
518
+ click_link "Add new page"
519
+
520
+ fill_in "Title", :with => "Huh?"
521
+ click_button "Save"
522
+
523
+ page.should have_content("You do not have the required permission to modify pages in this language")
524
+ end
525
+ end
526
+
527
+ describe "add page to second locale" do
528
+ before(:each) do
529
+ Refinery::I18n.stub(:frontend_locales).and_return([:en, :lv])
530
+ FactoryGirl.create(:page)
531
+ end
532
+
533
+ it "succeeds" do
534
+ visit refinery.admin_pages_path
535
+
536
+ click_link "Add new page"
537
+
538
+ within "#switch_locale_picker" do
539
+ click_link "Lv"
540
+ end
541
+ fill_in "Title", :with => "Brīva vieta reklāmai"
542
+ click_button "Save"
543
+
544
+ page.should have_content("'Brīva vieta reklāmai' was successfully added.")
545
+ Refinery::Page.count.should == 2
546
+ end
547
+ end
548
+
549
+ describe "delete page from main locale" do
550
+ before(:each) { FactoryGirl.create(:page) }
551
+
552
+ it "doesn't succeed" do
553
+ visit refinery.admin_pages_path
554
+
555
+ click_link "Remove this page forever"
556
+
557
+ page.should have_content("You do not have the required permission to modify pages in this language.")
558
+ Refinery::Page.count.should == 1
559
+ end
560
+ end
561
+
562
+ describe "Pages Link-to Dialog" do
563
+ before do
564
+ Refinery::I18n.frontend_locales = [:en, :ru]
565
+
566
+ # Create a page in both locales
567
+ about_page = FactoryGirl.create(:page, :title => 'About')
568
+ Globalize.locale = :ru
569
+ about_page.title = 'About Ru'
570
+ about_page.save
571
+ Globalize.locale = :en
572
+ end
573
+
574
+ describe "adding page link" do
575
+ describe "with relative urls" do
576
+ before(:each) { Refinery::Pages.absolute_page_links = false }
577
+
578
+ it "shows Russian pages if we're editing the Russian locale" do
579
+ visit 'refinery/pages_dialogs/link_to?wymeditor=true&switch_locale=ru'
580
+
581
+ page.should have_content("About Ru")
582
+ page.should have_selector("a[href='/ru/about-ru']")
583
+ end
584
+
585
+ it "shows default to the default locale if no query string is added" do
586
+ visit 'refinery/pages_dialogs/link_to?wymeditor=true'
587
+
588
+ page.should have_content("About")
589
+ page.should have_selector("a[href='/about']")
590
+ end
591
+ end
592
+ describe "with absolute urls" do
593
+ before(:each) { Refinery::Pages.absolute_page_links = true }
594
+
595
+ it "shows Russian pages if we're editing the Russian locale" do
596
+ visit 'refinery/pages_dialogs/link_to?wymeditor=true&switch_locale=ru'
597
+
598
+ page.should have_content("About Ru")
599
+ page.should have_selector("a[href='http://www.example.com/ru/about-ru']")
600
+ end
601
+
602
+ it "shows default to the default locale if no query string is added" do
603
+ visit 'refinery/pages_dialogs/link_to?wymeditor=true'
604
+
605
+ page.should have_content("About")
606
+ page.should have_selector("a[href='http://www.example.com/about']")
607
+ end
608
+ end
609
+ end
610
+ end
611
+ end
612
+ end
613
+ end