2009-10-12 08:37:42 -03:00
|
|
|
require 'test/test_helper'
|
|
|
|
|
2009-10-17 11:12:50 -03:00
|
|
|
class ConfirmationTest < ActionController::IntegrationTest
|
2009-10-12 08:37:42 -03:00
|
|
|
|
2009-10-18 10:36:20 -02:00
|
|
|
def visit_user_confirmation_with_token(confirmation_token)
|
|
|
|
visit user_confirmation_path(:confirmation_token => confirmation_token)
|
|
|
|
end
|
|
|
|
|
2009-10-12 09:56:12 -03:00
|
|
|
test 'user should be able to request a new confirmation' do
|
2009-10-15 16:54:04 -03:00
|
|
|
user = create_user(:confirm => false)
|
2009-10-12 08:37:42 -03:00
|
|
|
ActionMailer::Base.deliveries.clear
|
|
|
|
|
2009-10-12 09:56:12 -03:00
|
|
|
visit new_user_session_path
|
2009-10-12 08:37:42 -03:00
|
|
|
click_link 'Didn\'t receive confirmation instructions?'
|
|
|
|
|
2009-10-12 09:56:12 -03:00
|
|
|
fill_in 'email', :with => user.email
|
2009-10-12 08:37:42 -03: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 09:14:52 -02:00
|
|
|
test 'user with invalid confirmation token should not be able to confirm an account' do
|
2009-10-18 10:36:20 -02:00
|
|
|
visit_user_confirmation_with_token('invalid_confirmation')
|
2009-10-12 08:37:42 -03:00
|
|
|
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'confirmations/new'
|
|
|
|
assert_have_selector '#errorExplanation'
|
2009-10-18 09:14:52 -02:00
|
|
|
assert_contain 'Confirmation token is invalid'
|
2009-10-12 08:37:42 -03:00
|
|
|
end
|
|
|
|
|
2009-10-18 09:14:52 -02:00
|
|
|
test 'user with valid confirmation token should be able to confirm an account' do
|
2009-10-12 09:56:12 -03:00
|
|
|
user = create_user(:confirm => false)
|
|
|
|
assert_not user.confirmed?
|
2009-10-12 08:37:42 -03:00
|
|
|
|
2009-10-18 10:36:20 -02:00
|
|
|
visit_user_confirmation_with_token(user.confirmation_token)
|
2009-10-12 08:37:42 -03:00
|
|
|
|
2009-10-18 10:36:20 -02:00
|
|
|
assert_template 'home/index'
|
2009-10-18 10:39:22 -02:00
|
|
|
assert_contain 'Your account was successfully confirmed.'
|
2009-10-12 08:37:42 -03:00
|
|
|
|
2009-10-12 09:56:12 -03:00
|
|
|
assert user.reload.confirmed?
|
2009-10-12 08:37:42 -03:00
|
|
|
end
|
|
|
|
|
2009-10-12 09:56:12 -03:00
|
|
|
test 'user already confirmed user should not be able to confirm the account again' do
|
|
|
|
user = create_user
|
2009-10-18 10:36:20 -02:00
|
|
|
visit_user_confirmation_with_token(user.confirmation_token)
|
2009-10-12 08:37:42 -03:00
|
|
|
|
|
|
|
assert_template 'confirmations/new'
|
|
|
|
assert_have_selector '#errorExplanation'
|
|
|
|
assert_contain 'already confirmed'
|
|
|
|
end
|
2009-10-18 10:36:20 -02: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-12 08:37:42 -03:00
|
|
|
end
|