Skip to content

Commit

Permalink
Don't pluralize resource methods [#4704 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information
Javier Martín authored and spastorino committed Aug 18, 2010
1 parent 82eff0f commit 12f7f7a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 14 deletions.
28 changes: 14 additions & 14 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -498,16 +498,14 @@ def name
end

def plural
name.to_s.pluralize
@plural ||= name.to_s
end

def singular
name.to_s.singularize
@singular ||= name.to_s.singularize
end

def member_name
singular
end
alias :member_name :singular

# Checks for uncountable plurals, and appends "_index" if they're.
def collection_name
Expand All @@ -518,9 +516,7 @@ def resource_scope
{ :controller => controller }
end

def collection_scope
path
end
alias :collection_scope :path

def member_scope
"#{path}/:id"
Expand All @@ -547,15 +543,19 @@ def initialize(entities, options)
@options = options
end

def member_name
name
def plural
@plural ||= name.to_s.pluralize
end
alias :collection_name :member_name

def member_scope
path
def singular
@singular ||= name.to_s
end
alias :nested_scope :member_scope

alias :member_name :singular
alias :collection_name :singular

alias :member_scope :path
alias :nested_scope :path
end

def initialize(*args) #:nodoc:
Expand Down
62 changes: 62 additions & 0 deletions actionpack/test/dispatch/routing_test.rb
Expand Up @@ -337,6 +337,14 @@ def self.matches?(request)

resources :content

namespace :transport do
resources :taxis
end

namespace :medical do
resource :taxis
end

scope :constraints => { :id => /\d+/ } do
get '/tickets', :to => 'tickets#index', :as => :tickets
end
Expand Down Expand Up @@ -1884,6 +1892,60 @@ def test_only_scope_should_override_parent_except_scope
end
end

def test_resources_are_not_pluralized
with_test_routes do
get '/transport/taxis'
assert_equal 'transport/taxis#index', @response.body
assert_equal '/transport/taxis', transport_taxis_path

get '/transport/taxis/new'
assert_equal 'transport/taxis#new', @response.body
assert_equal '/transport/taxis/new', new_transport_taxi_path

post '/transport/taxis'
assert_equal 'transport/taxis#create', @response.body

get '/transport/taxis/1'
assert_equal 'transport/taxis#show', @response.body
assert_equal '/transport/taxis/1', transport_taxi_path(:id => '1')

get '/transport/taxis/1/edit'
assert_equal 'transport/taxis#edit', @response.body
assert_equal '/transport/taxis/1/edit', edit_transport_taxi_path(:id => '1')

put '/transport/taxis/1'
assert_equal 'transport/taxis#update', @response.body

delete '/transport/taxis/1'
assert_equal 'transport/taxis#destroy', @response.body
end
end

def test_singleton_resources_are_not_singularized
with_test_routes do
get '/medical/taxis/new'
assert_equal 'medical/taxes#new', @response.body
assert_equal '/medical/taxis/new', new_medical_taxis_path

post '/medical/taxis'
assert_equal 'medical/taxes#create', @response.body

get '/medical/taxis'
assert_equal 'medical/taxes#show', @response.body
assert_equal '/medical/taxis', medical_taxis_path

get '/medical/taxis/edit'
assert_equal 'medical/taxes#edit', @response.body
assert_equal '/medical/taxis/edit', edit_medical_taxis_path

put '/medical/taxis'
assert_equal 'medical/taxes#update', @response.body

delete '/medical/taxis'
assert_equal 'medical/taxes#destroy', @response.body
end
end

private
def with_test_routes
yield
Expand Down

0 comments on commit 12f7f7a

Please sign in to comment.