Permalink
Browse files

Merge branch 'master' of git://github.com/jordan-brough/rails_upgrade

* 'master' of git://github.com/jordan-brough/rails_upgrade:
  preserve :only & :except options on resources
  • Loading branch information...
2 parents e042045 + 0098452 commit b3188a6a3dc14af7136545561089dceea92fcc5c @radar radar committed Apr 7, 2011
Showing with 15 additions and 2 deletions.
  1. +5 −2 lib/routes_upgrader.rb
  2. +10 −0 test/routes_upgrader_test.rb
View
@@ -275,14 +275,17 @@ def initialize(name, options = {})
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
@@ -139,4 +139,14 @@ def test_generates_code_for_default_route
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

0 comments on commit b3188a6

Please sign in to comment.