refinerycms-pages 4.0.3 → 4.1.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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/refinery/admin/page_parts_controller.rb +2 -1
  3. data/app/controllers/refinery/admin/pages_controller.rb +12 -11
  4. data/app/controllers/refinery/admin/pages_dialogs_controller.rb +8 -8
  5. data/app/controllers/refinery/pages/admin/preview_controller.rb +7 -0
  6. data/app/controllers/refinery/pages_controller.rb +4 -1
  7. data/app/helpers/refinery/admin/pages_helper.rb +29 -7
  8. data/app/models/refinery/page.rb +39 -51
  9. data/app/models/refinery/page_part.rb +12 -6
  10. data/app/presenters/refinery/pages/menu_presenter.rb +2 -2
  11. data/app/views/refinery/admin/pages/_form.html.erb +10 -10
  12. data/app/views/refinery/admin/pages/_page.html.erb +17 -45
  13. data/app/views/refinery/admin/pages/_sortable_list.html.erb +1 -1
  14. data/app/views/refinery/admin/pages/children.html.erb +1 -1
  15. data/app/views/refinery/admin/pages_dialogs/_page_link.html.erb +1 -1
  16. data/app/views/refinery/admin/pages_dialogs/link_to.html.erb +28 -21
  17. data/config/locales/en.yml +3 -3
  18. data/config/locales/sk.yml +4 -2
  19. data/db/migrate/20100913234708_create_refinerycms_pages_schema.rb +27 -30
  20. data/db/seeds.rb +1 -1
  21. data/lib/generators/refinery/pages/pages_generator.rb +1 -1
  22. data/lib/generators/refinery/pages/templates/config/initializers/refinery/pages.rb.erb +10 -3
  23. data/lib/refinery/pages/configuration.rb +8 -5
  24. data/lib/refinery/pages/engine.rb +2 -1
  25. data/lib/refinery/pages/finder.rb +95 -96
  26. data/lib/refinery/pages/instance_methods.rb +6 -4
  27. data/lib/refinery/pages.rb +3 -3
  28. data/lib/refinerycms/pages.rb +1 -0
  29. data/refinerycms-pages.gemspec +16 -22
  30. data/spec/controllers/refinery/pages_controller_spec.rb +23 -6
  31. data/spec/factories/page_parts.rb +2 -2
  32. data/spec/helpers/refinery/pages/admin/pages_helper_spec.rb +8 -18
  33. data/spec/models/refinery/page_menu_spec.rb +2 -2
  34. data/spec/models/refinery/page_url_spec.rb +4 -4
  35. data/spec/support/refinery/pages/caching_helpers.rb +1 -1
  36. data/spec/support/selector_helpers.rb +43 -0
  37. data/spec/{features → system}/refinery/admin/pages_spec.rb +164 -155
  38. data/spec/{features → system}/refinery/pages_spec.rb +10 -10
  39. metadata +48 -106
  40. checksums.yaml.gz.sig +0 -0
  41. data.tar.gz.sig +0 -0
  42. metadata.gz.sig +0 -0
@@ -15,16 +15,16 @@ end
15
15
 
16
16
  def switch_page_form_locale(locale)
17
17
  within "#switch_locale_picker" do
18
- find("a", text: locale.upcase).click
18
+ find("a", id: locale.downcase).click
19
19
  end
20
20
 
21
21
  # make sure that the locale change has taken effect
22
- expect(page).to have_selector("#switch_locale_picker li.selected a##{locale.downcase}")
22
+ expect(page).to have_selector("#switch_locale_picker a.selected##{locale.downcase}")
23
23
  end
24
24
 
25
25
  module Refinery
26
26
  module Admin
27
- describe "Pages", :type => :feature do
27
+ describe "Pages", type: :system do
28
28
  refinery_login
29
29
 
30
30
  context "when no pages" do
@@ -45,6 +45,7 @@ module Refinery
45
45
  end
46
46
 
47
47
  context "when no pages" do
48
+
48
49
  it "doesn't show reorder pages link" do
49
50
  visit refinery.admin_pages_path
50
51
 
@@ -86,15 +87,14 @@ module Refinery
86
87
  end
87
88
 
88
89
  context "when sub pages exist" do
89
- let!(:company) { Page.create :title => 'Our Company' }
90
- let!(:team) { company.children.create :title => 'Our Team' }
91
- let!(:locations) { company.children.create :title => 'Our Locations' }
92
- let!(:location) { locations.children.create :title => 'New York' }
90
+ let!(:company) { Page.create title: 'Our Company' }
91
+ let!(:team) { company.children.create title: 'Our Team' }
92
+ let!(:locations) { company.children.create title: 'Our Locations' }
93
+ let!(:location) { locations.children.create title: 'New York' }
93
94
 
