Validates_confirmation_of won't work

Hello folks, this is the first time I’ve written to this forum. If
there’s already a topic on this, forgive me but the search isn’t working
right now.

I seem to have a problem validating confirmation of a password. The
first two snippets are some model code and some test code that work just
fine:

class Challenge < ActiveRecord::Base

validates_confirmation_of :title

class ChallengeTest < Test::Unit::TestCase

def test_create
c = Challenge.new
assert !c.save
c.title = c.title_confirmation = “some random title”
c.body = “some body text”
assert c.save
end

this yields:
$ ruby test/unit/challenge_test.rb
Loaded suite test/unit/challenge_test
Started

Finished in 0.521554 seconds.

2 tests, 3 assertions, 0 failures, 0 errors

the second snippet seems identical, but it yields a failed assertion:


class User < ActiveRecord::Base

validates_confirmation_of :password


class UserTest < Test::Unit::TestCase

def test_test
u = User.new( :username => “newbob”,
:password => “newpassword”,
:email => “[email protected]” )
u.password_confirmation = “newpassword”
assert u.save #(this is line 17)
end

this yields:
$ ruby test/unit/user_test.rb
Loaded suite test/unit/user_test
Started
F.
Finished in 0.343036 seconds.

  1. Failure:
    test_test(UserTest) [test/unit/user_test.rb:17]:
    is not true.

2 tests, 2 assertions, 1 failures, 0 errors

Can anyone see an error i can’t? For the life of me, I can’t seem to
figure out why the two would behave any differently. I can provide more
(surrounding) code if necessary, but it was already getting pretty long
. . .

Thanks

  • Sporky

For the record, I ran into this while trying to follow the tutorial at
http://www.aidanf.net/rails_user_authentication_tutorial.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs