How to write shoulda test for validating uniqueness of email address while
using has_secure_password?
I'm getting trying to write a shoulda test that validates the uniqueness
of an email address. This is for creating a new User account in Rails
4.0.0 and using has_secure_password. I'm getting this error:
1) User should require case sensitive unique value for email
Failure/Error: it { should validate_uniqueness_of(:email) }
RuntimeError:
Password digest missing on new record
# ./spec/models/user_spec.rb:8:in `block (2 levels) in <top (required)>'
Here's the user_spec.rb:
require "spec_helper"
describe User do
it { should validate_presence_of(:email) }
it { should validate_presence_of(:full_name) }
it { should validate_presence_of(:password_digest) }
it { should validate_uniqueness_of(:email) }
end
And here's the User model:
class User < ActiveRecord::Base
has_secure_password
validates :email, presence: true, uniqueness: true
validates :full_name, presence: true
validates :password_digest, presence: true
end
Any ideas why this isn't working?
No comments:
Post a Comment