diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-02-11 21:43:28 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2016-02-11 22:47:17 +0100 |
commit | 77bbf1e905f2ff82d715bac3f0b255cf3ade1d97 (patch) | |
tree | 92d656470f586125b41293f2d268d4d96855df29 /actionpack/lib | |
parent | f9f98b75b57f7ab264e6af0abcda898fe166b828 (diff) | |
download | rails-77bbf1e905f2ff82d715bac3f0b255cf3ade1d97.tar.gz rails-77bbf1e905f2ff82d715bac3f0b255cf3ade1d97.tar.bz2 rails-77bbf1e905f2ff82d715bac3f0b255cf3ade1d97.zip |
Make `parsed_body` extract parser from the content type.
We're not guaranteed to have a `RequestEncoder` to assign on `get` requests
because we aren't extracting the parser from the response content type.
Until now.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/testing/integration.rb | 12 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/testing/test_response.rb | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 742bce1ca6..f4534b4173 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) @@ -726,7 +729,8 @@ module ActionDispatch # response_parser: -> body { body } # # Where `param_encoder` defines how the params should be encoded and - # `response_parser` defines how the response body should be parsed. + # `response_parser` defines how the response body should be parsed through + # `parsed_body`. # # Consult the Rails Testing Guide for more. diff --git a/actionpack/lib/action_dispatch/testing/test_response.rb b/actionpack/lib/action_dispatch/testing/test_response.rb index 58d3e6eb0f..9d4b73a43d 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) + @parsed_body ||= @response_parser.call(body) end end end |