high_voltage 1.1.0 → 1.2.2

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.
Files changed (41) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +6 -0
  3. data/Appraisals +4 -6
  4. data/Gemfile.lock +3 -3
  5. data/MIT-LICENSE +1 -1
  6. data/NEWS.md +7 -0
  7. data/README.md +86 -16
  8. data/Rakefile +10 -6
  9. data/app/controllers/high_voltage/pages_controller.rb +12 -15
  10. data/config/routes.rb +3 -2
  11. data/gemfiles/{rails-3.0.10.gemfile → rails_3.0.18.gemfile} +1 -1
  12. data/gemfiles/{rails-3.1.0.gemfile → rails_3.1.9.gemfile} +1 -1
  13. data/gemfiles/rails_3.2.10.gemfile +7 -0
  14. data/lib/high_voltage/constraints/root_route.rb +22 -0
  15. data/lib/high_voltage/engine.rb +0 -2
  16. data/lib/high_voltage/page_finder.rb +37 -0
  17. data/lib/high_voltage/route_drawers/default.rb +15 -0
  18. data/lib/high_voltage/route_drawers/root.rb +16 -0
  19. data/lib/high_voltage/version.rb +1 -1
  20. data/lib/high_voltage.rb +12 -2
  21. data/spec/constraints/root_route_spec.rb +21 -0
  22. data/spec/controllers/alternative_finder_controller_spec.rb +12 -0
  23. data/spec/controllers/pages_controller_spec.rb +63 -41
  24. data/spec/controllers/subclassed_pages_controller_spec.rb +19 -20
  25. data/spec/dummy/app/controllers/alternative_finder_controller.rb +14 -0
  26. data/spec/dummy/app/controllers/subclassed_pages_controller.rb +0 -4
  27. data/spec/dummy/app/views/pages/also_dir/also_nested.html.erb +1 -0
  28. data/spec/dummy/app/views/pages/also_exists.html.erb +1 -0
  29. data/spec/dummy/app/views/pages/also_exists_but_references_nonexistent_partial.html.erb +2 -0
  30. data/spec/dummy/app/views/pages/rot13.html.erb +1 -0
  31. data/spec/dummy/config/application.rb +0 -1
  32. data/spec/dummy/config/environments/test.rb +0 -5
  33. data/spec/dummy/config/routes.rb +1 -0
  34. data/spec/high_voltage/page_finder_spec.rb +52 -0
  35. data/spec/high_voltage_spec.rb +2 -2
  36. data/spec/integration/navigation_spec.rb +3 -3
  37. data/spec/routing/routes_spec.rb +114 -32
  38. data/spec/spec_helper.rb +4 -16
  39. metadata +97 -88
  40. data/gemfiles/rails-3.0.10.gemfile.lock +0 -124
  41. data/gemfiles/rails-3.1.0.gemfile.lock +0 -137
@@ -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 "using default configuration" do
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 "should respond with success and render template" do
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 "should use the default layout used by ApplicationController" do
18
- response.should render_template("layouts/application")
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 "on GET to /pages/dir/nested" do
21
+ describe 'on GET to /pages/dir/nested' do
23
22
  before { get :show, :id => 'dir/nested' }
24
23
 
25
- it "should respond with success and render template" do
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 "should raise a routing error for an invalid page" do
32
- lambda { get :show, :id => "invalid" }.should raise_error(ActionController::RoutingError)
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 "should raise a routing error for a page in another directory" do
36
- lambda { get :show, :id => "../other/wrong" }.should raise_error(ActionController::RoutingError)
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 "should raise missing template error for valid page with invalid partial" do
40
- lambda { get :show, :id => "exists_but_references_nonexistent_partial" }.should raise_error(ActionView::MissingTemplate)
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 "using custom layout" do
52
+ context 'using custom layout' do
45
53
  before(:all) do
46
- @original_layout = HighVoltage::layout
47
- HighVoltage::layout = "alternate"
54
+ @original_layout = HighVoltage.layout
55
+ HighVoltage.layout = 'alternate'
48
56
  end
49
57
 
50
58
  after(:all) do
51
- HighVoltage::layout = @original_layout
59
+ HighVoltage.layout = @original_layout
52
60
  end
53
61
 
54
- describe "on GET to /pages/exists" do
55
- before { get :show, :id => "exists" }
56
-
57
- it "should use the custom configured layout" do
58
- response.should_not render_template("layouts/application")
59
- response.should render_template("layouts/alternate")
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 "using custom content path" do
72
+ context 'using custom content path' do
65
73
  before(:all) do
