high_voltage 1.1.1 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/.travis.yml +6 -0
- data/Appraisals +4 -6
- data/Gemfile.lock +3 -3
- data/MIT-LICENSE +1 -1
- data/README.md +83 -16
- data/Rakefile +10 -6
- data/app/controllers/high_voltage/pages_controller.rb +12 -15
- data/config/routes.rb +3 -2
- data/gemfiles/{rails-3.0.10.gemfile → rails-3.0.15.gemfile} +1 -1
- data/gemfiles/{rails-3.1.0.gemfile → rails-3.1.6.gemfile} +1 -1
- data/gemfiles/rails-3.2.6.gemfile +7 -0
- data/lib/high_voltage/constraints/root_route.rb +24 -0
- data/lib/high_voltage/engine.rb +0 -2
- data/lib/high_voltage/page_finder.rb +37 -0
- data/lib/high_voltage/route_drawers/default.rb +15 -0
- data/lib/high_voltage/route_drawers/root.rb +16 -0
- data/lib/high_voltage/version.rb +1 -1
- data/lib/high_voltage.rb +12 -2
- data/spec/constraints/root_route_spec.rb +21 -0
- data/spec/controllers/alternative_finder_controller_spec.rb +12 -0
- data/spec/controllers/pages_controller_spec.rb +63 -41
- data/spec/controllers/subclassed_pages_controller_spec.rb +19 -20
- data/spec/dummy/app/controllers/alternative_finder_controller.rb +14 -0
- data/spec/dummy/app/controllers/subclassed_pages_controller.rb +0 -4
- data/spec/dummy/app/views/pages/also_dir/also_nested.html.erb +1 -0
- data/spec/dummy/app/views/pages/also_exists.html.erb +1 -0
- data/spec/dummy/app/views/pages/also_exists_but_references_nonexistent_partial.html.erb +2 -0
- data/spec/dummy/app/views/pages/rot13.html.erb +1 -0
- data/spec/dummy/config/application.rb +0 -1
- data/spec/dummy/config/environments/test.rb +0 -5
- data/spec/dummy/config/routes.rb +1 -0
- data/spec/high_voltage/page_finder_spec.rb +52 -0
- data/spec/high_voltage_spec.rb +2 -2
- data/spec/integration/navigation_spec.rb +3 -3
- data/spec/routing/routes_spec.rb +114 -32
- data/spec/spec_helper.rb +4 -16
- metadata +99 -86
- data/gemfiles/rails-3.0.10.gemfile.lock +0 -124
- data/gemfiles/rails-3.1.0.gemfile.lock +0 -137
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
high_voltage (1.
|
|
4
|
+
high_voltage (1.2.1)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: http://rubygems.org/
|
|
@@ -22,7 +22,7 @@ GEM
|
|
|
22
22
|
builder (~> 2.1.2)
|
|
23
23
|
i18n (~> 0.5.0)
|
|
24
24
|
activesupport (3.0.10)
|
|
25
|
-
appraisal (0.
|
|
25
|
+
appraisal (0.4.1)
|
|
26
26
|
bundler
|
|
27
27
|
rake
|
|
28
28
|
builder (2.1.2)
|
|
@@ -55,7 +55,7 @@ GEM
|
|
|
55
55
|
rake (>= 0.8.7)
|
|
56
56
|
rdoc (~> 3.4)
|
|
57
57
|
thor (~> 0.14.4)
|
|
58
|
-
rake (0.9.2)
|
|
58
|
+
rake (0.9.2.2)
|
|
59
59
|
rdoc (3.9.4)
|
|
60
60
|
rspec (2.6.0)
|
|
61
61
|
rspec-core (~> 2.6.0)
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# High Voltage [](http://travis-ci.org/thoughtbot/high_voltage)
|
|
2
2
|
|
|
3
3
|
Rails engine for static pages.
|
|
4
4
|
|
|
@@ -57,26 +57,59 @@ In that case, you'd need an app/views/pages/home.html.erb file.
|
|
|
57
57
|
|
|
58
58
|
Generally speaking, you need to route to the 'show' action with an :id param of the view filename.
|
|
59
59
|
|
|
60
|
-
High Voltage will generate a named route method of `page_path` which you can use, as well. If you
|
|
61
|
-
want to generate a named route (with the :as routing option) for some route which will be handled
|
|
62
|
-
by High Voltage, make sure not to use :page as the name, because that will conflict with the named
|
|
63
|
-
route generated by High Voltage itself.
|
|
60
|
+
High Voltage will generate a named route method of `page_path` which you can use, as well. If you
|
|
61
|
+
want to generate a named route (with the :as routing option) for some route which will be handled
|
|
62
|
+
by High Voltage, make sure not to use :page as the name, because that will conflict with the named
|
|
63
|
+
route generated by High Voltage itself.
|
|
64
|
+
|
|
65
|
+
For example, this will work for top-level routes (we will
|
|
64
66
|
get a named route called `static_path` which does not conflict with the generated `page_path` method):
|
|
65
67
|
|
|
66
68
|
match '/:id' => 'high_voltage/pages#show', :as => :static, :via => :get
|
|
67
69
|
|
|
70
|
+
#### Specifying a root path
|
|
71
|
+
|
|
68
72
|
You can route the root url to a high voltage page like this:
|
|
69
73
|
|
|
70
74
|
root :to => 'high_voltage/pages#show', :id => 'home'
|
|
71
75
|
|
|
72
76
|
Which will render a homepage from app/views/pages/home.html.erb
|
|
73
77
|
|
|
78
|
+
#### Enabling root domain routes
|
|
79
|
+
|
|
80
|
+
You can remove the directory `pages` from the URL path and serve up routes from
|
|
81
|
+
the root of the domain path:
|
|
82
|
+
|
|
83
|
+
http://www.example.com/about
|
|
84
|
+
http://www.example.com/company
|
|
85
|
+
|
|
86
|
+
Would look for corresponding files:
|
|
87
|
+
|
|
88
|
+
app/views/pages/about.html.erb
|
|
89
|
+
app/views/pages/company.html.erb
|
|
90
|
+
|
|
91
|
+
This is accomplished by changing the `HighVoltage.route_drawer` to `HighVoltage::RouteDrawers::Root`
|
|
92
|
+
|
|
93
|
+
# config/initializers/high_voltage.rb
|
|
94
|
+
HighVoltage.route_drawer = HighVoltage::RouteDrawers::Root
|
|
95
|
+
|
|
96
|
+
Note: This is not a catchall route. It will check the `HighVoltage.content_path`
|
|
97
|
+
(by default this is `app/views/pages`) and validate the view exists.
|
|
98
|
+
|
|
99
|
+
#### Disabling routes
|
|
100
|
+
|
|
101
|
+
The default routes can be completely removed by changing the
|
|
102
|
+
`HighVoltage.routes` to `false`
|
|
103
|
+
|
|
104
|
+
# config/initializers/high_voltage.rb
|
|
105
|
+
HighVoltage.routes = false
|
|
106
|
+
|
|
74
107
|
Customize
|
|
75
108
|
--------
|
|
76
109
|
|
|
77
110
|
High Voltage uses a default path and folder of 'pages', i.e. 'url.com/pages/contact' , 'app/views/pages'
|
|
78
111
|
|
|
79
|
-
You can change this in an initializer:
|
|
112
|
+
You can change this in an initializer:
|
|
80
113
|
|
|
81
114
|
HighVoltage.content_path = "site/"
|
|
82
115
|
|
|
@@ -115,25 +148,58 @@ Then modify it to subclass from High Voltage, adding whatever you need:
|
|
|
115
148
|
end
|
|
116
149
|
end
|
|
117
150
|
|
|
151
|
+
Custom finding
|
|
152
|
+
--------------
|
|
153
|
+
|
|
154
|
+
You can further control the algorithm used to find pages by overriding
|
|
155
|
+
the `page_finder_factory` method:
|
|
156
|
+
|
|
157
|
+
class PagesController < HighVoltage::PagesController
|
|
158
|
+
private
|
|
159
|
+
|
|
160
|
+
def page_finder_factory
|
|
161
|
+
Rot13PageFinder
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
The easiest thing is to subclass `HighVoltage::PageFinder`, which
|
|
166
|
+
provides you with `page_id`:
|
|
167
|
+
|
|
168
|
+
class Rot13PageFinder < HighVoltage::PageFinder
|
|
169
|
+
def find
|
|
170
|
+
paths = super.split('/')
|
|
171
|
+
directory = paths[0..-2]
|
|
172
|
+
filename = paths[-1].tr('a-z','n-za-m')
|
|
173
|
+
|
|
174
|
+
File.join(*directory, filename)
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
Use this to create a custom file mapping, clean filenames for your file
|
|
179
|
+
system, A/B test, and so on.
|
|
180
|
+
|
|
118
181
|
Testing
|
|
119
182
|
-------
|
|
120
183
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
class PagesControllerTest < ActionController::TestCase
|
|
124
|
-
tests PagesController
|
|
184
|
+
You can test your static pages using [RSpec](https://github.com/rspec/rspec-rails)
|
|
185
|
+
and [shoulda-matchers](https://github.com/thoughtbot/shoulda-matchers):
|
|
125
186
|
|
|
187
|
+
# spec/controllers/pages_controller_spec.rb
|
|
188
|
+
describe PagesController, '#show' do
|
|
126
189
|
%w(earn_money screencast about contact).each do |page|
|
|
127
|
-
context
|
|
128
|
-
|
|
190
|
+
context 'on GET to /pages/#{page}' do
|
|
191
|
+
before do
|
|
192
|
+
get :show, :id => page
|
|
193
|
+
end
|
|
129
194
|
|
|
130
|
-
|
|
131
|
-
|
|
195
|
+
it { should respond_with(:success) }
|
|
196
|
+
it { should render_template(page) }
|
|
132
197
|
end
|
|
133
198
|
end
|
|
134
199
|
end
|
|
135
200
|
|
|
136
|
-
If you're not using a custom PagesController be sure to test
|
|
201
|
+
If you're not using a custom PagesController be sure to test
|
|
202
|
+
`HighVoltage::PagesController` instead.
|
|
137
203
|
|
|
138
204
|
Enjoy!
|
|
139
205
|
|
|
@@ -156,4 +222,5 @@ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
|
|
156
222
|
License
|
|
157
223
|
-------
|
|
158
224
|
|
|
159
|
-
High Voltage is Copyright © 2009-
|
|
225
|
+
High Voltage is Copyright © 2009-2012 thoughtbot. It is free software, and may
|
|
226
|
+
be redistributed under the terms specified in the MIT-LICENSE file.
|
data/Rakefile
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
require 'bundler/setup'
|
|
2
2
|
require 'bundler/gem_tasks'
|
|
3
3
|
require 'appraisal'
|
|
4
|
-
require 'rspec/core/rake_task'
|
|
5
4
|
|
|
5
|
+
require 'rspec/core/rake_task'
|
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
task :default do |t|
|
|
9
|
+
if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/
|
|
10
|
+
exec 'rake spec'
|
|
11
|
+
else
|
|
12
|
+
Rake::Task['appraise'].execute
|
|
13
|
+
end
|
|
14
|
+
end
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
exec('rake appraisal spec')
|
|
16
|
+
task :appraise => ['appraisal:install'] do |t|
|
|
17
|
+
exec 'rake appraisal'
|
|
14
18
|
end
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
class HighVoltage::PagesController < ApplicationController
|
|
2
|
-
|
|
3
2
|
unloadable
|
|
4
|
-
layout Proc.new { |_| HighVoltage
|
|
3
|
+
layout Proc.new { |_| HighVoltage.layout }
|
|
5
4
|
|
|
6
5
|
rescue_from ActionView::MissingTemplate do |exception|
|
|
7
|
-
if exception.message =~ %r{Missing template #{content_path}}
|
|
6
|
+
if exception.message =~ %r{Missing template #{page_finder.content_path}}
|
|
8
7
|
raise ActionController::RoutingError, "No such page: #{params[:id]}"
|
|
9
8
|
else
|
|
10
9
|
raise exception
|
|
@@ -15,19 +14,17 @@ class HighVoltage::PagesController < ApplicationController
|
|
|
15
14
|
render :template => current_page
|
|
16
15
|
end
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def current_page
|
|
21
|
-
"#{content_path}#{clean_path}"
|
|
22
|
-
end
|
|
17
|
+
private
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
end
|
|
19
|
+
def current_page
|
|
20
|
+
page_finder.find
|
|
21
|
+
end
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
def page_finder
|
|
24
|
+
page_finder_factory.new(params[:id])
|
|
25
|
+
end
|
|
32
26
|
|
|
27
|
+
def page_finder_factory
|
|
28
|
+
HighVoltage::PageFinder
|
|
29
|
+
end
|
|
33
30
|
end
|
data/config/routes.rb
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module HighVoltage
|
|
2
|
+
module Constraints
|
|
3
|
+
# Routing constraint to validate request.path has a corresponding view
|
|
4
|
+
class RootRoute
|
|
5
|
+
VIEW_EXTENSIONS = 'html.erb,html.haml,html'
|
|
6
|
+
|
|
7
|
+
def self.matches?(request)
|
|
8
|
+
pattern = file_pattern(request.path)
|
|
9
|
+
|
|
10
|
+
Dir.glob(pattern).any?
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def self.file_pattern(page_id)
|
|
16
|
+
"#{content_path}#{page_id}.{#{VIEW_EXTENSIONS}}"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.content_path
|
|
20
|
+
Rails.root.join('app', 'views', HighVoltage.content_path).to_s
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
data/lib/high_voltage/engine.rb
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module HighVoltage
|
|
2
|
+
# A command for finding pages by id. This encapsulates the concepts of
|
|
3
|
+
# mapping page names to file names.
|
|
4
|
+
class PageFinder
|
|
5
|
+
VALID_CHARACTERS = "a-zA-Z0-9~!@$%^&*()#`_+-=<>\"{}|[];',?".freeze
|
|
6
|
+
|
|
7
|
+
def initialize(page_id)
|
|
8
|
+
@page_id = page_id
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Produce a template path to the page, in a format understood by
|
|
12
|
+
# `render :template => find`
|
|
13
|
+
def find
|
|
14
|
+
"#{content_path}#{clean_path}"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def content_path
|
|
18
|
+
HighVoltage.content_path
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
protected
|
|
22
|
+
|
|
23
|
+
# The raw page id passed in by the user
|
|
24
|
+
attr_reader :page_id
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def clean_path
|
|
29
|
+
path = Pathname.new("/#{clean_id}")
|
|
30
|
+
path.cleanpath.to_s[1..-1]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def clean_id
|
|
34
|
+
@page_id.tr("^#{VALID_CHARACTERS}", '')
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module HighVoltage
|
|
2
|
+
module RouteDrawers
|
|
3
|
+
# Matches routes in the HighVoltage.content_path directory. By default this looks
|
|
4
|
+
# for /pages/id. e.g. http://www.example.com/pages/about_us
|
|
5
|
+
class Default
|
|
6
|
+
def self.match_attributes
|
|
7
|
+
{
|
|
8
|
+
"/#{HighVoltage.content_path}*id" => 'high_voltage/pages#show',
|
|
9
|
+
:as => :page,
|
|
10
|
+
:format => false
|
|
11
|
+
}
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module HighVoltage
|
|
2
|
+
module RouteDrawers
|
|
3
|
+
# Matches routes from root of the domain e.g. http://www.example.com/about_us
|
|
4
|
+
# Uses HighVoltage::Constraints::RootRoute to validate view exists.
|
|
5
|
+
class Root
|
|
6
|
+
def self.match_attributes
|
|
7
|
+
{
|
|
8
|
+
"/*id" => 'high_voltage/pages#show',
|
|
9
|
+
:as => :page,
|
|
10
|
+
:format => false,
|
|
11
|
+
:constraints => HighVoltage::Constraints::RootRoute
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/high_voltage/version.rb
CHANGED
data/lib/high_voltage.rb
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
require 'high_voltage/version'
|
|
2
|
+
require 'high_voltage/constraints/root_route'
|
|
3
|
+
require 'high_voltage/page_finder'
|
|
4
|
+
require 'high_voltage/route_drawers/default'
|
|
5
|
+
require 'high_voltage/route_drawers/root'
|
|
2
6
|
|
|
3
7
|
module HighVoltage
|
|
4
8
|
mattr_accessor :layout
|
|
5
|
-
@@layout =
|
|
9
|
+
@@layout = 'application'
|
|
6
10
|
|
|
7
11
|
mattr_accessor :content_path
|
|
8
|
-
@@content_path =
|
|
12
|
+
@@content_path = 'pages/'
|
|
13
|
+
|
|
14
|
+
mattr_accessor :route_drawer
|
|
15
|
+
@@route_drawer = HighVoltage::RouteDrawers::Default
|
|
16
|
+
|
|
17
|
+
mattr_accessor :routes
|
|
18
|
+
@@routes = true
|
|
9
19
|
|
|
10
20
|
def self.setup
|
|
11
21
|
yield self
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe HighVoltage::Constraints::RootRoute, '.matches?' do
|
|
4
|
+
context 'view file exists' do
|
|
5
|
+
it 'should return true' do
|
|
6
|
+
request = stub(:path => 'index')
|
|
7
|
+
Dir.stub!(:glob).and_return(['about.html.erb'])
|
|
8
|
+
|
|
9
|
+
HighVoltage::Constraints::RootRoute.matches?(request).should be_true
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
context 'view file does not exist' do
|
|
14
|
+
it 'should return false' do
|
|
15
|
+
request = stub(:path => 'index')
|
|
16
|
+
File.stub!(:glob).and_return([])
|
|
17
|
+
|
|
18
|
+
HighVoltage::Constraints::RootRoute.matches?(request).should be_false
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe AlternativeFinderController do
|
|
4
|
+
render_views
|
|
5
|
+
|
|
6
|
+
it 'renders the file from the alternative directory' do
|
|
7
|
+
get :show, :id => 'ebg13'
|
|
8
|
+
|
|
9
|
+
response.should be_success
|
|
10
|
+
response.should render_template('rot13')
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -1,106 +1,128 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
|
|
3
4
|
describe HighVoltage::PagesController do
|
|
4
|
-
|
|
5
5
|
render_views
|
|
6
6
|
|
|
7
|
-
context
|
|
8
|
-
|
|
9
|
-
describe "on GET to /pages/exists" do
|
|
7
|
+
context 'using default configuration' do
|
|
8
|
+
describe 'on GET to /pages/exists' do
|
|
10
9
|
before { get :show, :id => 'exists' }
|
|
11
10
|
|
|
12
|
-
it
|
|
11
|
+
it 'should respond with success and render template' do
|
|
13
12
|
response.should be_success
|
|
14
13
|
response.should render_template('exists')
|
|
15
14
|
end
|
|
16
15
|
|
|
17
|
-
it
|
|
18
|
-
response.should render_template(
|
|
16
|
+
it 'should use the default layout used by ApplicationController' do
|
|
17
|
+
response.should render_template('layouts/application')
|
|
19
18
|
end
|
|
20
19
|
end
|
|
21
20
|
|
|
22
|
-
describe
|
|
21
|
+
describe 'on GET to /pages/dir/nested' do
|
|
23
22
|
before { get :show, :id => 'dir/nested' }
|
|
24
23
|
|
|
25
|
-
it
|
|
24
|
+
it 'should respond with success and render template' do
|
|
26
25
|
response.should be_success
|
|
27
26
|
response.should render_template('pages/dir/nested')
|
|
28
27
|
end
|
|
29
28
|
end
|
|
30
29
|
|
|
31
|
-
it
|
|
32
|
-
lambda {
|
|
30
|
+
it 'should raise a routing error for an invalid page' do
|
|
31
|
+
lambda {
|
|
32
|
+
get :show,
|
|
33
|
+
:id => 'invalid'
|
|
34
|
+
}.should raise_error(ActionController::RoutingError)
|
|
33
35
|
end
|
|
34
36
|
|
|
35
|
-
it
|
|
36
|
-
lambda {
|
|
37
|
+
it 'should raise a routing error for a page in another directory' do
|
|
38
|
+
lambda {
|
|
39
|
+
get :show,
|
|
40
|
+
:id => '../other/wrong'
|
|
41
|
+
}.should raise_error(ActionController::RoutingError)
|
|
37
42
|
end
|
|
38
43
|
|
|
39
|
-
it
|
|
40
|
-
lambda {
|
|
44
|
+
it 'should raise missing template error for valid page with invalid partial' do
|
|
45
|
+
lambda {
|
|
46
|
+
get :show,
|
|
47
|
+
:id => 'exists_but_references_nonexistent_partial'
|
|
48
|
+
}.should raise_error(ActionView::MissingTemplate)
|
|
41
49
|
end
|
|
42
50
|
end
|
|
43
51
|
|
|
44
|
-
context
|
|
52
|
+
context 'using custom layout' do
|
|
45
53
|
before(:all) do
|
|
46
|
-
@original_layout = HighVoltage
|
|
47
|
-
HighVoltage
|
|
54
|
+
@original_layout = HighVoltage.layout
|
|
55
|
+
HighVoltage.layout = 'alternate'
|
|
48
56
|
end
|
|
49
57
|
|
|
50
58
|
after(:all) do
|
|
51
|
-
HighVoltage
|
|
59
|
+
HighVoltage.layout = @original_layout
|
|
52
60
|
end
|
|
53
61
|
|
|
54
|
-
describe
|
|
55
|
-
before { get :show, :id =>
|
|
56
|
-
|
|
57
|
-
it
|
|
58
|
-
response.should_not render_template(
|
|
59
|
-
response.should render_template(
|
|
62
|
+
describe 'on GET to /pages/exists' do
|
|
63
|
+
before { get :show, :id => 'exists' }
|
|
64
|
+
|
|
65
|
+
it 'should use the custom configured layout' do
|
|
66
|
+
response.should_not render_template('layouts/application')
|
|
67
|
+
response.should render_template('layouts/alternate')
|
|
60
68
|
end
|
|
61
69
|
end
|
|
62
70
|
end
|
|
63
71
|
|
|
64
|
-
context
|
|
72
|
+
context 'using custom content path' do
|
|
65
73
|
before(:all) do
|
|
66
|
-
@original_content_path = HighVoltage
|
|
67
|
-
HighVoltage
|
|
74
|
+
@original_content_path = HighVoltage.content_path
|
|
75
|
+
HighVoltage.content_path = 'other_pages/'
|
|
68
76
|
end
|
|
69
77
|
|
|
70
78
|
after(:all) do
|
|
71
|
-
HighVoltage
|
|
79
|
+
HighVoltage.content_path = @original_content_path
|
|
72
80
|
end
|
|
73
81
|
|
|
74
|
-
describe
|
|
82
|
+
describe 'on GET to /other_pages/also_exists' do
|
|
75
83
|
before { get :show, :id => 'also_exists' }
|
|
76
84
|
|
|
77
|
-
it
|
|
85
|
+
it 'should respond with success and render template' do
|
|
78
86
|
response.should be_success
|
|
79
87
|
response.should render_template('other_pages/also_exists')
|
|
80
88
|
end
|
|
81
89
|
end
|
|
82
90
|
|
|
83
|
-
describe
|
|
91
|
+
describe 'on GET to /other_pages/also_dir/nested' do
|
|
84
92
|
before { get :show, :id => 'also_dir/also_nested' }
|
|
85
93
|
|
|
86
|
-
it
|
|
94
|
+
it 'should respond with success and render template' do
|
|
87
95
|
response.should be_success
|
|
88
96
|
response.should render_template('other_pages/also_dir/also_nested')
|
|
89
97
|
end
|
|
90
98
|
end
|
|
91
99
|
|
|
92
|
-
it
|
|
93
|
-
lambda {
|
|
100
|
+
it 'should raise a routing error for an invalid page' do
|
|
101
|
+
lambda {
|
|
102
|
+
get :show,
|
|
103
|
+
:id => 'also_invalid'
|
|
104
|
+
}.should raise_error(ActionController::RoutingError)
|
|
94
105
|
end
|
|
95
106
|
|
|
96
|
-
it
|
|
97
|
-
lambda {
|
|
107
|
+
it 'should raise a routing error for a page in another directory' do
|
|
108
|
+
lambda {
|
|
109
|
+
get :show,
|
|
110
|
+
:id => '../other/wrong'
|
|
111
|
+
}.should raise_error(ActionController::RoutingError)
|
|
98
112
|
end
|
|
99
113
|
|
|
100
|
-
it
|
|
101
|
-
lambda {
|
|
114
|
+
it 'should raise a routing error for a page in another directory when using a Unicode exploit' do
|
|
115
|
+
lambda {
|
|
116
|
+
get :show,
|
|
117
|
+
:id => '/\\../other/wrong'
|
|
118
|
+
}.should raise_error(ActionController::RoutingError)
|
|
102
119
|
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
120
|
|
|
121
|
+
it 'should raise missing template error for valid page with invalid partial' do
|
|
122
|
+
lambda {
|
|
123
|
+
get :show,
|
|
124
|
+
:id => 'also_exists_but_references_nonexistent_partial'
|
|
125
|
+
}.should raise_error(ActionView::MissingTemplate)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
106
128
|
end
|