mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
added :before option to add_formats to insert above existing format
This commit is contained in:
@@ -180,6 +180,10 @@ describe ValidatesTimeliness::Formats do
|
||||
validate('2.12am', :time).should be_false
|
||||
end
|
||||
|
||||
it "should raise error if format does not exist" do
|
||||
lambda { formats.remove_formats(:time, "ss:hh:nn") }.should raise_error()
|
||||
end
|
||||
|
||||
after do
|
||||
formats.time_formats << 'h.nn_ampm'
|
||||
end
|
||||
@@ -190,7 +194,7 @@ describe ValidatesTimeliness::Formats do
|
||||
formats.compile_format_expressions
|
||||
end
|
||||
|
||||
it "should add format to format array" do
|
||||
it "should add format to format array" do
|
||||
formats.add_formats(:time, "h o'clock")
|
||||
formats.time_formats.should include("h o'clock")
|
||||
end
|
||||
@@ -201,8 +205,24 @@ describe ValidatesTimeliness::Formats do
|
||||
validate("12 o'clock", :time).should be_true
|
||||
end
|
||||
|
||||
it "should add format before specified format and be higher precedence" do
|
||||
formats.add_formats(:time, "ss:hh:nn", :before => 'hh:nn:ss')
|
||||
validate("59:23:58", :time).should be_true
|
||||
time_array = formats.extract_date_time_values('59:23:58', :time)
|
||||
time_array.should == [nil,nil,nil,23,58,59,nil]
|
||||
end
|
||||
|
||||
it "should raise error if format exists" do
|
||||
lambda { formats.add_formats(:time, "hh:nn:ss") }.should raise_error()
|
||||
end
|
||||
|
||||
it "should raise error if format exists" do
|
||||
lambda { formats.add_formats(:time, "ss:hh:nn", :before => 'nn:hh:ss') }.should raise_error()
|
||||
end
|
||||
|
||||
after do
|
||||
formats.time_formats.delete("h o'clock")
|
||||
formats.time_formats.delete("ss:hh:nn")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -53,10 +53,12 @@ describe ValidatesTimeliness::Validations do
|
||||
@person.should be_valid
|
||||
end
|
||||
|
||||
it "should be valid with values before epoch" do
|
||||
@person.birth_date_and_time = "1960-01-31 12:12:12"
|
||||
@person.birth_date = "1960-01-31"
|
||||
@person.birth_time = "23:59"
|
||||
# What is going on? No fall back.
|
||||
it "should be valid with values before out of Time range" do
|
||||
@person.birth_date_and_time = "1890-01-31 12:12:12"
|
||||
@person.birth_date = "1890-01-31"
|
||||
@person.birth_time = "23:59:59"
|
||||
puts @person.errors.inspect
|
||||
@person.should be_valid
|
||||
end
|
||||
|
||||
@@ -74,7 +76,7 @@ describe ValidatesTimeliness::Validations do
|
||||
before :all do
|
||||
class DateTimeBeforeAfter < Person
|
||||
validates_timeliness_of :birth_date_and_time, :type => :datetime,
|
||||
:before => Time.now, :after => 1.day.ago
|
||||
:before => lambda { Time.now }, :after => lambda { 1.day.ago}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -111,8 +113,8 @@ describe ValidatesTimeliness::Validations do
|
||||
before :all do
|
||||
class DateTimeOnOrBeforeAndAfter < Person
|
||||
validates_timeliness_of :birth_date_and_time, :type => :datetime,
|
||||
:on_or_before => Time.now.at_midnight,
|
||||
:on_or_after => 1.day.ago
|
||||
:on_or_before => lambda { Time.now.at_midnight },
|
||||
:on_or_after => lambda { 1.day.ago }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -311,8 +313,12 @@ describe ValidatesTimeliness::Validations do
|
||||
describe "with mixed value and restriction types" do
|
||||
before :all do
|
||||
class MixedBeforeAndAfter < Person
|
||||
validates_timeliness_of :birth_date_and_time, :before => Date.new(2008,1,2), :after => lambda { Time.mktime(2008, 1, 1) }
|
||||
validates_timeliness_of :birth_date, :type => :date, :on_or_before => Time.mktime(2008, 1, 2), :on_or_after => :birth_date_and_time
|
||||
validates_timeliness_of :birth_date_and_time,
|
||||
:before => Date.new(2008,1,2),
|
||||
:after => lambda { Time.mktime(2008, 1, 1) }
|
||||
validates_timeliness_of :birth_date, :type => :date,
|
||||
:on_or_before => lambda { Time.mktime(2008, 1, 2) },
|
||||
:on_or_after => :birth_date_and_time
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user