문제

Of the following tests:

  it { should have_valid(:date_time).when ("2014/April/15") }
  it { should_not have_valid(:date_time).when ("2014/April/15000") }
  it { should_not have_valid(:date_time).when ("2014/ZZZ/14") }
  it { should_not have_valid(:date_time).when(nil, '') }

the following two are not passing:

  it { should_not have_valid(:date_time).when ("2014/April/15000") }
  it { should_not have_valid(:date_time).when ("2014/ZZZ/14") }

I'm getting the error message argument out of range for both. In my model, I have the following:

class Textmessage < ActiveRecord::Base

  validates :date_time, presence: true
end

What would I need to add to my validations to get this to pass?

도움이 되었습니까?

해결책

This is the expected behavior from shoulda. Rails will raise an exception when given either of those strings for a DateTime column, not set an error on the model.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top