diff options
author | Steve Klabnik <steve@steveklabnik.com> | 2013-05-30 20:34:53 -0700 |
---|---|---|
committer | Steve Klabnik <steve@steveklabnik.com> | 2013-05-30 20:34:53 -0700 |
commit | 8603bc06ad54ef07e5d4bd073665d495d3561f98 (patch) | |
tree | 105772991f76781867b57dd08e0976c360676181 /actionpack/lib | |
parent | e43a99e2582d45b8dd0ffa17c65905a72d836c6b (diff) | |
download | rails-8603bc06ad54ef07e5d4bd073665d495d3561f98.tar.gz rails-8603bc06ad54ef07e5d4bd073665d495d3561f98.tar.bz2 rails-8603bc06ad54ef07e5d4bd073665d495d3561f98.zip |
Add propery docs to ActionDispatch::Response [ci skip]
After some discussion on Twitter with @skud, the documentation on ActionDispatch::Response is
a bit sparse. This class is useful when you're writing tests, as often you want to assert various
things about the response that's coming back. Better docs would make this easier for people new
to testing in Rails.
I only added some descriptions for various properties that were defined, and mostly just a sentence
or two. Most of these things are familliar if you're working with HTTP, but some words is better
than no words at all.
Hopefully further commits will fix up things that aren't just documentation.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 60a2cccdc5..5697282791 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -31,10 +31,17 @@ module ActionDispatch # :nodoc: # end # end class Response - attr_accessor :request, :header + # The request that the response is responding to. + attr_accessor :request + + # The HTTP status code. attr_reader :status + attr_writer :sending_file + # Get and set headers for this response. + attr_accessor :header + alias_method :headers=, :header= alias_method :headers, :header @@ -49,9 +56,12 @@ module ActionDispatch # :nodoc: # If a character set has been defined for this response (see charset=) then # the character set information will also be included in the content type # information. - attr_accessor :charset attr_reader :content_type + # The charset of the response. HTML wants to know the encoding of the + # content you're giving them, so we need to send that along. + attr_accessor :charset + CONTENT_TYPE = "Content-Type".freeze SET_COOKIE = "Set-Cookie".freeze LOCATION = "Location".freeze @@ -93,6 +103,7 @@ module ActionDispatch # :nodoc: end end + # The underlying body, as a streamable object. attr_reader :stream def initialize(status = 200, header = {}, body = []) @@ -142,6 +153,7 @@ module ActionDispatch # :nodoc: @status = Rack::Utils.status_code(status) end + # Sets the HTTP content type. def content_type=(content_type) @content_type = content_type.to_s end @@ -216,11 +228,13 @@ module ActionDispatch # :nodoc: ::Rack::Utils.delete_cookie_header!(header, key, value) end + # The location header we'll be responding with. def location headers[LOCATION] end alias_method :redirect_url, :location + # Sets the location header we'll be responding with. def location=(url) headers[LOCATION] = url end @@ -229,11 +243,13 @@ module ActionDispatch # :nodoc: stream.close if stream.respond_to?(:close) end + # Turns the Response into a Rack-compatible array of the status, headers, + # and body. def to_a rack_response @status, @header.to_hash end alias prepare! to_a - alias to_ary to_a # For implicit splat on 1.9.2 + alias to_ary to_a # Returns the response cookies, converted to a Hash of (name => value) pairs # |