diff options
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/routing_test.rb | 60 |
1 files changed, 60 insertions, 0 deletions
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 |