【问题标题】:ActsAsTenant current_tenant + Capybara + RSpec testingActsAsTenant current_tenant + Capybara + RSpec 测试
【发布时间】:2015-04-07 23:34:45
【问题描述】:

我正在尝试使用 Capybara/RSpec 创建一个具有有效 current_user 的集成测试(使用 Warden.test_mode!技巧),并且我还通过在测试中执行此操作创建了一个有效的 current_tenant:

ActsAsTenant.current_tenant = Account.first

运行测试时会出现“nil:NilClass 的未定义方法”错误,这是当前租户未设置的特征。我已验证 Account.first 确实包含我所期望的内容。

可能是什么问题,我该如何解决?

【问题讨论】:

    标签: ruby-on-rails-4 rspec capybara acts-as-tenant


    【解决方案1】:

    您可以在此处查看 gem 'act_as_tent' 文档 https://github.com/ErwinM/acts_as_tenant#testing

    【讨论】:

      【解决方案2】:

      您可能需要创建Account。如果您使用的是 FactoryBot,则可能如下所示:

      ActsAsTenant.current_tenant = FactoryBot.create :account

      您也可以考虑使用:

      ActsAsTenant.without_tenant do
        # more testy things
      end
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-12
        • 2012-08-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多