I have a user model and an operator model which belongs to user. I created some factories that associate them(in my feature, a user account is created when an operator signs up) so I made this step:
def create_operator_with_user(operator_name)
user = Factory(:user)
puts "MY PASS: #{user.password}"
operator = Factory(:operator, :chief_pilot_or_business_owner => operator_name, :user_id => user.id)
pew = User.find(operator.user_id)
puts "USER: #{operator.user.inspect} PASS: #{operator.user.password} PEWPASS: #{pew.password}"
end
this is my user factory:
Factory.define :admin, :class => User do |f|
f.sequence(:login) { |n| "admin#{n}"}
f.is_admin true
f.password "password"
f.password_confirmation "password"
f.sequence(:email) { |n| "test#{n}@test.com"}
end
Factory.define :user, :parent => :admin do |f|
f.sequence(:login) { |n| "user_#{n}" }
f.sequence(:email) { |n| "the_user_#{n}@asdf.com" }
end
I tried to run my feature and here was the output:
MY PASS: password
USER: #<User id: 181, login: "user_1", email: "the_user_1@asdf.com", crypted_password: "e9f6932a07cbe6e49073a331530f9dc01a3482502d25770be00...", password_salt: "YEjT9Q8EGYdrNh4qGZda", persistence_token: "259a61440f6ecd001e79a4aaf1c5c343e50be04388bbf1718c3...", created_at: "2011-06-02 04:24:34", updated_at: "2011-06-02 04:24:34", is_admin: true>
PASS:
PEWPASS:
So the question is, the user DOES have a password, since it was allowed to be created, not to mention it printed it out after being created using the factory. Problem is, when I try to access the password via User.find(user.id) or operator.user, why is it that password is blank?
If it helps, this is for authlogic
It seems that I was trying to access a protected attribute of authlogic, that’s why I couldn’t access the password even if I tried getting the user object again. My solution was to use a global variable instead (@user) so I could access it in other steps.