refinerycms-pages 2.0.10 → 2.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 (89) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/refinery/admin/pages_controller.rb +23 -17
  3. data/app/controllers/refinery/admin/pages_dialogs_controller.rb +8 -45
  4. data/app/controllers/refinery/pages/admin/preview_controller.rb +38 -0
  5. data/app/controllers/refinery/pages_controller.rb +26 -43
  6. data/app/helpers/refinery/admin/pages_helper.rb +19 -14
  7. data/app/models/refinery/page.rb +133 -194
  8. data/app/models/refinery/page_part.rb +1 -1
  9. data/{lib → app/presenters}/refinery/pages/content_page_presenter.rb +1 -5
  10. data/{lib → app/presenters}/refinery/pages/content_presenter.rb +1 -15
  11. data/app/presenters/refinery/pages/menu_presenter.rb +118 -0
  12. data/{lib → app/presenters}/refinery/pages/page_part_section_presenter.rb +0 -0
  13. data/{lib → app/presenters}/refinery/pages/section_presenter.rb +0 -0
  14. data/{lib → app/presenters}/refinery/pages/title_section_presenter.rb +0 -0
  15. data/app/sweepers/refinery/pages/page_sweeper.rb +29 -0
  16. data/app/views/refinery/admin/pages/_form.html.erb +4 -4
  17. data/app/views/refinery/admin/pages/_form_advanced_options.html.erb +3 -18
  18. data/app/views/refinery/admin/pages/_form_page_parts.html.erb +2 -2
  19. data/app/views/refinery/admin/pages/_page.html.erb +5 -5
  20. data/app/views/refinery/admin/pages/_records.html.erb +1 -3
  21. data/app/views/refinery/admin/pages/_sortable_list.html.erb +1 -1
  22. data/app/views/refinery/admin/pages/index.html.erb +1 -1
  23. data/app/views/refinery/admin/pages_dialogs/link_to.html.erb +0 -2
  24. data/config/locales/bg.yml +0 -11
  25. data/config/locales/cs.yml +1 -3
  26. data/config/locales/da.yml +15 -5
  27. data/config/locales/de.yml +16 -5
  28. data/config/locales/el.yml +0 -3
  29. data/config/locales/en.yml +1 -12
  30. data/config/locales/es.yml +0 -3
  31. data/config/locales/fi.yml +0 -3
  32. data/config/locales/fr.yml +0 -11
  33. data/config/locales/hu.yml +85 -0
  34. data/config/locales/it.yml +0 -10
  35. data/config/locales/ja.yml +0 -3
  36. data/config/locales/ko.yml +0 -11
  37. data/config/locales/lt.yml +0 -3
  38. data/config/locales/lv.yml +0 -3
  39. data/config/locales/nb.yml +0 -3
  40. data/config/locales/nl.yml +51 -40
  41. data/config/locales/pl.yml +23 -4
  42. data/config/locales/pt-BR.yml +0 -3
  43. data/config/locales/pt.yml +85 -0
  44. data/config/locales/rs.yml +0 -3
  45. data/config/locales/ru.yml +0 -3
  46. data/config/locales/sk.yml +0 -11
  47. data/config/locales/sl.yml +0 -3
  48. data/config/locales/sv.yml +0 -3
  49. data/config/locales/tr.yml +85 -0
  50. data/config/locales/uk.yml +82 -0
  51. data/config/locales/vi.yml +0 -3
  52. data/config/locales/zh-CN.yml +8 -11
  53. data/config/locales/zh-TW.yml +0 -3
  54. data/config/routes.rb +11 -5
  55. data/db/seeds.rb +16 -14
  56. data/lib/generators/refinery/pages/templates/config/initializers/refinery/pages.rb.erb +8 -4
  57. data/lib/refinery/pages.rb +5 -9
  58. data/lib/refinery/pages/caching.rb +60 -0
  59. data/lib/refinery/pages/configuration.rb +11 -7
  60. data/lib/refinery/pages/engine.rb +7 -8
  61. data/lib/refinery/pages/instance_methods.rb +4 -11
  62. data/lib/refinery/pages/render_options.rb +27 -0
  63. data/lib/refinery/pages/tab.rb +15 -4
  64. data/lib/refinery/pages/url.rb +74 -0
  65. data/refinerycms-pages.gemspec +4 -3
  66. data/spec/controllers/refinery/pages_controller_spec.rb +24 -0
  67. data/spec/factories/pages.rb +1 -1
  68. data/spec/{requests → features}/refinery/admin/pages_spec.rb +125 -42
  69. data/spec/{requests → features}/refinery/pages_spec.rb +139 -23
  70. data/spec/helpers/refinery/pages/admin/pages_helper_spec.rb +25 -25
  71. data/spec/lib/refinery/pages/caching_spec.rb +90 -0
  72. data/spec/lib/refinery/pages/tab_spec.rb +89 -0
  73. data/spec/lib/refinery/pages/url_spec.rb +74 -0
  74. data/spec/models/refinery/page_spec.rb +196 -71
  75. data/spec/{lib → presenters/refinery}/pages/content_page_presenter_spec.rb +0 -0
  76. data/spec/{lib → presenters/refinery}/pages/content_presenter_spec.rb +0 -0
  77. data/spec/presenters/refinery/pages/menu_presenter_spec.rb +58 -0
  78. data/spec/{lib → presenters/refinery}/pages/page_part_section_presenter_spec.rb +0 -0
  79. data/spec/{lib → presenters/refinery}/pages/section_presenter_spec.rb +0 -0
  80. data/spec/{lib → presenters/refinery}/pages/title_section_presenter_spec.rb +0 -0
  81. data/spec/support/refinery/pages/caching.rb +19 -0
  82. data/spec/support/refinery/pages/caching_helpers.rb +22 -0
  83. metadata +77 -33
  84. data/app/controllers/refinery/page_sweeper.rb +0 -34
  85. data/app/helpers/refinery/pages_helper.rb +0 -20
  86. data/app/views/refinery/admin/pages/_locale_picker.html.erb +0 -11
  87. data/config/locales/pt-PT.yml +0 -75
  88. data/spec/controllers/refinery/admin/pages_controller_spec.rb +0 -17
  89. data/spec/helpers/refinery/pages/pages_helper_spec.rb +0 -30
