refinerycms-pages 1.0.11 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. data/app/controllers/refinery/admin/page_parts_controller.rb +26 -0
  2. data/app/controllers/refinery/admin/pages_controller.rb +77 -0
  3. data/app/controllers/refinery/admin/pages_dialogs_controller.rb +91 -0
  4. data/app/controllers/refinery/page_sweeper.rb +29 -0
  5. data/app/controllers/refinery/pages_controller.rb +103 -0
  6. data/app/helpers/refinery/pages/content_pages_helper.rb +26 -0
  7. data/app/helpers/refinery/pages_helper.rb +4 -0
  8. data/app/models/refinery/page.rb +467 -0
  9. data/app/models/refinery/page_part.rb +33 -0
  10. data/app/presenters/refinery/page_presenter.rb +7 -0
  11. data/app/views/admin/pages/_sortable_list.html.erb +7 -4
  12. data/app/views/{admin → refinery/admin}/pages/_actions.html.erb +5 -4
  13. data/app/views/refinery/admin/pages/_form.html.erb +63 -0
  14. data/app/views/{admin → refinery/admin}/pages/_form_advanced_options.html.erb +35 -16
  15. data/app/views/refinery/admin/pages/_form_advanced_options_seo.html.erb +3 -0
  16. data/app/views/{admin → refinery/admin}/pages/_form_fields_after_title.html.erb +0 -0
  17. data/app/views/{admin → refinery/admin}/pages/_form_new_page_parts.html.erb +5 -7
  18. data/app/views/{admin → refinery/admin}/pages/_form_page_parts.html.erb +19 -11
  19. data/app/views/{admin → refinery/admin}/pages/_locale_picker.html.erb +3 -3
  20. data/app/views/refinery/admin/pages/_page.html.erb +48 -0
  21. data/app/views/{admin → refinery/admin}/pages/_page_part_field.html.erb +1 -1
  22. data/app/views/refinery/admin/pages/_records.html.erb +14 -0
  23. data/app/views/refinery/admin/pages/_sortable_list.html.erb +4 -0
  24. data/app/views/refinery/admin/pages/children.html.erb +1 -0
  25. data/app/views/refinery/admin/pages/edit.html.erb +1 -0
  26. data/app/views/refinery/admin/pages/index.html.erb +9 -0
  27. data/app/views/refinery/admin/pages/new.html.erb +1 -0
  28. data/app/views/refinery/admin/pages_dialogs/_page_link.html.erb +20 -0
  29. data/app/views/{admin → refinery/admin}/pages_dialogs/link_to.html.erb +31 -36
  30. data/app/views/refinery/pages/home.html.erb +1 -0
  31. data/app/views/refinery/pages/show.html.erb +1 -0
  32. data/config/locales/bg.yml +81 -73
  33. data/config/locales/cs.yml +71 -72
  34. data/config/locales/da.yml +69 -72
  35. data/config/locales/de.yml +69 -72
  36. data/config/locales/el.yml +70 -72
  37. data/config/locales/en.yml +88 -73
  38. data/config/locales/es.yml +70 -73
  39. data/config/locales/fi.yml +70 -73
  40. data/config/locales/fr.yml +69 -72
  41. data/config/locales/it.yml +92 -89
  42. data/config/locales/ja.yml +72 -0
  43. data/config/locales/ko.yml +83 -0
  44. data/config/locales/lt.yml +71 -73
  45. data/config/locales/lv.yml +71 -74
  46. data/config/locales/nb.yml +69 -72
  47. data/config/locales/nl.yml +68 -71
  48. data/config/locales/pl.yml +70 -73
  49. data/config/locales/pt-BR.yml +70 -73
  50. data/config/locales/pt-PT.yml +75 -0
  51. data/config/locales/rs.yml +69 -72
  52. data/config/locales/ru.yml +77 -96
  53. data/config/locales/sk.yml +69 -72
  54. data/config/locales/sl.yml +68 -71
  55. data/config/locales/sv.yml +69 -72
  56. data/config/locales/vi.yml +69 -72
  57. data/config/locales/zh-CN.yml +75 -72
  58. data/config/locales/zh-TW.yml +69 -72
  59. data/config/routes.rb +10 -5
  60. data/db/migrate/20100913234708_create_refinerycms_pages_schema.rb +49 -43
  61. data/db/seeds.rb +41 -0
  62. data/lib/generators/refinery/pages/pages_generator.rb +21 -0
  63. data/lib/generators/refinery/pages/templates/config/initializers/refinery/pages.rb.erb +44 -0
  64. data/lib/refinery/pages/admin/instance_methods.rb +10 -8
  65. data/lib/refinery/pages/configuration.rb +44 -0
  66. data/lib/refinery/pages/content_page_presenter.rb +33 -0
  67. data/lib/refinery/pages/content_presenter.rb +56 -0
  68. data/lib/refinery/pages/engine.rb +73 -0
  69. data/lib/refinery/pages/instance_methods.rb +12 -26
  70. data/lib/refinery/pages/page_part_section_presenter.rb +19 -0
  71. data/lib/refinery/pages/section_presenter.rb +69 -0
  72. data/lib/{pages/tabs.rb → refinery/pages/tab.rb} +0 -0
  73. data/lib/refinery/pages/title_section_presenter.rb +14 -0
  74. data/lib/refinery/pages/type.rb +17 -0
  75. data/lib/refinery/pages/types.rb +32 -0
  76. data/lib/refinery/pages.rb +55 -0
  77. data/lib/refinerycms-pages.rb +1 -61
  78. data/refinerycms-pages.gemspec +17 -118
  79. data/spec/factories/pages.rb +5 -0
  80. data/spec/helpers/refinery/pages/content_pages_helper_spec.rb +44 -0
  81. data/spec/lib/generators/refinery/pages/pages_generator_spec.rb +29 -0
  82. data/spec/lib/pages/content_page_presenter_spec.rb +43 -0
  83. data/spec/lib/pages/content_presenter_spec.rb +97 -0
  84. data/spec/lib/pages/page_part_section_presenter_spec.rb +35 -0
  85. data/spec/lib/pages/section_presenter_spec.rb +86 -0
  86. data/spec/lib/pages/title_section_presenter_spec.rb +21 -0
  87. data/spec/lib/pages_spec.rb +26 -0
  88. data/spec/models/refinery/page_spec.rb +415 -0
  89. data/spec/requests/refinery/admin/pages_spec.rb +581 -0
  90. data/spec/requests/refinery/pages_spec.rb +302 -0
  91. metadata +162 -153
  92. data/app/controllers/admin/page_parts_controller.rb +0 -24
  93. data/app/controllers/admin/pages_controller.rb +0 -68
  94. data/app/controllers/admin/pages_dialogs_controller.rb +0 -85
  95. data/app/controllers/pages_controller.rb +0 -33
  96. data/app/helpers/pages_helper.rb +0 -2
  97. data/app/models/page.rb +0 -391
  98. data/app/models/page_part.rb +0 -29
  99. data/app/presenters/page_presenter.rb +0 -7
  100. data/app/views/admin/pages/_form.html.erb +0 -61
  101. data/app/views/admin/pages/_form_advanced_options_seo.html.erb +0 -4
  102. data/app/views/admin/pages/_page.html.erb +0 -33
  103. data/app/views/admin/pages/_records.html.erb +0 -14
  104. data/app/views/admin/pages/edit.html.erb +0 -1
  105. data/app/views/admin/pages/index.html.erb +0 -11
  106. data/app/views/admin/pages/new.html.erb +0 -1
  107. data/app/views/admin/pages_dialogs/_page_link.html.erb +0 -14
  108. data/app/views/pages/home.html.erb +0 -1
  109. data/app/views/pages/show.html.erb +0 -1
  110. data/config/locales/jp.yml +0 -75
  111. data/config/locales/lolcat.yml +0 -76
  112. data/db/migrate/20101214040815_translate_page_plugin.rb +0 -29
  113. data/db/migrate/20101216194133_remove_cached_slug_from_pages.rb +0 -11
  114. data/db/migrate/20110307025652_translate_custom_title_on_pages.rb +0 -26
  115. data/db/migrate/20110314213540_remove_translated_fields_from_pages.rb +0 -13
  116. data/db/migrate/20110329080451_create_seo_meta.rb +0 -89
  117. data/db/seeds/pages.rb +0 -42
  118. data/features/manage_pages.feature +0 -48
  119. data/features/step_definitions/page_steps.rb +0 -72
  120. data/features/support/paths.rb +0 -28
  121. data/features/translate_pages.feature +0 -40
  122. data/features/visit_pages.feature +0 -68
  123. data/lib/gemspec.rb +0 -40
  124. data/lib/generators/refinerycms_pages_generator.rb +0 -8
  125. data/lib/pages/marketable_routes.rb +0 -12
  126. data/spec/models/page_spec.rb +0 -235
