1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

use classify in ParamsWrapper to derive model name from controller name

This commit is contained in:
lest 2011-12-05 19:05:03 +03:00
parent d4964b3386
commit 1f0e21ce30
2 changed files with 36 additions and 1 deletions

View file

@ -141,7 +141,7 @@ module ActionController
# try to find Foo::Bar::User, Foo::User and finally User.
def _default_wrap_model #:nodoc:
return nil if self.anonymous?
model_name = self.name.sub(/Controller$/, '').singularize
model_name = self.name.sub(/Controller$/, '').classify
begin
if model_klass = model_name.safe_constantize

View file

@ -285,3 +285,38 @@ class AnonymousControllerParamsWrapperTest < ActionController::TestCase
end
end
end
class IrregularInflectionParamsWrapperTest < ActionController::TestCase
include ParamsWrapperTestHelp
class ParamswrappernewsItem
def self.attribute_names
['test_attr']
end
end
class ParamswrappernewsController < ActionController::Base
class << self
attr_accessor :last_parameters
end
def parse
self.class.last_parameters = request.params.except(:controller, :action)
head :ok
end
end
tests ParamswrappernewsController
def test_uses_model_attribute_names_with_irregular_inflection
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'paramswrappernews_item', 'paramswrappernews'
end
with_default_wrapper_options do
@request.env['CONTENT_TYPE'] = 'application/json'
post :parse, { 'username' => 'sikachu', 'test_attr' => 'test_value' }
assert_parameters({ 'username' => 'sikachu', 'test_attr' => 'test_value', 'paramswrappernews_item' => { 'test_attr' => 'test_value' }})
end
end
end