@@ -0,0 +1,74 @@
1
+ module Refinery
2
+ module Pages
3
+ class Url
4
+
5
+ class Localised < Url
6
+ def self.handle?(page)
7
+ page.link_url.present?
8
+ end
9
+
10
+ def url
11
+ current_url = page.link_url
12
+
13
+ if current_url =~ %r{^/} &&
14
+ Refinery::I18n.current_frontend_locale != Refinery::I18n.default_frontend_locale
15
+ current_url = "/#{Refinery::I18n.current_frontend_locale}#{current_url}"
16
+ end
17
+
18
+ current_url
19
+ end
20
+ end
21
+
22
+ class Marketable < Url
23
+ def self.handle?(page)
24
+ Refinery::Pages.marketable_urls
25
+ end
26
+
27
+ def url
28
+ url_hash = base_url_hash.merge(:path => page.nested_url, :id => nil)
29
+ with_locale_param(url_hash)
30
+ end
31
+ end
32
+
33
+ class Normal < Url
34
+ def self.handle?(page)
35
+ page.to_param.present?
36
+ end
37
+
38
+ def url
39
+ url_hash = base_url_hash.merge(:path => nil, :id => page.to_param)
40
+ with_locale_param(url_hash)
41
+ end
42
+ end
43
+
44
+ def self.build(page)
45
+ klass = [ Localised, Marketable, Normal ].detect { |d| d.handle?(page) } || self
46
+ klass.new(page).url
47
+ end
48
+
49
+ def initialize(page)
50
+ @page = page
51
+ end
52
+
53
+ def url
54
+ raise NotImplementedError
55
+ end
56
+
57
+ private
58
+
59
+ attr_reader :page
60
+
61
+ def with_locale_param(url_hash)
62
+ if (locale = Refinery::I18n.current_frontend_locale) != ::I18n.locale
63
+ url_hash.update :locale => locale if locale
64
+ end
65
+ url_hash
66
+ end
67
+
68
+ def base_url_hash
69
+ { :controller => '/refinery/pages', :action => 'show', :only_path => true }
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -1,6 +1,5 @@
1
1
  # Encoding: UTF-8
