aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-04-25 03:54:46 +0000
committerRick Olson <technoweenie@gmail.com>2006-04-25 03:54:46 +0000
commit51cd1aec00c182c6789f09f9bf40365934034bcd (patch)
tree012105a1b37de543ed13b513285a006aa181112d /actionpack
parent71a570ffd7ecc94b5b474c659a34e36a29989a65 (diff)
downloadrails-51cd1aec00c182c6789f09f9bf40365934034bcd.tar.gz
rails-51cd1aec00c182c6789f09f9bf40365934034bcd.tar.bz2
rails-51cd1aec00c182c6789f09f9bf40365934034bcd.zip
Fix assert_redirected_to tests according to real-world usage.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4261 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG5
-rw-r--r--actionpack/lib/action_controller/assertions.rb26
-rw-r--r--actionpack/test/controller/action_pack_assertions_test.rb18
3 files changed, 38 insertions, 11 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 25e5643aa1..f037861288 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,10 @@
*SVN*
+* Fix assert_redirected_to tests according to real-world usage. Also, don't fail if you add an extra :controller option: [Rick]
+
+ redirect_to :action => 'new'
+ assert_redirected_to :controller => 'monkeys', :action => 'new'
+
* Cache CgiRequest#request_parameters so that multiple calls don't re-parse multipart data. [Rick]
* Diff compared routing options. Allow #assert_recognizes to take a second arg as a hash to specify optional request method [Rick]
diff --git a/actionpack/lib/action_controller/assertions.rb b/actionpack/lib/action_controller/assertions.rb
index 978838c7e1..4e3443c456 100644
--- a/actionpack/lib/action_controller/assertions.rb
+++ b/actionpack/lib/action_controller/assertions.rb
@@ -73,14 +73,16 @@ module Test #:nodoc:
def assert_redirected_to(options = {}, message=nil)
clean_backtrace do
assert_response(:redirect, message)
- ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
-
+ return true if options == @response.redirected_to
+ ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
+
begin
- url = {}
- f={
- :expected => options.is_a?(Symbol) ? @controller.send("hash_for_#{options}_url") : options.dup,
- :actual => @response.redirected_to.is_a?(Symbol) ? @controller.send("hash_for_#{@response.redirected_to}_url") : @response.redirected_to.dup
- }.each do |key, value|
+ url = {}
+ original = { :expected => options, :actual => @response.redirected_to.dup }
+ original.each do |key, value|
+ if value.is_a?(Symbol)
+ value = @controller.respond_to?(value, true) ? @controller.send(value) : @controller.send("hash_for_#{option}")
+ end
unless value.is_a?(Hash)
request = case value
when NilClass then nil
@@ -90,7 +92,15 @@ module Test #:nodoc:
value = request.path_parameters if request
end
- value.stringify_keys! if value.is_a?(Hash)
+ if value.is_a?(Hash) # stringify 2 levels of hash keys
+ value.stringify_keys!
+ value.values.select { |v| v.is_a?(Hash) }.collect { |v| v.stringify_keys! }
+ if key == :expected && value['controller'] == @controller.controller_name && original[:actual].is_a?(Hash)
+ original[:actual].stringify_keys!
+ value.delete('controller') if original[:actual]['controller'].nil? || original[:actual]['controller'] == value['controller']
+ end
+ end
+
if value.respond_to?(:[]) && value['controller']
if key == :actual && value['controller'].first != '/'
value['controller'] = ActionController::Routing.controller_relative_to(value['controller'], @controller.class.controller_path)
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index aae690d266..f55fb6cbf8 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -234,7 +234,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
process :redirect_to_named_route
assert_redirected_to 'http://test.host/route_one'
assert_redirected_to route_one_url
- assert_redirected_to :route_one
+ assert_redirected_to :route_one_url
end
end
@@ -256,7 +256,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
assert_redirected_to route_two_url
end
assert_raise(Test::Unit::AssertionFailedError) do
- assert_redirected_to :route_two
+ assert_redirected_to :route_two_url
end
end
end
@@ -456,7 +456,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
assert "Inconceivable!", @response.body
end
-
+
def test_follow_redirect_outside_current_action
process :redirect_to_controller
assert_redirected_to :controller => "elsewhere", :action => "flash_me"
@@ -464,6 +464,18 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
assert_raises(RuntimeError, "Can't follow redirects outside of current controller (elsewhere)") { follow_redirect }
end
+ def test_assert_redirection_fails_with_incorrect_controller
+ process :redirect_to_controller
+ assert_raise(Test::Unit::AssertionFailedError) do
+ assert_redirected_to :controller => "action_pack_assertions", :action => "flash_me"
+ end
+ end
+
+ def test_assert_redirection_with_extra_controller_option
+ get :redirect_to_action
+ assert_redirected_to :controller => 'action_pack_assertions', :action => "flash_me", :id => 1, :params => { :panda => 'fun' }
+ end
+
def test_redirected_to_url_leadling_slash
process :redirect_to_path
assert_redirected_to '/some/path'