我正在为应用程序编写测试并遇到问题。
我的模型有下一个验证:
def correct_date
errors.add(:occured_at, 'must be in past or present time') if occured_at > 5.minutes.from_now
end
当我在模型上运行最简单的测试时,它们都会失败。
describe 'associations' do
it { should belong_to(:category).optional }
end
我收到一个错误:
Failure/Error: errors.add(:occured_at, 'must be in past or present time') if occured_at > 5.minutes.from_now
NoMethodError:
undefined method `>' for nil:NilClass