2
- $:.push File.expand_path('../../core/lib', __FILE__)
3
- require 'refinery/version'
2
+ require File.expand_path('../../core/lib/refinery/version', __FILE__)
4
3
 
5
4
  version = Refinery::Version.to_s
6
5
 
@@ -20,8 +19,10 @@ Gem::Specification.new do |s|
20
19
  s.files = `git ls-files`.split("\n")
21
20
  s.test_files = `git ls-files -- spec/*`.split("\n")
22
21
 
22
+ s.add_dependency 'friendly_id', '~> 4.0.9'
23
+ s.add_dependency 'globalize3', '~> 0.3.0'
23
24
  s.add_dependency 'awesome_nested_set', '~> 2.1.3'
24
- s.add_dependency 'seo_meta', '~> 1.3.0'
25
+ s.add_dependency 'seo_meta', '~> 1.4.0'
25
26
  s.add_dependency 'refinerycms-core', version
26
27
  s.add_dependency 'babosa', '!= 0.3.6'
27
28
  end
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ module Refinery
4
+ describe PagesController do
5
+ before do
6
+ FactoryGirl.create(:page, :link_url => "/")
7
+ FactoryGirl.create(:page, :title => "test")
8
+ end
9
+
10
+ describe "#home" do
11
+ it "renders home template" do
12
+ get :home
13
+ expect(response).to render_template("home")
14
+ end
15
+ end
16
+
17
+ describe "#show" do
18
+ it "renders show template" do
19
+ get :show, :path => "test"
20
+ expect(response).to render_template("show")
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  FactoryGirl.define do
2
2
  factory :page, :class => Refinery::Page do
3
- title "Test title"
3
+ sequence(:title, "a") {|n| "Test title #{n}" }
4
4
  end
5
5
  end
@@ -18,7 +18,7 @@ end
18
18
  module Refinery
19
19
  module Admin
20
20
  describe "Pages" do
21
- login_refinery_user
21
+ refinery_login_with :refinery_user
22
22
 
23
23
  context "when no pages" do
24
24
  it "invites to create one" do
@@ -85,15 +85,15 @@ module Refinery
85
85
  end
86
86
 
87
87
  it "expands children", :js do
88
- find("#page_#{company.id} .toggle").click
88
+ find("#page_#{company.id} .title.toggle").click
89
89
 
90
90
  page.should have_content(team.title)
91
91
  page.should have_content(locations.title)
92
92
  end
93
93
 
94
94
  it "expands children when nested mutliple levels deep", :js do
95
- find("#page_#{company.id} .toggle").click
96
- find("#page_#{locations.id} .toggle").click
95
+ find("#page_#{company.id} .title.toggle").click
96
+ find("#page_#{locations.id} .title.toggle").click
97
97
 
98
98
  page.should have_content("New York")
99
99
  end
@@ -136,10 +136,13 @@ module Refinery
136
136
  Refinery::Page.count.should == 1
137
137
  end
138
138
 
139
- it "includes menu title field" do
139
+ it "includes menu title field", :js => true do
140
140
  visit refinery.new_admin_page_path
141
141
 
142
142
  fill_in "Title", :with => "My first page"
143
+
144
+ click_link "toggle_advanced_options"
145
+
143
146
  fill_in "Menu title", :with => "The first page"
144
147
 
145
148
  click_button "Save"
@@ -162,7 +165,7 @@ module Refinery
162
165
  click_link "Edit this page"
163
166
 
164
167
  fill_in "Title", :with => "Updated"
165
- click_button "Save"
168
+ find("#submit_button").click
166
169
 
167
170
  page.should have_content("'Updated' was successfully updated.")
