1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00
heartcombo--devise/test/integration/confirmable_test.rb

61 lines
1.9 KiB
Ruby
Raw Normal View History

2009-10-12 08:37:42 -03:00
require 'test/test_helper'
class ConfirmationTest < ActionController::IntegrationTest
2009-10-12 08:37:42 -03: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
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
test 'user with invalid confirmation token should not be able to confirm an account' do
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'
assert_contain 'Confirmation token is invalid'
2009-10-12 08:37:42 -03:00
end
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
visit_user_confirmation_with_token(user.confirmation_token)
2009-10-12 08:37:42 -03:00
assert_template 'home/index'
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
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
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