Skip to content
This repository
Browse code

Add a config option to disable default routes.

If you want more control over your routing you can disable the default
routes in an initializer:

    HighVoltage.routes = false
  • Loading branch information...
commit 7570889e4e07025a6034087ae804a67c7afacff7 1 parent 61b2358
Odin Dutton twe4ked authored mike-burns committed
6 README.md
Source Rendered
@@ -71,6 +71,12 @@ You can route the root url to a high voltage page like this:
71 71
72 72 Which will render a homepage from app/views/pages/home.html.erb
73 73
  74 +The default routes can be completely removed by changing the
  75 +`HighVoltage.routes` Boolean. For example, in
  76 +`config/initializers/high_voltage.rb`:
  77 +
  78 + HighVoltage.routes = false
  79 +
74 80 Customize
75 81 --------
76 82
5 config/routes.rb
... ... @@ -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 + match "/#{HighVoltage.content_path}*id" => 'high_voltage/pages#show', :as => :page, :format => false
  4 + end
4 5 end
3  lib/high_voltage.rb
@@ -7,6 +7,9 @@ module HighVoltage
7 7 mattr_accessor :content_path
8 8 @@content_path = "pages/"
9 9
  10 + mattr_accessor :routes
  11 + @@routes = true
  12 +
10 13 def self.setup
11 14 yield self
12 15 end
10 spec/routing/routes_spec.rb
@@ -65,4 +65,14 @@
65 65 end
66 66 end
67 67
  68 + context "with default configuration disabled" do
  69 + before do
  70 + HighVoltage.routes = false
  71 + Rails.application.reload_routes!
  72 + end
  73 +
  74 + it "should not recognize routes" do
  75 + { :get => "/pages/one/two" }.should_not be_routable
  76 + end
  77 + end
68 78 end

3 comments on commit 7570889

Manuel Meurer

Would be great if you could release a new version with this commit!

Harlow Ward
Collaborator

We've run into some issues with this commit on Travis-CI -- I discovered last week our API Key had changed and it hasn't been automatically running Pull Requests through Travis-CI.

With this commit we're showing failures:

1) HighVoltage::PagesController using default configuration should raise missing template error for valid page with invalid partial
85     Failure/Error: lambda { get :show, :id => 'exists_but_references_nonexistent_partial' }.should raise_error(ActionView::MissingTemplate)
86       expected ActionView::MissingTemplate, got #<ActionController::RoutingError: No route matches {:controller=>"high_voltage/pages", :action=>"show", :id=>"exists_but_references_nonexistent_partial"}>
87     # ./spec/controllers/pages_controller_spec.rb:39

Its possible the boolean @@routes = true isn't picked up correctly on Travis-CI and the routes aren't created. Everything passes when I run the tests locally.

Harlow Ward
Collaborator

Ok looks like it was an issue with the order the tests are run, and overriding HighVoltage.routes = false without setting it back to its original state.

This fixes the issue:

context "with default configuration disabled" do
  before do
    @original_routes_boolean = HighVoltage.routes
    HighVoltage.routes = false
    Rails.application.reload_routes!
  end

  after do
    HighVoltage.routes = @original_routes_boolean
    Rails.application.reload_routes!
  end

  it "should not recognize routes" do
    { :get => "/pages/one/two" }.should_not be_routable
  end
end
Please sign in to comment.
Something went wrong with that request. Please try again.