aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/assertions
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_controller/assertions')
-rw-r--r--actionpack/lib/action_controller/assertions/response_assertions.rb56
-rw-r--r--actionpack/lib/action_controller/assertions/routing_assertions.rb2
-rw-r--r--actionpack/lib/action_controller/assertions/selector_assertions.rb3
3 files changed, 46 insertions, 15 deletions
diff --git a/actionpack/lib/action_controller/assertions/response_assertions.rb b/actionpack/lib/action_controller/assertions/response_assertions.rb
index 7ab24389b8..5976090273 100644
--- a/actionpack/lib/action_controller/assertions/response_assertions.rb
+++ b/actionpack/lib/action_controller/assertions/response_assertions.rb
@@ -16,7 +16,7 @@ module ActionController
# ==== Examples
#
# # assert that the response was a redirection
- # assert_response :redirect
+ # assert_response :redirect
#
# # assert that the response code was status code 401 (unauthorized)
# assert_response 401
@@ -41,7 +41,7 @@ module ActionController
end
end
- # Assert that the redirection options passed in match those of the redirect called in the latest action.
+ # Assert that the redirection options passed in match those of the redirect called in the latest action.
# This match can be partial, such that assert_redirected_to(:controller => "weblog") will also
# match the redirection of redirect_to(:controller => "weblog", :action => "show") and so on.
#
@@ -60,12 +60,12 @@ module ActionController
clean_backtrace do
assert_response(:redirect, message)
return true if options == @response.redirected_to
-
+
# Support partial arguments for hash redirections
if options.is_a?(Hash) && @response.redirected_to.is_a?(Hash)
return true if options.all? {|(key, value)| @response.redirected_to[key] == value}
end
-
+
redirected_to_after_normalisation = normalize_argument_to_redirection(@response.redirected_to)
options_after_normalisation = normalize_argument_to_redirection(options)
@@ -75,29 +75,59 @@ module ActionController
end
end
- # Asserts that the request was rendered with the appropriate template file.
+ # Asserts that the request was rendered with the appropriate template file or partials
#
# ==== Examples
#
# # assert that the "new" view template was rendered
# assert_template "new"
#
- def assert_template(expected = nil, message=nil)
+ # # assert that the "_customer" partial was rendered twice
+ # assert_template :partial => '_customer', :count => 2
+ #
+ # # assert that no partials were rendered
+ # assert_template :partial => false
+ #
+ def assert_template(options = {}, message = nil)
clean_backtrace do
- rendered = @response.rendered_template.to_s
- msg = build_message(message, "expecting <?> but rendering with <?>", expected, rendered)
- assert_block(msg) do
- if expected.nil?
- @response.rendered_template.blank?
+ case options
+ when NilClass, String
+ rendered = @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?
+ else
+ rendered.to_s.match(options)
+ end
+ end
+ when Hash
+ if expected_partial = options[:partial]
+ partials = @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
+ msg = build_message(message,
+ "expecting ? to be rendered ? time(s) but rendered ? time(s)",
+ expected_partial, expected_count, actual_count)
+ assert(actual_count == expected_count.to_i, msg)
+ else
+ msg = build_message(message,
+ "expecting partial <?> but action rendered <?>",
+ options[:partial], partials.keys)
+ assert(partials.keys.any? { |p| p.to_s.match(expected_partial) }, msg)
+ end
else
- rendered.to_s.match(expected)
+ assert @response.rendered[:partials].empty?,
+ "Expected no partials to be rendered"
end
end
end
end
private
-
# Proxy to to_param if the object will respond to it.
def parameterize(value)
value.respond_to?(:to_param) ? value.to_param : value
diff --git a/actionpack/lib/action_controller/assertions/routing_assertions.rb b/actionpack/lib/action_controller/assertions/routing_assertions.rb
index 8a837c592c..5101751cea 100644
--- a/actionpack/lib/action_controller/assertions/routing_assertions.rb
+++ b/actionpack/lib/action_controller/assertions/routing_assertions.rb
@@ -134,7 +134,7 @@ module ActionController
path = "/#{path}" unless path.first == '/'
# Assume given controller
- request = ActionController::TestRequest.new({}, {}, nil)
+ request = ActionController::TestRequest.new
request.env["REQUEST_METHOD"] = request_method.to_s.upcase if request_method
request.path = path
diff --git a/actionpack/lib/action_controller/assertions/selector_assertions.rb b/actionpack/lib/action_controller/assertions/selector_assertions.rb
index e03fed7abb..7f8fe9ab19 100644
--- a/actionpack/lib/action_controller/assertions/selector_assertions.rb
+++ b/actionpack/lib/action_controller/assertions/selector_assertions.rb
@@ -402,6 +402,7 @@ module ActionController
if rjs_type
if rjs_type == :insert
position = args.shift
+ id = args.shift
insertion = "insert_#{position}".to_sym
raise ArgumentError, "Unknown RJS insertion type #{position}" unless RJS_STATEMENTS[insertion]
statement = "(#{RJS_STATEMENTS[insertion]})"
@@ -587,7 +588,7 @@ module ActionController
def response_from_page_or_rjs()
content_type = @response.content_type
- if content_type && content_type =~ /text\/javascript/
+ if content_type && Mime::JS =~ content_type
body = @response.body.dup
root = HTML::Node.new(nil)