mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
remaining specs for validator options
This commit is contained in:
parent
bbde35bf89
commit
b5661bacec
59
spec/validates_timeliness/validator/after_spec.rb
Normal file
59
spec/validates_timeliness/validator/after_spec.rb
Normal file
@ -0,0 +1,59 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness::Validator, ":after option" do
|
||||
include ModelHelpers
|
||||
|
||||
describe "for date type" do
|
||||
before do
|
||||
Person.validates_date :birth_date, :after => Date.new(2010, 1, 1)
|
||||
end
|
||||
|
||||
it "should not be valid for same date value" do
|
||||
invalid!(:birth_date, Date.new(2010, 1, 1), 'must be after 2010-01-01')
|
||||
end
|
||||
|
||||
it "should not be valid for date before restriction" do
|
||||
invalid!(:birth_date, Date.new(2009, 12, 31), 'must be after 2010-01-01')
|
||||
end
|
||||
|
||||
it "should be valid for date after restriction" do
|
||||
valid!(:birth_date, Date.new(2010, 1, 2))
|
||||
end
|
||||
end
|
||||
|
||||
describe "for time type" do
|
||||
before do
|
||||
Person.validates_time :birth_time, :after => Time.mktime(2000, 1, 1, 12, 0, 0)
|
||||
end
|
||||
|
||||
it "should not be valid for same time as restriction" do
|
||||
invalid!(:birth_time, Time.local_time(2000, 1, 1, 12, 0, 0), 'must be after 12:00:00')
|
||||
end
|
||||
|
||||
it "should not be valid for time before restriction" do
|
||||
invalid!(:birth_time, Time.local_time(2000, 1, 1, 11, 59, 59), 'must be after 12:00:00')
|
||||
end
|
||||
|
||||
it "should be valid for time after restriction" do
|
||||
valid!(:birth_time, Time.local_time(2000, 1, 1, 12, 00, 01))
|
||||
end
|
||||
end
|
||||
|
||||
describe "for datetime type" do
|
||||
before do
|
||||
Person.validates_datetime :birth_datetime, :after => DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 0)
|
||||
end
|
||||
|
||||
it "should not be valid for same datetime as restriction" do
|
||||
invalid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 0), 'must be after 2010-01-01 12:00:00')
|
||||
end
|
||||
|
||||
it "should be valid for datetime is before restriction" do
|
||||
invalid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 11, 59, 59), 'must be after 2010-01-01 12:00:00')
|
||||
end
|
||||
|
||||
it "should be valid for datetime is after restriction" do
|
||||
valid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 1))
|
||||
end
|
||||
end
|
||||
end
|
||||
59
spec/validates_timeliness/validator/before_spec.rb
Normal file
59
spec/validates_timeliness/validator/before_spec.rb
Normal file
@ -0,0 +1,59 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness::Validator, ":before option" do
|
||||
include ModelHelpers
|
||||
|
||||
describe "for date type" do
|
||||
before do
|
||||
Person.validates_date :birth_date, :before => Date.new(2010, 1, 1)
|
||||
end
|
||||
|
||||
it "should not be valid for date after restriction" do
|
||||
invalid!(:birth_date, Date.new(2010, 1, 2), 'must be before 2010-01-01')
|
||||
end
|
||||
|
||||
it "should not be valid for same date value" do
|
||||
invalid!(:birth_date, Date.new(2010, 1, 1), 'must be before 2010-01-01')
|
||||
end
|
||||
|
||||
it "should be valid for date before restriction" do
|
||||
valid!(:birth_date, Date.new(2009, 12, 31))
|
||||
end
|
||||
end
|
||||
|
||||
describe "for time type" do
|
||||
before do
|
||||
Person.validates_time :birth_time, :before => Time.mktime(2000, 1, 1, 12, 0, 0)
|
||||
end
|
||||
|
||||
it "should not be valid for time after restriction" do
|
||||
invalid!(:birth_time, Time.local_time(2000, 1, 1, 12, 00, 01), 'must be before 12:00:00')
|
||||
end
|
||||
|
||||
it "should not be valid for same time as restriction" do
|
||||
invalid!(:birth_time, Time.local_time(2000, 1, 1, 12, 0, 0), 'must be before 12:00:00')
|
||||
end
|
||||
|
||||
it "should be valid for time before restriction" do
|
||||
valid!(:birth_time, Time.local_time(2000, 1, 1, 11, 59, 59))
|
||||
end
|
||||
end
|
||||
|
||||
describe "for datetime type" do
|
||||
before do
|
||||
Person.validates_datetime :birth_datetime, :before => DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 0)
|
||||
end
|
||||
|
||||
it "should not be valid for datetime after restriction" do
|
||||
invalid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 1), 'must be before 2010-01-01 12:00:00')
|
||||
end
|
||||
|
||||
it "should not be valid for same datetime as restriction" do
|
||||
invalid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 0), 'must be before 2010-01-01 12:00:00')
|
||||
end
|
||||
|
||||
it "should be valid for datetime before restriction" do
|
||||
valid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 11, 59, 59))
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -8,53 +8,56 @@ describe ValidatesTimeliness::Validator, ":is_at option" do
|
||||
end
|
||||
|
||||
describe "for date type" do
|
||||
it "should not be valid for day before restriction" do
|
||||
before do
|
||||
Person.validates_date :birth_date, :is_at => Date.new(2010, 1, 1)
|
||||
end
|
||||
|
||||
it "should not be valid for date before restriction" do
|
||||
invalid!(:birth_date, Date.new(2009, 12, 31), 'must be at 2010-01-01')
|
||||
end
|
||||
|
||||
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 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 not be valid for time before restriction" do
|
||||
before do
|
||||
Person.validates_time :birth_time, :is_at => Time.mktime(2000, 1, 1, 12, 0, 0)
|
||||
end
|
||||
|
||||
it "should not be valid for time before restriction" do
|
||||
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, 12, 0, 0))
|
||||
end
|
||||
end
|
||||
|
||||
describe "for datetime type" do
|
||||
it "should not be valid for datetime where time part is before restriction" do
|
||||
before do
|
||||
Person.validates_datetime :birth_datetime, :is_at => DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 0)
|
||||
end
|
||||
|
||||
it "should not be valid for datetime before restriction" do
|
||||
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 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')
|
||||
it "should not be valid for datetime after restriction" do
|
||||
invalid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 1), 'must be at 2010-01-01 12:00:00')
|
||||
end
|
||||
|
||||
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))
|
||||
valid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 0))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
59
spec/validates_timeliness/validator/on_or_after_spec.rb
Normal file
59
spec/validates_timeliness/validator/on_or_after_spec.rb
Normal file
@ -0,0 +1,59 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness::Validator, ":on_or_after option" do
|
||||
include ModelHelpers
|
||||
|
||||
describe "for date type" do
|
||||
before do
|
||||
Person.validates_date :birth_date, :on_or_after => Date.new(2010, 1, 1)
|
||||
end
|
||||
|
||||
it "should not be valid for date before restriction" do
|
||||
invalid!(:birth_date, Date.new(2009, 12, 31), 'must be on or after 2010-01-01')
|
||||
end
|
||||
|
||||
it "should be valid for same date value" do
|
||||
valid!(:birth_date, Date.new(2010, 1, 1))
|
||||
end
|
||||
|
||||
it "should be valid for date after restriction" do
|
||||
valid!(:birth_date, Date.new(2010, 1, 2))
|
||||
end
|
||||
end
|
||||
|
||||
describe "for time type" do
|
||||
before do
|
||||
Person.validates_time :birth_time, :on_or_after => Time.mktime(2000, 1, 1, 12, 0, 0)
|
||||
end
|
||||
|
||||
it "should not be valid for time before restriction" do
|
||||
invalid!(:birth_time, Time.local_time(2000, 1, 1, 11, 59, 59), 'must be on or after 12:00:00')
|
||||
end
|
||||
|
||||
it "should be valid for time after restriction" do
|
||||
valid!(:birth_time, Time.local_time(2000, 1, 1, 12, 00, 01))
|
||||
end
|
||||
|
||||
it "should be valid for same time as restriction" do
|
||||
valid!(:birth_time, Time.local_time(2000, 1, 1, 12, 0, 0))
|
||||
end
|
||||
end
|
||||
|
||||
describe "for datetime type" do
|
||||
before do
|
||||
Person.validates_datetime :birth_datetime, :on_or_after => DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 0)
|
||||
end
|
||||
|
||||
it "should not be valid for datetime before restriction" do
|
||||
invalid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 11, 59, 59), 'must be on or after 2010-01-01 12:00:00')
|
||||
end
|
||||
|
||||
it "should be valid for same datetime as restriction" do
|
||||
valid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 0))
|
||||
end
|
||||
|
||||
it "should be valid for datetime after restriction" do
|
||||
valid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 1))
|
||||
end
|
||||
end
|
||||
end
|
||||
59
spec/validates_timeliness/validator/on_or_before_spec.rb
Normal file
59
spec/validates_timeliness/validator/on_or_before_spec.rb
Normal file
@ -0,0 +1,59 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness::Validator, ":on_or_before option" do
|
||||
include ModelHelpers
|
||||
|
||||
describe "for date type" do
|
||||
before do
|
||||
Person.validates_date :birth_date, :on_or_before => Date.new(2010, 1, 1)
|
||||
end
|
||||
|
||||
it "should not be valid for date after restriction" do
|
||||
invalid!(:birth_date, Date.new(2010, 1, 2), 'must be on or before 2010-01-01')
|
||||
end
|
||||
|
||||
it "should be valid for date before restriction" do
|
||||
valid!(:birth_date, Date.new(2009, 12, 31))
|
||||
end
|
||||
|
||||
it "should be valid for same date value" do
|
||||
valid!(:birth_date, Date.new(2010, 1, 1))
|
||||
end
|
||||
end
|
||||
|
||||
describe "for time type" do
|
||||
before do
|
||||
Person.validates_time :birth_time, :on_or_before => Time.mktime(2000, 1, 1, 12, 0, 0)
|
||||
end
|
||||
|
||||
it "should not be valid for time after restriction" do
|
||||
invalid!(:birth_time, Time.local_time(2000, 1, 1, 12, 00, 01), 'must be on or before 12:00:00')
|
||||
end
|
||||
|
||||
it "should be valid for time before restriction" do
|
||||
valid!(:birth_time, Time.local_time(2000, 1, 1, 11, 59, 59))
|
||||
end
|
||||
|
||||
it "should be valid for same time as restriction" do
|
||||
valid!(:birth_time, Time.local_time(2000, 1, 1, 12, 0, 0))
|
||||
end
|
||||
end
|
||||
|
||||
describe "for datetime type" do
|
||||
before do
|
||||
Person.validates_datetime :birth_datetime, :on_or_before => DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 0)
|
||||
end
|
||||
|
||||
it "should not be valid for datetime after restriction" do
|
||||
invalid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 1), 'must be on or before 2010-01-01 12:00:00')
|
||||
end
|
||||
|
||||
it "should be valid for same datetime as restriction" do
|
||||
valid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 12, 0, 0))
|
||||
end
|
||||
|
||||
it "should not be valid for datetime before restriction" do
|
||||
valid!(:birth_datetime, DateTime.civil_from_format(:local, 2010, 1, 1, 11, 59, 59))
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user