【问题标题】:Rails 6 all validate_presence_of tests failRails 6 所有 validate_presence_of 测试均失败
【发布时间】:2019-01-20 00:47:24
【问题描述】:

他们失败了:未初始化的常量 ActiveModel::SecurePassword::InstanceMethodsOnActivation

我正在尝试将 rails 5.2 应用程序更新到 rails 6 beta,除了我的 validate_presence_of 规格之外,一切似乎都运行良好。

例如

RSpec.describe Post, type: :model do
  context 'validations' do
    subject { Post.new(body: Faker::Movie.quote)}
    it { should validate_presence_of :body }
    it { should validate_length_of(:body).is_at_most(5000).on(:create) }
  end
end

validate_length_of 可以通过,而 validate_presence 不能。帖子确实属于从 Clearance::User 继承的用户,但我不确定为什么同一模型的不同测试中常量会有所不同?

【问题讨论】:

    标签: ruby-on-rails testing rspec ruby-on-rails-6


    【解决方案1】:

    我已经完成了这项工作。

    这里有一个对 shoulda_matchers 的拉取请求:

    https://github.com/thoughtbot/shoulda-matchers/pull/1169
    

    在 shoulda_matchers 团队合并之前,在这里使用我的版本:

    https://github.com/morsedigital/shoulda-matchers
    

    在您的 Gemfile 中:

    gem 'shoulda-matchers', groups: [:test], git: 'https://github.com/morsedigital/shoulda-matchers'
    

    【讨论】:

      【解决方案2】:

      原来这是 shoulda-matchers 的一个错误。

      https://github.com/thoughtbot/shoulda-matchers/issues/1167

      【讨论】:

        【解决方案3】:

        在我的情况下,这是快速修复:

        # spec/rails_helper.rb - add to bottom
        
        class ActiveModel::SecurePassword::InstanceMethodsOnActivation; end;
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-12-18
          • 1970-01-01
          • 1970-01-01
          • 2015-05-27
          • 1970-01-01
          • 2023-02-14
          • 1970-01-01
          相关资源
          最近更新 更多