Permalink
Browse files

There is no need to be destructive with the passed-in options.

This fixes a bug that is caused by Resource/SingletonResource mangling resource options when using inline "multi"-resource declarations.
  • Loading branch information...
1 parent c4cf907 commit 37b30d4b4eb983579f083627b3faa065be527a61 @thedarkone thedarkone committed with fxn Jul 28, 2011
Showing with 15 additions and 6 deletions.
  1. +6 −6 actionpack/lib/action_dispatch/routing/mapper.rb
  2. +9 −0 actionpack/test/controller/resources_test.rb
@@ -872,9 +872,9 @@ class Resource #:nodoc:
def initialize(entities, options = {})
@name = entities.to_s
- @path = (options.delete(:path) || @name).to_s
- @controller = (options.delete(:controller) || @name).to_s
- @as = options.delete(:as)
+ @path = (options[:path] || @name).to_s
+ @controller = (options[:controller] || @name).to_s
+ @as = options[:as]
@options = options
end
@@ -938,9 +938,9 @@ class SingletonResource < Resource #:nodoc:
def initialize(entities, options)
@as = nil
@name = entities.to_s
- @path = (options.delete(:path) || @name).to_s
- @controller = (options.delete(:controller) || plural).to_s
- @as = options.delete(:as)
+ @path = (options[:path] || @name).to_s
+ @controller = (options[:controller] || plural).to_s
+ @as = options[:as]
@options = options
end
@@ -91,6 +91,15 @@ def test_multiple_default_restful_routes
end
end
+ def test_multiple_resources_with_options
+ expected_options = {:controller => 'threads', :action => 'index'}
+
+ with_restful_routing :messages, :comments, expected_options.slice(:controller) do
+ assert_recognizes(expected_options, :path => 'comments')
+ assert_recognizes(expected_options, :path => 'messages')
+ end
+ end
+
def test_with_custom_conditions
with_restful_routing :messages, :conditions => { :subdomain => 'app' } do
assert @routes.recognize_path("/messages", :method => :get, :subdomain => 'app')

0 comments on commit 37b30d4

Please sign in to comment.