【发布时间】:2023-04-09 04:18:01
【问题描述】:
我正在开发一个 Rails 项目。最近我为模型添加了验证。下面是验证。
class Hub < ActiveRecord::Base
belongs_to :property, class_name: 'Property', foreign_key: :property_id
validates :property_id, uniqueness: { allow_nil: true }
但在大多数情况下,我们在 rspecs 中使用 @property。 例如:let(:hub) { FactoryGirl.create(:hub1, property: @property) }。因此,由于验证,所有 rspecs 都失败了。但我需要验证。解决所有失败的 rspec 的有效方法是什么。
【问题讨论】:
标签: ruby-on-rails unit-testing ruby-on-rails-4 rspec rspec-rails