2010-03-26 10:27:19 +00:00
|
|
|
require 'test_helper'
|
2009-10-12 11:37:42 +00:00
|
|
|
|
2009-10-17 14:12:50 +00:00
|
|
|
class ConfirmationTest < ActionController::IntegrationTest
|
2009-10-12 11:37:42 +00:00
|
|
|
|
2009-10-18 12:36:20 +00:00
|
|
|
def visit_user_confirmation_with_token(confirmation_token)
|
|
|
|
visit user_confirmation_path(:confirmation_token => confirmation_token)
|
|
|
|
end
|
|
|
|
|
2009-10-12 12:56:12 +00:00
|
|
|
test 'user should be able to request a new confirmation' do
|
2009-10-15 19:54:04 +00:00
|
|
|
user = create_user(:confirm => false)
|
2009-10-12 11:37:42 +00:00
|
|
|
ActionMailer::Base.deliveries.clear
|
|
|
|
|
2009-10-12 12:56:12 +00:00
|
|
|
visit new_user_session_path
|
2010-03-30 18:06:56 +00:00
|
|
|
click_link "Didn't receive confirmation instructions?"
|
2009-10-12 11:37:42 +00:00
|
|
|
|
2009-10-12 12:56:12 +00:00
|
|
|
fill_in 'email', :with => user.email
|
2009-10-12 11:37:42 +00:00
|
|
|
click_button 'Resend confirmation instructions'
|
|
|
|
|
2010-07-06 14:00:07 +00:00
|
|
|
assert_current_url '/users/sign_in'
|
2009-10-12 11:37:42 +00:00
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2009-10-18 11:14:52 +00:00
|
|
|
test 'user with invalid confirmation token should not be able to confirm an account' do
|
2009-10-18 12:36:20 +00:00
|
|
|
visit_user_confirmation_with_token('invalid_confirmation')
|
2010-04-13 21:28:13 +00:00
|
|
|
assert_have_selector '#error_explanation'
|
2009-12-21 20:10:23 +00:00
|
|
|
assert_contain /Confirmation token(.*)invalid/
|
2009-10-12 11:37:42 +00:00
|
|
|
end
|
|
|
|
|
2009-10-18 11:14:52 +00:00
|
|
|
test 'user with valid confirmation token should be able to confirm an account' do
|
2009-10-12 12:56:12 +00:00
|
|
|
user = create_user(:confirm => false)
|
|
|
|
assert_not user.confirmed?
|
2009-10-18 12:36:20 +00:00
|
|
|
visit_user_confirmation_with_token(user.confirmation_token)
|
2009-10-12 11:37:42 +00:00
|
|
|
|
2009-10-18 12:39:22 +00:00
|
|
|
assert_contain 'Your account was successfully confirmed.'
|
2010-07-06 14:00:07 +00:00
|
|
|
assert_current_url '/'
|
2009-10-12 12:56:12 +00:00
|
|
|
assert user.reload.confirmed?
|
2009-10-12 11:37:42 +00:00
|
|
|
end
|
|
|
|
|
2010-07-06 14:00:07 +00:00
|
|
|
test 'already confirmed user should not be able to confirm the account again' do
|
2009-11-24 20:02:36 +00:00
|
|
|
user = create_user(:confirm => false)
|
2009-12-21 20:10:23 +00:00
|
|
|
user.confirmed_at = Time.now
|
|
|
|
user.save
|
2009-10-18 12:36:20 +00:00
|
|
|
visit_user_confirmation_with_token(user.confirmation_token)
|
2009-10-12 11:37:42 +00:00
|
|
|
|
2010-04-13 21:28:13 +00:00
|
|
|
assert_have_selector '#error_explanation'
|
2009-10-12 11:37:42 +00:00
|
|
|
assert_contain 'already confirmed'
|
|
|
|
end
|
2009-10-18 12:36:20 +00:00
|
|
|
|
2010-07-06 14:00:07 +00:00
|
|
|
test 'already confirmed user should not be able to confirm the account again neither request confirmation' do
|
|
|
|
user = create_user(:confirm => false)
|
|
|
|
user.confirmed_at = Time.now
|
|
|
|
user.save
|
|
|
|
|
|
|
|
visit_user_confirmation_with_token(user.confirmation_token)
|
|
|
|
assert_contain 'already confirmed'
|
|
|
|
|
|
|
|
fill_in 'email', :with => user.email
|
|
|
|
click_button 'Resend confirmation instructions'
|
|
|
|
assert_contain 'already confirmed'
|
|
|
|
end
|
|
|
|
|
2009-10-18 12:36:20 +00:00
|
|
|
test 'sign in user automatically after confirming it\'s email' do
|
|
|
|
user = create_user(:confirm => false)
|
|
|
|
visit_user_confirmation_with_token(user.confirmation_token)
|
|
|
|
|
|
|
|
assert warden.authenticated?(:user)
|
|
|
|
end
|
2009-10-21 13:20:10 +00:00
|
|
|
|
2010-01-07 21:41:14 +00:00
|
|
|
test 'increases sign count when signed in through confirmation' do
|
|
|
|
user = create_user(:confirm => false)
|
|
|
|
visit_user_confirmation_with_token(user.confirmation_token)
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
assert_equal 1, user.sign_in_count
|
|
|
|
end
|
|
|
|
|
2009-11-23 00:19:29 +00:00
|
|
|
test 'not confirmed user with setup to block without confirmation should not be able to sign in' do
|
2009-11-23 00:33:19 +00:00
|
|
|
swap Devise, :confirm_within => 0.days do
|
|
|
|
sign_in_as_user(:confirm => false)
|
2009-10-21 13:20:10 +00:00
|
|
|
|
2009-11-23 00:33:19 +00:00
|
|
|
assert_contain 'You have to confirm your account before continuing'
|
|
|
|
assert_not warden.authenticated?(:user)
|
|
|
|
end
|
2009-10-21 13:20:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'not confirmed user but configured with some days to confirm should be able to sign in' do
|
2009-11-23 00:33:19 +00:00
|
|
|
swap Devise, :confirm_within => 1.day do
|
|
|
|
sign_in_as_user(:confirm => false)
|
2009-10-21 13:20:10 +00:00
|
|
|
|
2009-11-23 00:33:19 +00:00
|
|
|
assert_response :success
|
|
|
|
assert warden.authenticated?(:user)
|
|
|
|
end
|
2009-10-21 13:20:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'error message is configurable by resource name' do
|
2009-11-23 00:46:57 +00:00
|
|
|
store_translations :en, :devise => {
|
2010-04-03 11:11:45 +00:00
|
|
|
:failure => { :user => { :unconfirmed => "Not confirmed user" } }
|
2009-11-23 00:46:57 +00:00
|
|
|
} do
|
2010-04-03 09:43:31 +00:00
|
|
|
sign_in_as_user(:confirm => false)
|
2009-10-21 13:20:10 +00:00
|
|
|
assert_contain 'Not confirmed user'
|
|
|
|
end
|
|
|
|
end
|
2009-10-12 11:37:42 +00:00
|
|
|
end
|