168
171
  end
@@ -174,7 +177,7 @@ module Refinery
174
177
  find('a[tooltip^=Edit]').click
175
178
 
176
179
  fill_in "Title", :with => "Updated"
177
- click_button "Save & continue editing"
180
+ find("#submit_continue_button").click
178
181
  find('#flash').visible?
179
182
  end
180
183
 
@@ -185,7 +188,7 @@ module Refinery
185
188
  # Regression test for https://github.com/refinery/refinerycms/issues/1892
186
189
  context 'when saving to exit (a second time)' do
187
190
  it 'updates page', :js do
188
- click_button "Save"
191
+ find("#submit_button").click
189
192
  page.should have_content("'Updated' was successfully updated.")
190
193
  end
191
194
  end
@@ -206,6 +209,21 @@ module Refinery
206
209
  new_window_should_have_content("Some changes I'm unsure what they will look like")
207
210
  end
208
211
 
212
+ it 'will not show the site bar', :js do
213
+ visit refinery.admin_pages_path
214
+
215
+ find('a[tooltip^=Edit]').click
216
+ fill_in "Title", :with => "Some changes I'm unsure what they will look like"
217
+ click_button "Preview"
218
+
219
+ new_window_should_not_have_content(
220
+ ::I18n.t('switch_to_website', :scope => 'refinery.site_bar')
221
+ )
222
+ new_window_should_not_have_content(
223
+ ::I18n.t('switch_to_website_editor', :scope => 'refinery.site_bar')
224
+ )
225
+ end
226
+
209
227
  it 'will not save the preview changes', :js do
210
228
  visit refinery.admin_pages_path
211
229
 
@@ -314,13 +332,16 @@ module Refinery
314
332
  Refinery::I18n.stub(:frontend_locales).and_return([:en, :ru])
315
333
 
316
334
  # Create a home page in both locales (needed to test menus)
317
- home_page = FactoryGirl.create(:page, :title => 'Home',
318
- :link_url => '/',
319
- :menu_match => "^/$")
320
- Globalize.locale = :ru
321
- home_page.title = 'Домашняя страница'
322
- home_page.save
323
- Globalize.locale = :en
335
+ home_page = Globalize.with_locale(:en) do
336
+ Page.create :title => 'Home',
337
+ :link_url => '/',
338
+ :menu_match => "^/$"
339
+ end
340
+
341
+ Globalize.with_locale(:ru) do
342
+ home_page.title = 'Домашняя страница'
343
+ home_page.save
344
+ end
324
345
  end
325
346
 
326
347
  describe "add a page with title for default locale" do
@@ -356,7 +377,7 @@ module Refinery
356
377
 
357
378
  within "#menu" do
358
379
  page.should have_content('News')
359
- page.should have_css('a', :href => 'news')
380
+ page.should have_selector("a[href='/news']")
360
381
  end
361
382
  end
362
383
 
@@ -374,7 +395,6 @@ module Refinery
374
395
  let(:en_page_title) { 'News' }
375
396
  let(:en_page_slug) { 'news' }
376
397
  let(:ru_page_title) { 'Новости' }
377
- let(:ru_page_slug) { 'новости' }
378
398
  let(:ru_page_slug_encoded) { '%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8' }
379
399
  let!(:news_page) do
380
400
  Refinery::I18n.stub(:frontend_locales).and_return([:en, :ru])
@@ -408,7 +428,7 @@ module Refinery
408
428
  click_link "En"
409
429
  end
410
430
  fill_in "Title", :with => en_page_title
411
- click_button "Save"
431
+ find("#submit_button").click
412
432
 
413
433
  page.should have_content("'#{en_page_title}' was successfully updated.")
414
434
  Refinery::Page.count.should == 2
@@ -464,7 +484,7 @@ module Refinery
464
484
  }
465
485
  let(:ru_page_id) { ru_page.id }
466
486
  let(:ru_page_title) { 'Новости' }
467
- let(:ru_page_slug) { 'новости' }
487
+ let(:ru_page_slug_encoded) { '%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8' }
468
488
 
