Prevent login until email is confirmed

This commit is contained in:
Neil Lalonde
2013-02-11 11:18:26 -05:00
parent f21609fe2e
commit c18b85873f
5 changed files with 104 additions and 52 deletions

View File

@ -617,4 +617,30 @@ describe User do
it { should_not be_active }
end
describe 'email_confirmed?' do
let(:user) { Fabricate(:user) }
context 'when email has not been confirmed yet' do
it 'should return false' do
user.email_confirmed?.should be_false
end
end
context 'when email has been confirmed' do
it 'should return true' do
token = user.email_tokens.where(email: user.email).first
EmailToken.confirm(token.token)
user.email_confirmed?.should be_true
end
end
context 'when user has no email tokens for some reason' do
it 'should return false' do
user.email_tokens.each {|t| t.destroy}
user.reload
user.email_confirmed?.should be_false
end
end
end
end