Ruby on rails Rspec+;集成测试&x2B;activemodel=混乱:)
我有以下问题,我不明白: 我有一个用户模型:Ruby on rails Rspec+;集成测试&x2B;activemodel=混乱:),ruby-on-rails,rspec,factory-bot,Ruby On Rails,Rspec,Factory Bot,我有以下问题,我不明白: 我有一个用户模型: class User < ActiveRecord::Base ... private def generate_token(column) begin self[column] = SecureRandom.urlsafe_base64 end while User.exists?(column => self[column]) end end 哪一个在上失败了 User.e
class User < ActiveRecord::Base
...
private
def generate_token(column)
begin
self[column] = SecureRandom.urlsafe_base64
end while User.exists?(column => self[column])
end
end
哪一个在上失败了
User.exists?
与
将提及的行替换为
self.class.exists?
修正它。。
有人能带我走出困惑吗?:)
提前感谢。看起来该方法在与用户同名的作用域中运行,可能您是通过模块定义它(只是猜测)。顺便说一句,你可以这样写:
::User.exists?
它应该从根开始“名称空间解析”。真奇怪,我发现spec_helper.rb中有一个输入错误,所以我没有在测试环境中运行spec。。在测试中运行它们似乎可以解决这个问题。。另一件有趣的事情是,该规范是通过rspec命令传递的,但不是通过autotest传递的。。在我深入挖掘之后,我会写更多。谢谢你的……事情,我不知道:)
self.class.exists?
::User.exists?