From b34f4560960023fea06b133fbd17d1cba0314afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 25 Dec 2010 11:41:14 +0100 Subject: [PATCH] Invoke callbacks using the correct API --- CHANGELOG.rdoc | 1 + lib/devise/test_helpers.rb | 2 +- test/test_helpers_test.rb | 23 +++++++++++++++-------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index fdba197223..c23c64d516 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -5,6 +5,7 @@ * Fix an issue causing infinite redirects in production * rails g destroy works properly with devise generators (by github.com/andmej) * recall options is now passed forward by hooks (by github.com/siong1987) + * before_failure callbacks should work on test helpers (by github.com/twinge) * deprecations * Deprecated anybody_signed_in? in favor of signed_in? (by github.com/gavinhughes) diff --git a/lib/devise/test_helpers.rb b/lib/devise/test_helpers.rb index 67eba70e20..9f6a042fc0 100644 --- a/lib/devise/test_helpers.rb +++ b/lib/devise/test_helpers.rb @@ -44,7 +44,7 @@ def catch_with_redirect(&block) env = @controller.request.env env["PATH_INFO"] = "/#{result[:action]}" env["warden.options"] = result - Warden::Manager._before_failure.each{ |hook| hook.first.call(env, result) } + Warden::Manager._run_callbacks(:before_failure, env, result) status, headers, body = Devise::FailureApp.call(env).to_a @controller.send :render, :status => status, :text => body, diff --git a/test/test_helpers_test.rb b/test/test_helpers_test.rb index da0603c220..1350f0c870 100644 --- a/test/test_helpers_test.rb +++ b/test/test_helpers_test.rb @@ -81,15 +81,22 @@ class TestHelpersTest < ActionController::TestCase Warden::Manager._before_logout.pop end end - - test "before_failer call should work" do - Warden::Manager.before_failure do |env,opts| - # Do nothing - end - user = create_user - user.confirm! - sign_in user + test "before_failure call should work" do + begin + executed = false + Warden::Manager.before_failure do |env,opts| + executed = true + end + + user = create_user + sign_in user + + get :index + assert executed + ensure + Warden::Manager._before_failure.pop + end end test "allows to sign in with different users" do