:between option fix and spec

This commit is contained in:
Adam Meehan 2010-08-01 20:54:50 +10:00
parent 12b59739ad
commit 70b16b875c
2 changed files with 21 additions and 1 deletions

View File

@ -22,7 +22,7 @@ module ValidatesTimeliness
if range = options.delete(:between) if range = options.delete(:between)
raise ArgumentError, ":between must be a Range or an Array" unless range.is_a?(Range) || range.is_a?(Array) raise ArgumentError, ":between must be a Range or an Array" unless range.is_a?(Range) || range.is_a?(Array)
options[:on_or_after], options[:on_or_before] = range.begin, range.end options[:on_or_after], options[:on_or_before] = range.first, range.last
end end
super super
end end

View File

@ -46,4 +46,24 @@ describe ValidatesTimeliness::Validator do
valid!(:birth_date, '') valid!(:birth_date, '')
end end
end end
describe ":between option" do
describe "array value" do
it 'should be split option into :on_or_after and :on_or_before values' do
on_or_after, on_or_before = Date.new(2010,1,1), Date.new(2010,1,2)
Person.validates_time :birth_date, :between => [on_or_after, on_or_before]
Person.validators.first.options[:on_or_after].should == on_or_after
Person.validators.first.options[:on_or_before].should == on_or_before
end
end
describe "range value" do
it 'should be split option into :on_or_after and :on_or_before values' do
on_or_after, on_or_before = Date.new(2010,1,1), Date.new(2010,1,2)
Person.validates_time :birth_date, :between => on_or_after..on_or_before
Person.validators.first.options[:on_or_after].should == on_or_after
Person.validators.first.options[:on_or_before].should == on_or_before
end
end
end
end end