-
Notifications
You must be signed in to change notification settings - Fork 123
/
app_spec.rb
340 lines (278 loc) · 8.61 KB
/
app_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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
require File.join(File.dirname(__FILE__), "model_factory")
require File.join(File.dirname(__FILE__), "spec_helper")
describe "layout" do
include ModelFactory
include RequestSpecHelper
it "should not include GA JavaScript by default" do
stub_configuration
get "/"
body.should_not have_tag("script", /_getTracker\("UA-1234"\)/)
end
it "should include GA JavaScript if configured" do
stub_env_config_key("google_analytics_code", "UA-1234")
stub_configuration
get "/"
body.should have_tag("script", /_getTracker\("UA-1234"\)/)
end
end
describe "page with menus", :shared => true do
before(:each) do
@category = create_category
end
it "should link to menu items" do
create_menu(@category.path)
get @category.abspath
body.should have_tag(
"#sidebar ul.menu a[@href=#{@category.abspath}]", @category.heading)
end
it "should not be display menu if not configured" do
get @category.abspath
body.should_not have_tag("#sidebar ul.menu")
end
end
describe "home page" do
include ModelFactory
include RequestSpecHelper
before(:each) do
stub_configuration
create_category
get "/"
end
after(:each) do
remove_fixtures
FileModel.purge_cache
end
it_should_behave_like "page with menus"
it "should render successfully" do
last_response.should be_ok
end
it "should display title and subtitle in title tag" do
body.should have_tag("title", "My blog - about stuff")
end
it "should display site title in h1 tag" do
body.should have_tag("h1", /My blog/)
end
it "should display site subtitle in h1 tag" do
body.should have_tag("h1 small", /about stuff/)
end
it "should set description meta tag" do
body.should have_tag("meta[@name=description][@content='great web site']")
end
it "should set keywords meta tag" do
body.should have_tag("meta[@name=keywords][@content='home, page']")
end
describe "when articles have no summary" do
before(:each) do
create_article
get "/"
end
it "should display full content of article" do
body.should have_tag("p", "Content goes here")
end
it "should not display read more link" do
body.should_not have_tag("a", /continue/i)
end
end
describe "when articles have metadata" do
before(:each) do
@summary = 'Multiline\n\nsummary'
@read_more = "Continue at your leisure"
@article = create_article(:metadata => {
"summary" => @summary,
"read more" => @read_more
})
get "/"
end
it "should display link to article in h2 tag" do
body.should have_tag(
"h2 a[@href=#{@article.abspath}]", /^\s*#{@article.heading}$/)
end
it "should display article summary if available" do
body.should have_tag("p", @summary.split('\n\n').first)
end
it "should display read more link" do
body.should have_tag("a[@href=#{@article.abspath}]", @read_more)
end
end
end
describe "page with meta tags", :shared => true do
it "should set description meta tag" do
body.should have_tag("meta[@name=description][@content='#{@description}']")
end
it "should set the keywords meta tag" do
body.should have_tag("meta[@name=keywords][@content='#{@keywords}']")
end
end
describe "article" do
include ModelFactory
include RequestSpecHelper
before(:each) do
stub_configuration
@date = "07 September 2009"
@keywords = "things, stuff"
@description = "Page about stuff"
@summary = 'Multiline\n\nsummary'
@article = create_article(:metadata => {
"date" => @date.gsub("September", "Sep"),
"description" => @description,
"keywords" => @keywords,
"summary" => @summary,
})
end
after(:each) do
remove_fixtures
FileModel.purge_cache
end
describe "that's not assigned to a category" do
before(:each) do
get @article.abspath
end
it_should_behave_like "page with menus"
it_should_behave_like "page with meta tags"
it "should render successfully" do
last_response.should be_ok
end
it "should display the heading" do
body.should have_tag("h1", "My article")
end
it "should not display category links" do
body.should_not have_tag("div.breadcrumb div.categories", /filed in/)
end
it "should display the date" do
body.should have_tag("div.date", @date)
end
it "should display the content" do
body.should have_tag("p", "Content goes here")
end
end
describe "that's assigned to categories" do
before(:each) do
# FileModel.purge_cache
create_category(:heading => "Apple", :path => "the-apple")
create_category(:heading => "Banana", :path => "banana")
article = create_article(
:metadata => { "categories" => "banana, the-apple" })
get article.abspath
end
it "should render successfully" do
last_response.should be_ok
end
it "should link to each category" do
body.should have_tag("div.categories", /Filed under/)
body.should have_tag("div.categories") do |categories|
categories.should have_tag("a[@href=/banana]", "Banana")
categories.should have_tag("a[@href=/the-apple]", "Apple")
end
end
end
describe "with parent" do
before(:each) do
@category = create_category(:path => "topic")
article = create_article(:path => "topic/article")
get article.abspath
end
it "should link to parent in breadcrumb" do
body.should have_tag(
"div.breadcrumb/a[@href=#{@category.abspath}]", @category.heading)
end
it "should contain parent name in page title" do
body.should_not have_tag("title", /My blog/)
body.should have_tag("title", /- My category$/)
end
end
end
describe "page" do
include ModelFactory
include RequestSpecHelper
before(:each) do
stub_configuration
end
after(:each) do
remove_fixtures
FileModel.purge_cache
end
it_should_behave_like "page with menus"
describe "that doesn't exist" do
it "should return 404 if page not found" do
get "/no-such-page"
last_response.should_not be_ok
end
end
describe "that exists" do
before(:each) do
@description = "Page about stuff"
@keywords = "things, stuff"
@content = "Page content"
@category = create_category(
:content => "# My category\n\n#{@content}",
:metadata => {
"description" => @description,
"keywords" => @keywords
})
@article = create_category(
:path => "another-page",
:heading => "Categorised",
:metadata => { :categories => @category.path },
:content => "Article content")
@article2 = create_article(
:heading => "Second article", :path => "second-article")
get @category.abspath
end
it_should_behave_like "page with meta tags"
it "should render successfully" do
last_response.should be_ok
end
it "should display the heading" do
body.should have_tag("h1", @category.heading)
end
it "should display the content" do
body.should have_tag("p", @content)
end
it "should display links to relevant pages" do
body.should have_tag(
"h3 a[@href='#{@article.abspath}']", /^\s*#{@article.heading}$/)
body.should_not have_tag("h3", @article2.heading)
end
it "should not include Disqus comments by default" do
body.should_not have_tag('#disqus_thread')
end
end
describe "that is configured to show Disqus comments" do
before(:each) do
stub_config_key("disqus_short_name", "mysite")
@category = create_category
get @category.abspath
end
it "should display Disqus comments" do
body.should have_tag('#disqus_thread')
body.should have_tag('script[@src*="mysite/embed.js"]')
end
end
end
describe "attachments" do
include ModelFactory
include RequestSpecHelper
def create_attachment
stub_configuration
create_content_directories
path = File.join(Nesta::Configuration.attachment_path, "test.txt")
File.open(path, "w") { |file| file.write("I'm a test attachment") }
end
before(:each) do
create_attachment
get "/attachments/test.txt"
end
after(:each) do
remove_fixtures
FileModel.purge_cache
end
it "should be served successfully" do
last_response.should be_ok
end
it "should be sent to the client" do
body.should include("I'm a test attachment")
end
it "should set the appropriate MIME type" do
last_response.headers["Content-Type"].should == "text/plain"
end
end