Topic: Testing User Passwords

For those of you familiar with restful_authentication, you know that the user table does not have a password column, only crypted_password and salt columns

This poses a problem for me when I try to use fixtures

quentin:
  id: 1
  first_name: Billy
  middle_name: Bob
  last_name: Bungalow
  login: billy
  password: bb1975

context "User with fixtures loaded" do
  fixtures :users

  specify "should authenticate user" do
    users(:quentin).should == User.authenticate('billy','bb1975')
  end
end


I run autotest and get

ActiveRecord::StatementInvalid in 'User with fixtures loaded should reset password'
Mysql::Error: Unknown column 'password' in 'field list': INSERT INTO `users`

How do I circumvent this problem?

Re: Testing User Passwords

I would run the user into your database and then copy the appropriate cells from the database into the fixture.

So if the password is "test," first:

User.create(:name => "Veraticus", :password => "test", :password_confirmation => "test")

Go to the database and copy the hashed_password and salt columns into the fixture, and then in your fixture:

Veraticus:
  id: 1
  hashed_password: xxxxxxxxxxxxxxxxxxx
  salt: xxxxxxxxx

Then you should be able to test for password authentication.

Re: Testing User Passwords

You can add ruby code in your fixtures:

<% SALT = "tr@!" unless defined?(SALT) %>
Veraticus:
id: 1
name: Veraticus
salt: <%= SALT %>
hashed_password: <%= User.encrypted_password('secret' , SALT) %>

Re: Testing User Passwords

Eric_Jardas wrote:

You can add ruby code in your fixtures:

<% SALT = "tr@!" unless defined?(SALT) %>
Veraticus:
id: 1
name: Veraticus
salt: <%= SALT %>
hashed_password: <%= User.encrypted_password('secret' , SALT) %>

This is more along the lines of what I was thinking..unfortunately I can set that variable

./spec/fixtures/users.yml:1: syntax error, unexpected '=', expecting $end
<% SALT = 'tr@id' %>
                ^