Skip to content

Commit

Permalink
draw routes instead of routing hack
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Croak authored and thoughtbot-travis committed Jun 4, 2010
1 parent 161b056 commit f36ebc8
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 26 deletions.
5 changes: 0 additions & 5 deletions config/high_voltage_routes.rb

This file was deleted.

8 changes: 7 additions & 1 deletion install.rb
@@ -1 +1,7 @@
# Install hook code here
line = "HighVoltage::Routes.draw(map)"
path = "config/routes.rb"

puts "inserting #{line} into #{path}"

content = File.read(path).gsub(/^(class|module|.*Routes).*$/, {|match| "#{match}\n #{line}" })
File.open(path, 'wb') { |file| file.write(content) }
3 changes: 1 addition & 2 deletions lib/high_voltage.rb
@@ -1,5 +1,4 @@
module HighVoltage
end

require 'high_voltage/extensions/routes'

require 'high_voltage/routes'
15 changes: 0 additions & 15 deletions lib/high_voltage/extensions/routes.rb

This file was deleted.

21 changes: 21 additions & 0 deletions lib/high_voltage/routes.rb
@@ -0,0 +1,21 @@
module HighVoltage
class Routes
# In your application's config/routes.rb, draw High Voltage's routes:
#
# @example
# HighVoltage::Routes.draw(map)
#
# If you need to override a High Voltage route, invoke your app route
# earlier in the file so Rails' router short-circuits when it finds
# your route:
#
# @example
# map.resources :pages, :controller => :pages, :only => [:show]
# Clearance::Routes.draw(map)
def self.draw(map)
map.resources :pages,
:controller => 'high_voltage/pages',
:only => [:show]
end
end
end
3 changes: 0 additions & 3 deletions test/pages_controller_test.rb
Expand Up @@ -4,10 +4,8 @@ class ApplicationController < ActionController::Base
end

require "high_voltage/pages_controller"
require File.join(File.dirname(__FILE__), '..', 'config', 'high_voltage_routes')

class HighVoltage::PagesControllerTest < ActionController::TestCase

HighVoltage::PagesController.view_paths << "/tmp"

context "on GET to a page that exists" do
Expand Down Expand Up @@ -40,5 +38,4 @@ class HighVoltage::PagesControllerTest < ActionController::TestCase
setup { get :show, :id => "invalid" }
should_respond_with :missing
end

end
4 changes: 4 additions & 0 deletions test/test_helper.rb
Expand Up @@ -12,3 +12,7 @@

require 'shoulda'
require 'shoulda/rails'

ActionController::Routing::Routes.draw do |map|
HighVoltage::Routes.draw(map)
end

0 comments on commit f36ebc8

Please sign in to comment.