aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2007-10-13 03:28:35 +0000
committerMichael Koziarski <michael@koziarski.com>2007-10-13 03:28:35 +0000
commitbd03bf9f5e2a1a8a667785e82658e3efa3f08a25 (patch)
treeafc3085082a64434a14be2bd6a7b7beb6ccff83c /actionpack
parentfaff774f9d48095163161562480dfb426c0462f9 (diff)
downloadrails-bd03bf9f5e2a1a8a667785e82658e3efa3f08a25.tar.gz
rails-bd03bf9f5e2a1a8a667785e82658e3efa3f08a25.tar.bz2
rails-bd03bf9f5e2a1a8a667785e82658e3efa3f08a25.zip
Make sure that custom inflections are picked up by map.resources by triggering a routing reload when new inflections are defined. Closes #9815 [mislav, kampers]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7849 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/routing.rb27
-rw-r--r--actionpack/test/controller/routing_test.rb60
3 files changed, 82 insertions, 7 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 28c5556d81..8ba260dae6 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Make sure that custom inflections are picked up by map.resources. #9815 [mislav]
+
* Changed SanitizeHelper#sanitize to only allow the custom attributes and tags when specified in the call [DHH]
* Extracted sanitization methods from TextHelper to SanitizeHelper [DHH]
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb
index 3a4d2aafe3..78b1759e3f 100644
--- a/actionpack/lib/action_controller/routing.rb
+++ b/actionpack/lib/action_controller/routing.rb
@@ -196,11 +196,13 @@ module ActionController
#
# == Route globbing
#
- # Specifying <tt>*[string]</tt> as part of a rule like :
+ # Specifying <tt>*[string]</tt> as part of a rule like:
#
# map.connect '*path' , :controller => 'blog' , :action => 'unrecognized?'
#
- # will glob all remaining parts of the route that were not recognized earlier. This idiom must appear at the end of the path. The globbed values are in <tt>params[:path]</tt> in this case.
+ # will glob all remaining parts of the route that were not recognized earlier. This idiom
+ # must appear at the end of the path. The globbed values are in <tt>params[:path]</tt> in
+ # this case.
#
# == Reloading routes
#
@@ -208,7 +210,8 @@ module ActionController
#
# ActionController::Routing::Routes.reload
#
- # This will clear all named routes and reload routes.rb
+ # This will clear all named routes and reload routes.rb if the file has been modified from
+ # last load. To absolutely force reloading, use +reload!+.
#
# == Testing Routes
#
@@ -1248,12 +1251,12 @@ module ActionController
alias reload! load!
def reload
- if @routes_last_modified
- mtime=File.stat("#{RAILS_ROOT}/config/routes.rb").mtime
+ if @routes_last_modified && defined?(RAILS_ROOT)
+ mtime = File.stat("#{RAILS_ROOT}/config/routes.rb").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
- @routes_last_modified=mtime
+ @routes_last_modified = mtime
end
load!
end
@@ -1261,7 +1264,7 @@ module ActionController
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
+ @routes_last_modified = File.stat("#{RAILS_ROOT}/config/routes.rb").mtime
else
add_route ":controller/:action/:id"
end
@@ -1455,5 +1458,15 @@ module ActionController
end
Routes = RouteSet.new
+
+ ::Inflector.module_eval do
+ def inflections_with_route_reloading(&block)
+ returning(inflections_without_route_reloading(&block)) {
+ ActionController::Routing::Routes.reload! if block_given?
+ }
+ end
+
+ alias_method_chain :inflections, :route_reloading
+ end
end
end
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 2522b2398b..ce897db238 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -2031,3 +2031,63 @@ class RoutingTest < Test::Unit::TestCase
end
end
+
+uses_mocha 'route loading' do
+ class RouteLoadingTest < Test::Unit::TestCase
+
+ def setup
+ routes.instance_variable_set '@routes_last_modified', nil
+ silence_warnings { Object.const_set :RAILS_ROOT, '.' }
+
+ @stat = stub_everything
+ end
+
+ def teardown
+ Object.send :remove_const, :RAILS_ROOT
+ end
+
+ def test_load
+ File.expects(:stat).returns(@stat)
+ routes.expects(:load).with(regexp_matches(/routes\.rb$/))
+
+ routes.reload
+ end
+
+ def test_no_reload_when_not_modified
+ @stat.expects(:mtime).times(2).returns(1)
+ File.expects(:stat).times(2).returns(@stat)
+ routes.expects(:load).with(regexp_matches(/routes\.rb$/)).at_most_once
+
+ 2.times { routes.reload }
+ end
+
+ def test_reload_when_modified
+ @stat.expects(:mtime).at_least(2).returns(1, 2)
+ File.expects(:stat).at_least(2).returns(@stat)
+ routes.expects(:load).with(regexp_matches(/routes\.rb$/)).times(2)
+
+ 2.times { routes.reload }
+ end
+
+ def test_bang_forces_reload
+ @stat.expects(:mtime).at_least(2).returns(1)
+ File.expects(:stat).at_least(2).returns(@stat)
+ routes.expects(:load).with(regexp_matches(/routes\.rb$/)).times(2)
+
+ 2.times { routes.reload! }
+ end
+
+ def test_adding_inflections_forces_reload
+ Inflector::Inflections.instance.expects(:uncountable).with('equipment')
+ routes.expects(:reload!)
+
+ Inflector.inflections { |inflect| inflect.uncountable('equipment') }
+ end
+
+ private
+ def routes
+ ActionController::Routing::Routes
+ end
+
+ end
+end