1
0
Fork 0
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:
Carlos A. da Silva 2009-10-20 08:59:01 -02:00
parent d505fd15c0
commit 9720c36380
2 changed files with 10 additions and 18 deletions

View file

@ -61,7 +61,7 @@ module Devise
# Recreate the user based on the stored cookie # Recreate the user based on the stored cookie
def serialize_from_cookie(cookie) def serialize_from_cookie(cookie)
record_id, remember_token = cookie.split('::') 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) record if record.try(:valid_remember_token?, remember_token)
end end

View file

@ -45,23 +45,6 @@ class RememberableTest < ActiveSupport::TestCase
assert_not user.valid_remember_token?(user.remember_token) assert_not user.valid_remember_token?(user.remember_token)
end 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 test 'serialize into cookie' do
user = create_user user = create_user
user.remember_me! user.remember_me!
@ -73,4 +56,13 @@ class RememberableTest < ActiveSupport::TestCase
user.remember_me! user.remember_me!
assert_equal user, User.serialize_from_cookie("#{user.id}::#{user.remember_token}") assert_equal user, User.serialize_from_cookie("#{user.id}::#{user.remember_token}")
end 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 end