Class: ActionController::TestResponse

Inherits:
AbstractResponse show all
Defined in:
lib/action_controller/test_process.rb

Overview

:nodoc:

Constant Summary

Constants inherited from AbstractResponse

AbstractResponse::DEFAULT_HEADERS

Class Attribute Summary collapse

Attributes inherited from AbstractResponse

#assigns, #body, #cookies, #headers, #redirected_to, #redirected_to_method_params, #session, #template

Instance Method Summary collapse

Methods inherited from AbstractResponse

#redirect

Constructor Details

#initializeTestResponse

initializer



70
71
72
73
# File 'lib/action_controller/test_process.rb', line 70

def initialize
  TestResponse.assertion_target=self# if TestResponse.assertion_target.nil?
  super()
end

Class Attribute Details

.assertion_targetObject

Returns the value of attribute assertion_target.



66
67
68
# File 'lib/action_controller/test_process.rb', line 66

def assertion_target
  @assertion_target
end

Instance Method Details

#flashObject

a shortcut to the flash (or an empty hash if no flash.. hey! that rhymes!)



132
133
134
# File 'lib/action_controller/test_process.rb', line 132

def flash
  session['flash'] || {}
end

#has_flash?Boolean

do we have a flash?

Returns:

  • (Boolean)


137
138
139
# File 'lib/action_controller/test_process.rb', line 137

def has_flash?
  !session['flash'].nil?
end

#has_flash_object?(name = nil) ⇒ Boolean

does the specified flash object exist?

Returns:

  • (Boolean)


147
148
149
# File 'lib/action_controller/test_process.rb', line 147

def has_flash_object?(name=nil)
  !flash[name].nil?
end

#has_flash_with_contents?Boolean

do we have a flash that has contents?

Returns:

  • (Boolean)


142
143
144
# File 'lib/action_controller/test_process.rb', line 142

def has_flash_with_contents?
  !flash.empty?
end

#has_session_object?(name = nil) ⇒ Boolean

does the specified object exist in the session?

Returns:

  • (Boolean)


152
153
154
# File 'lib/action_controller/test_process.rb', line 152

def has_session_object?(name=nil)
  !session[name].nil?
end

#has_template_object?(name = nil) ⇒ Boolean

does the specified template object exist?

Returns:

  • (Boolean)


162
163
164
# File 'lib/action_controller/test_process.rb', line 162

def has_template_object?(name=nil)
  !template_objects[name].nil?      
end

#missing?Boolean

was the URL not found?

Returns:

  • (Boolean)


86
87
88
# File 'lib/action_controller/test_process.rb', line 86

def missing?
  response_code == 404
end

#redirect?Boolean

were we redirected?

Returns:

  • (Boolean)


91
92
93
# File 'lib/action_controller/test_process.rb', line 91

def redirect?
  (300..399).include?(response_code)
end

#redirect_urlObject

returns the redirection location or nil



101
102
103
# File 'lib/action_controller/test_process.rb', line 101

def redirect_url
  redirect? ? headers['location'] : nil
end

#redirect_url_match?(pattern) ⇒ Boolean

does the redirect location match this regexp pattern?

Returns:

  • (Boolean)


106
107
108
109
110
111
112
# File 'lib/action_controller/test_process.rb', line 106

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)



116
117
118
119
120
121
122
123
124
# File 'lib/action_controller/test_process.rb', line 116

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?

Returns:

  • (Boolean)


127
128
129
# File 'lib/action_controller/test_process.rb', line 127

def rendered_with_file?
  !rendered_file.nil?
end

#response_codeObject

the response code of the request



76
77
78
# File 'lib/action_controller/test_process.rb', line 76

def response_code
  headers['Status'][0,3].to_i rescue 0
end

#server_error?Boolean

was there a server-side error?

Returns:

  • (Boolean)


96
97
98
# File 'lib/action_controller/test_process.rb', line 96

def server_error?
  (500..599).include?(response_code)
end

#success?Boolean

was the response successful?

Returns:

  • (Boolean)


81
82
83
# File 'lib/action_controller/test_process.rb', line 81

def success?
  response_code == 200
end

#template_objectsObject

a shortcut to the template.assigns



157
158
159
# File 'lib/action_controller/test_process.rb', line 157

def template_objects
  template.assigns || {}
end