66
- @original_content_path = HighVoltage::content_path
67
- HighVoltage::content_path = "other_pages/"
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::content_path = @original_content_path
79
+ HighVoltage.content_path = @original_content_path
72
80
  end
73
81
 
74
- describe "on GET to /other_pages/also_exists" do
82
+ describe 'on GET to /other_pages/also_exists' do
75
83
  before { get :show, :id => 'also_exists' }
76
84
 
77
- it "should respond with success and render template" do
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 "on GET to /other_pages/also_dir/nested" do
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 "should respond with success and render template" do
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 "should raise a routing error for an invalid page" do
93
- lambda { get :show, :id => "also_invalid" }.should raise_error(ActionController::RoutingError)
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 "should raise a routing error for a page in another directory" do
97
- lambda { get :show, :id => "../other/wrong" }.should raise_error(ActionController::RoutingError)
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 "should raise missing template error for valid page with invalid partial" do
101
- lambda { get :show, :id => "also_exists_but_references_nonexistent_partial" }.should raise_error(ActionView::MissingTemplate)
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
@@ -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 "on GET to /subclassed_pages/also_exists" do
6
+ describe 'on GET to /subclassed_pages/also_exists' do
8
7
  before { get :show, :id => 'also_exists' }
9
8
 
10
- it "should respond with success and render template" do
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 "should use the custom configured layout" do
16
- response.should_not render_template("layouts/application")
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
- describe "on GET to /subclassed_pages/also_dir/nested" do
22
- before { get :show, :id => 'also_dir/also_nested' }
23
-
24
- it "should respond with success and render template" do
25
- response.should be_success
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 "should raise a routing error for a page in another directory" do
35
- lambda { get :show, :id => "../other/wrong" }.should raise_error(ActionController::RoutingError)
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 "should raise missing template error for valid page with invalid partial" do
39
- lambda { get :show, :id => "also_exists_but_references_nonexistent_partial" }.should raise_error(ActionView::MissingTemplate)
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
@@ -1,7 +1,3 @@
1
1
  class SubclassedPagesController < HighVoltage::PagesController
2
2
  layout 'alternate'
3
-
4
- def content_path
5
- 'other_pages/'
6
- end
7
3
  end
@@ -0,0 +1 @@
1
+ hello <%= 'world' %> from a nested dir
@@ -0,0 +1 @@
1
+ hello <%= 'world' %>
@@ -0,0 +1,2 @@
1
+ hello <%= 'world' %>
2
+ <%= render 'nonexistent' %>
@@ -0,0 +1 @@
1
+ alternative
@@ -3,7 +3,6 @@ require File.expand_path('../boot', __FILE__)
3
3
  require "active_model/railtie"
4
4
  require "action_controller/railtie"
5
5
  require "action_view/railtie"
6
- require "action_mailer/railtie"
7
6
 
8
7
  Bundler.require
9
8
  require "high_voltage"
@@ -20,11 +20,6 @@ Dummy::Application.configure do
20
20
  # Disable request forgery protection in test environment
21
21
  config.action_controller.allow_forgery_protection = false
22
22
 
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
23
  # Use SQL instead of Active Record's schema dumper when creating the test database.
29
24
  # This is necessary if your schema can't be completely dumped by the schema dumper,
30
25
  # like if you have constraints or database-specific column types
@@ -1,3 +1,4 @@
1
1
  Dummy::Application.routes.draw do
2
2
  match "/subclassed_pages/*id" => 'subclassed_pages#show', :format => false
3
+ match "/alternative_finder/*id" => 'alternative_finder#show', :format => false
3
4
  end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe HighVoltage::PageFinder do
4
+ it 'produces the name of an existing template' do
5
+ find('existing').should eq 'pages/existing'
6
+ end
7
+
8
+ it 'produces the name of a nested template' do
9
+ find('dir/nested').should eq 'pages/dir/nested'
10
+ end
11
+
12
+ it 'uses a custom content path' do
13
+ with_content_path('other_pages/') do
14
+ find('also_exists').should eq 'other_pages/also_exists'
15
+ end
16
+ end
17
+
18
+ it 'exposes the content path' do
19
+ with_content_path('another_thing/') do
20
+ page_finder.content_path.should eq 'another_thing/'
21
+ end
22
+ end
23
+
24
+ it 'provides the page_id' do
25
+ subclass = Class.new(HighVoltage::PageFinder) do
26
+ def page_name
27
+ "the page is #{page_id}"
28
+ end
29
+ end
30
+
31
+ subclass.new('sweet page').page_name.should eq 'the page is sweet page'
32
+ end
33
+
34
+ private
35
+
36
+ def find(page_id)
37
+ page_finder(page_id).find
38
+ end
39
+
40
+ def page_finder(page_id = 'whatever')
41
+ HighVoltage::PageFinder.new(page_id)
42
+ end
43
+
44
+ def with_content_path(path)
45
+ original_content_path = HighVoltage.content_path
46
+ HighVoltage.content_path = path
47
+
48
+ yield
49
+
50
+ HighVoltage.content_path = original_content_path
51
+ end
52
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe HighVoltage do
4
- it "should be valid" do
4
+ it 'should be valid' do
5
5
  HighVoltage.should be_a(Module)