94
95
  context "with auto expand option turned off" do
95
96
  before do
96
97
  allow(Refinery::Pages).to receive(:auto_expand_admin_tree).and_return(false)
97
-
98
98
  visit refinery.admin_pages_path
99
99
  end
100
100
 
@@ -109,15 +109,15 @@ module Refinery
109
109
  end
110
110
 
111
111
  it "expands children", js: true do
112
- find("#page_#{company.id} .title.toggle").click
112
+ find("#page_#{company.id} .icon.toggle").click
113
113
 
114
114
  expect(page).to have_content(team.title)
115
115
  expect(page).to have_content(locations.title)
116
116
  end
117
117
 
118
118
  it "expands children when nested multiple levels deep", js: true do
119
- find("#page_#{company.id} .title.toggle").click
120
- find("#page_#{locations.id} .title.toggle").click
119
+ find("#page_#{company.id} .icon.toggle").click
120
+ find("#page_#{locations.id} .icon.toggle").click
121
121
 
122
122
  expect(page).to have_content("New York")
123
123
  end
@@ -125,8 +125,8 @@ module Refinery
125
125
 
126
126
  context "with auto expand option turned on" do
127
127
  before do
128
- allow(Refinery::Pages).to receive(:auto_expand_admin_tree).and_return(true)
129
-
128
+ Refinery::Pages.auto_expand_admin_tree = true
129
+ Rails.cache.clear
130
130
  visit refinery.admin_pages_path
131
131
  end
132
132
 
@@ -134,17 +134,27 @@ module Refinery
134
134
  expect(page).to have_content(team.title)
135
135
  expect(page).to have_content(locations.title)
136
136
  end
137
+
138
+ it "refreshes the cache if sub_children change", js: true do
139
+ expect(page).to have_content(location.title)
140
+
141
+ within page.find("#page_#{location.id}") do
142
+ first(title_link_selector).click
143
+ end
144
+
145
+ fill_in "page_title", with: 'Las Vegas'
146
+ click_button "Save"
147
+ expect(page).to have_content('Las Vegas')
148
+ end
137
149
  end
138
150
  end
139
151
  end
140
152
 
141
- describe "new/create" do
142
- it "Creates a page", js:true do
153
+ describe " new / create " do
154
+ it " Creates a page ", js: true do
143
155
  visit refinery.admin_pages_path
144
-
145
- find('a', text: 'Add new page').trigger(:click)
146
-
147
- fill_in "Title", :with => "My first page"
156
+ find('a', text: 'Add new page').click
157
+ fill_in "Title", with: "My first page"
148
158
  expect { click_button "Save" }.to change(Refinery::Page, :count).from(0).to(1)
149
159
 
150
160
  expect(page).to have_content("'My first page' was successfully added.")
@@ -161,11 +171,11 @@ module Refinery
161
171
  it "includes menu title field", js: true do
162
172
  visit refinery.new_admin_page_path
163
173
 
164
- fill_in "Title", :with => "My first page"
174
+ fill_in "Title", with: "My first page"
165
175
 
166
- find('#toggle_advanced_options').trigger(:click)
176
+ find('#toggle_advanced_options').click
167
177
 
168
- fill_in "Menu title", :with => "The first page"
178
+ fill_in "Menu title", with: "The first page"
169
179
 
170
180
  # For some reason the first click doesn't always work?
171
181
  begin
@@ -179,13 +189,13 @@ module Refinery
179
189
  end
180
190
 
181
191
  it "allows to easily create nested page" do
182
- parent_page = Page.create! :title => "Rails 4"
192
+ parent_page = Page.create! title: "Rails 4"
183
193
 
184
194
  visit refinery.admin_pages_path
185
195
 
186
- find("a[href='#{refinery.new_admin_page_path(:parent_id => parent_page.id)}']").click
196
+ find("a[href='#{refinery.new_admin_page_path(parent_id: parent_page.id)}']").click
187
197
 
188
- fill_in "Title", :with => "Parent page"
198
+ fill_in "Title", with: "Parent page"
189
199
  click_button "Save"
190
200
 
191
201
  expect(page).to have_content("'Parent page' was successfully added.")
@@ -205,9 +215,9 @@ module Refinery
205
215
 
206
216
  context 'when saving and returning to index' do
207
217
  it "updates page", js: true do
208
- find("a[href$='#{updateable_page.slug}/edit']").trigger(:click)
218
+ first(edit_selector(slug: updateable_page.slug)).click
209
219
 
210
- fill_in "Title", :with => "Updated"
220
+ fill_in "Title", with: "Updated"
211
221
  find("#submit_button").click
