aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/testing/assertions/response.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-04-26 11:52:45 -0500
committerJoshua Peek <josh@joshpeek.com>2009-04-26 11:52:45 -0500
commitc8919f4c7ca13ad78987ea0c8497abe85249975b (patch)
treef25aa39f6bf7f91115dc2a1f5eb0f3078648e83b /actionpack/lib/action_controller/testing/assertions/response.rb
parent6940c0de12eedcff6529ba0dfef533513cbcd389 (diff)
downloadrails-c8919f4c7ca13ad78987ea0c8497abe85249975b.tar.gz
rails-c8919f4c7ca13ad78987ea0c8497abe85249975b.tar.bz2
rails-c8919f4c7ca13ad78987ea0c8497abe85249975b.zip
Require an ActionDispatch::Request to use response assertions
Diffstat (limited to 'actionpack/lib/action_controller/testing/assertions/response.rb')
-rw-r--r--actionpack/lib/action_controller/testing/assertions/response.rb24
1 files changed, 18 insertions, 6 deletions
diff --git a/actionpack/lib/action_controller/testing/assertions/response.rb b/actionpack/lib/action_controller/testing/assertions/response.rb
index ca0a9bbf52..c57cbecc44 100644
--- a/actionpack/lib/action_controller/testing/assertions/response.rb
+++ b/actionpack/lib/action_controller/testing/assertions/response.rb
@@ -22,6 +22,8 @@ module ActionController
# assert_response 401
#
def assert_response(type, message = nil)
+ validate_response!
+
clean_backtrace do
if [ :success, :missing, :redirect, :error ].include?(type) && @response.send("#{type}?")
assert_block("") { true } # to count the assertion
@@ -30,8 +32,8 @@ module ActionController
elsif type.is_a?(Symbol) && @response.response_code == ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE[type]
assert_block("") { true } # to count the assertion
else
- if @response.error?
- exception = @response.template.instance_variable_get(:@exception)
+ if @controller && @response.error?
+ exception = @controller.response.template.instance_variable_get(:@exception)
exception_message = exception && exception.message
assert_block(build_message(message, "Expected response to be a <?>, but was <?>\n<?>", type, @response.response_code, exception_message.to_s)) { false }
else
@@ -57,6 +59,8 @@ module ActionController
# assert_redirected_to @customer
#
def assert_redirected_to(options = {}, message=nil)
+ validate_response!
+
clean_backtrace do
assert_response(:redirect, message)
return true if options == @response.redirected_to
@@ -89,23 +93,25 @@ module ActionController
# assert_template :partial => false
#
def assert_template(options = {}, message = nil)
+ validate_response!
+
clean_backtrace do
case options
when NilClass, String
- rendered = @response.rendered[:template].to_s
+ rendered = @controller.response.rendered[:template].to_s
msg = build_message(message,
"expecting <?> but rendering with <?>",
options, rendered)
assert_block(msg) do
if options.nil?
- @response.rendered[:template].blank?
+ @controller.response.rendered[:template].blank?
else
rendered.to_s.match(options)
end
end
when Hash
if expected_partial = options[:partial]
- partials = @response.rendered[:partials]
+ partials = @controller.response.rendered[:partials]
if expected_count = options[:count]
found = partials.detect { |p, _| p.to_s.match(expected_partial) }
actual_count = found.nil? ? 0 : found.second
@@ -120,7 +126,7 @@ module ActionController
assert(partials.keys.any? { |p| p.to_s.match(expected_partial) }, msg)
end
else
- assert @response.rendered[:partials].empty?,
+ assert @controller.response.rendered[:partials].empty?,
"Expected no partials to be rendered"
end
end
@@ -145,6 +151,12 @@ module ActionController
@request.protocol + @request.host_with_port + after_routing
end
end
+
+ def validate_response!
+ unless @request.is_a?(ActionDispatch::Request)
+ raise ArgumentError, "@request must be an ActionDispatch::Request"
+ end
+ end
end
end
end