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

90 lines
2.8 KiB
Ruby
Raw Normal View History

2009-10-12 07:37:42 -04:00
require 'test/test_helper'
class ConfirmationTest < ActionController::IntegrationTest
2009-10-12 07:37:42 -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
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
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 07:37:42 -04:00
assert_response :success
assert_template 'confirmations/new'
assert_have_selector '#errorExplanation'
assert_contain 'Confirmation token is invalid'
2009-10-12 07:37:42 -04:00
end
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
visit_user_confirmation_with_token(user.confirmation_token)
2009-10-12 07:37:42 -04:00
assert_template 'home/index'
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
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
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
test 'not confirmed user with setup to block without confirmation should not be able to sign in' do
Devise.confirm_within = 0
sign_in_as_user(:confirm => false)
2009-11-16 11:31:09 -05:00
assert_contain 'You have to confirm your account before continuing'
assert_not warden.authenticated?(:user)
end
test 'not confirmed user but configured with some days to confirm should be able to sign in' do
Devise.confirm_within = 1
sign_in_as_user(:confirm => false)
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