2009-10-12 07:37:42 -04:00
|
|
|
require 'test/test_helper'
|
|
|
|
|
2009-10-17 10:12:50 -04:00
|
|
|
class ConfirmationTest < ActionController::IntegrationTest
|
2009-10-12 07:37:42 -04:00
|
|
|
|
2009-10-18 08:36:20 -04:00
|
|
|
def visit_user_confirmation_with_token(confirmation_token)
|
|
|
|
visit user_confirmation_path(:confirmation_token => confirmation_token)
|
|
|
|
end
|
|
|
|
|
2009-10-12 08:56:12 -04:00
|
|
|
test 'user should be able to request a new confirmation' do
|
2009-10-15 15:54:04 -04:00
|
|
|
user = create_user(:confirm => false)
|
2009-10-12 07:37:42 -04:00
|
|
|
ActionMailer::Base.deliveries.clear
|
|
|
|
|
2009-10-12 08:56:12 -04:00
|
|
|
visit new_user_session_path
|
2009-10-12 07:37:42 -04:00
|
|
|
click_link 'Didn\'t receive confirmation instructions?'
|
|
|
|
|
2009-10-12 08:56:12 -04:00
|
|
|
fill_in 'email', :with => user.email
|
2009-10-12 07:37:42 -04:00
|
|
|
click_button 'Resend confirmation instructions'
|
|
|
|
|
|
|
|
assert_template 'sessions/new'
|
|
|
|
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 07:14:52 -04:00
|
|
|
test 'user with invalid confirmation token should not be able to confirm an account' do
|
2009-10-18 08:36:20 -04:00
|
|
|
visit_user_confirmation_with_token('invalid_confirmation')
|
2009-10-12 07:37:42 -04:00
|
|
|
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'confirmations/new'
|
|
|
|
assert_have_selector '#errorExplanation'
|
2009-10-18 07:14:52 -04:00
|
|
|
assert_contain 'Confirmation token is invalid'
|
2009-10-12 07:37:42 -04:00
|
|
|
end
|
|
|
|
|
2009-10-18 07:14:52 -04:00
|
|
|
test 'user with valid confirmation token should be able to confirm an account' do
|
2009-10-12 08:56:12 -04:00
|
|
|
user = create_user(:confirm => false)
|
|
|
|
assert_not user.confirmed?
|
2009-10-12 07:37:42 -04:00
|
|
|
|
2009-10-18 08:36:20 -04:00
|
|
|
visit_user_confirmation_with_token(user.confirmation_token)
|
2009-10-12 07:37:42 -04:00
|
|
|
|
2009-10-18 08:36:20 -04:00
|
|
|
assert_template 'home/index'
|
2009-10-18 08:39:22 -04:00
|
|
|
assert_contain 'Your account was successfully confirmed.'
|
2009-10-12 07:37:42 -04:00
|
|
|
|
2009-10-12 08:56:12 -04:00
|
|
|
assert user.reload.confirmed?
|
2009-10-12 07:37:42 -04:00
|
|
|
end
|
|
|
|
|
2009-10-12 08:56:12 -04:00
|
|
|
test 'user already confirmed user should not be able to confirm the account again' do
|
|
|
|
user = create_user
|
2009-10-18 08:36:20 -04:00
|
|
|
visit_user_confirmation_with_token(user.confirmation_token)
|
2009-10-12 07:37:42 -04:00
|
|
|
|
|
|
|
assert_template 'confirmations/new'
|
|
|
|
assert_have_selector '#errorExplanation'
|
|
|
|
assert_contain 'already confirmed'
|
|
|
|
end
|
2009-10-18 08:36:20 -04: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 09:20:10 -04:00
|
|
|
|
2009-11-22 19:19:29 -05:00
|
|
|
test 'not confirmed user with setup to block without confirmation should not be able to sign in' do
|
2009-11-03 06:35:11 -05:00
|
|
|
Devise.confirm_within = 0
|
2009-11-22 19:19:29 -05:00
|
|
|
sign_in_as_user(:confirm => false)
|
2009-10-21 09:20:10 -04:00
|
|
|
|
2009-11-16 11:31:09 -05:00
|
|
|
assert_contain 'You have to confirm your account before continuing'
|
2009-10-21 09:20:10 -04:00
|
|
|
assert_not warden.authenticated?(:user)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'not confirmed user but configured with some days to confirm should be able to sign in' do
|
2009-11-03 06:35:11 -05:00
|
|
|
Devise.confirm_within = 1
|
2009-11-22 19:19:29 -05:00
|
|
|
sign_in_as_user(:confirm => false)
|
2009-10-21 09:20:10 -04:00
|
|
|
|
|
|
|
assert_response :success
|
|
|
|
assert warden.authenticated?(:user)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'error message is configurable by resource name' do
|
|
|
|
begin
|
|
|
|
I18n.backend.store_translations(:en, :devise => { :sessions =>
|
|
|
|
{ :admin => { :unconfirmed => "Not confirmed user" } } })
|
|
|
|
|
|
|
|
get new_admin_session_path(:unconfirmed => true)
|
|
|
|
|
|
|
|
assert_contain 'Not confirmed user'
|
|
|
|
ensure
|
|
|
|
I18n.reload!
|
|
|
|
end
|
|
|
|
end
|
2009-10-12 07:37:42 -04:00
|
|
|
end
|