mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
ignore_usec option added back
This commit is contained in:
parent
b2d1dcdd3f
commit
8aa26a7898
@ -13,6 +13,11 @@ module ValidatesTimeliness
|
|||||||
when :datetime
|
when :datetime
|
||||||
value.to_time
|
value.to_time
|
||||||
end
|
end
|
||||||
|
if options[:ignore_usec] && value.is_a?(Time)
|
||||||
|
ValidatesTimeliness::Parser.make_time(Array(value).reverse[4..9])
|
||||||
|
else
|
||||||
|
value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def dummy_time(value)
|
def dummy_time(value)
|
||||||
|
|||||||
@ -8,6 +8,8 @@ describe ValidatesTimeliness::Conversion do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#type_cast_value" do
|
describe "#type_cast_value" do
|
||||||
|
let(:options) { Hash.new }
|
||||||
|
|
||||||
describe "for date type" do
|
describe "for date type" do
|
||||||
it "should return same value for date value" do
|
it "should return same value for date value" do
|
||||||
type_cast_value(Date.new(2010, 1, 1), :date).should == Date.new(2010, 1, 1)
|
type_cast_value(Date.new(2010, 1, 1), :date).should == Date.new(2010, 1, 1)
|
||||||
@ -54,6 +56,15 @@ describe ValidatesTimeliness::Conversion do
|
|||||||
type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56), :datetime).should == Time.utc(2010, 1, 1, 12, 34, 56)
|
type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56), :datetime).should == Time.utc(2010, 1, 1, 12, 34, 56)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "ignore_usec option" do
|
||||||
|
let(:options) { {:ignore_usec => true} }
|
||||||
|
|
||||||
|
it "should ignore usec on time values when evaluated" do
|
||||||
|
value = Time.utc(2010, 1, 1, 12, 34, 56, 10000)
|
||||||
|
type_cast_value(value, :datetime).should == Time.utc(2010, 1, 1, 12, 34, 56)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#dummy_time" do
|
describe "#dummy_time" do
|
||||||
|
|||||||
@ -86,6 +86,17 @@ describe ValidatesTimeliness::Validator do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe ":ignore_usec option" do
|
||||||
|
it "should not be valid when usec values don't match and option is false" do
|
||||||
|
Person.validates_datetime :birth_datetime, :on_or_before => Time.utc(2010,1,2,3,4,5), :ignore_usec => false
|
||||||
|
invalid!(:birth_datetime, Time.utc(2010,1,2,3,4,5,10000))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be valid when usec values dont't match and option is true" do
|
||||||
|
Person.validates_datetime :birth_datetime, :on_or_before => Time.utc(2010,1,2,3,4,5), :ignore_usec => true
|
||||||
|
valid!(:birth_datetime, Time.utc(2010,1,2,3,4,5,10000))
|
||||||
|
end
|
||||||
|
end
|
||||||
describe "restriction value errors" do
|
describe "restriction value errors" do
|
||||||
let(:person) { Person.new(:birth_date => Date.today) }
|
let(:person) { Person.new(:birth_date => Date.today) }
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user