-
Notifications
You must be signed in to change notification settings - Fork 15
/
action_view_spec.rb
171 lines (146 loc) · 4.64 KB
/
action_view_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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
require 'spec/spec_helper'
describe ShareLayouts::Helpers::ActionView do
include ShareLayouts::Helpers::ActionView
dataset :layouts_layouts, :layouts_pages
test_helper :page
attr_accessor :request, :response
MAIN_RESULT = <<-TEXT
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body class="site parent">
something
</body>
</html>
TEXT
before(:each) do
@page = RailsPage.new(page_params(:class_name => "RailsPage"))
@content_for_layout = "something"
@radiant_layout = layouts(:parent).name
@request = OpenStruct.new(:path => "/some/page/")
end
it "should extract_content_captures_as_hash" do
extract_captures.should == {:body => "something"}
@content_for_sidebar = "sidebar"
extract_captures.should == {:body => "something", :sidebar => "sidebar"}
end
# testing assignment of layout
it "should assign_layout_of_page" do
assign_attributes!(@page)
@page.layout.should == layouts(:parent)
end
it "should assign_layout_of_page_when_missing" do
previous_layout = @page.layout
@radiant_layout = ''
assign_attributes!(@page)
previous_layout.should == @page.layout
end
# testing assignment of page.title
it "should assign_page_title_from_instance_var" do
@title = "My title"
assign_attributes!(@page)
@page.title.should == "My title"
end
it "should assign_page_title_from_capture" do
@content_for_title = "My title"
assign_attributes!(@page)
@page.title.should == "My title"
end
it "should assign_title_from_existing_page_title_when_not_specified" do
assign_attributes!(@page)
@page.title.should =~ /New Page/ # was 'New Page' before. I assume this changed in Radiant 0.8
end
it "should assign_empty_title_if_missing" do
@page.title = nil
@title.should be_nil
@content_for_title.should be_nil
@page.title.should be_nil
assign_attributes!(@page)
@page.title.should == ''
end
#testing assignment of page.breadcrumb
it "should assign_page_breadcrumb_from_instance_var" do
@breadcrumb = "My breadcrumb"
assign_attributes!(@page)
@page.breadcrumb.should == "My breadcrumb"
end
it "should assign_page_breadcrumb_from_capture" do
@content_for_breadcrumb = "My breadcrumb"
assign_attributes!(@page)
@page.breadcrumb.should == "My breadcrumb"
end
it "should assign_breadcrumb_from_existing_breadcrumb_when_not_specified" do
@page.breadcrumb = "existing breadcrumb"
assign_attributes!(@page)
@page.breadcrumb.should == 'existing breadcrumb'
end
it "should assign_breadcrumb_from_title_if_missing" do
@page.title = "Title into BC"
@page.breadcrumb = nil
@breadcrumb.should be_nil
@content_for_breadcrumb.should be_nil
@page.breadcrumb.should be_nil
assign_attributes!(@page)
@page.breadcrumb.should == 'Title into BC'
end
it "should assign_empty_breadcrumb_if_title_missing_too" do
@page.title = nil
@title.should be_nil
@content_for_title.should be_nil
@page.title.should be_nil
@page.breadcrumb = nil
@breadcrumb.should be_nil
@content_for_breadcrumb.should be_nil
@page.breadcrumb.should be_nil
assign_attributes!(@page)
@page.breadcrumb.should == ''
end
# testing assignment of page.breadcrumbs
it "should assign_breadcrumbs_from_instance_var" do
@breadcrumbs = "bc"
assign_attributes!(@page)
@page.breadcrumbs.should == 'bc'
end
it "should assign_breadcrumbs_from_capture" do
@content_for_breadcrumbs = "bc"
assign_attributes!(@page)
@page.breadcrumbs.should == 'bc'
end
it "should leave_breadcrumbs_nil_if_missing" do
@page.breadcrumbs = nil
@breadcrumbs.should be_nil
@content_for_breadcrumbs.should be_nil
@page.breadcrumbs.should be_nil
assign_attributes!(@page)
@page.breadcrumbs.should be_nil
end
# testing assigment of page.url
it "should assign_url_from_request_path" do
assign_attributes!(@page)
@page.url.should == '/some/page/'
end
# testing assigment of page.slug
it "should assign_slug_from_request_path" do
assign_attributes!(@page)
@page.slug.should == 'page'
end
# testing assignment of page.published_at
it "should assign_published_at" do
assign_attributes!(@page)
@page.published_at.should_not be_nil
end
it "should render_page" do
@title = "My Title"
radiant_layout.strip.should == MAIN_RESULT.strip
end
it "should find_page" do
@request.path = "/app/something/"
find_page.should == pages(:rails)
find_page.should be_a_kind_of(RailsPage)
@request.path = "/some-other/url/"
find_page.should_not == pages(:rails)
find_page.should be_a_kind_of(RailsPage)
end
end