diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-04-26 11:12:33 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-04-26 11:12:33 -0500 |
commit | 5352a2417b9f6297d16a6baefd1994be4d1e4a12 (patch) | |
tree | 38c734e7005d3ac5c28fd72cee2c04ef1801c944 /actionpack/lib/action_controller | |
parent | dbbe2e74ff5b6363da74fe63045b043c24041b1a (diff) | |
download | rails-5352a2417b9f6297d16a6baefd1994be4d1e4a12.tar.gz rails-5352a2417b9f6297d16a6baefd1994be4d1e4a12.tar.bz2 rails-5352a2417b9f6297d16a6baefd1994be4d1e4a12.zip |
Move useful response test helpers into request
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/testing/integration.rb | 7 | ||||
-rw-r--r-- | actionpack/lib/action_controller/testing/process.rb | 61 |
2 files changed, 6 insertions, 62 deletions
diff --git a/actionpack/lib/action_controller/testing/integration.rb b/actionpack/lib/action_controller/testing/integration.rb index 15d0603ac1..10260d5af2 100644 --- a/actionpack/lib/action_controller/testing/integration.rb +++ b/actionpack/lib/action_controller/testing/integration.rb @@ -304,8 +304,11 @@ module ActionController @response = @controller.response @controller.send(:set_test_assigns) else - @request = ::Rack::Request.new(env) - @response = response + @request = Request.new(env) + @response = Response.new + @response.status = @status + @response.headers = @headers + @response.body = @body end # Decorate the response with the standard behavior of the diff --git a/actionpack/lib/action_controller/testing/process.rb b/actionpack/lib/action_controller/testing/process.rb index f5742af472..05b756fa4d 100644 --- a/actionpack/lib/action_controller/testing/process.rb +++ b/actionpack/lib/action_controller/testing/process.rb @@ -156,54 +156,7 @@ module ActionController #:nodoc: # A refactoring of TestResponse to allow the same behavior to be applied # to the "real" CgiResponse class in integration tests. module TestResponseBehavior #:nodoc: - # The response code of the request - def response_code - status.to_s[0,3].to_i rescue 0 - end - - # Returns a String to ensure compatibility with Net::HTTPResponse - def code - status.to_s.split(' ')[0] - end - - def message - status.to_s.split(' ',2)[1] - end - - # Was the response successful? - def success? - (200..299).include?(response_code) - end - - # Was the URL not found? - def missing? - response_code == 404 - end - - # Were we redirected? - def redirect? - (300..399).include?(response_code) - end - - # Was there a server-side error? - def error? - (500..599).include?(response_code) - end - - alias_method :server_error?, :error? - - # Was there a client client? - def client_error? - (400..499).include?(response_code) - end - - # Returns the redirection location or nil - def redirect_url - headers['Location'] - end - - # Does the redirect location match this regexp pattern? - def redirect_url_match?( pattern ) + 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 @@ -252,18 +205,6 @@ module ActionController #:nodoc: !template_objects[name].nil? end - # Returns the response cookies, converted to a Hash of (name => value) pairs - # - # assert_equal 'AuthorOfNewPage', r.cookies['author'] - def cookies - cookies = {} - Array(headers['Set-Cookie']).each do |cookie| - key, value = cookie.split(";").first.split("=").map {|val| Rack::Utils.unescape(val)} - cookies[key] = value - end - cookies - end - # Returns binary content (downloadable file), converted to a String def binary_content raise "Response body is not a Proc: #{body_parts.inspect}" unless body_parts.kind_of?(Proc) |