Class: ActionController::TestResponse
- Inherits:
-
AbstractResponse
- Object
- AbstractResponse
- ActionController::TestResponse
- Defined in:
- lib/action_controller/test_process.rb
Overview
:nodoc:
Constant Summary
Constants inherited from AbstractResponse
AbstractResponse::DEFAULT_HEADERS
Class Attribute Summary collapse
-
.assertion_target ⇒ Object
Returns the value of attribute assertion_target.
Attributes inherited from AbstractResponse
#assigns, #body, #cookies, #headers, #redirected_to, #redirected_to_method_params, #session, #template
Instance Method Summary collapse
-
#flash ⇒ Object
a shortcut to the flash (or an empty hash if no flash.. hey! that rhymes!).
-
#has_flash? ⇒ Boolean
do we have a flash?.
-
#has_flash_object?(name = nil) ⇒ Boolean
does the specified flash object exist?.
-
#has_flash_with_contents? ⇒ Boolean
do we have a flash that has contents?.
-
#has_session_object?(name = nil) ⇒ Boolean
does the specified object exist in the session?.
-
#has_template_object?(name = nil) ⇒ Boolean
does the specified template object exist?.
-
#initialize ⇒ TestResponse
constructor
initializer.
-
#missing? ⇒ Boolean
was the URL not found?.
-
#redirect? ⇒ Boolean
were we redirected?.
-
#redirect_url ⇒ Object
returns the redirection location or nil.
-
#redirect_url_match?(pattern) ⇒ Boolean
does the redirect location match this regexp pattern?.
-
#rendered_file(with_controller = false) ⇒ Object
returns the template path of the file which was used to render this response (or nil).
-
#rendered_with_file? ⇒ Boolean
was this template rendered by a file?.
-
#response_code ⇒ Object
the response code of the request.
-
#server_error? ⇒ Boolean
was there a server-side error?.
-
#success? ⇒ Boolean
was the response successful?.
-
#template_objects ⇒ Object
a shortcut to the template.assigns.
Methods inherited from AbstractResponse
Constructor Details
#initialize ⇒ TestResponse
initializer
74 75 76 77 |
# File 'lib/action_controller/test_process.rb', line 74 def initialize TestResponse.assertion_target=self# if TestResponse.assertion_target.nil? super() end |
Class Attribute Details
.assertion_target ⇒ Object
Returns the value of attribute assertion_target.
70 71 72 |
# File 'lib/action_controller/test_process.rb', line 70 def assertion_target @assertion_target end |
Instance Method Details
#flash ⇒ Object
a shortcut to the flash (or an empty hash if no flash.. hey! that rhymes!)
136 137 138 |
# File 'lib/action_controller/test_process.rb', line 136 def flash session['flash'] || {} end |
#has_flash? ⇒ Boolean
do we have a flash?
141 142 143 |
# File 'lib/action_controller/test_process.rb', line 141 def has_flash? !session['flash'].nil? end |
#has_flash_object?(name = nil) ⇒ Boolean
does the specified flash object exist?
151 152 153 |
# File 'lib/action_controller/test_process.rb', line 151 def has_flash_object?(name=nil) !flash[name].nil? end |
#has_flash_with_contents? ⇒ Boolean
do we have a flash that has contents?
146 147 148 |
# File 'lib/action_controller/test_process.rb', line 146 def has_flash_with_contents? !flash.empty? end |
#has_session_object?(name = nil) ⇒ Boolean
does the specified object exist in the session?
156 157 158 |
# File 'lib/action_controller/test_process.rb', line 156 def has_session_object?(name=nil) !session[name].nil? end |
#has_template_object?(name = nil) ⇒ Boolean
does the specified template object exist?
166 167 168 |
# File 'lib/action_controller/test_process.rb', line 166 def has_template_object?(name=nil) !template_objects[name].nil? end |
#missing? ⇒ Boolean
was the URL not found?
90 91 92 |
# File 'lib/action_controller/test_process.rb', line 90 def missing? response_code == 404 end |
#redirect? ⇒ Boolean
were we redirected?
95 96 97 |
# File 'lib/action_controller/test_process.rb', line 95 def redirect? (300..399).include?(response_code) end |
#redirect_url ⇒ Object
returns the redirection location or nil
105 106 107 |
# File 'lib/action_controller/test_process.rb', line 105 def redirect_url redirect? ? headers['location'] : nil end |
#redirect_url_match?(pattern) ⇒ Boolean
does the redirect location match this regexp pattern?
110 111 112 113 114 115 116 |
# File 'lib/action_controller/test_process.rb', line 110 def redirect_url_match?( pattern ) return false if redirect_url.nil? p = Regexp.new(pattern) if pattern.class == String p = pattern if pattern.class == Regexp return false if p.nil? p.match(redirect_url) != nil end |
#rendered_file(with_controller = false) ⇒ Object
returns the template path of the file which was used to render this response (or nil)
120 121 122 123 124 125 126 127 128 |
# File 'lib/action_controller/test_process.rb', line 120 def rendered_file(with_controller=false) unless template.first_render.nil? unless with_controller template.first_render else template.first_render.split('/').last || template.first_render end end end |
#rendered_with_file? ⇒ Boolean
was this template rendered by a file?
131 132 133 |
# File 'lib/action_controller/test_process.rb', line 131 def rendered_with_file? !rendered_file.nil? end |
#response_code ⇒ Object
the response code of the request
80 81 82 |
# File 'lib/action_controller/test_process.rb', line 80 def response_code headers['Status'][0,3].to_i rescue 0 end |
#server_error? ⇒ Boolean
was there a server-side error?
100 101 102 |
# File 'lib/action_controller/test_process.rb', line 100 def server_error? (500..599).include?(response_code) end |
#success? ⇒ Boolean
was the response successful?
85 86 87 |
# File 'lib/action_controller/test_process.rb', line 85 def success? response_code == 200 end |
#template_objects ⇒ Object
a shortcut to the template.assigns
161 162 163 |
# File 'lib/action_controller/test_process.rb', line 161 def template_objects template.assigns || {} end |