nesta 0.11.1 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitmodules +6 -0
- data/.travis.yml +9 -4
- data/CHANGES +18 -2
- data/Gemfile +1 -1
- data/Gemfile.lock +70 -54
- data/LICENSE +1 -1
- data/RELEASING.md +5 -6
- data/Rakefile +20 -3
- data/lib/nesta/app.rb +4 -8
- data/lib/nesta/commands/command.rb +1 -2
- data/lib/nesta/commands/demo/content.rb +23 -5
- data/lib/nesta/commands/theme/install.rb +9 -7
- data/lib/nesta/helpers.rb +14 -0
- data/lib/nesta/models.rb +26 -22
- data/lib/nesta/navigation.rb +1 -1
- data/lib/nesta/version.rb +1 -1
- data/nesta.gemspec +10 -11
- data/templates/config/config.yml +1 -1
- data/{spec → test}/fixtures/nesta-plugin-test/Gemfile +0 -0
- data/{spec → test}/fixtures/nesta-plugin-test/Rakefile +0 -0
- data/{spec → test}/fixtures/nesta-plugin-test/lib/nesta-plugin-test.rb +0 -0
- data/{spec → test}/fixtures/nesta-plugin-test/lib/nesta-plugin-test/init.rb +0 -0
- data/{spec → test}/fixtures/nesta-plugin-test/lib/nesta-plugin-test/version.rb +0 -0
- data/{spec → test}/fixtures/nesta-plugin-test/nesta-plugin-test.gemspec +0 -0
- data/test/integration/atom_feed_test.rb +178 -0
- data/test/integration/commands/demo/content_test.rb +31 -0
- data/test/integration/commands/edit_test.rb +21 -0
- data/test/integration/commands/new_test.rb +120 -0
- data/test/integration/commands/plugin/create_test.rb +128 -0
- data/test/integration/commands/theme/create_test.rb +35 -0
- data/test/integration/commands/theme/enable_test.rb +22 -0
- data/test/integration/commands/theme/install_test.rb +62 -0
- data/test/integration/default_theme_test.rb +220 -0
- data/test/integration/overrides_test.rb +118 -0
- data/test/integration/route_handlers_test.rb +96 -0
- data/test/integration/sitemap_test.rb +85 -0
- data/test/integration_test_helper.rb +61 -0
- data/test/support/model_factory.rb +169 -0
- data/test/support/silence_commands_during_tests.rb +5 -0
- data/test/support/temporary_files.rb +33 -0
- data/test/support/test_configuration.rb +19 -0
- data/test/test_helper.rb +26 -0
- data/test/unit/commands_test.rb +23 -0
- data/test/unit/config_test.rb +138 -0
- data/test/unit/file_model_test.rb +71 -0
- data/test/unit/menu_test.rb +82 -0
- data/test/unit/page_test.rb +571 -0
- data/test/unit/path_test.rb +41 -0
- data/test/unit/plugin_test.rb +47 -0
- data/views/master.sass +1 -1
- metadata +81 -85
- data/smoke-test.sh +0 -107
- data/spec/atom_spec.rb +0 -141
- data/spec/commands/demo/content_spec.rb +0 -65
- data/spec/commands/edit_spec.rb +0 -27
- data/spec/commands/new_spec.rb +0 -88
- data/spec/commands/plugin/create_spec.rb +0 -97
- data/spec/commands/system_spec.rb +0 -25
- data/spec/commands/theme/create_spec.rb +0 -41
- data/spec/commands/theme/enable_spec.rb +0 -44
- data/spec/commands/theme/install_spec.rb +0 -56
- data/spec/config_spec.rb +0 -127
- data/spec/model_factory.rb +0 -92
- data/spec/models_spec.rb +0 -700
- data/spec/overrides_spec.rb +0 -132
- data/spec/page_spec.rb +0 -560
- data/spec/path_spec.rb +0 -28
- data/spec/plugin_spec.rb +0 -51
- data/spec/sitemap_spec.rb +0 -105
- data/spec/spec_helper.rb +0 -114
data/spec/overrides_spec.rb
DELETED
@@ -1,132 +0,0 @@
|
|
1
|
-
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
-
require File.expand_path('model_factory', File.dirname(__FILE__))
|
3
|
-
|
4
|
-
describe "Rendering" do
|
5
|
-
include ModelFactory
|
6
|
-
include RequestSpecHelper
|
7
|
-
|
8
|
-
def create_fixture(type, name, content)
|
9
|
-
base_path = {
|
10
|
-
local: Nesta::Path.local,
|
11
|
-
theme: Nesta::Path.themes(@theme)
|
12
|
-
}[type]
|
13
|
-
path = File.join(base_path, name)
|
14
|
-
@fixtures << path
|
15
|
-
FileUtils.mkdir_p(File.dirname(path))
|
16
|
-
open(path, 'w') { |file| file.write(content) }
|
17
|
-
end
|
18
|
-
|
19
|
-
def create_template(type, name, content)
|
20
|
-
create_fixture(type, File.join('views', 'layout.haml'), '= yield')
|
21
|
-
create_fixture(type, File.join('views', name), content)
|
22
|
-
end
|
23
|
-
|
24
|
-
def create_app_file(type)
|
25
|
-
create_fixture(type, 'app.rb', "DEFINED_IN_#{type.to_s.upcase}_FILE = true")
|
26
|
-
end
|
27
|
-
|
28
|
-
before(:each) do
|
29
|
-
@app_root = Nesta::App.root
|
30
|
-
Nesta::App.root = temp_path('root')
|
31
|
-
@theme = 'my-theme'
|
32
|
-
@fixtures = []
|
33
|
-
stub_configuration
|
34
|
-
end
|
35
|
-
|
36
|
-
after(:each) do
|
37
|
-
@fixtures.each { |path| FileUtils.rm(path) if File.exist?(path) }
|
38
|
-
Nesta::App.root = @app_root
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "when rendering stylesheets" do
|
42
|
-
it "should render Sass stylesheets" do
|
43
|
-
create_template(:local, 'master.sass', "body\n width: 10px * 2")
|
44
|
-
get "/css/master.css"
|
45
|
-
body.should match(/width: 20px;/)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should render SCSS stylesheets" do
|
49
|
-
create_template(:local, 'master.scss', "body {\n width: 10px * 2;\n}")
|
50
|
-
get "/css/master.css"
|
51
|
-
body.should match(/width: 20px;/)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should render the Gem's stylesheet if no other's found" do
|
55
|
-
get "/css/master.css"
|
56
|
-
last_response.should be_ok
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "when local files exist" do
|
61
|
-
before(:each) do
|
62
|
-
create_template(:local, 'page.haml', '%p Local template')
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should use local application files" do
|
66
|
-
create_app_file(:local)
|
67
|
-
Nesta::Overrides.load_local_app
|
68
|
-
Object.const_get(:DEFINED_IN_LOCAL_FILE).should be_true
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should use local template in place of default" do
|
72
|
-
get create_category.abspath
|
73
|
-
body.should have_selector("p:contains('Local template')")
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "when theme installed" do
|
78
|
-
before(:each) do
|
79
|
-
create_template(:theme, 'page.haml', '%p Theme template')
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should not require theme application file automatically" do
|
83
|
-
create_app_file(:theme)
|
84
|
-
lambda {
|
85
|
-
Object.const_get(:DEFINED_IN_THEME_FILE)
|
86
|
-
}.should raise_error(NameError)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should not use theme templates automatically" do
|
90
|
-
get create_category.abspath
|
91
|
-
body.should_not have_selector("p:contains('Theme template')")
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "and configured" do
|
95
|
-
before(:each) do
|
96
|
-
stub_config_key("theme", @theme)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should require theme application file" do
|
100
|
-
create_app_file(:theme)
|
101
|
-
Nesta::Overrides.load_theme_app
|
102
|
-
Object.const_get(:DEFINED_IN_THEME_FILE).should be_true
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should use theme's template in place of default" do
|
106
|
-
get create_category.abspath
|
107
|
-
body.should have_selector("p:contains('Theme template')")
|
108
|
-
end
|
109
|
-
|
110
|
-
context "and local files exist" do
|
111
|
-
before(:each) do
|
112
|
-
create_template(:local, "page.haml", "%p Local template")
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should require local and theme application files" do
|
116
|
-
create_app_file(:local)
|
117
|
-
create_app_file(:theme)
|
118
|
-
Nesta::Overrides.load_theme_app
|
119
|
-
Nesta::Overrides.load_local_app
|
120
|
-
Object.const_get(:DEFINED_IN_LOCAL_FILE).should be_true
|
121
|
-
Object.const_get(:DEFINED_IN_THEME_FILE).should be_true
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should use local template" do
|
125
|
-
get create_category.abspath
|
126
|
-
body.should_not have_selector("p:contains('Theme template')")
|
127
|
-
body.should have_selector("p:contains('Local template')")
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
data/spec/page_spec.rb
DELETED
@@ -1,560 +0,0 @@
|
|
1
|
-
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
-
require File.expand_path('model_factory', File.dirname(__FILE__))
|
3
|
-
|
4
|
-
shared_examples_for "page with keyword and description" do
|
5
|
-
it "should set the keywords meta tag" do
|
6
|
-
do_get
|
7
|
-
assert_xpath "//meta[@name='keywords'][@content='#{@keywords}']"
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should set description meta tag" do
|
11
|
-
do_get
|
12
|
-
assert_xpath "//meta[@name='description'][@content='#{@description}']"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
shared_examples_for "page that can display menus" do
|
17
|
-
it "should not display menu by default" do
|
18
|
-
do_get
|
19
|
-
last_response.should be_ok
|
20
|
-
assert_not_selector "#sidebar ul.menu"
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "and simple menu configured" do
|
24
|
-
before(:each) do
|
25
|
-
create_menu(@category.path)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should link to top level menu items" do
|
29
|
-
do_get
|
30
|
-
link_text = @category.link_text
|
31
|
-
href = @category.abspath
|
32
|
-
assert_selector "ul.menu a[@href$='#{href}']:contains('#{link_text}')"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "and nested menu configured" do
|
37
|
-
before(:each) do
|
38
|
-
@level2 = create_category(path: "level-2", heading: "Level 2",
|
39
|
-
metadata: {'link text' => "Level 2 link"})
|
40
|
-
@level3 = create_category(path: "level-3", heading: "Level 3")
|
41
|
-
text = <<-EOF
|
42
|
-
#{@category.abspath}
|
43
|
-
#{@level2.abspath}
|
44
|
-
#{@level3.abspath}
|
45
|
-
EOF
|
46
|
-
create_menu(text)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should display first level of nested sub menus" do
|
50
|
-
do_get
|
51
|
-
assert_selector "ul.menu li ul li a:contains('#{@level2.link_text}')"
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should not display nested menus to arbitrary depth" do
|
55
|
-
do_get
|
56
|
-
last_response.should be_ok
|
57
|
-
assert_not_selector "ul.menu li ul li ul"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "and menu links to home page" do
|
62
|
-
before(:each) do
|
63
|
-
text = <<-EOF
|
64
|
-
/
|
65
|
-
#{@category.abspath}
|
66
|
-
EOF
|
67
|
-
create_menu(text)
|
68
|
-
template_path = File.expand_path(
|
69
|
-
'templates', File.dirname(File.dirname(__FILE__)))
|
70
|
-
@default_homepage_content = File.read(File.join(template_path,
|
71
|
-
'index.haml'))
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should use 'Home' as the home page link if not otherwise specified" do
|
75
|
-
create_page(
|
76
|
-
path: 'index',
|
77
|
-
ext: :haml,
|
78
|
-
content: @default_homepage_content)
|
79
|
-
do_get
|
80
|
-
assert_selector "ul.menu a[@href='/']:contains('Home')"
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should use the heading if it exists" do
|
84
|
-
create_page(
|
85
|
-
path: 'index',
|
86
|
-
ext: :haml,
|
87
|
-
heading: 'My heading',
|
88
|
-
content: @default_homepage_content)
|
89
|
-
do_get
|
90
|
-
assert_selector "ul.menu a[@href='/']:contains('My heading')"
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should use the link text if specified" do
|
94
|
-
create_page(
|
95
|
-
path: 'index',
|
96
|
-
ext: :haml,
|
97
|
-
heading: 'My heading',
|
98
|
-
content: @default_homepage_content,
|
99
|
-
metadata: {'link text'=>'My link text'})
|
100
|
-
do_get
|
101
|
-
assert_selector "ul.menu a[@href='/']:contains('My link text')"
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "The layout" do
|
107
|
-
include ModelFactory
|
108
|
-
include RequestSpecHelper
|
109
|
-
|
110
|
-
it "should not include GA JavaScript by default" do
|
111
|
-
stub_configuration
|
112
|
-
get "/"
|
113
|
-
assert_not_selector "script", content: "ga('create', 'UA-1234'"
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should include GA JavaScript if configured" do
|
117
|
-
stub_config_key('google_analytics_code', 'UA-1234', rack_env: true)
|
118
|
-
stub_configuration
|
119
|
-
get "/"
|
120
|
-
assert_selector 'script', content: "ga('create', 'UA-1234'"
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe "The home page" do
|
125
|
-
include ModelFactory
|
126
|
-
include RequestSpecHelper
|
127
|
-
|
128
|
-
before(:each) do
|
129
|
-
stub_configuration
|
130
|
-
template_path = File.expand_path(
|
131
|
-
'templates', File.dirname(File.dirname(__FILE__)))
|
132
|
-
create_category(
|
133
|
-
path: 'index',
|
134
|
-
ext: :haml,
|
135
|
-
heading: 'Home',
|
136
|
-
content: File.read(File.join(template_path, 'index.haml'))
|
137
|
-
)
|
138
|
-
create_category
|
139
|
-
end
|
140
|
-
|
141
|
-
after(:each) do
|
142
|
-
remove_temp_directory
|
143
|
-
Nesta::FileModel.purge_cache
|
144
|
-
end
|
145
|
-
|
146
|
-
def do_get
|
147
|
-
get "/"
|
148
|
-
end
|
149
|
-
|
150
|
-
describe "when categories exist" do
|
151
|
-
before(:each) do
|
152
|
-
@category = create_category
|
153
|
-
end
|
154
|
-
|
155
|
-
it_should_behave_like "page that can display menus"
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should render successfully" do
|
159
|
-
do_get
|
160
|
-
last_response.should be_ok
|
161
|
-
end
|
162
|
-
|
163
|
-
it "should display site title in hgroup tag" do
|
164
|
-
do_get
|
165
|
-
assert_selector 'hgroup h1', content: "My blog"
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should display site subtitle in hgroup tag" do
|
169
|
-
do_get
|
170
|
-
assert_selector 'hgroup h2', content: "about stuff"
|
171
|
-
end
|
172
|
-
|
173
|
-
describe "when articles have no summary" do
|
174
|
-
before(:each) do
|
175
|
-
create_article
|
176
|
-
do_get
|
177
|
-
end
|
178
|
-
|
179
|
-
it "should display full content of article" do
|
180
|
-
assert_selector "p", content: "Content goes here"
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should not display read more link" do
|
184
|
-
last_response.should be_ok
|
185
|
-
assert_not_selector "a", content: 'continue'
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
describe "when articles have metadata" do
|
190
|
-
before(:each) do
|
191
|
-
@summary = 'Multiline\n\nsummary'
|
192
|
-
@read_more = "Continue at your leisure"
|
193
|
-
@article = create_article(metadata: {
|
194
|
-
"summary" => @summary,
|
195
|
-
"read more" => @read_more
|
196
|
-
})
|
197
|
-
do_get
|
198
|
-
end
|
199
|
-
|
200
|
-
it "should display link to article in h2 tag" do
|
201
|
-
link_text = @article.link_text
|
202
|
-
href = @article.abspath
|
203
|
-
assert_selector "h1 a[@href$='#{href}']:contains('#{link_text}')"
|
204
|
-
end
|
205
|
-
|
206
|
-
it "should display article summary if available" do
|
207
|
-
assert_selector 'p', content: @summary.split('\n\n').first
|
208
|
-
end
|
209
|
-
|
210
|
-
it "should display read more link" do
|
211
|
-
assert_selector "a[@href$='#{@article.abspath}']", content: @read_more
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
describe "An article" do
|
217
|
-
include ModelFactory
|
218
|
-
include RequestSpecHelper
|
219
|
-
|
220
|
-
before(:each) do
|
221
|
-
stub_configuration
|
222
|
-
@date = '07 September 2009'
|
223
|
-
@keywords = 'things, stuff'
|
224
|
-
@description = 'Page about stuff'
|
225
|
-
@summary = 'Multiline\n\nsummary'
|
226
|
-
@link_text = 'Link to page about stuff'
|
227
|
-
@article = create_article(metadata: {
|
228
|
-
'date' => @date.gsub('September', 'Sep'),
|
229
|
-
'description' => @description,
|
230
|
-
'keywords' => @keywords,
|
231
|
-
'summary' => @summary,
|
232
|
-
'link text' => @link_text
|
233
|
-
})
|
234
|
-
end
|
235
|
-
|
236
|
-
after(:each) do
|
237
|
-
remove_temp_directory
|
238
|
-
Nesta::FileModel.purge_cache
|
239
|
-
end
|
240
|
-
|
241
|
-
def do_get
|
242
|
-
get @article.abspath
|
243
|
-
end
|
244
|
-
|
245
|
-
it_should_behave_like "page with keyword and description"
|
246
|
-
|
247
|
-
describe "when categories exist" do
|
248
|
-
before(:each) do
|
249
|
-
@category = create_category
|
250
|
-
end
|
251
|
-
|
252
|
-
it_should_behave_like "page that can display menus"
|
253
|
-
end
|
254
|
-
|
255
|
-
it "should render successfully" do
|
256
|
-
do_get
|
257
|
-
last_response.should be_ok
|
258
|
-
end
|
259
|
-
|
260
|
-
it "should display the heading" do
|
261
|
-
do_get
|
262
|
-
assert_selector 'h1', content: 'My article'
|
263
|
-
end
|
264
|
-
|
265
|
-
it "should use link text for title tag" do
|
266
|
-
do_get
|
267
|
-
assert_selector 'title', content: @link_text
|
268
|
-
end
|
269
|
-
|
270
|
-
it "should display the date" do
|
271
|
-
do_get
|
272
|
-
assert_selector 'time', content: @date
|
273
|
-
end
|
274
|
-
|
275
|
-
it "should display the content" do
|
276
|
-
do_get
|
277
|
-
assert_selector 'p', content: 'Content goes here'
|
278
|
-
end
|
279
|
-
|
280
|
-
describe "that is assigned to categories" do
|
281
|
-
before(:each) do
|
282
|
-
create_category(heading: 'Apple', path: 'the-apple')
|
283
|
-
@category = create_category(heading: 'Banana', path: 'banana')
|
284
|
-
@article = create_article(
|
285
|
-
path: "#{@category.path}/article",
|
286
|
-
metadata: { 'categories' => 'banana, the-apple' }
|
287
|
-
)
|
288
|
-
end
|
289
|
-
|
290
|
-
it "should render successfully" do
|
291
|
-
do_get
|
292
|
-
last_response.should be_ok
|
293
|
-
end
|
294
|
-
|
295
|
-
it "should link to each category" do
|
296
|
-
do_get
|
297
|
-
assert_selector "p.meta a[href='/banana']", content: "Banana"
|
298
|
-
assert_selector "p.meta a[href='/the-apple']", content: "Apple"
|
299
|
-
end
|
300
|
-
|
301
|
-
it "should link to a category in breadcrumb" do
|
302
|
-
do_get
|
303
|
-
href = @category.abspath
|
304
|
-
link_text = @category.link_text
|
305
|
-
assert_selector "nav.breadcrumb a[href='#{href}']", content: link_text
|
306
|
-
end
|
307
|
-
|
308
|
-
it "should not include Disqus comments by default" do
|
309
|
-
do_get
|
310
|
-
last_response.should be_ok
|
311
|
-
assert_not_selector '#disqus_thread'
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
describe "that is configured to show Disqus comments" do
|
316
|
-
before(:each) do
|
317
|
-
stub_config_key("disqus_short_name", "mysite")
|
318
|
-
@category = create_category
|
319
|
-
end
|
320
|
-
|
321
|
-
it "should display Disqus comments" do
|
322
|
-
do_get
|
323
|
-
assert_selector '#disqus_thread'
|
324
|
-
assert_selector 'script[@src*="mysite.disqus.com/embed.js"]'
|
325
|
-
end
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
|
-
describe "A page" do
|
330
|
-
include ModelFactory
|
331
|
-
include RequestSpecHelper
|
332
|
-
|
333
|
-
before(:each) do
|
334
|
-
stub_configuration
|
335
|
-
end
|
336
|
-
|
337
|
-
after(:each) do
|
338
|
-
remove_temp_directory
|
339
|
-
Nesta::FileModel.purge_cache
|
340
|
-
end
|
341
|
-
|
342
|
-
def do_get
|
343
|
-
get @category.abspath
|
344
|
-
end
|
345
|
-
|
346
|
-
describe "that doesn't exist" do
|
347
|
-
it "should render the 404 page" do
|
348
|
-
get "/no-such-page"
|
349
|
-
last_response.should be_not_found
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
|
-
describe "that has meta data" do
|
354
|
-
before(:each) do
|
355
|
-
@title = 'Different title'
|
356
|
-
@content = "Page content"
|
357
|
-
@description = "Page about stuff"
|
358
|
-
@keywords = "things, stuff"
|
359
|
-
@articles_heading = "Posts about this stuff"
|
360
|
-
@category = create_category(
|
361
|
-
content: "# My category\n\n#{@content}",
|
362
|
-
metadata: {
|
363
|
-
'title' => @title,
|
364
|
-
'description' => @description,
|
365
|
-
'keywords' => @keywords,
|
366
|
-
'articles heading' => @articles_heading
|
367
|
-
}
|
368
|
-
)
|
369
|
-
end
|
370
|
-
|
371
|
-
it_should_behave_like "page with keyword and description"
|
372
|
-
it_should_behave_like "page that can display menus"
|
373
|
-
|
374
|
-
describe "whose URL ends in /" do
|
375
|
-
it "should be redirected, removing the slash" do
|
376
|
-
get @category.abspath + '/'
|
377
|
-
last_response.should be_redirect
|
378
|
-
end
|
379
|
-
end
|
380
|
-
|
381
|
-
it "should render successfully" do
|
382
|
-
do_get
|
383
|
-
last_response.should be_ok
|
384
|
-
end
|
385
|
-
|
386
|
-
it "should display the heading" do
|
387
|
-
do_get
|
388
|
-
assert_selector 'h1', content: @category.heading
|
389
|
-
end
|
390
|
-
|
391
|
-
it "should use title metadata to set heading" do
|
392
|
-
do_get
|
393
|
-
assert_selector 'title', content: @title
|
394
|
-
end
|
395
|
-
|
396
|
-
it "should display the content" do
|
397
|
-
do_get
|
398
|
-
assert_selector "p", content: @content
|
399
|
-
end
|
400
|
-
|
401
|
-
describe "with associated pages" do
|
402
|
-
before(:each) do
|
403
|
-
@category1 = create_category(
|
404
|
-
path: 'category1',
|
405
|
-
heading: 'Category 1',
|
406
|
-
metadata: {
|
407
|
-
'categories' => 'category-prefix/my-category:-1'
|
408
|
-
}
|
409
|
-
)
|
410
|
-
@category2 = create_category(
|
411
|
-
path: 'category2',
|
412
|
-
heading: 'Category 2',
|
413
|
-
metadata: {
|
414
|
-
'categories' => 'category-prefix/my-category:1'
|
415
|
-
}
|
416
|
-
)
|
417
|
-
end
|
418
|
-
|
419
|
-
it "should list highest priority pages at the top" do
|
420
|
-
do_get
|
421
|
-
assert_selector 'li:nth-child(1) h1 a', content: 'Category 2'
|
422
|
-
assert_selector 'li:nth-child(2) h1 a', content: 'Category 1'
|
423
|
-
end
|
424
|
-
end
|
425
|
-
|
426
|
-
describe "with associated articles" do
|
427
|
-
before(:each) do
|
428
|
-
@article = create_article(
|
429
|
-
path: "another-page",
|
430
|
-
heading: "Categorised",
|
431
|
-
metadata: { categories: @category.path,
|
432
|
-
'link text' => 'Categorised link'},
|
433
|
-
content: "Article content"
|
434
|
-
)
|
435
|
-
@article2 = create_article(
|
436
|
-
path: "second-article", heading: "Second article")
|
437
|
-
end
|
438
|
-
|
439
|
-
it "should display links to articles" do
|
440
|
-
do_get
|
441
|
-
href = @article.abspath
|
442
|
-
link_text = @article.link_text
|
443
|
-
assert_selector "h1 a[@href$='#{href}']", content: link_text
|
444
|
-
assert_not_selector "h3", content: @article2.link_text
|
445
|
-
end
|
446
|
-
|
447
|
-
it "should display the article heading" do
|
448
|
-
do_get
|
449
|
-
assert_selector 'h1', content: @articles_heading
|
450
|
-
end
|
451
|
-
end
|
452
|
-
end
|
453
|
-
|
454
|
-
describe "with associated categories" do
|
455
|
-
it "should link to the first assigned category in breadcrumb" do
|
456
|
-
category1 = create_category(path: 'category1', heading: 'Category 1')
|
457
|
-
create_category(path: 'category2', heading: 'Category 2')
|
458
|
-
@category = create_page(
|
459
|
-
path: "a-page",
|
460
|
-
heading: "A Page",
|
461
|
-
metadata: { 'categories' => 'category1, category2' }
|
462
|
-
)
|
463
|
-
do_get
|
464
|
-
href = category1.abspath
|
465
|
-
link_text = category1.link_text
|
466
|
-
assert_selector "nav.breadcrumb a[href='#{href}']", content: link_text
|
467
|
-
end
|
468
|
-
end
|
469
|
-
end
|
470
|
-
|
471
|
-
describe "A Haml page" do
|
472
|
-
include ModelFactory
|
473
|
-
include RequestSpecHelper
|
474
|
-
|
475
|
-
before(:each) do
|
476
|
-
stub_configuration
|
477
|
-
end
|
478
|
-
|
479
|
-
after(:each) do
|
480
|
-
remove_temp_directory
|
481
|
-
Nesta::FileModel.purge_cache
|
482
|
-
end
|
483
|
-
|
484
|
-
it "should be able to access helper methods" do
|
485
|
-
create_page(
|
486
|
-
path: "a-page",
|
487
|
-
ext: :haml,
|
488
|
-
content: "%div= format_date(Date.new(2010, 11, 23))",
|
489
|
-
heading: "A Page"
|
490
|
-
)
|
491
|
-
get "/a-page"
|
492
|
-
assert_selector "div", content: "23 November 2010"
|
493
|
-
end
|
494
|
-
|
495
|
-
it "should access helpers when rendering articles on a category page" do
|
496
|
-
category = create_page(
|
497
|
-
path: "a-page",
|
498
|
-
heading: "First heading",
|
499
|
-
content: "Blah blah"
|
500
|
-
)
|
501
|
-
create_article(
|
502
|
-
path: "an-article",
|
503
|
-
ext: :haml,
|
504
|
-
heading: "First heading",
|
505
|
-
metadata: { categories: category.path },
|
506
|
-
content: "%h1 Second heading\n\n%div= format_date(Date.new(2010, 11, 23))"
|
507
|
-
)
|
508
|
-
get "/a-page"
|
509
|
-
assert_selector "div", content: "23 November 2010"
|
510
|
-
end
|
511
|
-
end
|
512
|
-
|
513
|
-
describe "attachments" do
|
514
|
-
include ModelFactory
|
515
|
-
include RequestSpecHelper
|
516
|
-
|
517
|
-
before(:each) do
|
518
|
-
stub_configuration
|
519
|
-
create_content_directories
|
520
|
-
end
|
521
|
-
|
522
|
-
after(:each) do
|
523
|
-
remove_temp_directory
|
524
|
-
Nesta::FileModel.purge_cache
|
525
|
-
end
|
526
|
-
|
527
|
-
describe "in the attachments folder" do
|
528
|
-
before(:each) do
|
529
|
-
path = File.join(Nesta::Config.attachment_path, 'test.txt')
|
530
|
-
File.open(path, 'w') { |file| file.write("I'm a test attachment") }
|
531
|
-
end
|
532
|
-
|
533
|
-
it "should be served successfully" do
|
534
|
-
get "/attachments/test.txt"
|
535
|
-
last_response.should be_ok
|
536
|
-
end
|
537
|
-
|
538
|
-
it "should be sent to the client" do
|
539
|
-
get "/attachments/test.txt"
|
540
|
-
body.should include("I'm a test attachment")
|
541
|
-
end
|
542
|
-
|
543
|
-
it "should set the appropriate MIME type" do
|
544
|
-
get "/attachments/test.txt"
|
545
|
-
last_response.headers["Content-Type"].should =~ Regexp.new("^text/plain")
|
546
|
-
end
|
547
|
-
end
|
548
|
-
|
549
|
-
describe "outside the attachments folder" do
|
550
|
-
before(:each) do
|
551
|
-
path = File.join(Nesta::Config.page_path, 'index.haml')
|
552
|
-
File.open(path, 'w') { |file| file.write('%h1 Test page') }
|
553
|
-
end
|
554
|
-
|
555
|
-
it "should be directory traversal free" do
|
556
|
-
get '/attachments/../pages/index.haml'
|
557
|
-
last_response.should_not be_ok
|
558
|
-
end
|
559
|
-
end
|
560
|
-
end
|