Hi all,
I am trying to do some tests based on a tutorial here http://www.aidanf.net/rails_user_authentication_tutorial
here is the two tests that seem to 'blow up' when I have the use_instantiated_fixtures line in place.
require File.dirname(__FILE__) + '/../test_helper'
class UserTest < Test::Unit::TestCase self.use_instantiated_fixtures = true fixtures :users
# test basic authentication def test_auth # check that we can login a valid user assert_equal @bob, User.authenticate("bob", "test1") # wrong username assert_nil User.authenticate("notbob", "test1") # wrong pwd assert_nil User.authenticate("bob", "wrongpass") # both wrong assert_nil User.authenticate("notbob", "wrongpass") end
# can we change passwords def test_passwordchange # check that it exists in the first place assert_equal @longbob, User.authenticate("longbob", "longtest") # change password @longbob.password = @longbob.password_confirmation = "nonbobpasswd" assert @longbob.save # check that the new password works assert_equal @longbob, User.authenticate("longbob", "nonbobpasswd") # check that old password doesnt work any more assert_nil User.authenticate("longbob", "longtest") #change it back again @longbob.password = @longbob.password_confirmation = "longtest" assert @longbob.save assert_equal @longbob, User.authenticate("longbob", "longtest") assert_nil User.authenticate("longbob", "nonbobpasswd") end
# 2 other tests that work below here omitted # ...... end
This is the error listing I get
ruby user_test.rb
Loaded suite user_test Started F..F Finished in 0.279297 seconds.
1) Failure: test_auth(UserTest) [user_test.rb:10]: <#<User:0x99f7b18 @attributes= {"salt"=>"813762200.1356", "name"=>"bob", "hashed_password"=>"69f50afebdc75388afbe144e3355b6c08066a0bc", "lastname"=>"bob", "firstname"=>"bob", "id"=>"1000001", "email"=>"bob@mcbob.com"}>> expected but was <nil>.
2) Failure: test_passwordchange(UserTest) [user_test.rb:22]: <#<User:0x99affc0 @attributes= {"salt"=>"808396800.134522", "name"=>"longbob", "hashed_password"=>"f1bd0a176e98e973b03529ee89303e24acca00c6", "lastname"=>"bob", "firstname"=>"long", "id"=>"1000003", "email"=>"lbob@mcbob.com"}>> expected but was <nil>.
4 tests, 11 assertions, 2 failures, 0 errors
Now if i comment out the line I get this instead
ruby user_test.rb
Loaded suite user_test Started ...E Finished in 0.149724 seconds.
1) Error: test_passwordchange(UserTest): NoMethodError: You have a nil object when you didn't expect it! The error occurred while evaluating nil.password_confirmation= user_test.rb:24:in `test_passwordchange'
4 tests, 14 assertions, 0 failures, 1 errors
Having tried other good and bad values in test_auth I reckon that the whole content of this method is not providing good testing ....
And test_passwordchange seems to be completely missing an instance variable.
What am I missing ?? I am using Rails version 1.2.3
mjt