6
6
  end
7
- end
7
+ end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Navigation" do
3
+ describe 'Navigation' do
4
4
  include Capybara::DSL
5
-
6
- it "should be a valid app" do
5
+
6
+ it 'should be a valid app' do
7
7
  ::Rails.application.should be_a(Dummy::Application)
8
8
  end
9
9
  end
@@ -1,68 +1,150 @@
1
1
  require 'spec_helper'
2
- describe 'routes' do
3
- context "using default configuration" do
4
2
 
5
- it "should generate normal resource route with id" do
6
- page_path(:id => "one").should == "/pages/one"
3
+ describe 'routes' do
4
+ context 'using default configuration' do
5
+ it 'should generate normal resource route with id' do
6
+ page_path(:id => 'one').should eq '/pages/one'
7
7
  end
8
8
 
9
- it "should generate normal resource route with string" do
10
- page_path("one").should == "/pages/one"
9
+ it 'should generate normal resource route with string' do
10
+ page_path('one').should eq '/pages/one'
11
11
  end
12
12
 
13
- it "should generate nested route with string" do
14
- page_path("one/two").should == "/pages/one/two"
13
+ it 'should generate nested route with string' do
14
+ page_path('one/two').should eq '/pages/one/two'
15
15
  end
16
16
 
17
- it "should recognize nested route" do
18
- assert_recognizes({ :controller => "high_voltage/pages", :action => "show", :id => "one/two" }, "/pages/one/two")
17
+ it 'should recognize nested route' do
18
+ assert_recognizes(
19
+ {
20
+ :controller => 'high_voltage/pages',
21
+ :action => 'show',
22
+ :id => 'one/two'
23
+ },
24
+ '/pages/one/two'
25
+ )
19
26
  end
20
27
 
21
- it "should recognize normal route" do
22
- assert_recognizes({ :controller => "high_voltage/pages", :action => "show", :id => "one" }, "/pages/one")
28
+ it 'should recognize normal route' do
29
+ assert_recognizes(
30
+ {
31
+ :controller => 'high_voltage/pages',
32
+ :action => 'show',
33
+ :id => 'one'
34
+ },
35
+ '/pages/one'
36
+ )
23
37
  end
24
38
 
25
- it "should recognize normal route with dots" do
26
- assert_recognizes({ :controller => "high_voltage/pages", :action => "show", :id => "one.two.three" }, "/pages/one.two.three")
39
+ it 'should recognize normal route with dots' do
40
+ assert_recognizes(
41
+ {
42
+ :controller => 'high_voltage/pages',
43
+ :action => 'show',
44
+ :id => 'one.two.three'
45
+ },
46
+ '/pages/one.two.three'
47
+ )
27
48
  end
28
49
  end
29
50
 
30
- context "using a custom content_path" do
51
+ context 'using root routing configuration' do
52
+ around do |example|
53
+ cached_high_voltage_route_drawer = HighVoltage.route_drawer
54
+ HighVoltage.route_drawer = HighVoltage::RouteDrawers::Root
55
+ Rails.application.reload_routes!
56
+
57
+ example.run
31
58
 
32
- before(:all) do
33
- @original_content_path = HighVoltage::content_path
34
- HighVoltage::content_path = "other_pages/"
59
+ HighVoltage.route_drawer = cached_high_voltage_route_drawer
35
60
  Rails.application.reload_routes!
36
61
  end
37
62
 
