mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
ignore time part for dates in validation
This commit is contained in:
parent
eafce02a73
commit
20ed2b1633
@ -34,6 +34,10 @@ module ValidatesTimeliness
|
|||||||
if type == :time
|
if type == :time
|
||||||
# Rails dummy time date part is defined as 2000-01-01
|
# Rails dummy time date part is defined as 2000-01-01
|
||||||
time_array[0..2] = 2000, 1, 1
|
time_array[0..2] = 2000, 1, 1
|
||||||
|
elsif type == :date
|
||||||
|
# throw away time part and check date
|
||||||
|
time_array[3..5] = 0, 0, 0
|
||||||
|
Date.new(*time_array[0..2])
|
||||||
else
|
else
|
||||||
# Date.new enforces days per month, unlike Time
|
# Date.new enforces days per month, unlike Time
|
||||||
Date.new(*time_array[0..2])
|
Date.new(*time_array[0..2])
|
||||||
|
|||||||
@ -146,6 +146,12 @@ describe ValidatesTimeliness::Validations do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "for date type" do
|
describe "for date type" do
|
||||||
|
it "should validate with invalid time part" do
|
||||||
|
person = BasicValidation.new
|
||||||
|
person.birth_date = "1980-01-01 25:61:61"
|
||||||
|
person.should be_valid
|
||||||
|
end
|
||||||
|
|
||||||
describe "with before and after restrictions" do
|
describe "with before and after restrictions" do
|
||||||
before :all do
|
before :all do
|
||||||
class DateBeforeAfter < Person
|
class DateBeforeAfter < Person
|
||||||
@ -210,6 +216,12 @@ describe ValidatesTimeliness::Validations do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "for time type" do
|
describe "for time type" do
|
||||||
|
it "should validate with invalid date part" do
|
||||||
|
person = BasicValidation.new
|
||||||
|
person.birth_time = "1980-02-30 23:59:59"
|
||||||
|
person.should be_valid
|
||||||
|
end
|
||||||
|
|
||||||
describe "with before and after restrictions" do
|
describe "with before and after restrictions" do
|
||||||
before :all do
|
before :all do
|
||||||
class TimeBeforeAfter < Person
|
class TimeBeforeAfter < Person
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user