refinerycms-page-menus 2.0.3 → 2.0.4

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 (67) hide show
  1. data/app/assets/javascripts/refinery/backend.js.coffee +24 -0
  2. data/app/assets/stylesheets/refinery/select_form.css.scss +182 -0
  3. data/app/controllers/refinery/admin/page_menus_controller.rb +57 -1
  4. data/app/controllers/refinery/admin/page_positions_controller.rb +19 -39
  5. data/app/helpers/refinery/page_positions_helper.rb +66 -0
  6. data/app/models/refinery/page_menu.rb +3 -15
  7. data/app/models/refinery/page_position.rb +87 -15
  8. data/app/views/refinery/admin/page_menus/_form.html.erb +27 -35
  9. data/app/views/refinery/admin/page_menus/_form_actions.html.erb +23 -0
  10. data/app/views/refinery/admin/page_menus/_page_menu.html.erb +16 -0
  11. data/app/views/refinery/admin/page_menus/_page_menus.html.erb +2 -0
  12. data/app/views/refinery/admin/page_menus/_records.html.erb +18 -0
  13. data/app/views/refinery/admin/page_menus/_sortable_list.html.erb +5 -0
  14. data/app/views/refinery/admin/page_menus/edit.html.erb +12 -1
  15. data/app/views/refinery/admin/page_menus/index.html.erb +3 -0
  16. data/app/views/refinery/admin/page_positions/_custom_link.html.erb +14 -0
  17. data/app/views/refinery/admin/page_positions/_page_position.html.erb +25 -48
  18. data/app/views/refinery/admin/page_positions/_resource_link.html.erb +14 -0
  19. data/app/views/refinery/admin/page_positions/_resource_link_editor_box.html.erb +21 -0
  20. data/app/views/refinery/admin/page_positions/create.js.erb +5 -0
  21. data/app/views/refinery/admin/page_positions/destroy.js.erb +3 -0
  22. data/config/locales/da.yml +9 -5
  23. data/config/locales/en.yml +25 -82
  24. data/config/locales/fr.yml +37 -0
  25. data/config/routes.rb +15 -4
  26. data/db/migrate/{20120406121839_create_page_menus.rb → 01_create_page_menus.rb} +0 -0
  27. data/db/migrate/{20120411133453_add_permatitle_to_page_menus.rb → 02_add_permatitle_to_page_menus.rb} +0 -0
  28. data/db/migrate/{20120411134419_add_menu_match_to_page_positions.rb → 03_add_menu_match_to_page_positions.rb} +0 -0
  29. data/db/migrate/04_add_flex_fields_to_page_positions.rb +9 -0
  30. data/db/migrate/05_remove_refinery_page_id_from_refinery_page_positions.rb +9 -0
  31. data/db/seeds.rb +18 -0
  32. data/lib/generators/refinery/page_menus/page_menus_generator.rb +12 -2
  33. data/lib/generators/refinery/page_menus/templates/config/initializers/refinery/page_menus.rb.erb +11 -0
  34. data/lib/refinery/page_menus/configuration.rb +24 -3
  35. data/lib/refinery/page_menus/controller_extension.rb +7 -3
  36. data/lib/refinery/page_menus/engine.rb +9 -9
  37. data/lib/refinery/page_menus/instance_methods.rb +1 -1
  38. data/lib/refinery/page_menus/version.rb +18 -0
  39. data/lib/refinery/page_menus.rb +1 -2
  40. data/readme.md +66 -1
  41. metadata +91 -52
  42. data/.gitignore +0 -2
  43. data/app/views/refinery/admin/page_positions/_actions.html.erb +0 -45
  44. data/app/views/refinery/admin/page_positions/_records.html.erb +0 -14
  45. data/app/views/refinery/admin/page_positions/_sortable_list.html.erb +0 -4
  46. data/app/views/refinery/admin/page_positions/index.html.erb +0 -11
  47. data/app/views/refinery/admin/pages/_actions.html.erb +0 -40
  48. data/app/views/refinery/admin/pages/_list_actions.html.erb +0 -28
  49. data/app/views/refinery/admin/pages/_list_page.html.erb +0 -46
  50. data/app/views/refinery/admin/pages/_list_records.html.erb +0 -16
  51. data/app/views/refinery/admin/pages/list.html.erb +0 -8
  52. data/app/views/refinery/admin/pages_shared/_submenu.html.erb +0 -65
  53. data/lib/refinery/page_menus/model_extension.rb +0 -14
  54. data/license.md +0 -21
  55. data/refinerycms-page-menus.gemspec +0 -25
  56. data/spec/factories/pages.rb +0 -5
  57. data/spec/helpers/refinery/pages/content_pages_helper_spec.rb +0 -44
  58. data/spec/lib/generators/refinery/pages/pages_generator_spec.rb +0 -29
  59. data/spec/lib/pages/content_page_presenter_spec.rb +0 -43
  60. data/spec/lib/pages/content_presenter_spec.rb +0 -111
  61. data/spec/lib/pages/page_part_section_presenter_spec.rb +0 -35
  62. data/spec/lib/pages/section_presenter_spec.rb +0 -86
  63. data/spec/lib/pages/title_section_presenter_spec.rb +0 -21
  64. data/spec/lib/pages_spec.rb +0 -26
  65. data/spec/models/refinery/page_spec.rb +0 -415
  66. data/spec/requests/refinery/admin/pages_spec.rb +0 -613
  67. data/spec/requests/refinery/pages_spec.rb +0 -302
@@ -1,613 +0,0 @@
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