format option added back

This commit is contained in:
Adam Meehan 2010-09-17 13:45:56 +10:00
parent 8aa26a7898
commit 716f9e4f2e
2 changed files with 22 additions and 1 deletions

View File

@ -56,7 +56,7 @@ module ValidatesTimeliness
def parse(value)
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
@timezone_aware ? Time.zone.parse(value) : value.to_time(ValidatesTimeliness.default_timezone)
end

View File

@ -97,6 +97,27 @@ describe ValidatesTimeliness::Validator do
valid!(:birth_datetime, Time.utc(2010,1,2,3,4,5,10000))
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
let(:person) { Person.new(:birth_date => Date.today) }