@@ -0,0 +1,97 @@
1
+ require "spec_helper"
2
+
3
+ module Refinery
4
+ module Pages
5
+ describe ContentPresenter do
6
+ let(:section1) { double(SectionPresenter, :id => 'foo', :has_content? => true) }
7
+ let(:section2) { double(SectionPresenter, :id => 'bar', :has_content? => true) }
8
+
9
+ describe "when building css classes for blank sections" do
10
+ let(:section) { double(SectionPresenter, :not_present_css_class => 'no_section1') }
11
+
12
+ it "includes css class for any section which doesnt have content" do
13
+ section.stub(:has_content?).with(true).and_return(false)
14
+ content = ContentPresenter.new
15
+ content.add_section section
16
+
17
+ content.blank_section_css_classes(true).should == ['no_section1']
18
+ end
19
+
20
+ it "doesnt include sections which have content" do
21
+ section.stub(:has_content?).with(true).and_return(true)
22
+ content = ContentPresenter.new
23
+ content.add_section section
24
+
25
+ content.blank_section_css_classes(true).should be_empty
26
+ end
27
+ end
28
+
29
+ describe "when hiding sections" do
30
+ before do
31
+ @content = ContentPresenter.new
32
+ @content.add_section section1
33
+ @content.add_section section2
34
+ end
35
+
36
+ it "hides a section specified by id" do
37
+ section2.should_receive(:hide)
38
+ @content.hide_sections('bar')
39
+ end
40
+ end
41
+
42
+ describe "when fetching template overrides" do
43
+ before do
44
+ @content = ContentPresenter.new
45
+ end
46
+
47
+ it "yields a section with an id and stores the result in its override html" do
48
+ section = double(SectionPresenter, :id => 'foo')
49
+ section.should_receive(:override_html=).with('some override')
50
+ @content.add_section section
51
+
52
+ @content.fetch_template_overrides do |section_id|
53
+ section_id.should == 'foo'
54
+ 'some override'
55
+ end
56
+ end
57
+
58
+ it "doesnt yield a section without an id" do
59
+ section = double(SectionPresenter, :id => nil)
60
+ section.should_receive(:override_html=).never
61
+ @content.add_section section
62
+
63
+ @content.fetch_template_overrides do |section_id|
64
+ raise "this should not occur"
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "when rendering as html" do
70
+ it "is empty section tag if it has no sections" do
71
+ content = ContentPresenter.new
72
+ content.to_html.should == "<section class=\"\" id=\"body_content\"></section>"
73
+ end
74
+
75
+ it "returns sections joined by a newline inside section tag" do
76
+ section1.stub(:wrapped_html).and_return('foo')
77
+ section2.stub(:wrapped_html).and_return('bar')
78
+ content = ContentPresenter.new([section1, section2])
79
+ content.to_html.should == "<section class=\"\" id=\"body_content\">foo\nbar</section>"
80
+ end
81
+
82
+ it "passes can_use_fallback option on to sections" do
83
+ section1.should_receive(:wrapped_html).with(false).and_return('foo')
84
+ content = ContentPresenter.new([section1])
85
+ content.to_html(false)
86
+ end
87
+
88
+ it "doesnt include sections with nil content" do
89
+ section1.stub(:wrapped_html).and_return('foo')
90
+ section2.stub(:wrapped_html).and_return(nil)
91
+ content = ContentPresenter.new([section1, section2])
92
+ content.to_html.should == "<section class=\"\" id=\"body_content\">foo</section>"
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ module Refinery
4
+ module Pages
5
+ describe PagePartSectionPresenter do
6
+ it "can be built from a page part" do
7
+ part = double(PagePart, :body => 'part_body', :title => 'A Wonderful Page Part')
8
+ section = PagePartSectionPresenter.new(part)
9
+ section.fallback_html.should == 'part_body'
10
+ section.id.should == :a_wonderful_page_part
11
+ end
12
+
13
+ it "marks the body as html safe" do
14
+ part = double(PagePart, :body => '<p>part_body</p>', :title => nil)
15
+ section = PagePartSectionPresenter.new(part)
16
+ section.fallback_html.should be_html_safe
17
+ section.wrapped_html.should == "<section><div class=\"inner\"><p>part_body</p></div></section>"
18
+ end
19
+
20
+ it "handles a nil page body" do
21
+ part = double(PagePart, :body => nil, :title => nil)
22
+ section = PagePartSectionPresenter.new(part)
23
+ section.fallback_html.should be_nil
24
+ section.wrapped_html.should be_nil
25
+ section.has_content?.should be_false
26
+ end
27
+
28
+ it "has no id if title is nil" do
29
+ part = double(PagePart, :body => 'foobar', :title => nil)
30
+ section = PagePartSectionPresenter.new(part)
31
+ section.id.should be_nil
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,86 @@
1
+ require "spec_helper"
2
+
3
+ module Refinery
4
+ module Pages
5
+ describe SectionPresenter do
6
+ it "can build a css class for when it is not present based on id" do
7
+ section = SectionPresenter.new(:fallback_html => 'foobar', :id => 'mynode')
8
+ section.not_present_css_class.should == 'no_mynode'
9
+ end
10
+
11
+ it "allows access to constructor arguments" do
12
+ section = SectionPresenter.new(:fallback_html => 'foobar', :id => 'mynode', :hidden => true)
13
+ section.fallback_html.should == 'foobar'
14
+ section.id.should == 'mynode'
15
+ section.should be_hidden
16
+ end
17
+
18
+ it "should be visible if not hidden" do
19
+ section = SectionPresenter.new(:hidden => false)
20
+ section.should be_visible
21
+ end
22
+
23
+ it "should be not visible if hidden" do
24
+ section = SectionPresenter.new(:hidden => true)
25
+ section.should_not be_visible
26
+ end
27
+
28
+ describe "when building html for a section" do
29
+ it "wont show a hidden section" do
30
+ section = SectionPresenter.new(:fallback_html => 'foobar', :hidden => true)
31
+ section.has_content?(true).should be_false
32
+ section.wrapped_html(true).should be_nil
33
+ end
34
+
35
+ it "can be hidden with the hide method" do
36
+ section = SectionPresenter.new(:fallback_html => 'foobar')
37
+ section.hide
38
+ section.has_content?(true).should be_false
39
+ section.wrapped_html(true).should be_nil
40
+ end
41
+
42
+ it "will use the specified id" do
43
+ section = SectionPresenter.new(:fallback_html => 'foobar', :id => 'mynode')
44
+ section.has_content?(true).should be_true
45
+ section.wrapped_html(true).should == '<section id="mynode"><div class="inner">foobar</div></section>'
46
+ end
47
+
48
+ describe "if allowed to use fallback html" do
49
+ it "wont show a section with no fallback or override" do
50
+ section = SectionPresenter.new
51
+ section.has_content?(true).should be_false
52
+ section.wrapped_html(true).should be_nil
53
+ end
54
+
55
+ it "uses wrapped fallback html" do
56
+ section = SectionPresenter.new(:fallback_html => 'foobar')
57
+ section.has_content?(true).should be_true
58
+ section.wrapped_html(true).should == '<section><div class="inner">foobar</div></section>'
59
+ end
60
+
61
+ it "uses wrapped override html if present" do
62
+ section = SectionPresenter.new(:fallback_html => 'foobar')
63
+ section.override_html = 'hello world'
64
+ section.has_content?(true).should be_true
65
+ section.wrapped_html(true).should == '<section><div class="inner">hello world</div></section>'
66
+ end
67
+ end
68
+
69
+ describe "if not allowed to use fallback html" do
70
+ it "wont show a section with no override" do
71
+ section = SectionPresenter.new(:fallback_html => 'foobar')
72
+ section.has_content?(false).should be_false
73
+ section.wrapped_html(false).should be_nil
74
+ end
75
+
76
+ it "uses wrapped override html if present" do
77
+ section = SectionPresenter.new(:fallback_html => 'foobar')
78
+ section.override_html = 'hello world'
79
+ section.has_content?(false).should be_true
80
+ section.wrapped_html(false).should == '<section><div class="inner">hello world</div></section>'
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ module Refinery
4
+ module Pages
5
+ describe TitleSectionPresenter do
6
+ describe "when building html for a section" do
7
+ it "wraps a title section in a title element" do
8
+ section = TitleSectionPresenter.new(:fallback_html => 'foobar')
9
+ section.has_content?(true).should be_true
10
+ section.wrapped_html(true).should == '<h1>foobar</h1>'
11
+ end
12
+
13
+ it "will use the specified id" do
14
+ section = TitleSectionPresenter.new(:fallback_html => 'foobar', :id => 'mynode')
15
+ section.has_content?(true).should be_true
16
+ section.wrapped_html(true).should == '<h1 id="mynode">foobar</h1>'
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+
3
+ module Refinery
4
+ describe Pages do
5
+ describe ".valid_templates" do
6
+ before do
7
+ File.open(File.join(subject.root, "spec", "ugisozols.html"), "w+") do
8
+ end
9
+ end
10
+
11
+ after { File.delete(File.join(subject.root, "spec", "ugisozols.html")) }
12
+
13
+ context "when pattern match valid templates" do
14
+ it "returns an array of valid templates" do
15
+ subject.valid_templates('spec', '*html*').should include("ugisozols")
16
+ end
17
+ end
18
+
19
+ context "when pattern doesn't match valid templates" do
20
+ it "returns empty array" do
21
+ subject.valid_templates('huh', '*html*').should == []
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -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