Ruby on rails rspec用户测试给出;未定义的局部变量或方法“在'处确认”&引用;

Ruby on rails rspec用户测试给出;未定义的局部变量或方法“在'处确认”&引用;,ruby-on-rails,ruby,rspec,devise,rspec2,Ruby On Rails,Ruby,Rspec,Devise,Rspec2,我的rspec测试给了我 NameError: undefined local variable or method `confirmed_at' for #<User:0xca6ff98> 我在上找不到任何关于已确认的_的参考资料 我设计了1.4.8 我的用户迁移是: class DeviseCreateUsers < ActiveRecord::Migration def self.up create_table(:users) do |t|

我的rspec测试给了我

 NameError:
   undefined local variable or method `confirmed_at' for #<User:0xca6ff98>
我在上找不到任何关于已确认的_的参考资料

我设计了1.4.8 我的用户迁移是:

class DeviseCreateUsers < ActiveRecord::Migration
  def self.up
    create_table(:users) do |t|
      t.database_authenticatable :null => false
      t.recoverable
      t.rememberable
      t.trackable

      # t.encryptable
      # t.confirmable
      # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
      # t.token_authenticatable


      t.timestamps
    end

    add_index :users, :email,                :unique => true
    add_index :users, :reset_password_token, :unique => true
    # add_index :users, :confirmation_token,   :unique => true
    # add_index :users, :unlock_token,         :unique => true
    # add_index :users, :authentication_token, :unique => true
  end

  def self.down
    drop_table :users
  end
end
看起来你错过了设计过程中的“可确认”配置。您可以自己添加缺少的三列,或者尝试类似的操作(请参阅下面的底部附近的Reza.Hashemi的消息:

然后编辑到以下位置的迁移:

def self.up 
  change_table(:users) do |t| 
    t.confirmable 
  end 
end 
最后,通常的情况是:

$ rake db:migrate
我认为上述流程应该添加三个栏:

  • 确认时间:datetime
  • 确认\u令牌:字符串
  • 确认发送时间:datetime

对于Mongoid,请查看用户模型——所需字段可能会被注释掉。对于我来说,它们是:

## Confirmable
field :confirmation_token,   :type => String
field :confirmed_at,         :type => Time
field :confirmation_sent_at, :type => Time
field :unconfirmed_email,    :type => String # Only if using reconfirmable

Desive在你的用户中是否需要一个
confirm_at
?我从未使用过它,所以这只是一个猜测。谢谢mu!是的,似乎是这样,但它的生成器没有包含它,这似乎很奇怪,在我手动添加它之前,我想看看是否有其他人看到过。可能缺少迁移?是的,这很有帮助,谢谢。我必须添加confirmed_at:datetime和confirmation_token:string和confirmation_sent_at:datetime在thend中(哇!)。但我确实一个接一个地添加了它们,然后我终于可以通过规范。我不知道这可能是个临时问题。发表你的评论加上这个作为答案,我可以接受。我会小心的。@Jeff:对不起,我现在不使用Desive,所以我不知道v3需要什么。@Muistoshort无论如何,谢谢。我没有屏住呼吸!
def self.up 
  change_table(:users) do |t| 
    t.confirmable 
  end 
end 
$ rake db:migrate
## Confirmable
field :confirmation_token,   :type => String
field :confirmed_at,         :type => Time
field :confirmation_sent_at, :type => Time
field :unconfirmed_email,    :type => String # Only if using reconfirmable