469
489
  before do
470
490
  ru_page
@@ -513,7 +533,7 @@ module Refinery
513
533
 
514
534
  within "#menu" do
515
535
  page.should have_content(ru_page_title)
516
- page.should have_css('a', :href => ru_page_slug)
536
+ page.should have_selector("a[href*='/#{ru_page_slug_encoded}']")
517
537
  end
518
538
  end
519
539
 
@@ -548,34 +568,73 @@ module Refinery
548
568
  end
549
569
  end
550
570
 
571
+ describe "delete existing page part", :js do
572
+ let!(:some_page) { Page.create! :title => "Some Page" }
573
+
574
+ before do
575
+ some_page.parts.create! :title => "First Part", :position => 1
576
+ some_page.parts.create! :title => "Second Part", :position => 2
577
+ some_page.parts.create! :title => "Third Part", :position => 3
578
+
579
+ Refinery::Pages.stub(:new_page_parts).and_return(true)
580
+ end
581
+
582
+ it "deletes page parts" do
583
+ visit refinery.edit_admin_page_path(some_page.id)
584
+
585
+ within "#page_parts" do
586
+ page.should have_content("First Part")
587
+ page.should have_content("Second Part")
588
+ page.should have_content("Third Part")
589
+ end
590
+
591
+ 2.times do
592
+ click_link "delete_page_part"
593
+ page.driver.browser.switch_to.alert.accept
594
+ end
595
+
596
+ within "#page_parts" do
597
+ page.should have_no_content("First Part")
598
+ page.should have_no_content("Second Part")
599
+ page.should have_content("Third Part")
600
+ end
601
+
602
+ click_button "submit_button"
603
+
604
+ visit refinery.edit_admin_page_path(some_page.id)
605
+
606
+ within "#page_parts" do
607
+ page.should have_no_content("First Part")
608
+ page.should have_no_content("Second Part")
609
+ page.should have_content("Third Part")
610
+ end
611
+ end
612
+ end
613
+
551
614
  describe 'advanced options' do
552
615
  describe 'view and layout templates' do
553
616
  context 'when parent page has templates set' do
554
617
  before do
555
618
  Refinery::Pages.stub(:use_layout_templates).and_return(true)
556
- Refinery::Pages.stub(:use_view_templates).and_return(true)
557
619
  Refinery::Pages.stub(:layout_template_whitelist).and_return(['abc', 'refinery'])
558
- Refinery::Pages.stub(:view_template_whitelist).and_return(['abc', 'refinery'])
559
620
  Refinery::Pages.stub(:valid_templates).and_return(['abc', 'refinery'])
560
621
  parent_page = Page.create :title => 'Parent Page',
561
622
  :view_template => 'refinery',
562
623
  :layout_template => 'refinery'
563
- parent_page.children.create :title => 'Child Page'
624
+ @page = parent_page.children.create :title => 'Child Page'
564
625
  end
565
626
 
566
- specify 'sub page should inherit them' do
567
- visit refinery.admin_pages_path
627
+ specify 'sub page should inherit them', :js => true do
628
+ visit refinery.edit_admin_page_path(@page.id)
568
629
 
569
- within '.nested' do
570
- click_link 'Edit this page'
571
- end
630
+ click_link 'toggle_advanced_options'
572
631
 
573
632
  within '#page_layout_template' do
574
- page.find('option[value=refinery]').selected?.should eq('selected')
633
+ page.find('option[value=refinery]').should be_selected
575
634
  end
576
635
 
577
636
  within '#page_view_template' do
578
- page.find('option[value=refinery]').selected?.should eq('selected')
637
+ page.find('option[value=refinery]').should be_selected
579
638
  end
580
639
  end
581
640
  end
@@ -599,10 +658,30 @@ module Refinery
599
658
  page.should have_content("header class='regression'")
600
659
  end
601
660
  end
