【问题标题】:devise helper method, confirm! cannot be used/found within factory setup设计辅助方法,确认!无法在出厂设置中使用/找到
【发布时间】:2011-11-20 21:05:18
【问题描述】:

所有,

  • 语言:Ruby on rails
  • 版本:rails 3
  • 有问题的宝石:devise 和 factory_girl_rails

我参考了https://github.com/plataformatec/devise/wiki/How-To:-Controllers-and-Views-tests-with-Rails-3-(and-rspec) 并尝试使用工厂女孩为我的控制器规格设置管理员和常规设计用户。我在设计中使用可确认模块。

在 spec/support/controller_macros.rb 中,我调用了确认!从工厂获取用户对象后。 代码/评论说

> "user.confirm!# 或者在工厂内部设置一个confirmed_at。仅限 > 如果您使用的是可确认模块,则需要"

当我在用户工厂 spec/factories/users.rb 中设置“confirmed_at”的值并运行我的控制器规格(rake spec:controllers)时,它可以工作,但是当我没有设置“confirmed_at”的值时并依靠确认!在 spec/support/controller_macros.rb 中,似乎确认了!没有找到。

我什至尝试在 spec/support/controller_macros.rb 文件,但仍然失败。

我得到的错误是

 Failure/Error: Unable to find matching line from backtrace
 NoMethodError:
   undefined method `confirm!' for #<User:0x71d9c7901e48>
 # ./spec/support/controller_macros.rb:8:in `login_user'

我的 spec/spec_helper.rb 内容如下。

----------- spec/spec_helper.rb - 开始 ---------------------------- ENV["RAILS_ENV"] ||= '测试' 需要 File.expand_path("../../config/environment", __FILE__) 需要'rspec/rails' 需要'webrat' # 需要支持带有自定义匹配器和宏等的 ruby​​ 文件, # 在 spec/support/ 及其子目录中。 目录[Rails.root.join("spec/support/**/*.rb")].each {|f|要求 f} RSpec.configure 做 |config| config.mock_with :rspec config.include 设计::TestHelpers, :type => :controller config.extend ControllerMacros, :type => :controller # 如果您不使用 ActiveRecord 或 ActiveRecord 固定装置,请删除此行 config.fixture_path = "#{::Rails.root}/spec/fixtures" # 如果你没有使用 ActiveRecord,或者你不想运行你的每一个 # 事务中的示例,删除以下行或分配 false # 而不是真的。 config.use_transactional_fixtures = true 结尾

----------- spec/spec_helper.rb - 结束 ----------------------------

导致确认的可能是什么错误!找不到/工作?

谢谢你:)

【问题讨论】:

    标签: ruby-on-rails-3 devise factory-bot


    【解决方案1】:

    确认!如果您使用 :confirmable devise 模块,这只是必要的。

    在您的 user.rb(设计模型)中,将 :confirmable 放入您的设计选项中,或者如果您不想使用此模块(此模块向用户发送确认电子邮件。)删除确认!来自你的 controller_macros.rb。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-12
      • 1970-01-01
      • 2016-06-03
      相关资源
      最近更新 更多