From bd03bf9f5e2a1a8a667785e82658e3efa3f08a25 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Sat, 13 Oct 2007 03:28:35 +0000 Subject: 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 --- actionpack/test/controller/routing_test.rb | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'actionpack/test/controller/routing_test.rb') 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 -- cgit v1.2.3