212
222
 
213
223
  expect(page).to have_content("'Updated' was successfully updated.")
@@ -216,10 +226,10 @@ module Refinery
216
226
 
217
227
  context 'when saving and continuing to edit', js: true do
218
228
  before :each do
219
- expect(page).to have_selector("a[href$='#{updateable_page.slug}/edit']", visible: true)
220
- find("a[href$='#{updateable_page.slug}/edit']").click
229
+ expect(page).to have_selector(edit_selector(slug: updateable_page.slug), visible: true)
230
+ first(edit_selector(slug: updateable_page.slug)).click
221
231
 
222
- fill_in "Title", :with => "Updated you"
232
+ fill_in "Title", with: "Updated you"
223
233
  find("#submit_continue_button").click
224
234
  find('#flash').visible?
225
235
  end
@@ -249,12 +259,12 @@ module Refinery
249
259
  describe 'Previewing', js: true do
250
260
  let(:preview_content) { "Some changes I'm unsure what they will look like".freeze }
251
261
  context "an existing page" do
252
- before { Page.create :title => 'Preview me' }
262
+ before { Page.create title: 'Preview me' }
253
263
 
254
264
  it 'will show the preview changes in a new window' do
255
265
  visit refinery.admin_pages_path
256
266
 
257
- find('a[tooltip^=Edit]').click
267
+ first(edit_selector).click
258
268
  fill_in "Title", with: preview_content
259
269
  window = window_opened_by do
260
270
  click_button "Preview"
@@ -268,7 +278,7 @@ module Refinery
268
278
  it 'will not show the site bar' do
269
279
  visit refinery.admin_pages_path
270
280
 
271
- find('a[tooltip^=Edit]').click
281
+ first(edit_selector).click
272
282
  fill_in "Title", with: preview_content
273
283
  window = window_opened_by do
274
284
  click_button "Preview"
@@ -277,11 +287,11 @@ module Refinery
277
287
  expect_window_without_content(
278
288
  ::I18n.t('switch_to_website', scope: 'refinery.site_bar'),
279
289
  window: window
280
- )
290
+ )
281
291
  expect_window_without_content(
282
292
  ::I18n.t('switch_to_website_editor', scope: 'refinery.site_bar'),
283
293
  window: window
284
- )
294
+ )
285
295
 
286
296
  window.close
287
297
  end
@@ -289,7 +299,7 @@ module Refinery
289
299
  it 'will not save the preview changes' do
290
300
  visit refinery.admin_pages_path
291
301
 
292
- find('a[tooltip^=Edit]').click
302
+ first(edit_selector).click
293
303
  fill_in "Title", with: preview_content
294
304
  window = window_opened_by do
295
305
  click_button "Preview"
@@ -298,7 +308,7 @@ module Refinery
298
308
  expect_window_with_content(
299
309
  preview_content,
300
310
  window: window
301
- )
311
+ )
302
312
 
303
313
  window.close
304
314
 
@@ -309,8 +319,8 @@ module Refinery
309
319
  it 'will show the preview in a new window after save-and-continue' do
310
320
  visit refinery.admin_pages_path
311
321
 
312
- find('a[tooltip^=Edit]').click
313
- fill_in "Title", :with => "Save this"
322
+ first(edit_selector).click
323
+ fill_in "Title", with: "Save this"
314
324
  click_button "Save & continue editing"
315
325
  expect(page).to have_content("'Save this' was successfully updated")
316
326
 
@@ -320,9 +330,9 @@ module Refinery
320
330
 
321
331
  expect_window_with_content("Save this", window: window)
322
332
  expect_window_without_content(
323
- ::I18n.t('switch_to_website', :scope => 'refinery.site_bar'),
333
+ ::I18n.t('switch_to_website', scope: 'refinery.site_bar'),
324
334
  window: window
325
- )
335
+ )
326
336
 
327
337
  window.close
328
338
  end
@@ -332,8 +342,8 @@ module Refinery
332
342
  it 'will save-and-continue after show the preview in a new window' do
333
343
  visit refinery.admin_pages_path
334
344
 
335
- find('a[tooltip^=Edit]').click
336
- fill_in "Title", :with => "Save this"
345
+ first(title_link_selector).click
346
+ fill_in "Title", with: "Save this"
337
347
 
338
348
  window = window_opened_by do
339
349
  click_button "Preview"
@@ -341,23 +351,26 @@ module Refinery
341
351
 
342
352
  expect_window_with_content("Save this", window: window)
343
353
  expect_window_without_content(
344
- ::I18n.t('switch_to_website', :scope => 'refinery.site_bar'),
354
+ ::I18n.t('switch_to_website', scope: 'refinery.site_bar'),
345
355
  window: window
346
356
  )
