mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
:between option fix and spec
This commit is contained in:
parent
12b59739ad
commit
70b16b875c
@ -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
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user