2010-03-26 10:27:19 +00:00
|
|
|
require 'test_helper'
|
2009-09-17 14:06:46 +00:00
|
|
|
|
|
|
|
class ConfirmableTest < ActiveSupport::TestCase
|
|
|
|
|
2009-09-17 23:03:38 +00:00
|
|
|
def setup
|
2009-09-18 00:29:13 +00:00
|
|
|
setup_mailer
|
2009-09-17 23:03:38 +00:00
|
|
|
end
|
|
|
|
|
2009-10-18 11:14:52 +00:00
|
|
|
test 'should generate confirmation token after creating a record' do
|
|
|
|
assert_nil new_user.confirmation_token
|
|
|
|
assert_not_nil create_user.confirmation_token
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should never generate the same confirmation token for different users' do
|
|
|
|
confirmation_tokens = []
|
2009-11-25 01:19:12 +00:00
|
|
|
3.times do
|
2009-10-18 11:14:52 +00:00
|
|
|
token = create_user.confirmation_token
|
|
|
|
assert !confirmation_tokens.include?(token)
|
|
|
|
confirmation_tokens << token
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-11-25 01:19:12 +00:00
|
|
|
test 'should confirm a user by updating confirmed at' do
|
2009-09-17 14:06:46 +00:00
|
|
|
user = create_user
|
|
|
|
assert_nil user.confirmed_at
|
|
|
|
assert user.confirm!
|
|
|
|
assert_not_nil user.confirmed_at
|
|
|
|
end
|
|
|
|
|
2009-10-18 11:14:52 +00:00
|
|
|
test 'should clear confirmation token while confirming a user' do
|
2009-10-15 20:36:44 +00:00
|
|
|
user = create_user
|
2009-10-18 11:14:52 +00:00
|
|
|
assert_present user.confirmation_token
|
2009-10-15 20:36:44 +00:00
|
|
|
user.confirm!
|
2009-10-18 11:14:52 +00:00
|
|
|
assert_nil user.confirmation_token
|
2009-10-15 20:36:44 +00:00
|
|
|
end
|
|
|
|
|
2009-09-17 14:06:46 +00:00
|
|
|
test 'should verify whether a user is confirmed or not' do
|
|
|
|
assert_not new_user.confirmed?
|
|
|
|
user = create_user
|
|
|
|
assert_not user.confirmed?
|
|
|
|
user.confirm!
|
|
|
|
assert user.confirmed?
|
|
|
|
end
|
|
|
|
|
2009-11-25 01:19:12 +00:00
|
|
|
test 'should not confirm a user already confirmed' do
|
2009-09-17 14:06:46 +00:00
|
|
|
user = create_user
|
|
|
|
assert user.confirm!
|
2010-02-16 16:00:36 +00:00
|
|
|
assert_blank user.errors[:email]
|
2009-11-25 01:19:12 +00:00
|
|
|
|
2009-09-17 14:06:46 +00:00
|
|
|
assert_not user.confirm!
|
2010-11-05 12:03:52 +00:00
|
|
|
assert_equal "was already confirmed, please try signing in", user.errors[:email].join
|
2009-09-17 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
2011-02-06 15:34:31 +00:00
|
|
|
test 'should find and confirm a user automatically' do
|
2009-09-17 14:06:46 +00:00
|
|
|
user = create_user
|
2010-03-10 15:13:54 +00:00
|
|
|
confirmed_user = User.confirm_by_token(user.confirmation_token)
|
2009-09-17 14:06:46 +00:00
|
|
|
assert_equal confirmed_user, user
|
|
|
|
assert user.reload.confirmed?
|
|
|
|
end
|
|
|
|
|
2009-11-25 01:19:12 +00:00
|
|
|
test 'should return a new record with errors when a invalid token is given' do
|
2010-03-10 15:13:54 +00:00
|
|
|
confirmed_user = User.confirm_by_token('invalid_confirmation_token')
|
2010-03-28 20:26:07 +00:00
|
|
|
assert_not confirmed_user.persisted?
|
2010-02-16 16:00:36 +00:00
|
|
|
assert_equal "is invalid", confirmed_user.errors[:confirmation_token].join
|
2009-09-18 13:20:45 +00:00
|
|
|
end
|
|
|
|
|
2009-11-25 01:19:12 +00:00
|
|
|
test 'should return a new record with errors when a blank token is given' do
|
2010-03-10 15:13:54 +00:00
|
|
|
confirmed_user = User.confirm_by_token('')
|
2010-03-28 20:26:07 +00:00
|
|
|
assert_not confirmed_user.persisted?
|
2010-02-16 16:00:36 +00:00
|
|
|
assert_equal "can't be blank", confirmed_user.errors[:confirmation_token].join
|
2009-09-17 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'should generate errors for a user email if user is already confirmed' do
|
|
|
|
user = create_user
|
2009-12-21 20:10:23 +00:00
|
|
|
user.confirmed_at = Time.now
|
|
|
|
user.save
|
2010-03-10 15:13:54 +00:00
|
|
|
confirmed_user = User.confirm_by_token(user.confirmation_token)
|
2009-09-17 14:06:46 +00:00
|
|
|
assert confirmed_user.confirmed?
|
2010-11-05 12:03:52 +00:00
|
|
|
assert_equal "was already confirmed, please try signing in", confirmed_user.errors[:email].join
|
2009-09-17 14:06:46 +00:00
|
|
|
end
|
2009-09-17 22:54:19 +00:00
|
|
|
|
2009-09-18 00:29:13 +00:00
|
|
|
test 'should send confirmation instructions by email' do
|
2011-08-12 16:27:57 +00:00
|
|
|
assert_email_sent "mynewuser@example.com" do
|
|
|
|
create_user :email => "mynewuser@example.com"
|
2009-09-18 00:29:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should not send confirmation when trying to save an invalid user' do
|
2009-09-18 13:20:45 +00:00
|
|
|
assert_email_not_sent do
|
2009-09-18 00:29:13 +00:00
|
|
|
user = new_user
|
|
|
|
user.stubs(:valid?).returns(false)
|
|
|
|
user.save
|
|
|
|
end
|
|
|
|
end
|
2009-10-08 03:53:04 +00:00
|
|
|
|
2009-12-14 23:30:28 +00:00
|
|
|
test 'should not generate a new token neither send e-mail if skip_confirmation! is invoked' do
|
|
|
|
user = new_user
|
|
|
|
user.skip_confirmation!
|
|
|
|
|
|
|
|
assert_email_not_sent do
|
|
|
|
user.save!
|
|
|
|
assert_nil user.confirmation_token
|
|
|
|
assert_not_nil user.confirmed_at
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-22 17:43:01 +00:00
|
|
|
test 'should skip confirmation e-mail without confirming if skip_confirmation_notification! is invoked' do
|
|
|
|
user = new_user
|
|
|
|
user.skip_confirmation_notification!
|
|
|
|
|
|
|
|
assert_email_not_sent do
|
|
|
|
user.save!
|
|
|
|
assert !user.confirmed?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-08 03:53:04 +00:00
|
|
|
test 'should find a user to send confirmation instructions' do
|
|
|
|
user = create_user
|
|
|
|
confirmation_user = User.send_confirmation_instructions(:email => user.email)
|
|
|
|
assert_equal confirmation_user, user
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should return a new user if no email was found' do
|
2011-04-18 01:14:56 +00:00
|
|
|
confirmation_user = User.send_confirmation_instructions(:email => "invalid@example.com")
|
2010-03-28 20:26:07 +00:00
|
|
|
assert_not confirmation_user.persisted?
|
2009-10-08 03:53:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'should add error to new user email if no email was found' do
|
2011-04-18 01:14:56 +00:00
|
|
|
confirmation_user = User.send_confirmation_instructions(:email => "invalid@example.com")
|
2009-10-08 03:53:04 +00:00
|
|
|
assert confirmation_user.errors[:email]
|
2010-02-16 16:00:36 +00:00
|
|
|
assert_equal "not found", confirmation_user.errors[:email].join
|
2009-10-08 03:53:04 +00:00
|
|
|
end
|
|
|
|
|
2011-07-29 21:17:31 +00:00
|
|
|
test 'should send email instructions for the user confirm its email' do
|
2009-10-08 03:53:04 +00:00
|
|
|
user = create_user
|
2011-08-12 16:27:57 +00:00
|
|
|
assert_email_sent user.email do
|
2009-10-08 03:53:04 +00:00
|
|
|
User.send_confirmation_instructions(:email => user.email)
|
|
|
|
end
|
|
|
|
end
|
2011-02-06 21:23:36 +00:00
|
|
|
|
2010-05-06 12:48:26 +00:00
|
|
|
test 'should always have confirmation token when email is sent' do
|
|
|
|
user = new_user
|
|
|
|
user.instance_eval { def confirmation_required?; false end }
|
|
|
|
user.save
|
|
|
|
user.send_confirmation_instructions
|
2010-07-14 16:03:34 +00:00
|
|
|
assert_not_nil user.reload.confirmation_token
|
2010-05-06 12:48:26 +00:00
|
|
|
end
|
2009-10-08 22:50:46 +00:00
|
|
|
|
2009-10-30 09:49:18 +00:00
|
|
|
test 'should not resend email instructions if the user change his email' do
|
2009-10-08 22:50:46 +00:00
|
|
|
user = create_user
|
|
|
|
user.email = 'new_test@example.com'
|
|
|
|
assert_email_not_sent do
|
|
|
|
user.save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-30 09:49:18 +00:00
|
|
|
test 'should not reset confirmation status or token when updating email' do
|
2009-10-08 22:50:46 +00:00
|
|
|
user = create_user
|
|
|
|
user.confirm!
|
|
|
|
user.email = 'new_test@example.com'
|
|
|
|
user.save!
|
2009-10-15 19:54:04 +00:00
|
|
|
|
2009-10-30 09:49:18 +00:00
|
|
|
user.reload
|
|
|
|
assert user.confirmed?
|
|
|
|
assert_nil user.confirmation_token
|
2009-10-15 20:05:46 +00:00
|
|
|
end
|
|
|
|
|
2009-10-15 19:54:04 +00:00
|
|
|
test 'should not be able to send instructions if the user is already confirmed' do
|
|
|
|
user = create_user
|
|
|
|
user.confirm!
|
2010-03-10 15:13:54 +00:00
|
|
|
assert_not user.resend_confirmation_token
|
2009-10-15 19:54:04 +00:00
|
|
|
assert user.confirmed?
|
2010-11-05 12:03:52 +00:00
|
|
|
assert_equal 'was already confirmed, please try signing in', user.errors[:email].join
|
2009-10-15 19:54:04 +00:00
|
|
|
end
|
2009-10-20 23:32:30 +00:00
|
|
|
|
|
|
|
test 'confirm time should fallback to devise confirm in default configuration' do
|
2011-12-11 19:18:02 +00:00
|
|
|
swap Devise, :allow_unconfirmed_access_for => 1.day do
|
2009-10-20 23:32:30 +00:00
|
|
|
user = new_user
|
2009-10-22 11:09:34 +00:00
|
|
|
user.confirmation_sent_at = 2.days.ago
|
2011-03-25 14:39:08 +00:00
|
|
|
assert_not user.active_for_authentication?
|
2009-11-25 01:19:12 +00:00
|
|
|
|
2011-12-11 19:18:02 +00:00
|
|
|
Devise.allow_unconfirmed_access_for = 3.days
|
2011-03-25 14:39:08 +00:00
|
|
|
assert user.active_for_authentication?
|
2009-10-20 23:32:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should be active when confirmation sent at is not overpast' do
|
2011-12-11 19:18:02 +00:00
|
|
|
swap Devise, :allow_unconfirmed_access_for => 5.days do
|
|
|
|
Devise.allow_unconfirmed_access_for = 5.days
|
2009-11-25 01:19:12 +00:00
|
|
|
user = create_user
|
|
|
|
|
|
|
|
user.confirmation_sent_at = 4.days.ago
|
2011-03-25 14:39:08 +00:00
|
|
|
assert user.active_for_authentication?
|
2009-11-25 01:19:12 +00:00
|
|
|
|
|
|
|
user.confirmation_sent_at = 5.days.ago
|
2011-03-25 14:39:08 +00:00
|
|
|
assert_not user.active_for_authentication?
|
2009-11-25 01:19:12 +00:00
|
|
|
end
|
2009-10-20 23:32:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'should be active when already confirmed' do
|
|
|
|
user = create_user
|
|
|
|
assert_not user.confirmed?
|
2011-03-25 14:39:08 +00:00
|
|
|
assert_not user.active_for_authentication?
|
2009-11-25 01:19:12 +00:00
|
|
|
|
2009-10-20 23:32:30 +00:00
|
|
|
user.confirm!
|
|
|
|
assert user.confirmed?
|
2011-03-25 14:39:08 +00:00
|
|
|
assert user.active_for_authentication?
|
2009-10-20 23:32:30 +00:00
|
|
|
end
|
|
|
|
|
2009-11-25 01:19:12 +00:00
|
|
|
test 'should not be active when confirm in is zero' do
|
2011-12-11 19:18:02 +00:00
|
|
|
Devise.allow_unconfirmed_access_for = 0.days
|
2009-10-20 23:32:30 +00:00
|
|
|
user = create_user
|
|
|
|
user.confirmation_sent_at = Date.today
|
2011-03-25 14:39:08 +00:00
|
|
|
assert_not user.active_for_authentication?
|
2009-10-20 23:32:30 +00:00
|
|
|
end
|
|
|
|
|
2013-02-13 18:12:47 +00:00
|
|
|
test 'should be active when we set allow_unconfirmed_access_for to nil' do
|
|
|
|
Devise.allow_unconfirmed_access_for = nil
|
|
|
|
user = create_user
|
|
|
|
user.confirmation_sent_at = Date.today
|
|
|
|
assert user.active_for_authentication?
|
|
|
|
end
|
|
|
|
|
2009-10-20 23:32:30 +00:00
|
|
|
test 'should not be active without confirmation' do
|
|
|
|
user = create_user
|
2009-12-21 20:10:23 +00:00
|
|
|
user.confirmation_sent_at = nil
|
|
|
|
user.save
|
2011-03-25 14:39:08 +00:00
|
|
|
assert_not user.reload.active_for_authentication?
|
2009-10-20 23:32:30 +00:00
|
|
|
end
|
2011-02-06 21:23:36 +00:00
|
|
|
|
2010-05-05 21:31:11 +00:00
|
|
|
test 'should be active without confirmation when confirmation is not required' do
|
|
|
|
user = create_user
|
|
|
|
user.instance_eval { def confirmation_required?; false end }
|
|
|
|
user.confirmation_sent_at = nil
|
|
|
|
user.save
|
2011-03-25 14:39:08 +00:00
|
|
|
assert user.reload.active_for_authentication?
|
2010-05-05 21:31:11 +00:00
|
|
|
end
|
2011-02-06 21:23:36 +00:00
|
|
|
|
2011-07-29 21:17:31 +00:00
|
|
|
test 'should find a user to send email instructions for the user confirm its email by authentication_keys' do
|
2011-01-27 16:20:37 +00:00
|
|
|
swap Devise, :authentication_keys => [:username, :email] do
|
|
|
|
user = create_user
|
|
|
|
confirm_user = User.send_confirmation_instructions(:email => user.email, :username => user.username)
|
|
|
|
assert_equal confirm_user, user
|
|
|
|
end
|
|
|
|
end
|
2011-02-06 21:23:36 +00:00
|
|
|
|
2011-01-27 16:20:37 +00:00
|
|
|
test 'should require all confirmation_keys' do
|
2011-02-06 21:23:36 +00:00
|
|
|
swap Devise, :confirmation_keys => [:username, :email] do
|
|
|
|
user = create_user
|
|
|
|
confirm_user = User.send_confirmation_instructions(:email => user.email)
|
|
|
|
assert_not confirm_user.persisted?
|
|
|
|
assert_equal "can't be blank", confirm_user.errors[:username].join
|
|
|
|
end
|
2011-01-27 16:20:37 +00:00
|
|
|
end
|
2012-07-09 12:43:12 +00:00
|
|
|
|
2012-07-11 13:49:41 +00:00
|
|
|
def confirm_user_by_token_with_confirmation_sent_at(confirmation_sent_at)
|
2012-07-09 12:43:12 +00:00
|
|
|
user = create_user
|
2012-07-16 09:20:01 +00:00
|
|
|
user.update_attribute(:confirmation_sent_at, confirmation_sent_at)
|
2012-07-09 12:43:12 +00:00
|
|
|
confirmed_user = User.confirm_by_token(user.confirmation_token)
|
|
|
|
assert_equal confirmed_user, user
|
|
|
|
user.reload.confirmed?
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should accept confirmation email token even after 5 years when no expiration is set' do
|
|
|
|
assert confirm_user_by_token_with_confirmation_sent_at(5.years.ago)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should accept confirmation email token after 2 days when expiration is set to 3 days' do
|
2012-07-22 12:02:27 +00:00
|
|
|
swap Devise, :confirm_within => 3.days do
|
2012-07-09 12:43:12 +00:00
|
|
|
assert confirm_user_by_token_with_confirmation_sent_at(2.days.ago)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should not accept confirmation email token after 4 days when expiration is set to 3 days' do
|
2012-07-22 12:02:27 +00:00
|
|
|
swap Devise, :confirm_within => 3.days do
|
2012-07-11 16:30:36 +00:00
|
|
|
assert_not confirm_user_by_token_with_confirmation_sent_at(4.days.ago)
|
2012-07-09 12:43:12 +00:00
|
|
|
end
|
|
|
|
end
|
2012-07-23 14:05:51 +00:00
|
|
|
|
|
|
|
test 'should generate a new token if the previous one has expired' do
|
|
|
|
swap Devise, :confirm_within => 3.days do
|
|
|
|
user = create_user
|
|
|
|
user.update_attribute(:confirmation_sent_at, 4.days.ago)
|
|
|
|
old = user.confirmation_token
|
|
|
|
user.resend_confirmation_token
|
|
|
|
assert_not_equal user.confirmation_token, old
|
|
|
|
end
|
|
|
|
end
|
2009-09-17 14:06:46 +00:00
|
|
|
end
|
2011-04-03 19:26:14 +00:00
|
|
|
|
2011-12-11 19:07:30 +00:00
|
|
|
class ReconfirmableTest < ActiveSupport::TestCase
|
2011-12-20 19:54:49 +00:00
|
|
|
test 'should not worry about validations on confirm even with reconfirmable' do
|
|
|
|
admin = create_admin
|
|
|
|
admin.reset_password_token = "a"
|
|
|
|
assert admin.confirm!
|
|
|
|
end
|
|
|
|
|
2011-04-03 19:26:14 +00:00
|
|
|
test 'should generate confirmation token after changing email' do
|
2011-12-11 19:07:30 +00:00
|
|
|
admin = create_admin
|
|
|
|
assert admin.confirm!
|
|
|
|
assert_nil admin.confirmation_token
|
|
|
|
assert admin.update_attributes(:email => 'new_test@example.com')
|
|
|
|
assert_not_nil admin.confirmation_token
|
2011-04-03 19:26:14 +00:00
|
|
|
end
|
|
|
|
|
2012-03-09 17:12:30 +00:00
|
|
|
test 'should not generate confirmation token if skipping reconfirmation after changing email' do
|
|
|
|
admin = create_admin
|
|
|
|
assert admin.confirm!
|
|
|
|
admin.skip_reconfirmation!
|
|
|
|
assert admin.update_attributes(:email => 'new_test@example.com')
|
|
|
|
assert_nil admin.confirmation_token
|
|
|
|
end
|
|
|
|
|
2011-12-31 11:22:58 +00:00
|
|
|
test 'should regenerate confirmation token after changing email' do
|
|
|
|
admin = create_admin
|
|
|
|
assert admin.confirm!
|
|
|
|
assert admin.update_attributes(:email => 'old_test@example.com')
|
|
|
|
token = admin.confirmation_token
|
|
|
|
assert admin.update_attributes(:email => 'new_test@example.com')
|
|
|
|
assert_not_equal token, admin.confirmation_token
|
|
|
|
end
|
|
|
|
|
2011-04-03 19:26:14 +00:00
|
|
|
test 'should send confirmation instructions by email after changing email' do
|
2011-12-11 19:07:30 +00:00
|
|
|
admin = create_admin
|
|
|
|
assert admin.confirm!
|
2011-08-12 16:27:57 +00:00
|
|
|
assert_email_sent "new_test@example.com" do
|
2011-12-11 19:07:30 +00:00
|
|
|
assert admin.update_attributes(:email => 'new_test@example.com')
|
2011-04-03 19:26:14 +00:00
|
|
|
end
|
2012-12-13 07:53:23 +00:00
|
|
|
assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded
|
2011-04-03 19:26:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'should not send confirmation by email after changing password' do
|
2011-12-11 19:07:30 +00:00
|
|
|
admin = create_admin
|
|
|
|
assert admin.confirm!
|
2011-04-03 19:26:14 +00:00
|
|
|
assert_email_not_sent do
|
2011-12-11 19:07:30 +00:00
|
|
|
assert admin.update_attributes(:password => 'newpass', :password_confirmation => 'newpass')
|
2011-04-03 19:26:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should stay confirmed when email is changed' do
|
2011-12-11 19:07:30 +00:00
|
|
|
admin = create_admin
|
|
|
|
assert admin.confirm!
|
|
|
|
assert admin.update_attributes(:email => 'new_test@example.com')
|
|
|
|
assert admin.confirmed?
|
2011-04-03 19:26:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'should update email only when it is confirmed' do
|
2011-12-11 19:07:30 +00:00
|
|
|
admin = create_admin
|
|
|
|
assert admin.confirm!
|
|
|
|
assert admin.update_attributes(:email => 'new_test@example.com')
|
|
|
|
assert_not_equal 'new_test@example.com', admin.email
|
|
|
|
assert admin.confirm!
|
|
|
|
assert_equal 'new_test@example.com', admin.email
|
2011-04-03 19:26:14 +00:00
|
|
|
end
|
|
|
|
|
2011-12-11 19:07:30 +00:00
|
|
|
test 'should not allow admin to get past confirmation email by resubmitting their new address' do
|
|
|
|
admin = create_admin
|
|
|
|
assert admin.confirm!
|
|
|
|
assert admin.update_attributes(:email => 'new_test@example.com')
|
|
|
|
assert_not_equal 'new_test@example.com', admin.email
|
|
|
|
assert admin.update_attributes(:email => 'new_test@example.com')
|
|
|
|
assert_not_equal 'new_test@example.com', admin.email
|
2011-08-12 20:51:04 +00:00
|
|
|
end
|
|
|
|
|
2011-12-11 19:07:30 +00:00
|
|
|
test 'should find a admin by send confirmation instructions with unconfirmed_email' do
|
|
|
|
admin = create_admin
|
|
|
|
assert admin.confirm!
|
|
|
|
assert admin.update_attributes(:email => 'new_test@example.com')
|
|
|
|
confirmation_admin = Admin.send_confirmation_instructions(:email => admin.unconfirmed_email)
|
|
|
|
assert_equal confirmation_admin, admin
|
2011-04-03 19:26:14 +00:00
|
|
|
end
|
|
|
|
|
2011-12-11 19:07:30 +00:00
|
|
|
test 'should return a new admin if no email or unconfirmed_email was found' do
|
|
|
|
confirmation_admin = Admin.send_confirmation_instructions(:email => "invalid@email.com")
|
|
|
|
assert_not confirmation_admin.persisted?
|
2011-04-03 19:26:14 +00:00
|
|
|
end
|
|
|
|
|
2011-12-11 19:07:30 +00:00
|
|
|
test 'should add error to new admin email if no email or unconfirmed_email was found' do
|
|
|
|
confirmation_admin = Admin.send_confirmation_instructions(:email => "invalid@email.com")
|
|
|
|
assert confirmation_admin.errors[:email]
|
|
|
|
assert_equal "not found", confirmation_admin.errors[:email].join
|
2011-04-03 19:26:14 +00:00
|
|
|
end
|
2011-04-17 21:37:47 +00:00
|
|
|
|
2011-12-11 19:07:30 +00:00
|
|
|
test 'should find admin with email in unconfirmed_emails' do
|
|
|
|
admin = create_admin
|
|
|
|
admin.unconfirmed_email = "new_test@email.com"
|
|
|
|
assert admin.save
|
|
|
|
admin = Admin.find_by_unconfirmed_email_with_errors(:email => "new_test@email.com")
|
|
|
|
assert admin.persisted?
|
2011-04-17 21:37:47 +00:00
|
|
|
end
|
2012-02-17 17:14:20 +00:00
|
|
|
|
|
|
|
test 'required_fields should contain the fields that Devise uses' do
|
2012-02-20 12:17:32 +00:00
|
|
|
assert_same_content Devise::Models::Confirmable.required_fields(User), [
|
2012-02-17 17:14:20 +00:00
|
|
|
:confirmation_sent_at,
|
|
|
|
:confirmation_token,
|
|
|
|
:confirmed_at
|
|
|
|
]
|
|
|
|
end
|
2012-02-22 15:03:30 +00:00
|
|
|
|
|
|
|
test 'required_fields should also contain unconfirmable when reconfirmable_email is true' do
|
|
|
|
assert_same_content Devise::Models::Confirmable.required_fields(Admin), [
|
|
|
|
:confirmation_sent_at,
|
|
|
|
:confirmation_token,
|
|
|
|
:confirmed_at,
|
2012-02-22 18:49:09 +00:00
|
|
|
:unconfirmed_email
|
2012-02-22 15:03:30 +00:00
|
|
|
]
|
|
|
|
end
|
2011-04-03 19:26:14 +00:00
|
|
|
end
|