347
357
 
348
358
  window.close
349
359
 
360
+ # Wait for JavaScript setTimeout to restore form action after preview
361
+ expect(page).to have_no_css("form[action*='/preview/']", wait: 1)
362
+
350
363
  click_button "Save & continue editing"
351
364
  expect(page).to have_content("'Save this' was successfully updated")
352
365
  end
353
366
 
354
- it 'will show pages with inherited templates', js:true do
367
+ it 'will show pages with inherited templates', js: true do
355
368
  visit refinery.admin_pages_path
356
369
 
357
- find('a[tooltip^=Edit]').click
358
- fill_in 'Title', :with => 'Searchable'
359
- find('#toggle_advanced_options').trigger(:click)
360
- select 'Searchable', :from => 'View template'
370
+ first(edit_selector).click
371
+ fill_in 'Title', with: 'Searchable'
372
+ find('#toggle_advanced_options').click
373
+ select 'Searchable', from: 'View template'
361
374
  Timeout::timeout(5) do
362
375
  click_button 'Preview'
363
376
  sleep 0.1 and redo unless windows.many?
@@ -367,11 +380,11 @@ module Refinery
367
380
  end
368
381
 
369
382
  context 'a brand new page' do
370
- it "will not save when just previewing", js:true do
383
+ it "will not save when just previewing", js: true do
371
384
  visit refinery.admin_pages_path
372
385
 
373
- find('a', text: 'Add new page').trigger(:click)
374
- fill_in "Title", :with => "My first page"
386
+ find('a', text: 'Add new page').click
387
+ fill_in "Title", with: "My first page"
375
388
  window = window_opened_by do
376
389
  click_button "Preview"
377
390
  end
@@ -384,34 +397,36 @@ module Refinery
384
397
  end
385
398
 
386
399
  context 'a nested page' do
387
- let!(:parent_page) { Page.create :title => "Our Parent Page" }
388
- let!(:nested_page) { parent_page.children.create :title => 'Preview Me' }
400
+ let!(:parent_page) { Page.create title: "Our Parent Page" }
401
+ let!(:nested_page) { parent_page.children.create title: 'Preview Me' }
389
402
 
390
- it "works like an un-nested page" do
403
+ it "works like an un-nested page", js: true do
391
404
  visit refinery.admin_pages_path
392
405
 
393
- within "#page_#{nested_page.id}" do
394
- find('a[tooltip^=Edit]').click
406
+ within "#page_#{nested_page.id} .item" do
407
+ first(title_link_selector).click
395
408
  end
396
409
 
397
410
  fill_in "Title", with: preview_content
398
- window = window_opened_by do
411
+ window = page.window_opened_by do
399
412
  click_button "Preview"
400
413
  end
401
414
 
402
- expect_window_with_content(preview_content)
415
+ expect_window_with_content(preview_content, window: window)
403
416
  end
404
417
  end
405
418
  end
406
419
 
407
420
  describe "destroy" do
408
- context "when page can be deleted", js:true do
409
- before { Page.create :title => "Delete me" }
421
+ context "when page can be deleted", js: true do
422
+ before { Page.create title: "Delete me" }
410
423
 
411
424
  it "will show delete button" do
412
425
  visit refinery.admin_pages_path
413
426
 
414
- find('a[tooltip="Remove this page forever"]').trigger(:click)
427
+ find('a[tooltip="Remove this page forever"]').click
428
+
429
+ page.accept_alert
415
430
 
416
431
  expect(page).to have_content("'Delete me' was successfully removed.")
417
432
 
@@ -420,7 +435,7 @@ module Refinery
420
435
  end
421
436
 
422
437
  context "when page can't be deleted" do
423
- before { Page.create :title => "Indestructible", :deletable => false }
438
+ before { Page.create title: "Indestructible", deletable: false }
424
439
 
425
440
  it "wont show delete button" do
426
441
  visit refinery.admin_pages_path
@@ -432,12 +447,12 @@ module Refinery
432
447
  end
433
448
 
434
449
  context "duplicate page titles" do
435
- before { Page.create :title => "I was here first" }
450
+ before { Page.create title: "I was here first" }
436
451
 
437
452
  it "will append nr to url path" do
438
453
  visit refinery.new_admin_page_path
439
454
 
440
- fill_in "Title", :with => "I was here first"
455
+ fill_in "Title", with: "I was here first"
441
456
  click_button "Save"
442
457
 
443
458
  expect(Refinery::Page.last.url[:path].first).to match(%r{\Ai-was-here-first-.+?})
