mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Updating tests and fix rememberable serialize_from_cookie.
This commit is contained in:
parent
d505fd15c0
commit
9720c36380
2 changed files with 10 additions and 18 deletions
|
@ -61,7 +61,7 @@ module Devise
|
|||
# Recreate the user based on the stored cookie
|
||||
def serialize_from_cookie(cookie)
|
||||
record_id, remember_token = cookie.split('::')
|
||||
record = find_by_id(attributes[:id])
|
||||
record = find_by_id(record_id)
|
||||
record if record.try(:valid_remember_token?, remember_token)
|
||||
end
|
||||
|
||||
|
|
|
@ -45,23 +45,6 @@ class RememberableTest < ActiveSupport::TestCase
|
|||
assert_not user.valid_remember_token?(user.remember_token)
|
||||
end
|
||||
|
||||
test 'find a user by its id and remember it if the token is valid' do
|
||||
user = create_user
|
||||
user.remember_me!
|
||||
remembered_user = User.remember_me!(:id => user.id, :remember_token => user.remember_token)
|
||||
assert_not_nil remembered_user
|
||||
assert_equal remembered_user, user
|
||||
end
|
||||
|
||||
test 'remember me should return nil if no user is found' do
|
||||
assert_nil User.remember_me!(:id => 0)
|
||||
end
|
||||
|
||||
test 'remember me return nil if is a valid user with invalid token' do
|
||||
user = create_user
|
||||
assert_nil User.remember_me!(:id => user.id, :remember_token => 'invalid_token')
|
||||
end
|
||||
|
||||
test 'serialize into cookie' do
|
||||
user = create_user
|
||||
user.remember_me!
|
||||
|
@ -73,4 +56,13 @@ class RememberableTest < ActiveSupport::TestCase
|
|||
user.remember_me!
|
||||
assert_equal user, User.serialize_from_cookie("#{user.id}::#{user.remember_token}")
|
||||
end
|
||||
|
||||
test 'serialize should return nil if no user is found' do
|
||||
assert_nil User.serialize_from_cookie('0::123')
|
||||
end
|
||||
|
||||
test 'remember me return nil if is a valid user with invalid token' do
|
||||
user = create_user
|
||||
assert_nil User.serialize_from_cookie("#{user.id}::#{user.remember_token}123")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue