aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2008-05-01 17:26:31 -0500
committerDavid Heinemeier Hansson <david@loudthinking.com>2008-05-01 17:26:31 -0500
commit926f4648f0628009336c44f4d31019819434e39c (patch)
tree41832ea22ba2c567cca2cad41db1cb966be090ae /actionpack
parente931394d098714c6a4cbb91b8c8c00bd9d6fb850 (diff)
downloadrails-926f4648f0628009336c44f4d31019819434e39c.tar.gz
rails-926f4648f0628009336c44f4d31019819434e39c.tar.bz2
rails-926f4648f0628009336c44f4d31019819434e39c.zip
Made the location of the routes file configurable with config.routes_configuration_file (Scott Fleckenstein) [#88 state:resolved]
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/routing/route_set.rb12
-rw-r--r--actionpack/test/controller/routing_test.rb10
2 files changed, 16 insertions, 6 deletions
diff --git a/actionpack/lib/action_controller/routing/route_set.rb b/actionpack/lib/action_controller/routing/route_set.rb
index 6ba1a5c3ea..5bc13cf268 100644
--- a/actionpack/lib/action_controller/routing/route_set.rb
+++ b/actionpack/lib/action_controller/routing/route_set.rb
@@ -189,7 +189,7 @@ module ActionController
end
end
- attr_accessor :routes, :named_routes
+ attr_accessor :routes, :named_routes, :configuration_file
def initialize
self.routes = []
@@ -238,8 +238,8 @@ module ActionController
alias reload! load!
def reload
- if @routes_last_modified && defined?(RAILS_ROOT)
- mtime = File.stat("#{RAILS_ROOT}/config/routes.rb").mtime
+ if @routes_last_modified && configuration_file
+ mtime = File.stat(configuration_file).mtime
# if it hasn't been changed, then just return
return if mtime == @routes_last_modified
# if it has changed then record the new time and fall to the load! below
@@ -249,9 +249,9 @@ module ActionController
end
def load_routes!
- if defined?(RAILS_ROOT) && defined?(::ActionController::Routing::Routes) && self == ::ActionController::Routing::Routes
- load File.join("#{RAILS_ROOT}/config/routes.rb")
- @routes_last_modified = File.stat("#{RAILS_ROOT}/config/routes.rb").mtime
+ if configuration_file
+ load configuration_file
+ @routes_last_modified = File.stat(configuration_file).mtime
else
add_route ":controller/:action/:id"
end
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 5756c05e2e..640afd58f8 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -2341,11 +2341,13 @@ uses_mocha 'route loading' do
def setup
routes.instance_variable_set '@routes_last_modified', nil
silence_warnings { Object.const_set :RAILS_ROOT, '.' }
+ ActionController::Routing::Routes.configuration_file = File.join(RAILS_ROOT, 'config', 'routes.rb')
@stat = stub_everything
end
def teardown
+ ActionController::Routing::Routes.configuration_file = nil
Object.send :remove_const, :RAILS_ROOT
end
@@ -2386,6 +2388,14 @@ uses_mocha 'route loading' do
Inflector.inflections { |inflect| inflect.uncountable('equipment') }
end
+
+ def test_load_with_configuration
+ routes.configuration_file = "foobarbaz"
+ File.expects(:stat).returns(@stat)
+ routes.expects(:load).with("foobarbaz")
+
+ routes.reload
+ end
private
def routes