@@ -447,25 +462,27 @@ module Refinery
447
462
  context "with translations" do
448
463
  before do
449
464
  allow(Refinery::I18n).to receive(:frontend_locales).and_return([:en, :ru])
465
+ end
450
466
 
467
+ before do
451
468
  # Create a home page in both locales (needed to test menus)
452
- home_page = Globalize.with_locale(:en) do
453
- Page.create :title => 'Home',
454
- :link_url => '/',
455
- :menu_match => "^/$"
469
+ home_page = Mobility.with_locale(:en) do
470
+ Page.create title: 'Home',
471
+ link_url: '/',
472
+ menu_match: "^/$"
456
473
  end
457
474
 
458
- Globalize.with_locale(:ru) do
475
+ Mobility.with_locale(:ru) do
459
476
  home_page.title = 'Домашняя страница'
460
477
  home_page.save
461
478
  end
462
479
  end
463
480
 
464
- describe "add a page with title for default locale", js:true do
481
+ describe "add a page with title for default locale", js: true do
465
482
  before do
466
483
  visit refinery.admin_pages_path
467
- find('a', text: "Add new page").trigger(:click)
468
- fill_in "Title", :with => "News"
484
+ find('a', text: "Add new page").click
485
+ fill_in "Title", with: "News"
469
486
  click_button "Save"
470
487
  end
471
488
 
@@ -474,24 +491,21 @@ module Refinery
474
491
  expect(Refinery::Page.count).to eq(2)
475
492
  end
476
493
 
477
- it "shows locale flag for page" do
478
- p = ::Refinery::Page.by_slug('news').first
479
- within "#page_#{p.id} .locales" do
480
- expect(page).to have_css('.locale_marker')
481
- expect(page).to have_content('EN')
494
+ it "doesn't show locale for default frontend locale" do
495
+ within "#page_#{::Refinery::Page.by_slug('news').first.id}" do
496
+ expect(page).not_to have_selector(".locales")
497
+ expect(page).not_to have_selector(locale_link_selector(locale: 'en'))
482
498
  end
483
499
  end
484
500
 
485
501
  it "shows title in the admin menu" do
486
- p = ::Refinery::Page.by_slug('news').first
487
- within "#page_#{p.id}" do
502
+ within "#page_#{::Refinery::Page.by_slug('news').first.id}" do
488
503
  expect(page).to have_content('News')
489
- expect(page.find('a[tooltip="Edit this page"]')[:href]).to include('news')
504
+ expect(page.first(title_link_selector)[:text]).to have_content('News')
490
505
  end
491
506
  end
492
507
 
493
508
  it "shows in frontend menu for 'en' locale" do
494
- # page.driver.debug
495
509
  visit "/"
496
510
 
497
511
  within "#menu" do
@@ -505,7 +519,7 @@ module Refinery
505
519
 
506
520
  within "#menu" do
507
521
  # we should only have the home page in the menu
508
- expect(page).to have_css('li', :count => 1)
522
+ expect(page).to have_css('li', count: 1)
509
523
  end
510
524
  end
511
525
  end
@@ -516,17 +530,12 @@ module Refinery
516
530
  let(:ru_page_title) { 'Новости' }
517
531
  let(:ru_page_slug_encoded) { '%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8' }
518
532
  let!(:news_page) do
519
- allow(Refinery::I18n).to receive(:frontend_locales).and_return([:en, :ru])
520
-
521
- _page = Globalize.with_locale(:en) {
522
- Page.create :title => en_page_title
523
- }
524
- Globalize.with_locale(:ru) do
525
- _page.title = ru_page_title
526
- _page.save
533
+ Mobility.with_locale(:en) { Page.create(title: en_page_title) }.tap do |localised_page|
534
+ Mobility.with_locale(:ru) do
535
+ localised_page.title = ru_page_title
536
+ localised_page.save
537
+ end
527
538
  end
528
-
529
- _page
530
539
  end
531
540
 
532
541
  it "can have a title for each locale" do
@@ -536,7 +545,7 @@ module Refinery
536
545
  click_link "Add new page"
537
546
  switch_page_form_locale "RU"
538
547
 
539
- fill_in "Title", :with => ru_page_title
548
+ fill_in "Title", with: ru_page_title
540
549
  click_button "Save"
541
550
  expect(page).to have_selector("#page_#{Page.last.id} .actions")
542
551
 
@@ -545,20 +554,23 @@ module Refinery
545
554
  end
546
555
 
547
556
  switch_page_form_locale "EN"
548
- fill_in "Title", :with => en_page_title
557
+ fill_in "Title", with: en_page_title
549
558
  find("#submit_button").click
550
559
 
