0

尝试添加一个非常简单spec的方法来验证范围的唯一性,但规范失败并显示如下错误消息:

0) VaccineLot asd is expected to validate that :number is case-insensitively unique within the scope of :hospital_id
     Failure/Error: it { is_expected.to validate_uniqueness_of(:number).case_insensitive.scoped_to(:hospital_id) }

     ArgumentError:
       wrong number of arguments (given 2, expected 1)

模型看起来像:

class Model
  ...
  ...

  validates :number, presence: true, uniqueness: { case_sensitive: false, scope: :hospital_id }
  validates :expires_on, presence: true, timeliness: { date: true }

  before_validation :set_lot_number, on: :create

  private

  def set_lot_number
    return if number.blank? || expires_on.blank?

    self.number = [number, expires_on.strftime('%Y-%m-%d')].join('-')
  end
end

规格就像:

subject { Fabricate.build(:model) }

it { is_expected.to validate_uniqueness_of(:number).case_insensitive.scoped_to(:hospital_id) }

不知道我错过了什么。任何帮助都将是可观的。

4

0 回答 0