diff --git a/actionpack/lib/action_controller/routing/route_set.rb b/actionpack/lib/action_controller/routing/route_set.rb index 5bc13cf..cc7c699 100644 --- a/actionpack/lib/action_controller/routing/route_set.rb +++ b/actionpack/lib/action_controller/routing/route_set.rb @@ -202,8 +202,8 @@ module ActionController @builder ||= RouteBuilder.new end - def draw - clear! + def draw(clear = true) + clear! if clear yield Mapper.new(self) install_helpers end diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 07c13eb..b5dda5f 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -1610,6 +1610,27 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do assert_equal 1, set.routes.size end + def test_draw_default_clear_parameter + set.expects(:clear!).once + set.draw do |map| + map.connect '/hello/world', :controller => 'a', :action => 'b' + end + end + + def test_draw_clear_parameter_is_false + set.expects(:clear!).never + set.draw(false) do |map| + map.connect '/hello/world', :controller => 'a', :action => 'b' + end + end + + def test_draw_clear_parameter_is_true + set.expects(:clear!).once + set.draw(true) do |map| + map.connect '/hello/world', :controller => 'a', :action => 'b' + end + end + def test_named_draw assert_equal 0, set.routes.size set.draw do |map|