551
560
  expect(page).to have_content("'#{en_page_title}' was successfully updated.")
552
561
  expect(Refinery::Page.count).to eq(2)
553
562
  end
554
563
 
555
- it "is shown with both locales in the index" do
564
+ it "is shown with only the non-default locale in the index" do
556
565
  visit refinery.admin_pages_path
557
566
 
558
- within "#page_#{news_page.id} .locales" do
559
- expect(page).to have_css('.locale_marker', count: 2)
560
- expect(page).to have_content('EN')
561
- expect(page).to have_content('RU')
567
+ within "#page_#{news_page.id}" do
568
+ expect(page).to have_selector(".locales")
569
+
570
+ within ".locales" do
571
+ expect(page).to have_selector(locale_link_selector(locale: 'ru'))
572
+ expect(page).to have_no_selector(locale_link_selector(locale: 'en'))
573
+ end
562
574
  end
563
575
  end
564
576
 
@@ -574,7 +586,7 @@ module Refinery
574
586
  visit refinery.admin_pages_path
575
587
 
576
588
  within "#page_#{news_page.id}" do
577
- expect(page.find('a[tooltip="Edit this page"]')[:href]).to include(en_page_slug)
589
+ expect(page.first(title_link_selector)[:href]).to match(en_page_slug)
578
590
  end
579
591
  end
580
592
 
@@ -595,10 +607,10 @@ module Refinery
595
607
  end
596
608
  end
597
609
 
