I’m using a virtual attribute for password in my user model and a
hashed_password field for the persisted hashed value (a la AWDWR).
However, I am having issues using fixtures and unit tests to validate my
models.
Example, I have a User model that has a password validation clause that
looks something like this:
validates_length_of :password, :within => 6…30
And I have a fixture for a test user that looks something like this:
user_jeff:
id: 1
username: jeff
real_name: Jeff Shmeff
salt: <%= SALT %>
hashed_password: <%= User.encrypted_password(‘secret’, SALT) %>
email: [email protected]
if I ever attempt something like this in my User unit tests…
user = users(:user_jeff)
assert user.valid?
I will get an assertion failure like this:
‘Password is too short (minimum is 6 characters)’
temporarily to get around this, I’ve taken to doing something like this
in my test setup method:
def setup
@user = User.find(1)
@user.password = “this is a hack”
end
and usint @user for most of my tests instead of users(:user_jeff).
But, that sucks.
Any suggestions as to what I SHOULD be doing?
Jeff