mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
format option added back
This commit is contained in:
parent
8aa26a7898
commit
716f9e4f2e
@ -56,7 +56,7 @@ module ValidatesTimeliness
|
|||||||
|
|
||||||
def parse(value)
|
def parse(value)
|
||||||
if ValidatesTimeliness.use_plugin_parser
|
if ValidatesTimeliness.use_plugin_parser
|
||||||
ValidatesTimeliness::Parser.parse(value, @type, :timezone_aware => @timezone_aware, :strict => false)
|
ValidatesTimeliness::Parser.parse(value, @type, :timezone_aware => @timezone_aware, :format => options[:format], :strict => false)
|
||||||
else
|
else
|
||||||
@timezone_aware ? Time.zone.parse(value) : value.to_time(ValidatesTimeliness.default_timezone)
|
@timezone_aware ? Time.zone.parse(value) : value.to_time(ValidatesTimeliness.default_timezone)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -97,6 +97,27 @@ describe ValidatesTimeliness::Validator do
|
|||||||
valid!(:birth_datetime, Time.utc(2010,1,2,3,4,5,10000))
|
valid!(:birth_datetime, Time.utc(2010,1,2,3,4,5,10000))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe ":format option" do
|
||||||
|
before(:all) do
|
||||||
|
ValidatesTimeliness.use_plugin_parser = true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be valid when value matches format" do
|
||||||
|
Person.validates_date :birth_date, :format => 'dd-mm-yyyy'
|
||||||
|
valid!(:birth_date, '11-12-1913')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not be valid when value does not match format" do
|
||||||
|
Person.validates_date :birth_date, :format => 'dd/mm/yyyy'
|
||||||
|
invalid!(:birth_date, '1913-12-11', 'is not a valid date')
|
||||||
|
end
|
||||||
|
|
||||||
|
after(:all) do
|
||||||
|
ValidatesTimeliness.use_plugin_parser = false
|
||||||
|
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