Class: ActionDispatch::TestResponse

Inherits:
Response
  • Object
show all
Defined in:
lib/action_dispatch/testing/test_response.rb

Overview

Integration test methods such as ActionDispatch::Integration::Session#get and ActionDispatch::Integration::Session#post return objects of class TestResponse, which represent the HTTP response results of the requested controller actions.

See Response for more information on controller response objects.

Constant Summary

Constants inherited from Response

Response::CONTENT_TYPE, Response::LOCATION, Response::NO_CONTENT_CODES, Response::SET_COOKIE

Constants included from Http::FilterRedirect

Http::FilterRedirect::FILTERED

Instance Attribute Summary

Attributes inherited from Response

#header, #request, #status, #stream

Attributes included from Http::Cache::Response

#cache_control

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Response

#abort, #await_commit, #await_sent, #body, #body=, #body_parts, #charset, #charset=, #close, #code, #commit!, #committed?, #content_type, #content_type=, #cookies, create, #delete_header, #each, #get_header, #has_header?, merge_default_headers, #message, #reset_body!, #response_code, #send_file, #sending!, #sending?, #sending_file=, #sent!, #sent?, #set_header, #to_a, #write

Methods included from Http::Cache::Response

#date, #date=, #date?, #etag=, #etag?, #last_modified, #last_modified=, #last_modified?, #strong_etag=, #strong_etag?, #weak_etag=, #weak_etag?

Methods included from Http::FilterRedirect

#filtered_location

Constructor Details

#initializeTestResponse

:nodoc:



17
18
19
20
# File 'lib/action_dispatch/testing/test_response.rb', line 17

def initialize(*) # :nodoc:
  super
  @response_parser = RequestEncoder.parser(content_type)
end

Class Method Details

.from_response(response) ⇒ Object



13
14
15
# File 'lib/action_dispatch/testing/test_response.rb', line 13

def self.from_response(response)
  new response.status, response.headers, response.body
end

Instance Method Details

#error?Boolean

Was there a server-side error?

Returns:

  • (Boolean)


41
42
43
44
45
46
47
# File 'lib/action_dispatch/testing/test_response.rb', line 41

def error?
  ActiveSupport::Deprecation.warn(<<-MSG.squish)
   The error? predicate is deprecated and will be removed in Rails 6.0.
   Please use server_error? as provided by Rack::Response::Helpers.
  MSG
  server_error?
end

#missing?Boolean

Was the URL not found?

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/action_dispatch/testing/test_response.rb', line 32

def missing?
  ActiveSupport::Deprecation.warn(<<-MSG.squish)
   The missing? predicate is deprecated and will be removed in Rails 6.0.
   Please use not_found? as provided by Rack::Response::Helpers.
  MSG
  not_found?
end

#parsed_bodyObject



49
50
51
# File 'lib/action_dispatch/testing/test_response.rb', line 49

def parsed_body
  @parsed_body ||= @response_parser.call(body)
end

#success?Boolean

Was the response successful?

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/action_dispatch/testing/test_response.rb', line 23

def success?
  ActiveSupport::Deprecation.warn(<<-MSG.squish)
   The success? predicate is deprecated and will be removed in Rails 6.0.
   Please use successful? as provided by Rack::Response::Helpers.
  MSG
  successful?
end