/
content_presenter_spec.rb
111 lines (91 loc) · 3.82 KB
/
content_presenter_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
require "spec_helper"
module Refinery
module Pages
describe ContentPresenter do
let(:section1) { double(SectionPresenter, :id => 'foo', :has_content? => true) }
let(:section2) { double(SectionPresenter, :id => 'bar', :has_content? => true) }
describe "when building css classes for blank sections" do
let(:section) { double(SectionPresenter, :not_present_css_class => 'no_section1') }
it "includes css class for any section which doesnt have content" do
section.stub(:has_content?).with(true).and_return(false)
content = ContentPresenter.new
content.add_section section
content.blank_section_css_classes(true).should == ['no_section1']
end
it "doesnt include sections which have content" do
section.stub(:has_content?).with(true).and_return(true)
content = ContentPresenter.new
content.add_section section
content.blank_section_css_classes(true).should be_empty
end
end
describe "when hiding sections" do
before do
@content = ContentPresenter.new
@content.add_section section1
@content.add_section section2
end
it "hides a section specified by id" do
section2.should_receive :hide
@content.hide_sections 'bar'
end
# Regression for https://github.com/refinery/refinerycms/issues/1516
it "accepts an array" do
section2.should_receive :hide
@content.hide_sections ['bar']
end
it "hides nothing if nil" do
section1.stub(:hidden?).and_return false
section2.stub(:hidden?).and_return false
@content.hide_sections nil
@content.hidden_sections.count.should == 0
end
end
describe "when fetching template overrides" do
before do
@content = ContentPresenter.new
end
it "yields a section with an id and stores the result in its override html" do
section = double(SectionPresenter, :id => 'foo')
section.should_receive(:override_html=).with('some override')
@content.add_section section
@content.fetch_template_overrides do |section_id|
section_id.should == 'foo'
'some override'
end
end
it "doesnt yield a section without an id" do
section = double(SectionPresenter, :id => nil)
section.should_receive(:override_html=).never
@content.add_section section
@content.fetch_template_overrides do |section_id|
raise "this should not occur"
end
end
end
describe "when rendering as html" do
it "is empty section tag if it has no sections" do
content = ContentPresenter.new
content.to_html.should == "<section class=\"\" id=\"body_content\"></section>"
end
it "returns sections joined by a newline inside section tag" do
section1.stub(:wrapped_html).and_return('foo')
section2.stub(:wrapped_html).and_return('bar')
content = ContentPresenter.new([section1, section2])
content.to_html.should == "<section class=\"\" id=\"body_content\">foo\nbar</section>"
end
it "passes can_use_fallback option on to sections" do
section1.should_receive(:wrapped_html).with(false).and_return('foo')
content = ContentPresenter.new([section1])
content.to_html(false)
end
it "doesnt include sections with nil content" do
section1.stub(:wrapped_html).and_return('foo')
section2.stub(:wrapped_html).and_return(nil)
content = ContentPresenter.new([section1, section2])
content.to_html.should == "<section class=\"\" id=\"body_content\">foo</section>"
end
end
end
end
end