Skip to content

Commit

Permalink
Merge pull request rails#2330 from thedarkone/resources-router-fix
Browse files Browse the repository at this point in the history
Inline resources router fix
  • Loading branch information
josevalim committed Jul 28, 2011
2 parents adce9b4 + a5f57a7 commit b295ea1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
15 changes: 7 additions & 8 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -936,12 +936,11 @@ class SingletonResource < Resource #:nodoc:
DEFAULT_ACTIONS = [:show, :create, :update, :destroy, :new, :edit]

def initialize(entities, options)
super

@as = nil
@name = entities.to_s
@path = (options.delete(:path) || @name).to_s
@controller = (options.delete(:controller) || plural).to_s
@as = options.delete(:as)
@options = options
@controller = (options[:controller] || plural).to_s
@as = options[:as]
end

def plural
Expand Down
9 changes: 9 additions & 0 deletions actionpack/test/controller/resources_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit b295ea1

Please sign in to comment.