【发布时间】:2015-09-17 23:34:21
【问题描述】:
我遇到了一个问题,我的模型上的自定义验证导致所有 shoulda 验证都失败。
基本上:
class User < ActiveRecord::Base
validates_presence_of :name
validate :some_date_validation
private
def some_date_validation
if date_given > birthday
errors.add(:birthday, "Some sort of error message")
end
end
end
然后在规范中:
require 'rails_helper'
RSpec.describe User, type: :model do
describe "shoulda validations" do
it { should validate_presence_of(:name) }
end
end
这将导致我的测试失败,因为其他验证不会通过。这是为什么呢?
【问题讨论】:
标签: ruby-on-rails validation rspec