public
Description: PLEASE CHECK http://github.com/lifo/docrails/wikis
Homepage: http://weblog.rubyonrails.org/2008/5/2/help-improve-rails-documentation-on-git-branch
Clone URL: git://github.com/lifo/docrails.git
Write overviews for AbstractController::TestResponse and 
AbstractController::AbstractResponse.
Hongli Lai (Phusion) (author)
Fri Jul 18 11:48:18 -0700 2008
commit  3dbc1cfeb3e9984fa4584b231d3bb78ff1a94f9c
tree    edbf8ca2fb01b4c93c342634208410a6947c66b0
parent  632a4705b9d492bf3c9c2973b12330ad73e6f420
...
1
2
3
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
6
7
 
 
 
 
 
 
8
9
10
11
12
 
 
 
 
 
 
 
 
13
14
15
16
 
17
18
19
...
73
74
75
76
77
 
...
1
2
 
 
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
...
115
116
117
 
118
119
0
@@ -1,19 +1,61 @@
0
 require 'digest/md5'
0
 
0
-module ActionController
0
-  class AbstractResponse #:nodoc:
0
+module ActionController # :nodoc:
0
+  # Represents an HTTP response generated by a controller action. One can use an
0
+  # ActionController::AbstractResponse object to retrieve the current state of the
0
+  # response, or customize the response. An AbstractResponse object can either
0
+  # represent a "real" HTTP response (i.e. one that is meant to be sent back to the
0
+  # web browser) or a test response (i.e. one that is generated from integration
0
+  # tests). See CgiResponse and TestResponse, respectively.
0
+  #
0
+  # AbstractResponse is mostly a Ruby on Rails framework implement detail, and should
0
+  # never be used directly in controllers. Controllers should use the methods defined
0
+  # in ActionController::Base instead. For example, if you want to set the HTTP
0
+  # response's content MIME type, then use ActionControllerBase#headers instead of
0
+  # AbstractResponse#headers.
0
+  #
0
+  # Nevertheless, integration tests may want to inspect controller responses in more
0
+  # detail, and that's when AbstractResponse can be useful for application developers.
0
+  # Integration test methods such as ActionController::Integration::Session#get and
0
+  # ActionController::Integration::Session#post return objects of type TestResponse
0
+  # (which are of course also of type AbstractResponse).
0
+  #
0
+  # For example, the following demo integration "test" prints the body of the
0
+  # controller response to the console:
0
+  #
0
+  #  class DemoControllerTest < ActionController::IntegrationTest
0
+  #    def test_print_root_path_to_console
0
+  #      get('/')
0
+  #      puts @response.body
0
+  #    end
0
+  #  end
0
+  class AbstractResponse
0
     DEFAULT_HEADERS = { "Cache-Control" => "no-cache" }
0
     attr_accessor :request
0
-    attr_accessor :body, :headers, :session, :cookies, :assigns, :template, :redirected_to, :redirected_to_method_params, :layout
0
+    
0
+    # The body content (e.g. HTML) of the response, as a String.
0
+    attr_accessor :body
0
+    # The headers of the response, as a Hash. It maps header names to header values.
0
+    attr_accessor :headers
0
+    attr_accessor :session, :cookies, :assigns, :template, :redirected_to, :redirected_to_method_params, :layout
0
 
0
     def initialize
0
       @body, @headers, @session, @assigns = "", DEFAULT_HEADERS.merge("cookie" => []), [], []
0
     end
0
 
0
+    # Sets the HTTP response's content MIME type. For example, in the controller
0
+    # you could write this:
0
+    #
0
+    #  response.content_type = "text/plain"
0
+    #
0
+    # If a character set has been defined for this response (see charset=) then
0
+    # the character set information will also be included in the content type
0
+    # information.
0
     def content_type=(mime_type)
0
       self.headers["Content-Type"] = charset ? "#{mime_type}; charset=#{charset}" : mime_type
0
     end
0
     
0
+    # Returns the response's content MIME type, or nil if content type has been set.
0
     def content_type
0
       content_type = String(headers["Content-Type"] || headers["type"]).split(";")[0]
0
       content_type.blank? ? nil : content_type
0
@@ -73,4 +115,4 @@ module ActionController
0
         self.headers["Content-Length"] = body.size unless body.respond_to?(:call)
0
       end
0
   end
0
-end
0
\ No newline at end of file
0
+end
...
273
274
275
276
 
 
 
 
 
 
 
277
278
279
...
273
274
275
 
276
277
278
279
280
281
282
283
284
285
0
@@ -273,7 +273,13 @@ module ActionController #:nodoc:
0
     end
0
   end
0
 
0
-  class TestResponse < AbstractResponse #:nodoc:
0
+  # Integration test methods such as ActionController::Integration::Session#get
0
+  # and ActionController::Integration::Session#post return objects of class
0
+  # TestResponse, which represent the HTTP response results of the requested
0
+  # controller actions.
0
+  #
0
+  # See AbstractResponse for more information on controller response objects.
0
+  class TestResponse < AbstractResponse
0
     include TestResponseBehavior
0
   end
0
 

Comments