mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Added four tests related to Warden callbacks
Two tests are to ensure that the callbacks are called at all. The other two test ensure that the user parameter provided to the callback is not nil. Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
ff0b4deb1a
commit
57ab87a1b6
1 changed files with 47 additions and 0 deletions
|
@ -53,6 +53,53 @@ class TestHelpersTest < ActionController::TestCase
|
|||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
test "defined Warden after_authentication callback should be called when sign_in is called" do
|
||||
Warden::Manager.after_authentication do |user, auth, opts|
|
||||
@after_authentication_called = true
|
||||
end
|
||||
user = create_user
|
||||
user.confirm!
|
||||
|
||||
sign_in user
|
||||
assert_equal true, @after_authentication_called
|
||||
end
|
||||
|
||||
test "defined Warden before_logout callback should be called when sign_out is called" do
|
||||
Warden::Manager.before_logout do |user, auth, opts|
|
||||
@before_logout_called = true
|
||||
end
|
||||
user = create_user
|
||||
user.confirm!
|
||||
|
||||
sign_in user
|
||||
sign_out user
|
||||
assert_equal true, @before_logout_called
|
||||
end
|
||||
|
||||
test "the user parameter in warden after_authentication callbacks should not be nil" do
|
||||
Warden::Manager.after_authentication do |user, auth, opts|
|
||||
assert_not_nil user
|
||||
end
|
||||
user = create_user
|
||||
user.confirm!
|
||||
|
||||
sign_in user
|
||||
end
|
||||
|
||||
# Not sure if the warden manager needs to be reset after the test cases which modify
|
||||
# the callbacks, maybe the original values can just be restored or the warden manager
|
||||
# class definition file can be reloaded.
|
||||
test "the user parameter in warden before_logout callbacks should not be nil" do
|
||||
Warden::Manager.before_logout do |user, auth, opts|
|
||||
assert_not_nil user
|
||||
end
|
||||
user = create_user
|
||||
user.confirm!
|
||||
|
||||
sign_in user
|
||||
sign_out user
|
||||
end
|
||||
|
||||
test "allows to sign in with different users" do
|
||||
first_user = create_user
|
||||
first_user.confirm!
|
||||
|
|
Loading…
Reference in a new issue