remove duplication type_cast_value specs

This commit is contained in:
Adam Meehan 2010-08-02 18:12:24 +10:00
parent e06054dd4c
commit 896fd83be5

View File

@ -8,78 +8,53 @@ describe ValidatesTimeliness::Validator, ":is_at option" do
end end
describe "for date type" do describe "for date type" do
it "should be equal to same date value" do it "should not be valid for day before restriction" do
Person.validates_date :birth_date, :is_at => Date.new(2010, 1, 1) Person.validates_date :birth_date, :is_at => Date.new(2010, 1, 1)
valid!(:birth_date, Date.new(2010, 1, 1)) invalid!(:birth_date, Date.new(2009, 12, 31), 'must be at 2010-01-01')
end end
it "should be equal to Time with same date part" do it "should not be valid for date after restriction" do
Person.validates_date :birth_date, :is_at => Time.local_time(2010, 1, 1, 0, 0, 0) Person.validates_date :birth_date, :is_at => Date.new(2010, 1, 1)
valid!(:birth_date, Date.new(2010, 1, 1)) invalid!(:birth_date, Date.new(2010, 1, 2), 'must be at 2010-01-01')
end end
it "should be equal to DateTime with same date part" do it "should be valid for same date value" do
Person.validates_date :birth_date, :is_at => DateTime.civil_from_format(:local, 2010, 1, 1, 0, 0, 0) Person.validates_date :birth_date, :is_at => Date.new(2010, 1, 1)
valid!(:birth_date, Date.new(2010, 1, 1)) valid!(:birth_date, Date.new(2010, 1, 1))
end end
end end
describe "for time type" do describe "for time type" do
it "should be equal to Date if attribute value is midnight" do it "should not be valid for time before restriction" do
Person.validates_time :birth_time, :is_at => Date.new(2010, 1, 1) Person.validates_time :birth_time, :is_at => Time.mktime(2000, 1, 1, 12, 0, 0)
invalid!(:birth_time, Time.local_time(2000, 1, 1, 11, 59, 59), 'must be at 12:00:00')
end
it "should not be valid for time after restriction" do
Person.validates_time :birth_time, :is_at => Time.mktime(2000, 1, 1, 12, 0, 0)
invalid!(:birth_time, Time.local_time(2000, 1, 1, 12, 00, 01), 'must be at 12:00:00')
end
it "should be valid for same time as restriction" do
Person.validates_time :birth_time, :is_at => Time.local_time(2000, 1, 1, 0, 0, 0)
valid!(:birth_time, Time.local_time(2000, 1, 1, 0, 0, 0)) valid!(:birth_time, Time.local_time(2000, 1, 1, 0, 0, 0))
end end
it "should not be be equal to Date if attribute value is other than midnight" do
Person.validates_time :birth_time, :is_at => Date.new(2010, 1, 1)
invalid!(:birth_time, Time.local_time(2000, 1, 1, 9, 30, 0))
end
it "should be equal to local Time with same time part" do
Person.validates_time :birth_time, :is_at => Time.local_time(2010, 1, 1, 0, 0, 0)
valid!(:birth_time, Time.local_time(2000, 1, 1, 0, 0, 0))
end
it "should not be equal to UTC Time with same time part" do
Person.validates_time :birth_time, :is_at => Time.utc(2010, 1, 1, 0, 0, 0)
invalid!(:birth_time, Time.local_time(2000, 1, 1, 0, 0, 0))
end
it "should be equal to local DateTime with same time part" do
Person.validates_time :birth_time, :is_at => DateTime.civil_from_format(:local, 2010, 1, 1, 0, 0, 0)
valid!(:birth_time, Time.local_time(2000, 1, 1, 0, 0, 0))
end
it "should not be equal to UTC DateTime with same time part" do
Person.validates_time :birth_time, :is_at => DateTime.new(2010, 1, 1, 0, 0, 0)
invalid!(:birth_time, Time.local_time(2000, 1, 1, 0, 0, 0))
end
end end
describe "for datetime type" do describe "for datetime type" do
it "should be equal to Date with same" do it "should not be valid for datetime where time part is before restriction" do
Person.validates_datetime :birth_datetime, :is_at => Date.new(2010, 1, 1) Person.validates_datetime :birth_datetime, :is_at => DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 0)
valid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 0, 0, 0)) invalid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 11, 59, 59), 'must be at 2010-01-01 12:00:00')
end end
it "should be equal to local Time with same component values" do it "should not be valid for datetime where date is before restriction" do
Person.validates_datetime :birth_datetime, :is_at => Time.local_time(2010, 1, 1, 0, 0, 0) Person.validates_datetime :birth_datetime, :is_at => DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 0)
valid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 0, 0, 0)) invalid!(:birth_datetime, DateTime.civil_from_format(:local, 2009, 12, 31, 12, 0, 0), 'must be at 2010-01-01 12:00:00')
end end
it "should not be equal to UTC Time with same component values" do it "should be valid for same datetime as restriction" do
Person.validates_datetime :birth_datetime, :is_at => Time.utc(2010, 1, 1, 0, 0, 0)
invalid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 0, 0, 0))
end
it "should be equal to same local DateTime value" do
Person.validates_datetime :birth_datetime, :is_at => DateTime.civil_from_format(:local, 2010, 1, 1, 0, 0, 0) Person.validates_datetime :birth_datetime, :is_at => DateTime.civil_from_format(:local, 2010, 1, 1, 0, 0, 0)
valid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 0, 0, 0)) valid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 0, 0, 0))
end end
it "should not be equal to UTC DateTime with same component values" do
Person.validates_datetime :birth_datetime, :is_at => DateTime.new(2010, 1, 1, 0, 0, 0)
invalid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 0, 0, 0))
end
end end
end end