high_voltage 1.2.0 → 2.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +2 -2
- data/.travis.yml +5 -6
- data/Appraisals +14 -3
- data/Gemfile.lock +53 -67
- data/MIT-LICENSE +1 -1
- data/NEWS.md +23 -0
- data/README.md +201 -71
- data/Rakefile +11 -10
- data/app/controllers/concerns/high_voltage/static_page.rb +41 -0
- data/app/controllers/high_voltage/pages_controller.rb +1 -35
- data/config/routes.rb +3 -2
- data/high_voltage.gemspec +5 -3
- data/lib/high_voltage/constraints/root_route.rb +22 -0
- data/lib/high_voltage/engine.rb +9 -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 +19 -2
- data/spec/constraints/root_route_spec.rb +25 -0
- data/spec/controllers/action_caching_controller_spec.rb +23 -0
- data/spec/controllers/alternative_finder_controller_spec.rb +12 -0
- data/spec/controllers/page_caching_controller_spec.rb +20 -0
- data/spec/controllers/pages_controller_spec.rb +56 -40
- 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 +1 -7
- data/spec/dummy/config/initializers/secret_key_base.rb +1 -0
- data/spec/dummy/config/routes.rb +2 -1
- data/spec/high_voltage/page_finder_spec.rb +52 -0
- data/spec/high_voltage_spec.rb +7 -3
- data/spec/integration/navigation_spec.rb +3 -3
- data/spec/minimal_spec_helper.rb +5 -0
- data/spec/routing/routes_spec.rb +107 -33
- data/spec/spec_helper.rb +7 -18
- data/spec/support/caching.rb +12 -0
- data/spec/support/concern_reload.rb +11 -0
- metadata +119 -44
- data/gemfiles/rails-3.0.15.gemfile +0 -7
- data/gemfiles/rails-3.1.6.gemfile +0 -7
- data/gemfiles/rails-3.2.6.gemfile +0 -7
|
@@ -1,37 +1,3 @@
|
|
|
1
1
|
class HighVoltage::PagesController < ApplicationController
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
unloadable
|
|
5
|
-
layout Proc.new { |_| HighVoltage.layout }
|
|
6
|
-
|
|
7
|
-
rescue_from ActionView::MissingTemplate do |exception|
|
|
8
|
-
if exception.message =~ %r{Missing template #{content_path}}
|
|
9
|
-
raise ActionController::RoutingError, "No such page: #{params[:id]}"
|
|
10
|
-
else
|
|
11
|
-
raise exception
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def show
|
|
16
|
-
render :template => current_page
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
protected
|
|
20
|
-
|
|
21
|
-
def current_page
|
|
22
|
-
"#{content_path}#{clean_path}"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def clean_path
|
|
26
|
-
path = Pathname.new("/#{clean_id}")
|
|
27
|
-
path.cleanpath.to_s[1..-1]
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def content_path
|
|
31
|
-
HighVoltage.content_path
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def clean_id
|
|
35
|
-
params[:id].tr("^#{VALID_CHARACTERS}", '')
|
|
36
|
-
end
|
|
2
|
+
include HighVoltage::StaticPage
|
|
37
3
|
end
|
data/config/routes.rb
CHANGED
data/high_voltage.gemspec
CHANGED
|
@@ -8,15 +8,17 @@ Gem::Specification.new do |s|
|
|
|
8
8
|
s.email = ['support@thoughtbot.com']
|
|
9
9
|
s.homepage = 'http://github.com/thoughtbot/high_voltage'
|
|
10
10
|
s.summary = 'Simple static page rendering controller'
|
|
11
|
-
s.description = 'Fire in the disco.
|
|
11
|
+
s.description = 'Fire in the disco. Fire in the ... taco bell.'
|
|
12
|
+
s.license = 'MIT'
|
|
12
13
|
|
|
13
14
|
s.files = `git ls-files`.split("\n")
|
|
14
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
15
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
16
17
|
s.require_paths = ["lib"]
|
|
17
18
|
|
|
19
|
+
s.add_development_dependency("activesupport", ">= 3.1.0")
|
|
18
20
|
s.add_development_dependency("appraisal")
|
|
21
|
+
s.add_development_dependency("capybara", "= 2.0.3")
|
|
22
|
+
s.add_development_dependency("pry-debugger")
|
|
19
23
|
s.add_development_dependency("rspec-rails")
|
|
20
|
-
s.add_development_dependency("capybara", ">= 0.4.0")
|
|
21
|
-
s.add_development_dependency("sqlite3")
|
|
22
24
|
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module HighVoltage
|
|
2
|
+
module Constraints
|
|
3
|
+
# Routing constraint to validate request.path has a corresponding view
|
|
4
|
+
class RootRoute
|
|
5
|
+
def self.matches?(request)
|
|
6
|
+
pattern = file_pattern(request.path)
|
|
7
|
+
|
|
8
|
+
Dir.glob(pattern).any?
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def self.file_pattern(page_id)
|
|
14
|
+
"#{content_path}#{page_id}.html*"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.content_path
|
|
18
|
+
Rails.root.join('app', 'views', HighVoltage.content_path).to_s
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/high_voltage/engine.rb
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
module HighVoltage
|
|
2
|
-
|
|
3
2
|
class Engine < Rails::Engine
|
|
4
|
-
|
|
3
|
+
initializer 'Require concerns path' do |app|
|
|
4
|
+
concerns_path = 'app/controllers/concerns'
|
|
5
5
|
|
|
6
|
+
unless app.paths.keys.include?(concerns_path)
|
|
7
|
+
app.paths.add(concerns_path)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
require 'concerns/high_voltage/static_page'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
6
13
|
end
|
|
@@ -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,12 +1,29 @@
|
|
|
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'
|
|
6
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
|
2
7
|
|
|
3
8
|
module HighVoltage
|
|
4
9
|
mattr_accessor :layout
|
|
5
|
-
@@layout =
|
|
10
|
+
@@layout = 'application'
|
|
6
11
|
|
|
7
12
|
mattr_accessor :content_path
|
|
8
|
-
@@content_path =
|
|
13
|
+
@@content_path = 'pages/'
|
|
9
14
|
|
|
15
|
+
mattr_accessor :route_drawer
|
|
16
|
+
@@route_drawer = HighVoltage::RouteDrawers::Default
|
|
17
|
+
|
|
18
|
+
mattr_accessor :routes
|
|
19
|
+
@@routes = true
|
|
20
|
+
|
|
21
|
+
mattr_accessor :action_caching
|
|
22
|
+
@@action_caching = false
|
|
23
|
+
|
|
24
|
+
mattr_accessor :page_caching
|
|
25
|
+
@@page_caching = false
|
|
26
|
+
|
|
10
27
|
def self.setup
|
|
11
28
|
yield self
|
|
12
29
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
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 = double(path: 'index')
|
|
7
|
+
Dir.stub(:glob).and_return(['about.html.erb'])
|
|
8
|
+
|
|
9
|
+
result = HighVoltage::Constraints::RootRoute.matches?(request)
|
|
10
|
+
|
|
11
|
+
expect(result).to be_true
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context 'view file does not exist' do
|
|
16
|
+
it 'should return false' do
|
|
17
|
+
request = double(path: 'index')
|
|
18
|
+
File.stub(:glob).and_return([])
|
|
19
|
+
|
|
20
|
+
result = HighVoltage::Constraints::RootRoute.matches?(request)
|
|
21
|
+
|
|
22
|
+
expect(result).to be_false
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe HighVoltage::PagesController, 'action_caching' do
|
|
4
|
+
it 'caches the action when action_caching is set to true', enable_caching: true do
|
|
5
|
+
expect do
|
|
6
|
+
HighVoltage.action_caching = true
|
|
7
|
+
concern_reload
|
|
8
|
+
get :show, id: :exists
|
|
9
|
+
end.to change { action_was_cached(:exists) }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'does not cache the action when action_caching is set to false', enable_caching: true do
|
|
13
|
+
expect do
|
|
14
|
+
HighVoltage.action_caching = false
|
|
15
|
+
concern_reload
|
|
16
|
+
get :show, id: :exists
|
|
17
|
+
end.to_not change { action_was_cached(:exists) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def action_was_cached(page)
|
|
21
|
+
ActionController::Base.cache_store.exist?("views/test.host#{page_path(page)}")
|
|
22
|
+
end
|
|
23
|
+
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
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe HighVoltage::PagesController, 'action_caching' do
|
|
4
|
+
it 'caches the page when page_caching is set to true', enable_caching: true do
|
|
5
|
+
controller.should_receive(:cache_page).at_least(:once)
|
|
6
|
+
|
|
7
|
+
HighVoltage.page_caching = true
|
|
8
|
+
concern_reload
|
|
9
|
+
get :show, id: :exists
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'does not cache the page when page_caching is set to false', enable_caching: true do
|
|
13
|
+
controller.should_receive(:cache_page).never
|
|
14
|
+
|
|
15
|
+
HighVoltage.page_caching = false
|
|
16
|
+
concern_reload
|
|
17
|
+
get :show, id: :exists
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
@@ -1,112 +1,128 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
|
-
|
|
3
2
|
require 'spec_helper'
|
|
4
3
|
|
|
5
4
|
describe HighVoltage::PagesController do
|
|
6
|
-
|
|
7
5
|
render_views
|
|
8
6
|
|
|
9
|
-
context
|
|
10
|
-
|
|
11
|
-
describe "on GET to /pages/exists" do
|
|
7
|
+
context 'using default configuration' do
|
|
8
|
+
describe 'on GET to /pages/exists' do
|
|
12
9
|
before { get :show, :id => 'exists' }
|
|
13
10
|
|
|
14
|
-
it
|
|
11
|
+
it 'should respond with success and render template' do
|
|
15
12
|
response.should be_success
|
|
16
13
|
response.should render_template('exists')
|
|
17
14
|
end
|
|
18
15
|
|
|
19
|
-
it
|
|
20
|
-
response.should render_template(
|
|
16
|
+
it 'should use the default layout used by ApplicationController' do
|
|
17
|
+
response.should render_template('layouts/application')
|
|
21
18
|
end
|
|
22
19
|
end
|
|
23
20
|
|
|
24
|
-
describe
|
|
21
|
+
describe 'on GET to /pages/dir/nested' do
|
|
25
22
|
before { get :show, :id => 'dir/nested' }
|
|
26
23
|
|
|
27
|
-
it
|
|
24
|
+
it 'should respond with success and render template' do
|
|
28
25
|
response.should be_success
|
|
29
26
|
response.should render_template('pages/dir/nested')
|
|
30
27
|
end
|
|
31
28
|
end
|
|
32
29
|
|
|
33
|
-
it
|
|
34
|
-
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)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
it
|
|
38
|
-
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)
|
|
39
42
|
end
|
|
40
43
|
|
|
41
|
-
it
|
|
42
|
-
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)
|
|
43
49
|
end
|
|
44
50
|
end
|
|
45
51
|
|
|
46
|
-
context
|
|
52
|
+
context 'using custom layout' do
|
|
47
53
|
before(:all) do
|
|
48
54
|
@original_layout = HighVoltage.layout
|
|
49
|
-
HighVoltage.layout =
|
|
55
|
+
HighVoltage.layout = 'alternate'
|
|
50
56
|
end
|
|
51
57
|
|
|
52
58
|
after(:all) do
|
|
53
59
|
HighVoltage.layout = @original_layout
|
|
54
60
|
end
|
|
55
61
|
|
|
56
|
-
describe
|
|
57
|
-
before { get :show, :id =>
|
|
58
|
-
|
|
59
|
-
it
|
|
60
|
-
response.should_not render_template(
|
|
61
|
-
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')
|
|
62
68
|
end
|
|
63
69
|
end
|
|
64
70
|
end
|
|
65
71
|
|
|
66
|
-
context
|
|
72
|
+
context 'using custom content path' do
|
|
67
73
|
before(:all) do
|
|
68
74
|
@original_content_path = HighVoltage.content_path
|
|
69
|
-
HighVoltage.content_path =
|
|
75
|
+
HighVoltage.content_path = 'other_pages/'
|
|
70
76
|
end
|
|
71
77
|
|
|
72
78
|
after(:all) do
|
|
73
79
|
HighVoltage.content_path = @original_content_path
|
|
74
80
|
end
|
|
75
81
|
|
|
76
|
-
describe
|
|
82
|
+
describe 'on GET to /other_pages/also_exists' do
|
|
77
83
|
before { get :show, :id => 'also_exists' }
|
|
78
84
|
|
|
79
|
-
it
|
|
85
|
+
it 'should respond with success and render template' do
|
|
80
86
|
response.should be_success
|
|
81
87
|
response.should render_template('other_pages/also_exists')
|
|
82
88
|
end
|
|
83
89
|
end
|
|
84
90
|
|
|
85
|
-
describe
|
|
91
|
+
describe 'on GET to /other_pages/also_dir/nested' do
|
|
86
92
|
before { get :show, :id => 'also_dir/also_nested' }
|
|
87
93
|
|
|
88
|
-
it
|
|
94
|
+
it 'should respond with success and render template' do
|
|
89
95
|
response.should be_success
|
|
90
96
|
response.should render_template('other_pages/also_dir/also_nested')
|
|
91
97
|
end
|
|
92
98
|
end
|
|
93
99
|
|
|
94
|
-
it
|
|
95
|
-
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)
|
|
96
105
|
end
|
|
97
106
|
|
|
98
|
-
it
|
|
99
|
-
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)
|
|
100
112
|
end
|
|
101
113
|
|
|
102
|
-
it
|
|
103
|
-
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)
|
|
104
119
|
end
|
|
105
120
|
|
|
106
|
-
it
|
|
107
|
-
lambda {
|
|
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)
|
|
108
126
|
end
|
|
109
127
|
end
|
|
110
|
-
|
|
111
|
-
|
|
112
128
|
end
|
|
@@ -1,41 +1,40 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe SubclassedPagesController do
|
|
4
|
-
|
|
5
4
|
render_views
|
|
6
5
|
|
|
7
|
-
describe
|
|
6
|
+
describe 'on GET to /subclassed_pages/also_exists' do
|
|
8
7
|
before { get :show, :id => 'also_exists' }
|
|
9
8
|
|
|
10
|
-
it
|
|
9
|
+
it 'should respond with success and render template' do
|
|
11
10
|
response.should be_success
|
|
12
11
|
response.should render_template('also_exists')
|
|
13
12
|
end
|
|
14
13
|
|
|
15
|
-
it
|
|
16
|
-
response.should_not render_template(
|
|
14
|
+
it 'should use the custom configured layout' do
|
|
15
|
+
response.should_not render_template('layouts/application')
|
|
17
16
|
response.should render_template('layouts/alternate')
|
|
18
17
|
end
|
|
19
18
|
end
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
response.should render_template('other_pages/also_dir/also_nested')
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "should raise a routing error for an invalid page" do
|
|
31
|
-
lambda { get :show, :id => "invalid" }.should raise_error(ActionController::RoutingError)
|
|
20
|
+
it 'should raise a routing error for an invalid page' do
|
|
21
|
+
lambda {
|
|
22
|
+
get :show,
|
|
23
|
+
:id => 'invalid'
|
|
24
|
+
}.should raise_error(ActionController::RoutingError)
|
|
32
25
|
end
|
|
33
26
|
|
|
34
|
-
it
|
|
35
|
-
lambda {
|
|
27
|
+
it 'should raise a routing error for a page in another directory' do
|
|
28
|
+
lambda {
|
|
29
|
+
get :show,
|
|
30
|
+
:id => '../other/wrong'
|
|
31
|
+
}.should raise_error(ActionController::RoutingError)
|
|
36
32
|
end
|
|
37
33
|
|
|
38
|
-
it
|
|
39
|
-
lambda {
|
|
34
|
+
it 'should raise missing template error for valid page with invalid partial' do
|
|
35
|
+
lambda {
|
|
36
|
+
get :show,
|
|
37
|
+
:id => 'also_exists_but_references_nonexistent_partial'
|
|
38
|
+
}.should raise_error(ActionView::MissingTemplate)
|
|
40
39
|
end
|
|
41
40
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class AlternativeFinderController < HighVoltage::PagesController
|
|
2
|
+
private
|
|
3
|
+
|
|
4
|
+
def page_finder_factory
|
|
5
|
+
Rot13PageFinder
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class Rot13PageFinder < HighVoltage::PageFinder
|
|
9
|
+
def find
|
|
10
|
+
paths = super.split('/')
|
|
11
|
+
"#{paths[0..-2].join('/')}/#{paths[-1].tr('a-z','n-za-m')}"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hello <%= 'world' %> from a nested dir
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hello <%= 'world' %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
alternative
|
|
@@ -7,8 +7,7 @@ Dummy::Application.configure do
|
|
|
7
7
|
# and recreated between test runs. Don't rely on the data there!
|
|
8
8
|
config.cache_classes = true
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
config.whiny_nils = true
|
|
10
|
+
config.eager_load = false
|
|
12
11
|
|
|
13
12
|
# Show full error reports and disable caching
|
|
14
13
|
config.consider_all_requests_local = true
|
|
@@ -20,11 +19,6 @@ Dummy::Application.configure do
|
|
|
20
19
|
# Disable request forgery protection in test environment
|
|
21
20
|
config.action_controller.allow_forgery_protection = false
|
|
22
21
|
|
|
23
|
-
# Tell Action Mailer not to deliver emails to the real world.
|
|
24
|
-
# The :test delivery method accumulates sent emails in the
|
|
25
|
-
# ActionMailer::Base.deliveries array.
|
|
26
|
-
config.action_mailer.delivery_method = :test
|
|
27
|
-
|
|
28
22
|
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
|
29
23
|
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
|
30
24
|
# like if you have constraints or database-specific column types
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Dummy::Application.config.secret_key_base = '9c0b876ab8f513cc23d354b6d684c88eb9bc5f73ddc8d5843e7c6ac9176c5819adc2620e220980a3cb818de687753f1bfc56c66c4454b74fc7d432813f8e555a'
|
data/spec/dummy/config/routes.rb
CHANGED