Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top