/
pages_controller_spec.rb
112 lines (84 loc) · 3.49 KB
/
pages_controller_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
# encoding: UTF-8
require 'spec_helper'
describe HighVoltage::PagesController do
render_views
context "using default configuration" do
describe "on GET to /pages/exists" do
before { get :show, :id => 'exists' }
it "should respond with success and render template" do
response.should be_success
response.should render_template('exists')
end
it "should use the default layout used by ApplicationController" do
response.should render_template("layouts/application")
end
end
describe "on GET to /pages/dir/nested" do
before { get :show, :id => 'dir/nested' }
it "should respond with success and render template" do
response.should be_success
response.should render_template('pages/dir/nested')
end
end
it "should raise a routing error for an invalid page" do
lambda { get :show, :id => "invalid" }.should raise_error(ActionController::RoutingError)
end
it "should raise a routing error for a page in another directory" do
lambda { get :show, :id => "../other/wrong" }.should raise_error(ActionController::RoutingError)
end
it "should raise missing template error for valid page with invalid partial" do
lambda { get :show, :id => "exists_but_references_nonexistent_partial" }.should raise_error(ActionView::MissingTemplate)
end
end
context "using custom layout" do
before(:all) do
@original_layout = HighVoltage.layout
HighVoltage.layout = "alternate"
end
after(:all) do
HighVoltage.layout = @original_layout
end
describe "on GET to /pages/exists" do
before { get :show, :id => "exists" }
it "should use the custom configured layout" do
response.should_not render_template("layouts/application")
response.should render_template("layouts/alternate")
end
end
end
context "using custom content path" do
before(:all) do
@original_content_path = HighVoltage.content_path
HighVoltage.content_path = "other_pages/"
end
after(:all) do
HighVoltage.content_path = @original_content_path
end
describe "on GET to /other_pages/also_exists" do
before { get :show, :id => 'also_exists' }
it "should respond with success and render template" do
response.should be_success
response.should render_template('other_pages/also_exists')
end
end
describe "on GET to /other_pages/also_dir/nested" do
before { get :show, :id => 'also_dir/also_nested' }
it "should respond with success and render template" do
response.should be_success
response.should render_template('other_pages/also_dir/also_nested')
end
end
it "should raise a routing error for an invalid page" do
lambda { get :show, :id => "also_invalid" }.should raise_error(ActionController::RoutingError)
end
it "should raise a routing error for a page in another directory" do
lambda { get :show, :id => "../other/wrong" }.should raise_error(ActionController::RoutingError)
end
it "should raise a routing error for a page in another directory when using a Unicode exploit" do
lambda { get :show, :id => "/\\../other/wrong" }.should raise_error(ActionController::RoutingError)
end
it "should raise missing template error for valid page with invalid partial" do
lambda { get :show, :id => "also_exists_but_references_nonexistent_partial" }.should raise_error(ActionView::MissingTemplate)
end
end
end