Save user password as a bcrypt hash

* Replace password field by password_hash
* Add User#password attribute
* Implement password hashing and verification with BCrypt mixin
This commit is contained in:
Thibault Jouan
2011-08-09 17:04:47 +00:00
parent 0fb9496fb3
commit 1fc3be42de
4 changed files with 58 additions and 5 deletions

View File

@@ -24,6 +24,26 @@ describe User do
it { should_not be_valid }
end
context 'when password_confirmation does not match password' do
before do
user.password_confirmation = 'WRONG'
end
it { should_not be_valid }
end
describe '#hash_password' do
it 'is received when #save is sent' do
user.should_receive(:hash_password)
user.save
end
it 'stores a bcrypt hash of the password' do
user.save
BCrypt::Password.new(user.password_hash).should == user.password
end
end
describe '.authenticate' do
let (:user) { Factory.create(:user) }