提交 a2c9a730 编写于 作者: J Jorge Bejar 提交者: Santiago Pastorino

Include ParamsWrapper in AC::API

ParamsWrapper was initially removed from API controllers according to
the following discusision:
https://github.com/rails-api/rails-api/issues/33

However, we're including it again so Rails API devs can decide
whether to enable or disable it.
上级 ebcc15ca
......@@ -128,7 +128,11 @@ def self.without_modules(*modules)
# Add instrumentations hooks at the bottom, to ensure they instrument
# all the methods properly.
Instrumentation
Instrumentation,
# Params wrapper should come before instrumentation so they are
# properly showed in logs
ParamsWrapper
]
MODULES.each do |mod|
......
require 'abstract_unit'
class ParamsWrapperForApiTest < ActionController::TestCase
class UsersController < ActionController::API
attr_accessor :last_parameters
wrap_parameters :person, format: [:json]
def test
self.last_parameters = params.except(:controller, :action)
head :ok
end
end
class Person; end
tests UsersController
def test_specify_wrapper_name
@request.env['CONTENT_TYPE'] = 'application/json'
post :test, params: { 'username' => 'sikachu' }
expected = { 'username' => 'sikachu', 'person' => { 'username' => 'sikachu' }}
assert_equal expected, @controller.last_parameters
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册