diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/testing/integration.rb | 9 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/testing/test_response.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/integration_test.rb | 10 |
3 files changed, 17 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 742bce1ca6..8a8e22053a 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -381,7 +381,7 @@ module ActionDispatch response = _mock_session.last_response @response = ActionDispatch::TestResponse.from_response(response) @response.request = @request - @response.response_parser = request_encoder + @response.response_parser = RequestEncoder.parser(@response.content_type) @html_document = nil @url_options = nil @@ -397,6 +397,8 @@ module ActionDispatch class RequestEncoder # :nodoc: @encoders = {} + attr_reader :response_parser + def initialize(mime_name, param_encoder, response_parser, url_encoded_form = false) @mime = Mime[mime_name] @@ -424,8 +426,9 @@ module ActionDispatch @param_encoder.call(params) end - def parse_body(body) - @response_parser.call(body) + def self.parser(content_type) + mime = Mime::Type.lookup(content_type) + encoder(mime ? mime.ref : nil).response_parser end def self.encoder(name) diff --git a/actionpack/lib/action_dispatch/testing/test_response.rb b/actionpack/lib/action_dispatch/testing/test_response.rb index 58d3e6eb0f..4f289ad4b5 100644 --- a/actionpack/lib/action_dispatch/testing/test_response.rb +++ b/actionpack/lib/action_dispatch/testing/test_response.rb @@ -22,7 +22,7 @@ module ActionDispatch attr_writer :response_parser # :nodoc: def parsed_body - @response_parser.parse_body(body) + @response_parser.call(body) end end end diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index cb524bacb2..ea50f05f4d 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -1171,6 +1171,16 @@ class IntegrationRequestEncodersTest < ActionDispatch::IntegrationTest Mime::Type.unregister :wibble end + def test_parsed_body_without_as_option + with_routing do |routes| + routes.draw { get ':action' => FooController } + + get '/foos_json.json', params: { foo: 'heyo' } + + assert_equal({ 'foo' => 'heyo' }, response.parsed_body) + end + end + private def post_to_foos(as:) with_routing do |routes| |