mirror of
https://github.com/heartcombo/devise.git
synced 2026-04-28 03:00:29 -04:00
implementation of a much simpler solution
This commit is contained in:
@@ -6,7 +6,7 @@ class ConfirmationTest < ActionController::IntegrationTest
|
||||
visit user_confirmation_path(:confirmation_token => confirmation_token)
|
||||
end
|
||||
|
||||
test 'user should be able to request a new confirmation' do
|
||||
def resend_confirmation
|
||||
user = create_user(:confirm => false)
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
@@ -15,10 +15,23 @@ class ConfirmationTest < ActionController::IntegrationTest
|
||||
|
||||
fill_in 'email', :with => user.email
|
||||
click_button 'Resend confirmation instructions'
|
||||
end
|
||||
|
||||
test 'user should be able to request a new confirmation' do
|
||||
resend_confirmation
|
||||
|
||||
assert_current_url '/users/sign_in'
|
||||
assert_contain 'You will receive an email with instructions about how to confirm your account in a few minutes'
|
||||
assert_equal 1, ActionMailer::Base.deliveries.size
|
||||
assert_equal ['please-change-me@config-initializers-devise.com'], ActionMailer::Base.deliveries.first.from
|
||||
end
|
||||
|
||||
test 'user should receive a confirmation from a custom mailer' do
|
||||
User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)
|
||||
|
||||
resend_confirmation
|
||||
|
||||
assert_equal ['custom@example.com'], ActionMailer::Base.deliveries.first.from
|
||||
end
|
||||
|
||||
test 'user with invalid confirmation token should not be able to confirm an account' do
|
||||
|
||||
@@ -6,7 +6,7 @@ class LockTest < ActionController::IntegrationTest
|
||||
visit user_unlock_path(:unlock_token => unlock_token)
|
||||
end
|
||||
|
||||
test 'user should be able to request a new unlock token' do
|
||||
def send_unlock_request
|
||||
user = create_user(:locked => true)
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
@@ -15,10 +15,23 @@ class LockTest < ActionController::IntegrationTest
|
||||
|
||||
fill_in 'email', :with => user.email
|
||||
click_button 'Resend unlock instructions'
|
||||
end
|
||||
|
||||
test 'user should be able to request a new unlock token' do
|
||||
send_unlock_request
|
||||
|
||||
assert_template 'sessions/new'
|
||||
assert_contain 'You will receive an email with instructions about how to unlock your account in a few minutes'
|
||||
assert_equal 1, ActionMailer::Base.deliveries.size
|
||||
assert_equal ['please-change-me@config-initializers-devise.com'], ActionMailer::Base.deliveries.first.from
|
||||
end
|
||||
|
||||
test 'user should receive the instructions from a custom mailer' do
|
||||
User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)
|
||||
|
||||
send_unlock_request
|
||||
|
||||
assert_equal ['custom@example.com'], ActionMailer::Base.deliveries.first.from
|
||||
end
|
||||
|
||||
test 'unlocked user should not be able to request a unlock token' do
|
||||
|
||||
@@ -38,6 +38,16 @@ class PasswordTest < ActionController::IntegrationTest
|
||||
assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
|
||||
end
|
||||
|
||||
test 'reset password with email should send an email from a custom mailer' do
|
||||
create_user(:email => 'Foo@Bar.com')
|
||||
|
||||
User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)
|
||||
request_forgot_password do
|
||||
fill_in 'email', :with => 'foo@bar.com'
|
||||
end
|
||||
assert_equal ['custom@example.com'], ActionMailer::Base.deliveries.last.from
|
||||
end
|
||||
|
||||
test 'reset password with email of different case should fail when email is NOT the list of case insensitive keys' do
|
||||
swap Devise, :case_insensitive_keys => [] do
|
||||
create_user(:email => 'Foo@Bar.com')
|
||||
|
||||
@@ -36,13 +36,19 @@ class RegistrationTest < ActionController::IntegrationTest
|
||||
assert_current_url "/?custom=1"
|
||||
end
|
||||
|
||||
test 'a guest user should be able to sign up successfully and be blocked by confirmation' do
|
||||
def user_sign_up
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
get new_user_registration_path
|
||||
|
||||
fill_in 'email', :with => 'new_user@test.com'
|
||||
fill_in 'password', :with => 'new_user123'
|
||||
fill_in 'password confirmation', :with => 'new_user123'
|
||||
click_button 'Sign up'
|
||||
end
|
||||
|
||||
test 'a guest user should be able to sign up successfully and be blocked by confirmation' do
|
||||
user_sign_up
|
||||
|
||||
assert_contain 'You have signed up successfully. However, we could not sign you in because your account is unconfirmed.'
|
||||
assert_not_contain 'You have to confirm your account before continuing'
|
||||
@@ -55,6 +61,17 @@ class RegistrationTest < ActionController::IntegrationTest
|
||||
assert_not user.confirmed?
|
||||
end
|
||||
|
||||
test 'a guest user should receive the confirmation instructions from the default mailer' do
|
||||
user_sign_up
|
||||
assert_equal ['please-change-me@config-initializers-devise.com'], ActionMailer::Base.deliveries.first.from
|
||||
end
|
||||
|
||||
test 'a guest user should receive the confirmation instructions from a custom mailer' do
|
||||
User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)
|
||||
user_sign_up
|
||||
assert_equal ['custom@example.com'], ActionMailer::Base.deliveries.first.from
|
||||
end
|
||||
|
||||
test 'a guest user should be blocked by confirmation and redirected to a custom path' do
|
||||
Devise::RegistrationsController.any_instance.stubs(:after_inactive_sign_up_path_for).returns("/?custom=1")
|
||||
get new_user_registration_path
|
||||
|
||||
@@ -8,6 +8,11 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
||||
Devise.mailer_sender = 'test@example.com'
|
||||
end
|
||||
|
||||
def teardown
|
||||
Devise.mailer = 'Devise::Mailer'
|
||||
Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
|
||||
end
|
||||
|
||||
def user
|
||||
@user ||= create_user
|
||||
end
|
||||
|
||||
@@ -8,6 +8,11 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
||||
Devise.mailer_sender = 'test@example.com'
|
||||
end
|
||||
|
||||
def teardown
|
||||
Devise.mailer = 'Devise::Mailer'
|
||||
Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
|
||||
end
|
||||
|
||||
def user
|
||||
@user ||= begin
|
||||
user = create_user
|
||||
|
||||
@@ -8,6 +8,11 @@ class UnlockInstructionsTest < ActionMailer::TestCase
|
||||
Devise.mailer_sender = 'test@example.com'
|
||||
end
|
||||
|
||||
def teardown
|
||||
Devise.mailer = 'Devise::Mailer'
|
||||
Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
|
||||
end
|
||||
|
||||
def user
|
||||
@user ||= begin
|
||||
user = create_user
|
||||
|
||||
@@ -6,4 +6,5 @@ module SharedAdmin
|
||||
:timeoutable, :recoverable, :rememberable, :lockable,
|
||||
:unlock_strategy => :time
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user