38
- after(:all) do
39
- HighVoltage::content_path = @original_content_path
63
+ it 'should generate normal resource route with id' do
64
+ page_path(:id => 'one').should eq '/one'
65
+ end
66
+
67
+ it 'should generate normal resource route with string' do
68
+ page_path('one').should eq '/one'
69
+ end
70
+
71
+ it 'should generate nested route with string' do
72
+ page_path('one/two').should eq '/one/two'
73
+ end
74
+ end
75
+
76
+ context 'using a custom content_path' do
77
+ around do |example|
78
+ cached_high_voltage_content_path = HighVoltage.content_path
79
+ HighVoltage.content_path = 'other_pages/'
80
+ Rails.application.reload_routes!
81
+
82
+ example.run
83
+
84
+ HighVoltage.content_path = cached_high_voltage_content_path
40
85
  Rails.application.reload_routes!
41
86
  end
42
87
 
43
- it "should generate normal resource route with id" do
44
- page_path(:id => "one").should == "/other_pages/one"
88
+ it 'should generate normal resource route with id' do
89
+ page_path(:id => 'one').should eq '/other_pages/one'
45
90
  end
46
91
 
47
- it "should generate normal resource route with string" do
48
- page_path("one").should == "/other_pages/one"
92
+ it 'should generate normal resource route with string' do
93
+ page_path('one').should eq '/other_pages/one'
49
94
  end
50
95
 
51
- it "should generate nested route with string" do
52
- page_path("one/two").should == "/other_pages/one/two"
96
+ it 'should generate nested route with string' do
97
+ page_path('one/two').should eq '/other_pages/one/two'
53
98
  end
54
99
 
55
- it "should recognize nested route" do
56
- assert_recognizes({:controller => "high_voltage/pages", :action => "show", :id => "one/two"}, "/other_pages/one/two")
100
+ it 'should recognize nested route' do
101
+ assert_recognizes(
102
+ {
103
+ :controller => 'high_voltage/pages',
104
+ :action => 'show',
105
+ :id => 'one/two'
106
+ },
107
+ '/other_pages/one/two'
108
+ )
57
109
  end
58
110
 
59
- it "should recognize normal route" do
60
- assert_recognizes({:controller => "high_voltage/pages", :action => "show", :id => "one"}, "/other_pages/one")
111
+ it 'should recognize normal route' do
112
+ assert_recognizes(
113
+ {
114
+ :controller => 'high_voltage/pages',
115
+ :action => 'show',
116
+ :id => 'one'
117
+ },
118
+ '/other_pages/one'
119
+ )
61
120
  end
62
121
 
63
- it "should recognize normal route with dots" do
64
- assert_recognizes({:controller => "high_voltage/pages", :action => "show", :id => "one.two.three"}, "/other_pages/one.two.three")
122
+ it 'should recognize normal route with dots' do
123
+ assert_recognizes(
124
+ {
125
+ :controller => 'high_voltage/pages',
126
+ :action => 'show',
127
+ :id => 'one.two.three'
128
+ },
129
+ '/other_pages/one.two.three'
130
+ )
65
131
  end
66
132
  end
67
133
 
134
+ context 'with default configuration disabled' do
135
+ around do |example|
136
+ cached_high_voltage_routes = HighVoltage.routes
137
+ HighVoltage.routes = false
138
+ Rails.application.reload_routes!
139
+
140
+ example.run
141
+
142
+ HighVoltage.routes = cached_high_voltage_routes
143
+ Rails.application.reload_routes!
144
+ end
145
+
146
+ it 'should not recognize routes' do
147
+ { :get => '/pages/one/two' }.should_not be_routable
148
+ end
149
+ end
68
150
  end
data/spec/spec_helper.rb CHANGED
@@ -1,30 +1,18 @@
1
- # Configure Rails Envinronment
2
- ENV["RAILS_ENV"] = "test"
1
+ ENV['RAILS_ENV'] = 'test'
3
2
 
4
3
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
- require "rails/test_help"
6
- require "rspec/rails"
7
-
8
- ActionMailer::Base.delivery_method = :test
9
- ActionMailer::Base.perform_deliveries = true
10
- ActionMailer::Base.default_url_options[:host] = "test.com"
4
+ require 'rails/test_help'
5
+ require 'rspec/rails'
6
+ require 'capybara/rails'
11
7
 
12
8
  Rails.backtrace_cleaner.remove_silencers!
13
-
14
- # Configure capybara for integration testing
15
- require "capybara/rails"
16
9
  Capybara.default_driver = :rack_test
17
10
  Capybara.default_selector = :css
18
11
 
19
- # Load support files
20
12
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
21
13
 
22
14
  RSpec.configure do |config|
23
- # Remove this line if you don't want RSpec's should and should_not
24
- # methods or matchers
25
15
  require 'rspec/expectations'
26
16
  config.include RSpec::Matchers
27
-
28
- # == Mock Framework
29
17
  config.mock_with :rspec
30
18
  end