mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Don't force singularization of singleton resource names, e.g. /preferences [#4089 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
This commit is contained in:
parent
16572fd46e
commit
96bc6bcfee
2 changed files with 15 additions and 8 deletions
|
@ -362,11 +362,11 @@ module ActionDispatch
|
|||
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
|
||||
|
@ -393,7 +393,7 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def name
|
||||
options[:as] || plural
|
||||
options[:as] || @name
|
||||
end
|
||||
|
||||
def controller
|
||||
|
@ -438,8 +438,8 @@ module ActionDispatch
|
|||
end
|
||||
end
|
||||
|
||||
def name
|
||||
options[:as] || singular
|
||||
def member_name
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -468,8 +468,8 @@ module ActionDispatch
|
|||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -1125,6 +1126,12 @@ class ResourcesTest < ActionController::TestCase
|
|||
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|
|
||||
|
|
Loading…
Reference in a new issue