Add validation on User password presence

This commit is contained in:
Thibault Jouan 2011-09-13 20:10:38 +00:00
parent ffa811db46
commit 638d379ec6
2 changed files with 11 additions and 1 deletions

View File

@ -11,8 +11,10 @@ class User < ActiveRecord::Base
validates :email,
:presence => true,
:uniqueness => true
validates :password,
:presence => true,
:confirmation => true
validates_presence_of :password_hash
validates_confirmation_of :password
def password=(plain_password)
@password = plain_password

View File

@ -16,6 +16,14 @@ describe User do
it { should_not be_valid }
end
context 'when password empty' do
before do
user.password = ''
end
it { should_not be_valid }
end
context 'when password_confirmation does not match password' do
before do
user.password_confirmation = user.password + 'INVALID'