I've searched this issue on the forum and have used a solution on the spork site to remove "--drb" from spec options, got it to load and run and still this persistent error keeps popping up. I've also run it without spork. I've read ahead on a bunch of rspec info and as stated dug through spork info, but nothing yet. I've also ran checks for typos, indentation, encoding... and am at a loss still. Other issues, I've been able to fix, but this one's got me. Here it is below if anyone has a suggestion:
Failures:
1) User password en开发者_开发百科cryption has_password? method should be false if the passwords don't match Failure/Error: @user = User.create!(@attr) ActiveRecord::UnknownAttributeError: unknown attribute: password # ./spec/models/user_spec.rb:94:in `block (3 levels) in '
Finished in 0.836 seconds 1 example, 1 failure <-- Slave(1) run done!
are you certain you have added :password as a virtual attribute on your User model? It's easy to miss but you need to include the line
attr_accessor :password
It's possible that this has changed between the time the question was asked (2011) and now, but I initially ran into the same issue -- I'd added all of the tests for password etc, and the User initialization itself was failing across the board with "unknown attribute: password".
On the face of it, GrahamJRoy's answer (and more importantly, subsequent comment of elaboration) addressed my confusion perfectly.
However, I then kept reading the next section of the tutorial and learned that the following line in the User model implies the same thing:
has_secure_password
Once I added this, I no longer needed the explicit attr_accessor declaration:
attr_accessor :password, :password_confirmation
My only complaint with the tutorial here is that Michael doesn't warn you that ALL of your User references will begin to fail if you add the :password and :password_confirmation to User.new() when the tutorial first shows you the updated constructor. I was expecting only the new tests to fail, thought I was off-track, and so searched elsewhere (such as here) for a solution before continuing the tutorial.
Make sure to change attr_accessible
to attr_accessor
in models/user.rb
I made the same mistake and overlooked it.
精彩评论