mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
remove duplication type_cast_value specs
This commit is contained in:
parent
e06054dd4c
commit
896fd83be5
@ -8,78 +8,53 @@ describe ValidatesTimeliness::Validator, ":is_at option" do
|
||||
end
|
||||
|
||||
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)
|
||||
valid!(:birth_date, Date.new(2010, 1, 1))
|
||||
invalid!(:birth_date, Date.new(2009, 12, 31), 'must be at 2010-01-01')
|
||||
end
|
||||
|
||||
it "should be equal to Time with same date part" do
|
||||
Person.validates_date :birth_date, :is_at => Time.local_time(2010, 1, 1, 0, 0, 0)
|
||||
valid!(:birth_date, Date.new(2010, 1, 1))
|
||||
it "should not be valid for date after restriction" do
|
||||
Person.validates_date :birth_date, :is_at => Date.new(2010, 1, 1)
|
||||
invalid!(:birth_date, Date.new(2010, 1, 2), 'must be at 2010-01-01')
|
||||
end
|
||||
|
||||
it "should be equal to DateTime with same date part" do
|
||||
Person.validates_date :birth_date, :is_at => DateTime.civil_from_format(:local, 2010, 1, 1, 0, 0, 0)
|
||||
it "should be valid for same date value" do
|
||||
Person.validates_date :birth_date, :is_at => Date.new(2010, 1, 1)
|
||||
valid!(:birth_date, Date.new(2010, 1, 1))
|
||||
end
|
||||
end
|
||||
|
||||
describe "for time type" do
|
||||
it "should be equal to Date if attribute value is midnight" do
|
||||
Person.validates_time :birth_time, :is_at => Date.new(2010, 1, 1)
|
||||
it "should not be valid for time before 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, 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))
|
||||
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
|
||||
|
||||
describe "for datetime type" do
|
||||
it "should be equal to Date with same" do
|
||||
Person.validates_datetime :birth_datetime, :is_at => Date.new(2010, 1, 1)
|
||||
valid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 0, 0, 0))
|
||||
it "should not be valid for datetime where time part is before restriction" do
|
||||
Person.validates_datetime :birth_datetime, :is_at => DateTime.civil_from_format(:local, 2010, 1, 1, 12, 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
|
||||
|
||||
it "should be equal to local Time with same component values" do
|
||||
Person.validates_datetime :birth_datetime, :is_at => Time.local_time(2010, 1, 1, 0, 0, 0)
|
||||
valid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 0, 0, 0))
|
||||
it "should not be valid for datetime where date is before restriction" do
|
||||
Person.validates_datetime :birth_datetime, :is_at => DateTime.civil_from_format(:local, 2010, 1, 1, 12, 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
|
||||
|
||||
it "should not be equal to UTC Time with same component values" 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
|
||||
it "should be valid for same datetime as restriction" do
|
||||
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))
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user