1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Fix tests for email token expiration

The tests work now, but are a bit wonky because User.create does things
I don't understand.
This commit is contained in:
Nils Landt 2012-07-11 18:30:36 +02:00
parent 42a0c30139
commit 6e48fcee76
4 changed files with 26 additions and 26 deletions

View file

@ -52,22 +52,11 @@ class ConfirmationTest < ActionController::IntegrationTest
test 'user with valid confirmation token should not be able to confirm an account after the token has expired' do
swap Devise, :expire_confirmation_token_after => 3.days do
# TODO: once again, confirmation_sent_at is not being set to the correct date
# TODO: why is confirmation_sent_at not set correctly when passed to create_user?
# TODO: User.create! always sets confirmation_sent_at to Time.now
user = create_user(:confirm => false, :confirmation_sent_at => 4.days.ago)
#user.confirmation_sent_at = 4.days.ago
assert_not user.confirmed?
visit_user_confirmation_with_token(user.confirmation_token)
assert_contain 'Your account was successfully confirmed.'
assert_current_url '/'
assert user.reload.confirmed?
end
end
test 'user with valid confirmation token should be able to confirm an account before the token has expires' do
swap Devise, :expire_confirmation_token_after => 3.days do
# TODO: once again, confirmation_sent_at is not being set to the correct date
user = create_user(:confirm => false, :confirmation_sent_at => 2.days.ago)
user.confirmation_sent_at = 4.days.ago
user.save
assert_not user.confirmed?
visit_user_confirmation_with_token(user.confirmation_token)
@ -77,6 +66,21 @@ class ConfirmationTest < ActionController::IntegrationTest
end
end
test 'user with valid confirmation token should be able to confirm an account before the token has expired' do
swap Devise, :expire_confirmation_token_after => 3.days do
# TODO: why is confirmation_sent_at not set correctly when passed to create_user?
user = create_user(:confirm => false, :confirmation_sent_at => 2.days.ago)
user.confirmation_sent_at = 2.days.ago
user.save
assert_not user.confirmed?
visit_user_confirmation_with_token(user.confirmation_token)
assert_contain 'Your account was successfully confirmed.'
assert_current_url '/'
assert user.reload.confirmed?
end
end
test 'user should be redirected to a custom path after confirmation' do
Devise::ConfirmationsController.any_instance.stubs(:after_confirmation_path_for).returns("/?custom=1")

View file

@ -237,8 +237,11 @@ class ConfirmableTest < ActiveSupport::TestCase
end
def confirm_user_by_token_with_confirmation_sent_at(confirmation_sent_at)
# TODO: why is confirmation_sent_at not set correctly when passed to create_user?
# TODO: User.create! always sets confirmation_sent_at to Time.now
user = create_user
user.confirmation_sent_at = confirmation_sent_at
user.save
confirmed_user = User.confirm_by_token(user.confirmation_token)
assert_equal confirmed_user, user
user.reload.confirmed?
@ -256,15 +259,7 @@ class ConfirmableTest < ActiveSupport::TestCase
test 'should not accept confirmation email token after 4 days when expiration is set to 3 days' do
swap Devise, :expire_confirmation_token_after => 3.days do
#assert_not confirm_user_by_token_with_confirmation_sent_at(4.days.ago)
# TODO: confirmation_sent_at is Time.now during confirm_by_token
# TODO: when everything works, use the test line above
user = create_user
user.confirmation_sent_at = 4.days.ago
assert_not user.confirmed?
confirmed_user = User.confirm_by_token(user.confirmation_token)
assert_equal confirmed_user, user
assert_not user.reload.confirmed?
assert_not confirm_user_by_token_with_confirmation_sent_at(4.days.ago)
end
end
end

View file

@ -7,7 +7,7 @@ module SharedUser
:trackable, :validatable, :omniauthable
attr_accessor :other_key
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
attr_accessible :username, :email, :password, :password_confirmation, :remember_me, :confirmation_sent_at
# They need to be included after Devise is called.
extend ExtendMethods

View file

@ -26,7 +26,8 @@ class ActiveSupport::TestCase
{ :username => "usertest",
:email => generate_unique_email,
:password => '12345678',
:password_confirmation => '12345678' }.update(attributes)
:password_confirmation => '12345678',
:confirmation_sent_at => nil }.update(attributes)
end
def new_user(attributes={})