Factory won't set password and password_confirmation
My User.rb has:
attr_accessor :password, :password_confirmation
attr_accessible :password, :password_confirmation
My factory_girl for a user is:
Factory.define :user do |u|
u.password "my_password"
u.password_confirmation "my_password"
end
My User.rb sets the encrypted_password field when the object is saved.
It se开发者_StackOverflow社区ems when the values that I set in my factory (the passwords), are not being set at all.
In my tests I have to do:
it "should ...." do
user = Factory(:user)
user.password = "abc123"
end
Why would this be the case?
I have the password attribute as both an accessor and accessible.
Is something conflicting?
The problem with the above, I believe, is that those attr_accessor
fields are not persisted in the database, so they are 'lost' when declared in factories.rb
. The solution for that is to set them explicitly when creating a new object from factory:
user = Factory(:user, :password => '123')
Also see:
- http://groups.google.com/group/factory_girl/browse_thread/thread/4db1151333a96c50
精彩评论