diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-07-10 22:02:12 +0200 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2016-07-10 22:02:12 +0200 |
commit | 333670ceb96e74399645fca3201969e63c3c403b (patch) | |
tree | 1b799b6ba8c6b6df018b3f4e3aec15ffd0b29ac4 /actionpack/lib/action_dispatch/testing/test_response.rb | |
parent | db1582ac342be68bf5addd1b770e7dec2abe44d2 (diff) | |
download | rails-333670ceb96e74399645fca3201969e63c3c403b.tar.gz rails-333670ceb96e74399645fca3201969e63c3c403b.tar.bz2 rails-333670ceb96e74399645fca3201969e63c3c403b.zip |
Let TestResponse assign a parser.
Previously we'd only assign a response parser when a request came through
Action Dispatch integration tests. This made calls to `parsed_body` when a TestResponse
was manually instantiated — though own doing or perhaps from a framework — unintentionally
blow up because no parser was set at that time.
The response can lookup a parser entirely through its own ivars. Extract request encoder to
its own file and assume that a viable content type is present at TestResponse instantiation.
Since the default response parser is a no-op, making `parsed_body` equal to `body`, no
exceptions will be thrown.
Diffstat (limited to 'actionpack/lib/action_dispatch/testing/test_response.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/testing/test_response.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/testing/test_response.rb b/actionpack/lib/action_dispatch/testing/test_response.rb index 9d4b73a43d..bedb7a5558 100644 --- a/actionpack/lib/action_dispatch/testing/test_response.rb +++ b/actionpack/lib/action_dispatch/testing/test_response.rb @@ -1,3 +1,5 @@ +require 'action_dispatch/testing/request_encoder' + module ActionDispatch # Integration test methods such as ActionDispatch::Integration::Session#get # and ActionDispatch::Integration::Session#post return objects of class @@ -10,6 +12,11 @@ module ActionDispatch new response.status, response.headers, response.body end + def initialize(*) # :nodoc: + super + @response_parser = RequestEncoder.parser(content_type) + end + # Was the response successful? alias_method :success?, :successful? @@ -19,8 +26,6 @@ module ActionDispatch # Was there a server-side error? alias_method :error?, :server_error? - attr_writer :response_parser # :nodoc: - def parsed_body @parsed_body ||= @response_parser.call(body) end |