Skip to content

Commit

Permalink
Invoke callbacks using the correct API
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Dec 25, 2010
1 parent e95eb93 commit b34f456
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/devise/test_helpers.rb
Expand Up @@ -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,
Expand Down
23 changes: 15 additions & 8 deletions test/test_helpers_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit b34f456

Please sign in to comment.