From 0098452976529957faffd0da59856bde24242a3f Mon Sep 17 00:00:00 2001 From: Jordan Brough Date: Fri, 10 Dec 2010 13:51:59 -0500 Subject: [PATCH] preserve :only & :except options on resources --- lib/routes_upgrader.rb | 7 +++++-- test/routes_upgrader_test.rb | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/routes_upgrader.rb b/lib/routes_upgrader.rb index 82dea89..e7b88b7 100644 --- a/lib/routes_upgrader.rb +++ b/lib/routes_upgrader.rb @@ -275,14 +275,17 @@ module Rails end def to_route_code + # preserve :only & :except options + copied_options = @options.reject { |k,v| ![:only, :except].member?(k) } + copied_options_str = copied_options.empty? ? '' : ', ' + copied_options.inspect.gsub(/\A\{|\}\z/, '') if !@children.empty? || @options.has_key?(:collection) || @options.has_key?(:member) - prefix = ["#{route_method} :#{@name} do"] + prefix = ["#{route_method} :#{@name}#{copied_options_str} do"] lines = prefix + custom_methods + [@children.map {|r| r.to_route_code}.join("\n"), "end"] indent_lines(lines) else - base = "#{route_method} :%s" + base = "#{route_method} :%s#{copied_options_str}" indent_lines [base % [@name]] end end diff --git a/test/routes_upgrader_test.rb b/test/routes_upgrader_test.rb index 3d2c6a3..c4c658e 100644 --- a/test/routes_upgrader_test.rb +++ b/test/routes_upgrader_test.rb @@ -139,4 +139,14 @@ end assert_equal new_routes_code, result end + + def test_preserves_resources_except_option + route = Rails::Upgrading::FakeResourceRoute.new("hats", :except => [:index]) + assert_equal "resources :hats, :except=>[:index]", route.to_route_code + end + + def test_preserves_resources_only_option + route = Rails::Upgrading::FakeResourceRoute.new("hats", :only => :show) + assert_equal "resources :hats, :only=>:show", route.to_route_code + end end \ No newline at end of file