提交 168c0887 编写于 作者: J José Valim

Merge pull request #3863 from lest/params-wrapper-inflections

use classify in ParamsWrapper to derive model name from controller name
......@@ -141,7 +141,7 @@ def inherited(klass)
# 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
......
......@@ -285,3 +285,38 @@ def test_does_wrap_params_if_name_provided
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册