661
+
662
+ describe "with full page caching", :caching do
663
+ include CachingHelpers
664
+ let(:cached_page) { Page.create :title => 'Cached page' }
665
+
666
+ before do
667
+ cache_page(cached_page)
668
+ end
669
+
670
+ describe "creating updating or destroying a page" do
671
+ it "should clear the page cache" do
672
+ cached_page.should be_cached
673
+
674
+ visit refinery.admin_pages_path
675
+ click_link "Remove this page forever"
676
+
677
+ cached_page.should_not be_cached
678
+ end
679
+ end
680
+ end
602
681
  end
603
682
 
604
683
  describe "TranslatePages" do
605
- login_refinery_translator
684
+ refinery_login_with :refinery_translator
606
685
 
607
686
  describe "add page to main locale" do
608
687
  it "doesn't succeed" do
@@ -657,11 +736,14 @@ module Refinery
657
736
  Refinery::I18n.frontend_locales = [:en, :ru]
658
737
 
659
738
  # Create a page in both locales
660
- about_page = FactoryGirl.create(:page, :title => 'About')
661
- Globalize.locale = :ru
662
- about_page.title = 'About Ru'
663
- about_page.save
664
- Globalize.locale = :en
739
+ about_page = Globalize.with_locale(:en) do
740
+ Page.create :title => 'About'
741
+ end
742
+
743
+ Globalize.with_locale(:ru) do
744
+ about_page.title = 'About Ru'
745
+ about_page.save
746
+ end
665
747
  end
666
748
 
667
749
  let(:about_page) do
@@ -678,14 +760,14 @@ module Refinery
678
760
  before { Refinery::Pages.absolute_page_links = false }
679
761
 
680
762
  it "shows Russian pages if we're editing the Russian locale" do
681
- visit 'refinery/pages_dialogs/link_to?wymeditor=true&switch_locale=ru'
763
+ visit refinery.link_to_admin_pages_dialogs_path(:wymeditor => true, :switch_locale => :ru)
682
764
 
683
765
  page.should have_content("About Ru")
684
766
  page.should have_selector("a[href='/ru/about-ru']")
685
767
  end
686
768
 
687
769
  it "shows default to the default locale if no query string is added" do
688
- visit 'refinery/pages_dialogs/link_to?wymeditor=true'
770
+ visit refinery.link_to_admin_pages_dialogs_path(:wymeditor => true)
689
771
 
690
772
  page.should have_content("About")
691
773
  page.should have_selector("a[href='/about']")
@@ -696,14 +778,14 @@ module Refinery
696
778
  before { Refinery::Pages.absolute_page_links = true }
697
779
 
698
780
  it "shows Russian pages if we're editing the Russian locale" do
699
- visit 'refinery/pages_dialogs/link_to?wymeditor=true&switch_locale=ru'
781
+ visit refinery.link_to_admin_pages_dialogs_path(:wymeditor => true, :switch_locale => :ru)
700
782
 
701
783
  page.should have_content("About Ru")
702
784
  page.should have_selector("a[href='http://www.example.com/ru/about-ru']")
703
785
  end
704
786
 
705
787
  it "shows default to the default locale if no query string is added" do
706
- visit 'refinery/pages_dialogs/link_to?wymeditor=true'
788
+ visit refinery.link_to_admin_pages_dialogs_path(:wymeditor => true)
707
789
 
708
790
  page.should have_content("About")
709
791
  page.should have_selector("a[href='http://www.example.com/about']")
@@ -715,7 +797,8 @@ module Refinery
715
797
  specify "dialog has correct links", :js do
716
798
  visit refinery.edit_admin_page_path(about_page)
717
799
 
718
- click_link "Add Link"
800
+
801
+ find("#page_part_body .wym_tools_link a").click
719
802
 
720
803
  page.should have_selector("iframe#dialog_frame")
721
804
 
@@ -730,7 +813,7 @@ module Refinery
730
813
  click_link "Ru"
731
814
  end
732
815
 
733
- click_link "Add Link"
816
+ find("#page_part_body .wym_tools_link a").click
734
817
 
735
818
  page.should have_selector("iframe#dialog_frame")
736
819