Skip to content

Commit

Permalink
Don't force singularization of singleton resource names, e.g. /prefer…
Browse files Browse the repository at this point in the history
…ences [#4089 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information
pixeltrix authored and josh committed Mar 15, 2010
1 parent 16572fd commit 96bc6bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
16 changes: 8 additions & 8 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -362,11 +362,11 @@ def self.default_actions
attr_reader :plural, :singular, :options

def initialize(entities, options = {})
entities = entities.to_s
@name = entities.to_s
@options = options

@plural = entities.pluralize
@singular = entities.singularize
@plural = @name.pluralize
@singular = @name.singularize
end

def default_actions
Expand All @@ -393,7 +393,7 @@ def action_type(action)
end

def name
options[:as] || plural
options[:as] || @name
end

def controller
Expand Down Expand Up @@ -438,8 +438,8 @@ def action_type(action)
end
end

def name
options[:as] || singular
def member_name
name
end
end

Expand Down Expand Up @@ -468,8 +468,8 @@ def resource(*resources, &block)
post :create if resource.actions.include?(:create)
put :update if resource.actions.include?(:update)
delete :destroy if resource.actions.include?(:destroy)
get :new, :as => resource.singular if resource.actions.include?(:new)
get :edit, :as => resource.singular if resource.actions.include?(:edit)
get :new, :as => resource.name if resource.actions.include?(:new)
get :edit, :as => resource.name if resource.actions.include?(:edit)
end
end

Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/controller/resources_test.rb
Expand Up @@ -16,6 +16,7 @@ class AccountsController < ResourcesController; end
class AdminController < ResourcesController; end
class ProductsController < ResourcesController; end
class ImagesController < ResourcesController; end
class PreferencesController < ResourcesController; end

module Backoffice
class ProductsController < ResourcesController; end
Expand Down Expand Up @@ -1125,6 +1126,12 @@ def test_default_singleton_restful_route_uses_get
end
end

def test_singleton_resource_name_is_not_singularized
with_singleton_resources(:preferences) do
assert_singleton_restful_for :preferences
end
end

protected
def with_restful_routing(*args)
with_routing do |set|
Expand Down

0 comments on commit 96bc6bc

Please sign in to comment.