refinerycms-pages 2.1.5 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/refinery/admin/page_parts_controller.rb +6 -1
- data/app/controllers/refinery/admin/pages_controller.rb +53 -45
- data/app/controllers/refinery/pages/admin/preview_controller.rb +12 -3
- data/app/controllers/refinery/pages_controller.rb +12 -12
- data/app/helpers/refinery/admin/pages_helper.rb +5 -4
- data/app/helpers/refinery/pages/content_pages_helper.rb +6 -1
- data/app/models/refinery/page.rb +115 -141
- data/app/models/refinery/page_part.rb +32 -7
- data/app/presenters/refinery/pages/content_presenter.rb +7 -5
- data/app/presenters/refinery/pages/menu_presenter.rb +41 -15
- data/app/presenters/refinery/pages/page_part_section_presenter.rb +1 -7
- data/app/presenters/refinery/pages/section_presenter.rb +2 -6
- data/app/views/refinery/admin/pages/_actions.html.erb +4 -13
- data/app/views/refinery/admin/pages/_form.html.erb +7 -10
- data/app/views/refinery/admin/pages/_form_advanced_options.html.erb +5 -3
- data/app/views/refinery/admin/pages/_form_extra_fields_for_more_options.html.erb +1 -0
- data/app/views/refinery/admin/pages/_form_new_page_parts.html.erb +8 -0
- data/app/views/refinery/admin/pages/_form_page_parts.html.erb +10 -21
- data/app/views/refinery/admin/pages/_page.html.erb +31 -31
- data/app/views/refinery/admin/pages/_page_part_field.html.erb +2 -1
- data/app/views/refinery/admin/pages/_records.html.erb +3 -3
- data/app/views/refinery/admin/pages/_save_and_continue_callback.html.erb +1 -0
- data/app/views/refinery/admin/pages/index.html.erb +2 -4
- data/app/views/refinery/admin/pages_dialogs/link_to.html.erb +1 -1
- data/config/locales/bg.yml +1 -2
- data/config/locales/ca.yml +85 -0
- data/config/locales/cs.yml +13 -3
- data/config/locales/da.yml +1 -2
- data/config/locales/de.yml +0 -1
- data/config/locales/el.yml +41 -29
- data/config/locales/en.yml +2 -2
- data/config/locales/es.yml +2 -4
- data/config/locales/fi.yml +1 -4
- data/config/locales/fr.yml +2 -2
- data/config/locales/hu.yml +1 -2
- data/config/locales/it.yml +15 -16
- data/config/locales/ja.yml +1 -3
- data/config/locales/ko.yml +1 -4
- data/config/locales/lt.yml +1 -3
- data/config/locales/lv.yml +0 -2
- data/config/locales/nb.yml +1 -4
- data/config/locales/nl.yml +1 -2
- data/config/locales/pl.yml +1 -13
- data/config/locales/pt-BR.yml +1 -3
- data/config/locales/pt.yml +1 -2
- data/config/locales/rs.yml +1 -3
- data/config/locales/ru.yml +8 -5
- data/config/locales/sk.yml +1 -2
- data/config/locales/sl.yml +1 -3
- data/config/locales/sv.yml +1 -3
- data/config/locales/tr.yml +1 -2
- data/config/locales/uk.yml +1 -5
- data/config/locales/vi.yml +1 -3
- data/config/locales/zh-CN.yml +1 -4
- data/config/locales/zh-TW.yml +1 -3
- data/config/routes.rb +16 -16
- data/db/migrate/20100913234708_create_refinerycms_pages_schema.rb +28 -11
- data/db/migrate/20140105190324_add_custom_slug_to_refinery_pages.rb +20 -0
- data/db/migrate/20150130044643_add_slug_to_refinery_page_parts.rb +6 -0
- data/db/migrate/20150720155305_update_slug_and_title_in_refinery_page_parts.rb +13 -0
- data/db/seeds.rb +42 -36
- data/lib/generators/refinery/pages/templates/config/initializers/refinery/pages.rb.erb +12 -0
- data/lib/refinery/pages.rb +4 -3
- data/lib/refinery/pages/admin/instance_methods.rb +3 -3
- data/lib/refinery/pages/configuration.rb +7 -1
- data/lib/refinery/pages/engine.rb +19 -18
- data/lib/refinery/pages/finder.rb +179 -0
- data/lib/refinery/pages/instance_methods.rb +3 -14
- data/lib/refinery/pages/tab.rb +2 -2
- data/lib/refinery/pages/types.rb +1 -1
- data/lib/refinery/pages/url.rb +15 -3
- data/license.md +1 -1
- data/refinerycms-pages.gemspec +8 -5
- data/spec/controllers/refinery/admin/pages_controller_spec.rb +53 -0
- data/spec/controllers/refinery/pages_controller_spec.rb +1 -1
- data/spec/factories/pages.rb +1 -1
- data/spec/features/refinery/admin/pages_spec.rb +274 -290
- data/spec/features/refinery/pages_spec.rb +123 -138
- data/spec/helpers/refinery/pages/admin/pages_helper_spec.rb +15 -11
- data/spec/helpers/refinery/pages/content_pages_helper_spec.rb +11 -11
- data/spec/lib/generators/refinery/pages/pages_generator_spec.rb +1 -1
- data/spec/lib/pages_spec.rb +2 -2
- data/spec/lib/refinery/pages/tab_spec.rb +9 -9
- data/spec/lib/refinery/pages/url_spec.rb +12 -12
- data/spec/models/refinery/page_finder_spec.rb +72 -0
- data/spec/models/refinery/page_menu_spec.rb +107 -0
- data/spec/models/refinery/page_meta_data_spec.rb +49 -0
- data/spec/models/refinery/page_part_spec.rb +67 -0
- data/spec/models/refinery/page_spec.rb +16 -534
- data/spec/models/refinery/page_url_spec.rb +320 -0
- data/spec/presenters/refinery/pages/content_page_presenter_spec.rb +9 -9
- data/spec/presenters/refinery/pages/content_presenter_spec.rb +20 -20
- data/spec/presenters/refinery/pages/menu_presenter_spec.rb +44 -6
- data/spec/presenters/refinery/pages/page_part_section_presenter_spec.rb +12 -12
- data/spec/presenters/refinery/pages/section_presenter_spec.rb +22 -22
- data/spec/presenters/refinery/pages/title_section_presenter_spec.rb +4 -4
- data/spec/support/refinery/pages/caching_helpers.rb +2 -2
- metadata +55 -25
- data/app/helpers/refinery/admin/page_parts_helper.rb +0 -6
- data/app/helpers/refinery/admin/pages_dialogs_helper.rb +0 -6
- data/app/sweepers/refinery/pages/page_sweeper.rb +0 -29
- data/lib/refinery/pages/caching.rb +0 -60
- data/spec/lib/refinery/pages/caching_spec.rb +0 -90
- data/spec/support/refinery/pages/caching.rb +0 -19
@@ -2,29 +2,29 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
module Refinery
|
4
4
|
module Admin
|
5
|
-
describe PagesHelper do
|
5
|
+
describe PagesHelper, :type => :helper do
|
6
6
|
describe "#template_options" do
|
7
7
|
context "when page layout/view template is set" do
|
8
8
|
it "returns those templates as selected" do
|
9
9
|
page = FactoryGirl.create(:page)
|
10
10
|
|
11
11
|
page.view_template = "rspec_template"
|
12
|
-
helper.template_options(:view_template, page).
|
12
|
+
expect(helper.template_options(:view_template, page)).to eq(:selected => "rspec_template")
|
13
13
|
|
14
14
|
page.layout_template = "rspec_layout"
|
15
|
-
helper.template_options(:layout_template, page).
|
15
|
+
expect(helper.template_options(:layout_template, page)).to eq(:selected => "rspec_layout")
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
context "when page layout template is set using symbols" do
|
20
20
|
before do
|
21
|
-
Pages.config.
|
21
|
+
allow(Pages.config).to receive(:layout_template_whitelist).and_return [:three, :one, :two]
|
22
22
|
end
|
23
23
|
|
24
24
|
it "works as expected" do
|
25
25
|
page = FactoryGirl.create(:page, :layout_template => "three")
|
26
26
|
|
27
|
-
helper.template_options(:layout_template, page).
|
27
|
+
expect(helper.template_options(:layout_template, page)).to eq(:selected => 'three')
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -35,7 +35,7 @@ module Refinery
|
|
35
35
|
page = FactoryGirl.create(:page, :parent_id => parent.id)
|
36
36
|
|
37
37
|
expected_layout = { :selected => parent.layout_template }
|
38
|
-
helper.template_options(:layout_template, page).
|
38
|
+
expect(helper.template_options(:layout_template, page)).to eq(expected_layout)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -44,7 +44,7 @@ module Refinery
|
|
44
44
|
page = FactoryGirl.create(:page)
|
45
45
|
|
46
46
|
expected_layout = { :selected => "application" }
|
47
|
-
helper.template_options(:layout_template, page).
|
47
|
+
expect(helper.template_options(:layout_template, page)).to eq(expected_layout)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -57,7 +57,9 @@ module Refinery
|
|
57
57
|
it "adds 'hidden' label" do
|
58
58
|
page.show_in_menu = false
|
59
59
|
|
60
|
-
helper.page_meta_information(page).
|
60
|
+
expect(helper.page_meta_information(page)).to eq(
|
61
|
+
%Q{<span class="label">#{::I18n.t('refinery.admin.pages.page.hidden')}</span>}
|
62
|
+
)
|
61
63
|
end
|
62
64
|
end
|
63
65
|
|
@@ -65,7 +67,9 @@ module Refinery
|
|
65
67
|
it "adds 'draft' label" do
|
66
68
|
page.draft = true
|
67
69
|
|
68
|
-
helper.page_meta_information(page).
|
70
|
+
expect(helper.page_meta_information(page)).to eq(
|
71
|
+
%Q{<span class="label notice">#{::I18n.t('refinery.admin.pages.page.draft')}</span>}
|
72
|
+
)
|
69
73
|
end
|
70
74
|
end
|
71
75
|
end
|
@@ -87,14 +91,14 @@ module Refinery
|
|
87
91
|
|
88
92
|
context "when title is present" do
|
89
93
|
it "returns it" do
|
90
|
-
helper.page_title_with_translations(page).
|
94
|
+
expect(helper.page_title_with_translations(page)).to eq("draft")
|
91
95
|
end
|
92
96
|
end
|
93
97
|
|
94
98
|
context "when title for current locale isn't available" do
|
95
99
|
it "returns existing title from translations" do
|
96
100
|
Page.translation_class.where(:locale => :en).first.destroy
|
97
|
-
helper.page_title_with_translations(page).
|
101
|
+
expect(helper.page_title_with_translations(page)).to eq("melnraksts")
|
98
102
|
end
|
99
103
|
end
|
100
104
|
end
|
@@ -2,28 +2,28 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Refinery
|
4
4
|
module Pages
|
5
|
-
describe ContentPagesHelper do
|
5
|
+
describe ContentPagesHelper, :type => :helper do
|
6
6
|
let(:content_presenter) { double(ContentPresenter, :hide_sections => nil, :fetch_template_overrides => nil, :to_html => nil) }
|
7
7
|
|
8
8
|
describe "when rendering content presenter" do
|
9
9
|
it "asks to content presenter to hide sections if told to" do
|
10
|
-
content_presenter.
|
10
|
+
expect(content_presenter).to receive(:hide_sections).with(['foo', 'bar'])
|
11
11
|
render_content_presenter(content_presenter, :hide_sections => ['foo', 'bar'])
|
12
12
|
end
|
13
13
|
|
14
14
|
it "attempts to fetch template overrides declared elsewhere via content_for" do
|
15
|
-
content_presenter.
|
16
|
-
self.
|
15
|
+
expect(content_presenter).to receive(:fetch_template_overrides).and_yield(12)
|
16
|
+
expect(self).to receive(:content_for).with(12)
|
17
17
|
render_content_presenter(content_presenter)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "outputs the html rendered by the content presenter" do
|
21
|
-
content_presenter.
|
22
|
-
render_content_presenter(content_presenter).
|
21
|
+
expect(content_presenter).to receive(:to_html).and_return('foobar')
|
22
|
+
expect(render_content_presenter(content_presenter)).to eq('foobar')
|
23
23
|
end
|
24
24
|
|
25
25
|
it "passes can_use_fallback option through to html rendering" do
|
26
|
-
content_presenter.
|
26
|
+
expect(content_presenter).to receive(:to_html).with(true)
|
27
27
|
render_content_presenter(content_presenter, :can_use_fallback => true)
|
28
28
|
end
|
29
29
|
end
|
@@ -32,11 +32,11 @@ module Refinery
|
|
32
32
|
let(:page) { double(Page) }
|
33
33
|
|
34
34
|
it "builds a content page presenter and returns its html" do
|
35
|
-
self.
|
36
|
-
Refinery::Pages::ContentPagePresenter.
|
37
|
-
content_presenter.
|
35
|
+
expect(self).to receive(:page_title).and_return('some title')
|
36
|
+
expect(Refinery::Pages::ContentPagePresenter).to receive(:new).with(page, 'some title').and_return(content_presenter)
|
37
|
+
expect(content_presenter).to receive(:to_html).and_return('barfoo')
|
38
38
|
|
39
|
-
render_content_page(page).
|
39
|
+
expect(render_content_page(page)).to eq('barfoo')
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
data/spec/lib/pages_spec.rb
CHANGED
@@ -12,13 +12,13 @@ module Refinery
|
|
12
12
|
|
13
13
|
context "when pattern match valid templates" do
|
14
14
|
it "returns an array of valid templates" do
|
15
|
-
subject.valid_templates('spec', '*html*').
|
15
|
+
expect(subject.valid_templates('spec', '*html*')).to include("ugisozols")
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
context "when pattern doesn't match valid templates" do
|
20
20
|
it "returns empty array" do
|
21
|
-
subject.valid_templates('huh', '*html*').
|
21
|
+
expect(subject.valid_templates('huh', '*html*')).to eq([])
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -14,7 +14,7 @@ module Refinery
|
|
14
14
|
tab.partial = "rspec"
|
15
15
|
end
|
16
16
|
|
17
|
-
Refinery::Pages.tabs.
|
17
|
+
expect(Refinery::Pages.tabs).to include(rspec_tab)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -29,7 +29,7 @@ module Refinery
|
|
29
29
|
tab.partial = "rspec"
|
30
30
|
end
|
31
31
|
|
32
|
-
Refinery::Pages.tabs_for_template("huh").
|
32
|
+
expect(Refinery::Pages.tabs_for_template("huh")).to include(rspec_tab)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "returns tabs with matched template" do
|
@@ -39,7 +39,7 @@ module Refinery
|
|
39
39
|
tab.templates = "rspec"
|
40
40
|
end
|
41
41
|
|
42
|
-
Refinery::Pages.tabs_for_template("rspec").
|
42
|
+
expect(Refinery::Pages.tabs_for_template("rspec")).to include(rspec_tab)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -50,19 +50,19 @@ module Refinery
|
|
50
50
|
|
51
51
|
describe ".register" do
|
52
52
|
it "requires name to be set" do
|
53
|
-
|
53
|
+
expect {
|
54
54
|
Refinery::Pages::Tab.register do |tab|
|
55
55
|
tab.partial = "rspec"
|
56
56
|
end
|
57
|
-
}.
|
57
|
+
}.to raise_error(ArgumentError)
|
58
58
|
end
|
59
59
|
|
60
60
|
it "requires partial to be set" do
|
61
|
-
|
61
|
+
expect {
|
62
62
|
Refinery::Pages::Tab.register do |tab|
|
63
63
|
tab.name = "rspec"
|
64
64
|
end
|
65
|
-
}.
|
65
|
+
}.to raise_error(ArgumentError)
|
66
66
|
end
|
67
67
|
|
68
68
|
it "sets #templates if it's not set" do
|
@@ -71,7 +71,7 @@ module Refinery
|
|
71
71
|
tab.partial = "rspec"
|
72
72
|
end
|
73
73
|
|
74
|
-
rspec_tab.templates.
|
74
|
+
expect(rspec_tab.templates).to eq(["all"])
|
75
75
|
end
|
76
76
|
|
77
77
|
it "converts #templates to array if it's not an array already" do
|
@@ -81,7 +81,7 @@ module Refinery
|
|
81
81
|
tab.templates = "rspec"
|
82
82
|
end
|
83
83
|
|
84
|
-
rspec_tab.templates.
|
84
|
+
expect(rspec_tab.templates).to eq(["rspec"])
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
@@ -6,7 +6,7 @@ module Refinery
|
|
6
6
|
describe ".handle?" do
|
7
7
|
it "returns true if link_url is present" do
|
8
8
|
page = double(:page, :link_url => "/")
|
9
|
-
Url::Localised.handle?(page).
|
9
|
+
expect(Url::Localised.handle?(page)).to be_truthy
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -15,17 +15,17 @@ module Refinery
|
|
15
15
|
|
16
16
|
context "when current frontend locale != default frontend locale" do
|
17
17
|
it "returns link_url prefixed with current frontend locale" do
|
18
|
-
Refinery::I18n.
|
19
|
-
Refinery::I18n.
|
20
|
-
Url::Localised.new(page).url.
|
18
|
+
allow(Refinery::I18n).to receive(:current_frontend_locale).and_return(:lv)
|
19
|
+
allow(Refinery::I18n).to receive(:default_frontend_locale).and_return(:en)
|
20
|
+
expect(Url::Localised.new(page).url).to eq("/lv/test")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
context "when current frontend locale == default frontend locale" do
|
25
25
|
it "returns unaltered link_url" do
|
26
|
-
Refinery::I18n.
|
27
|
-
Refinery::I18n.
|
28
|
-
Url::Localised.new(page).url.
|
26
|
+
allow(Refinery::I18n).to receive(:current_frontend_locale).and_return(:en)
|
27
|
+
allow(Refinery::I18n).to receive(:default_frontend_locale).and_return(:en)
|
28
|
+
expect(Url::Localised.new(page).url).to eq("/test")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -35,15 +35,15 @@ module Refinery
|
|
35
35
|
describe ".handle?" do
|
36
36
|
it "returns true if marketable_url config is set to true" do
|
37
37
|
page = double(:page)
|
38
|
-
Refinery::Pages.
|
39
|
-
Url::Marketable.handle?(page).
|
38
|
+
allow(Refinery::Pages).to receive(:marketable_url).and_return(true)
|
39
|
+
expect(Url::Marketable.handle?(page)).to be_truthy
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
describe "#url" do
|
44
44
|
it "returns hash" do
|
45
45
|
page = double(:page, :nested_url => "test")
|
46
|
-
Url::Marketable.new(page).url.
|
46
|
+
expect(Url::Marketable.new(page).url).to eq({
|
47
47
|
:controller => "/refinery/pages", :action => "show", :only_path => true,
|
48
48
|
:path => "test", :id => nil
|
49
49
|
})
|
@@ -55,14 +55,14 @@ module Refinery
|
|
55
55
|
describe ".handle?" do
|
56
56
|
it "returns true if to_param is present" do
|
57
57
|
page = double(:page, :to_param => "test")
|
58
|
-
Url::Normal.handle?(page).
|
58
|
+
expect(Url::Normal.handle?(page)).to be_truthy
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
describe "#url" do
|
63
63
|
it "returns hash" do
|
64
64
|
page = double(:page, :to_param => "test")
|
65
|
-
Url::Normal.new(page).url.
|
65
|
+
expect(Url::Normal.new(page).url).to eq({
|
66
66
|
:controller => "/refinery/pages", :action => "show", :only_path => true,
|
67
67
|
:path => nil, :id => "test"
|
68
68
|
})
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Refinery
|
5
|
+
describe Page do
|
6
|
+
let(:page_title) { 'RSpec is great for testing too' }
|
7
|
+
let(:child_title) { 'The child page' }
|
8
|
+
|
9
|
+
let(:created_page) { subject.class.create!(:title => page_title, :deletable => true) }
|
10
|
+
let(:created_child) { created_page.children.create!(:title => child_title) }
|
11
|
+
|
12
|
+
describe '.find_by_path' do
|
13
|
+
let(:page_title) { 'team' }
|
14
|
+
let(:child_title) { 'about' }
|
15
|
+
let(:created_root_about) { subject.class.create!(:title => child_title, :deletable => true) }
|
16
|
+
|
17
|
+
before do
|
18
|
+
# Ensure pages are created.
|
19
|
+
created_child
|
20
|
+
created_root_about
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return (root) about page when looking for '/about'" do
|
24
|
+
expect(Page.find_by_path('/about')).to eq(created_root_about)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return child about page when looking for '/team/about'" do
|
28
|
+
expect(Page.find_by_path('/team/about')).to eq(created_child)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe ".find_by_path_or_id" do
|
33
|
+
let!(:market) { FactoryGirl.create(:page, :title => "market") }
|
34
|
+
let(:path) { "market" }
|
35
|
+
let(:id) { market.id }
|
36
|
+
|
37
|
+
context "when path param is present" do
|
38
|
+
context "when path is friendly_id" do
|
39
|
+
it "finds page using path" do
|
40
|
+
expect(Page.find_by_path_or_id(path, "")).to eq(market)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when path is not friendly_id" do
|
45
|
+
it "finds page using id" do
|
46
|
+
expect(Page.find_by_path_or_id(id, "")).to eq(market)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when id param is present" do
|
52
|
+
it "finds page using id" do
|
53
|
+
expect(Page.find_by_path_or_id("", id)).to eq(market)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe ".find_by_path_or_id!" do
|
59
|
+
it "delegates to find_by_path_or_id" do
|
60
|
+
lambda do
|
61
|
+
expect(Page).to receive(:find_by_path_or_id).with("path", "id")
|
62
|
+
Page.find_by_path_or_id!("path", "id")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "throws exception when page isn't found" do
|
67
|
+
expect { Page.find_by_path_or_id!("not", "here") }.to raise_error(ActiveRecord::RecordNotFound)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Refinery
|
5
|
+
describe Page do
|
6
|
+
let(:page_title) { 'RSpec is great for testing too' }
|
7
|
+
let(:page) { subject.class.new(:title => page_title, :deletable => true)}
|
8
|
+
|
9
|
+
describe "#to_refinery_menu_item" do
|
10
|
+
let(:page) do
|
11
|
+
Page.new(
|
12
|
+
:id => 5,
|
13
|
+
:parent_id => 8,
|
14
|
+
:menu_match => "^/foo$"
|
15
|
+
|
16
|
+
# Page does not allow setting lft and rgt, so stub them.
|
17
|
+
).tap do |p|
|
18
|
+
p[:lft] = 6
|
19
|
+
p[:rgt] = 7
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
subject { page.to_refinery_menu_item }
|
24
|
+
|
25
|
+
shared_examples_for("Refinery menu item hash") do
|
26
|
+
[ [:id, 5],
|
27
|
+
[:lft, 6],
|
28
|
+
[:rgt, 7],
|
29
|
+
[:parent_id, 8],
|
30
|
+
[:menu_match, "^/foo$"]
|
31
|
+
].each do |attr, value|
|
32
|
+
it "returns the correct :#{attr}" do
|
33
|
+
expect(subject[attr]).to eq(value)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns the correct :url" do
|
38
|
+
expect(subject[:url]).to be_a(Hash) # guard against nil
|
39
|
+
expect(subject[:url]).to eq(page.url)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with #menu_title" do
|
44
|
+
before do
|
45
|
+
page[:menu_title] = "Menu Title"
|
46
|
+
end
|
47
|
+
|
48
|
+
it_should_behave_like "Refinery menu item hash"
|
49
|
+
|
50
|
+
it "returns the menu_title for :title" do
|
51
|
+
expect(subject[:title]).to eq("Menu Title")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with #title" do
|
56
|
+
before do
|
57
|
+
page[:title] = "Title"
|
58
|
+
end
|
59
|
+
|
60
|
+
it_should_behave_like "Refinery menu item hash"
|
61
|
+
|
62
|
+
it "returns the title for :title" do
|
63
|
+
expect(subject[:title]).to eq("Title")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#in_menu?" do
|
69
|
+
context "when live? and show_in_menu? returns true" do
|
70
|
+
it "returns true" do
|
71
|
+
allow(page).to receive(:live?).and_return(true)
|
72
|
+
allow(page).to receive(:show_in_menu?).and_return(true)
|
73
|
+
expect(page.in_menu?).to be_truthy
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when live? or show_in_menu? doesn't return true" do
|
78
|
+
it "returns false" do
|
79
|
+
allow(page).to receive(:live?).and_return(true)
|
80
|
+
allow(page).to receive(:show_in_menu?).and_return(false)
|
81
|
+
expect(page.in_menu?).to be_falsey
|
82
|
+
|
83
|
+
allow(page).to receive(:live?).and_return(false)
|
84
|
+
allow(page).to receive(:show_in_menu?).and_return(true)
|
85
|
+
expect(page.in_menu?).to be_falsey
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#not_in_menu?" do
|
91
|
+
context "when in_menu? returns true" do
|
92
|
+
it "returns false" do
|
93
|
+
allow(page).to receive(:in_menu?).and_return(true)
|
94
|
+
expect(page.not_in_menu?).to be_falsey
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "when in_menu? returns false" do
|
99
|
+
it "returns true" do
|
100
|
+
allow(page).to receive(:in_menu?).and_return(false)
|
101
|
+
expect(page.not_in_menu?).to be_truthy
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|