598
- describe "add a page with title only for secondary locale", js:true do
610
+ describe "add a page with title only for secondary locale", js: true do
599
611
  let(:ru_page) {
600
- Globalize.with_locale(:ru) {
601
- Page.create :title => ru_page_title
612
+ Mobility.with_locale(:ru) {
613
+ Page.create title: ru_page_title
602
614
  }
603
615
  }
604
616
  let(:ru_page_id) { ru_page.id }
@@ -612,10 +624,10 @@ module Refinery
612
624
 
613
625
  it "lets you add a Russian title without an English title" do
614
626
  ru_page.destroy!
615
- find('a', text: 'Add new page').trigger(:click)
627
+ find('a', text: 'Add new page').click
616
628
  switch_page_form_locale "RU"
617
629
 
618
- fill_in "Title", :with => ru_page_title
630
+ fill_in "Title", with: ru_page_title
619
631
  click_button "Save"
620
632
 
621
633
  expect(page).to have_content("'#{ru_page_title}' was successfully added.")
@@ -624,13 +636,13 @@ module Refinery
624
636
 
625
637
  it "shows locale indicator for page" do
626
638
  within "#page_#{ru_page_id}" do
627
- expect(page).to have_selector('.locale_marker', text: 'RU')
639
+ expect(page).to have_selector(locale_link_selector(locale: 'ru'))
628
640
  end
629
641
  end
630
642
 
631
643
  it "doesn't show locale indicator for primary locale" do
632
644
  within "#page_#{ru_page_id}" do
633
- expect(page).to_not have_selector('.locale_marker', text: 'EN')
645
+ expect(page).to_not have_selector(locale_picker('en'))
634
646
  end
635
647
  end
636
648
 
@@ -640,9 +652,9 @@ module Refinery
640
652
  end
641
653
  end
642
654
 
643
- it "uses slug in admin" do
655
+ it "uses secondary locale slug in admin" do
644
656
  within "#page_#{ru_page_id}" do
645
- expect(page.find('a[tooltip="Edit this page"]')[:href]).to include(ru_page_slug_encoded)
657
+ expect(page.find(title_link_selector)[:href]).to match(ru_page_slug_encoded)
646
658
  end
647
659
  end
648
660
 
@@ -660,23 +672,23 @@ module Refinery
660
672
 
661
673
  within "#menu" do
662
674
  # we should only have the home page in the menu
663
- expect(page).to have_css('li', :count => 1)
675
+ expect(page).to have_css('li', count: 1)
664
676
  end
665
677
  end
666
678
 
667
679
  context "when page is a child page" do
668
680
  it 'succeeds' do
669
681
  ru_page.destroy!
670
- parent_page = Page.create(:title => "Parent page")
671
- sub_page = Globalize.with_locale(:ru) {
672
- Page.create :title => ru_page_title, :parent_id => parent_page.id
682
+ parent_page = Page.create(title: "Parent page")
683
+ sub_page = Mobility.with_locale(:ru) {
684
+ Page.create title: ru_page_title, parent_id: parent_page.id
673
685
  }
674
686
  expect(sub_page.parent).to eq(parent_page)
675
687
  visit refinery.admin_pages_path
676
688
  within "#page_#{sub_page.id}" do
677
- find("a.edit_icon").trigger(:click)
689
+ first(edit_selector).click
678
690
  end
679
- fill_in "Title", :with => ru_page_title
691
+ fill_in "Title", with: ru_page_title
680
692
  click_button "Save"
681
693
  expect(page).to have_content("'#{ru_page_title}' was successfully updated")
682
694
  end
@@ -691,10 +703,10 @@ module Refinery
691
703
 
692
704
  it "adds new page part", js: true do
693
705
  visit refinery.new_admin_page_path
694
- find("#add_page_part").trigger(:click)
706
+ find("#add_page_part").click
695
707
 
696
708
  within "#new_page_part_dialog" do
697
- fill_in "new_page_part_title", :with => "testy"
709
+ fill_in "new_page_part_title", with: "testy"
698
710
  click_button "Save"
699
711
  end
700
712
 
@@ -705,12 +717,12 @@ module Refinery
705
717
  end
706
718
 
707
719
  describe "delete existing page part" do
708
- let!(:some_page) { Page.create! :title => "Some Page" }
720
+ let!(:some_page) { Page.create! title: "Some Page" }
709
721
 
710
722
  before do
711
- some_page.parts.create! :title => "First Part", :slug => "first_part", :position => 1
712
- some_page.parts.create! :title => "Second Part", :slug => "second_part", :position => 2
713
- some_page.parts.create! :title => "Third Part", :slug => "third_part", :position => 3
723
+ some_page.parts.create! title: "First Part", slug: "first_part", position: 1
724
+ some_page.parts.create! title: "Second Part", slug: "second_part", position: 2
725
+ some_page.parts.create! title: "Third Part", slug: "third_part", position: 3
714
726
 
715
727
  allow(Refinery::Pages).to receive(:new_page_parts).and_return(true)
716
728
  end
@@ -725,7 +737,7 @@ module Refinery
725
737
  end
726
738
 
727
739
  2.times do
728
- find("#delete_page_part").trigger(:click)
740
+ find("#delete_page_part").click
729
741
  # Poltergeist automatically accepts dialogues.
730
742
  if Capybara.javascript_driver != :poltergeist
731
743
  page.driver.browser.switch_to.alert.accept
@@ -757,16 +769,16 @@ module Refinery
757
769
  allow(Refinery::Pages).to receive(:use_layout_templates).and_return(true)
758
770
  allow(Refinery::Pages).to receive(:layout_template_whitelist).and_return(['abc', 'refinery'])
759
771
  allow(Refinery::Pages).to receive(:valid_templates).and_return(['abc', 'refinery'])
760
- parent_page = Page.create :title => 'Parent Page',
761
- :view_template => 'refinery',
762
- :layout_template => 'refinery'
763
- @page = parent_page.children.create :title => 'Child Page'
772
+ parent_page = Page.create title: 'Parent Page',
773
+ view_template: 'refinery',
774
+ layout_template: 'refinery'
775
+ @page = parent_page.children.create title: 'Child Page'
764
776
  end
765
777
 
766
778
  specify 'sub page should inherit them', js: true do
767
779
  visit refinery.edit_admin_page_path(@page.id)
768
780
 
769
- find('#toggle_advanced_options').trigger(:click)
781
+ find('#toggle_advanced_options').click
770
782
 
771
783
  within '#page_layout_template' do
772
784
  expect(page.find('option[value=refinery]')).to be_selected
@@ -783,7 +795,7 @@ module Refinery
783
795
  # regression spec for https://github.com/refinery/refinerycms/issues/1891
784
796
  describe "a page part with HTML" do
785
797
  before do
786
- page = Refinery::Page.create! :title => "test"
798
+ page = Refinery::Page.create! title: "test"
787
799
  Refinery::Pages.default_parts.each_with_index do |default_page_part, index|
788
800
  page.parts.create(
789
801
  title: default_page_part[:title],
@@ -794,37 +806,35 @@ module Refinery
794
806
  end
795
807
  end
796
808
 
797
- specify "should retain the html", js:true do
809
+ specify "should retain the html", js: true do
798
810
  visit refinery.admin_pages_path
799
- find('a[tooltip="Edit this page"]').trigger(:click)
800
- Capybara.ignore_hidden_elements = false
801
- expect(page).to have_content("header class='regression'")
802
- Capybara.ignore_hidden_elements = true
811
+ first(edit_selector(slug: 'test')).click
812
+ Capybara.ignore_hidden_elements do
813
+ expect(page).to have_content("header class='regression'")
814
+ end
803
815
  end
804
816
  end
805
817
  end
806
818
 
807
- describe "TranslatePages", :type => :feature do
808
- before { Globalize.locale = :en }
819
+ describe "TranslatePages", type: :system do
820
+ before { Mobility.locale = :en }
809
821
  refinery_login
810
822
 
811
823
  describe "a page with a single locale" do
812
824
  before do
813
825
  allow(Refinery::I18n).to receive(:frontend_locales).and_return([:en, :lv])
814
- Page.create :title => 'First Page'
815
826
  end
827
+ let(:first_page) { Page.create title: 'First Page' }
816
828
 
817
829
  it "can have a second locale added to it" do
818
- visit refinery.admin_pages_path
830
+ visit refinery.edit_admin_page_path(first_page.id)
819
831
 
820
- click_link "Add new page"
821
- switch_page_form_locale "LV"
822
-
823
- fill_in "Title", :with => "Brīva vieta reklāmai"
832
+ switch_page_form_locale "lv"
833
+ fill_in "Title", with: "Brīva vieta reklāmai"
824
834
  click_button "Save"
825
835
 
826
- expect(page).to have_content("'Brīva vieta reklāmai' was successfully added.")
827
- expect(Refinery::Page.count).to eq(2)
836
+ expect(page).to have_content("'Brīva vieta reklāmai' was successfully updated.")
837
+ expect(first_page.translations.count).to eq(2)
828
838
  end
829
839
  end
830
840
 
@@ -833,11 +843,11 @@ module Refinery
833
843
  allow(Refinery::I18n).to receive(:frontend_locales).and_return [:en, :ru]
834
844
 
835
845
  # Create a page in both locales
836
- about_page = Globalize.with_locale(:en) do
837
- Page.create :title => 'About'
846
+ about_page = Mobility.with_locale(:en) do
847
+ Page.create title: 'About'
838
848
  end
839
849
 
840
- Globalize.with_locale(:ru) do
850
+ Mobility.with_locale(:ru) do
841
851
  about_page.title = 'About Ru'
842
852
  about_page.save
843
853
  end
@@ -847,7 +857,7 @@ module Refinery
847
857
  page = Refinery::Page.last
848
858
  # we need page parts so that there's a visual editor
849
859
  Refinery::Pages.default_parts.each_with_index do |default_page_part, index|
850
- page.parts.create(:title => default_page_part[:title], :slug => default_page_part[:slug], :body => nil, :position => index)
860
+ page.parts.create(title: default_page_part[:title], slug: default_page_part[:slug], body: nil, position: index)
851
861
  end
852
862
  page
853
863
  end
@@ -857,14 +867,14 @@ module Refinery
857
867
  before { Refinery::Pages.absolute_page_links = false }
858
868
 
859
869
  it "shows Russian pages if we're editing the Russian locale" do
860
- visit refinery.link_to_admin_pages_dialogs_path(:visual_editor => true, :switch_locale => :ru)
870
+ visit refinery.link_to_admin_pages_dialogs_path(visual_editor: true, switch_locale: :ru)
861
871
 
862
872
  expect(page).to have_content("About Ru")
863
873
  expect(page).to have_selector("a[href='/ru/about-ru']")
864
874
  end
865
875
 
866
876
  it "shows default to the default locale if no query string is added" do
867
- visit refinery.link_to_admin_pages_dialogs_path(:visual_editor => true)
877
+ visit refinery.link_to_admin_pages_dialogs_path(visual_editor: true)
868
878
 
869
879
  expect(page).to have_content("About")
870
880
  expect(page).to have_selector("a[href='/about']")
@@ -875,17 +885,16 @@ module Refinery
875
885
  before { Refinery::Pages.absolute_page_links = true }
876
886
 
877
887
  it "shows Russian pages if we're editing the Russian locale" do
878
- visit refinery.link_to_admin_pages_dialogs_path(:visual_editor => true, :switch_locale => :ru)
879
-
888
+ visit refinery.link_to_admin_pages_dialogs_path(visual_editor: true, switch_locale: :ru)
880
889
  expect(page).to have_content("About Ru")
881
- expect(page).to have_selector("a[href='http://www.example.com/ru/about-ru']")
890
+ expect(page).to have_selector("a[href$='ru/about-ru']")
882
891
  end
883
892
 
884
893
  it "shows default to the default locale if no query string is added" do
885
- visit refinery.link_to_admin_pages_dialogs_path(:visual_editor => true)
894
+ visit refinery.link_to_admin_pages_dialogs_path(visual_editor: true)
886
895
 
887
896
  expect(page).to have_content("About")
888
- expect(page).to have_selector("a[href='http://www.example.com/about']")
897
+ expect(page).to have_selector("a[href$='about']")
889
898
  end
890
899
  end
891
900
  end