工厂女孩访问某些属性时遇到问题
我有一个用户模型和一个属于用户的操作员模型。我创建了一些关联它们的工厂(在我的功能中,当操作员注册时创建用户帐户),所以我做了这一步:
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
这是我的用户工厂:
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
我尝试运行我的功能,这是输出:
MY PASS: password
USER: #<User id: 181, login: "user_1", email: "[email protected]", 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:
所以问题也就是说,用户确实有密码,因为它被允许创建,更不用说它在使用工厂创建后打印出来了。问题是,当我尝试通过 User.find(user.id) 或operator.user 访问密码时,为什么密码为空?
如果有帮助,这是为了 authlogic
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: "[email protected]", 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来我正在尝试访问 authlogic 的受保护属性,这就是为什么即使我尝试再次获取用户对象也无法访问密码。我的解决方案是使用全局变量(@user),这样我就可以在其他步骤中访问它。
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.
这有效吗?
Does this work?