high_voltage 1.1.1 → 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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.travis.yml +6 -1
  4. data/Appraisals +13 -4
  5. data/Gemfile.lock +53 -67
  6. data/MIT-LICENSE +1 -1
  7. data/NEWS.md +23 -0
  8. data/README.md +201 -71
  9. data/Rakefile +10 -5
  10. data/app/controllers/concerns/high_voltage/static_page.rb +41 -0
  11. data/app/controllers/high_voltage/pages_controller.rb +1 -31
  12. data/config/routes.rb +3 -2
  13. data/high_voltage.gemspec +5 -3
  14. data/lib/high_voltage/constraints/root_route.rb +22 -0
  15. data/lib/high_voltage/engine.rb +9 -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 +19 -2
  21. data/spec/constraints/root_route_spec.rb +25 -0
  22. data/spec/controllers/action_caching_controller_spec.rb +23 -0
  23. data/spec/controllers/alternative_finder_controller_spec.rb +12 -0
  24. data/spec/controllers/page_caching_controller_spec.rb +20 -0
  25. data/spec/controllers/pages_controller_spec.rb +63 -41
  26. data/spec/controllers/subclassed_pages_controller_spec.rb +19 -20
  27. data/spec/dummy/app/controllers/alternative_finder_controller.rb +14 -0
  28. data/spec/dummy/app/controllers/subclassed_pages_controller.rb +0 -4
  29. data/spec/dummy/app/views/pages/also_dir/also_nested.html.erb +1 -0
  30. data/spec/dummy/app/views/pages/also_exists.html.erb +1 -0
  31. data/spec/dummy/app/views/pages/also_exists_but_references_nonexistent_partial.html.erb +2 -0
  32. data/spec/dummy/app/views/pages/rot13.html.erb +1 -0
  33. data/spec/dummy/config/application.rb +0 -1
  34. data/spec/dummy/config/environments/test.rb +1 -7
  35. data/spec/dummy/config/initializers/secret_key_base.rb +1 -0
  36. data/spec/dummy/config/routes.rb +2 -1
  37. data/spec/high_voltage/page_finder_spec.rb +52 -0
  38. data/spec/high_voltage_spec.rb +7 -3
  39. data/spec/integration/navigation_spec.rb +3 -3
  40. data/spec/minimal_spec_helper.rb +5 -0
  41. data/spec/routing/routes_spec.rb +107 -33
  42. data/spec/spec_helper.rb +7 -18
  43. data/spec/support/caching.rb +12 -0
  44. data/spec/support/concern_reload.rb +11 -0
  45. metadata +121 -98
  46. data/gemfiles/rails-3.0.10.gemfile +0 -7
  47. data/gemfiles/rails-3.0.10.gemfile.lock +0 -124
  48. data/gemfiles/rails-3.1.0.gemfile +0 -7
  49. data/gemfiles/rails-3.1.0.gemfile.lock +0 -137
data/config/routes.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  Rails.application.routes.draw do
2
- match "/#{HighVoltage::content_path}*id" => 'high_voltage/pages#show', :as => :page, :format => false
3
-
2
+ if HighVoltage.routes
3
+ get HighVoltage.route_drawer.match_attributes
4
+ end
4
5
  end
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. Fire in the ... taco bell.'
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
@@ -1,6 +1,13 @@
1
1
  module HighVoltage
2
-
3
2
  class Engine < Rails::Engine
4
- end
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
@@ -1,3 +1,3 @@
1
1
  module HighVoltage
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
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 = "application"
10
+ @@layout = 'application'
6
11
 
7
12
  mattr_accessor :content_path
8
- @@content_path = "pages/"
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,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"
@@ -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
- # Log error messages when you accidentally call methods on nil.
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'
@@ -1,3 +1,4 @@
1
1
  Dummy::Application.routes.draw do
2
- match "/subclassed_pages/*id" => 'subclassed_pages#show', :format => false
2
+ get "/subclassed_pages/*id" => 'subclassed_pages#show', :format => false
3
+ get "/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,11 @@
1
- require 'spec_helper'
1
+ require 'minimal_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
+
8
+ it 'should be loadable without preloading rails' do
9
+ expect { require 'high_voltage' }.not_to raise_error
10
+ end
11
+ 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