mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
do not instantiate a param parser middleware
we don't actually need a param parser middleware instance since the request object will take care of parsing parameters for us. For now, we'll just configure the parameter parsers on the request in this class.
This commit is contained in:
parent
b93c226d19
commit
a1ced8b52c
2 changed files with 14 additions and 14 deletions
|
@ -22,13 +22,9 @@ module ActionDispatch
|
|||
#
|
||||
# The +parsers+ argument can take Hash of parsers where key is identifying
|
||||
# content mime type, and value is a lambda that is going to process data.
|
||||
def initialize(app, parsers = {})
|
||||
@app = app
|
||||
def self.new(app, parsers = {})
|
||||
ActionDispatch::Request.parameter_parsers = ActionDispatch::Request::DEFAULT_PARSERS.merge(parsers)
|
||||
end
|
||||
|
||||
def call(env)
|
||||
@app.call(env)
|
||||
app
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -97,24 +97,28 @@ class WebServiceTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_parsing_json_doesnot_rescue_exception
|
||||
with_test_route_set do
|
||||
with_params_parsers Mime::JSON => Proc.new { |data| raise Interrupt } do
|
||||
assert_raises(Interrupt) do
|
||||
post "/",
|
||||
params: '{"title":"JSON"}}',
|
||||
headers: { 'CONTENT_TYPE' => 'application/json' }
|
||||
end
|
||||
req = Class.new(ActionDispatch::Request) do
|
||||
def params_parsers
|
||||
{ Mime::JSON => Proc.new { |data| raise Interrupt } }
|
||||
end
|
||||
|
||||
def content_length; get_header('rack.input').length; end
|
||||
end.new({ 'rack.input' => StringIO.new('{"title":"JSON"}}'), 'CONTENT_TYPE' => 'application/json' })
|
||||
|
||||
assert_raises(Interrupt) do
|
||||
req.request_parameters
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def with_params_parsers(parsers = {})
|
||||
old_session = @integration_session
|
||||
@app = ActionDispatch::ParamsParser.new(app.routes, parsers)
|
||||
original_parsers = ActionDispatch::Request.parameter_parsers
|
||||
ActionDispatch::Request.parameter_parsers = original_parsers.merge parsers
|
||||
reset!
|
||||
yield
|
||||
ensure
|
||||
ActionDispatch::Request.parameter_parsers = original_parsers
|
||||
@integration_session = old_session
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue