Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top