mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
Fixed :between option.
This commit is contained in:
parent
01d1dc7c5e
commit
d14ae09820
@ -27,12 +27,13 @@ module ValidatesTimeliness
|
||||
def initialize(options)
|
||||
@type = options.delete(:type) || :datetime
|
||||
@allow_nil, @allow_blank = options.delete(:allow_nil), options.delete(:allow_blank)
|
||||
@restrictions_to_check = RESTRICTIONS.keys & options.keys
|
||||
|
||||
if range = options.delete(:between)
|
||||
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.first, range.last
|
||||
end
|
||||
|
||||
@restrictions_to_check = RESTRICTIONS.keys & options.keys
|
||||
super
|
||||
end
|
||||
|
||||
|
||||
@ -70,18 +70,26 @@ describe ValidatesTimeliness::Validator 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.validates_date :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
|
||||
invalid!(:birth_date, on_or_after - 1, "must be on or after 2010-01-01")
|
||||
invalid!(:birth_date, on_or_before + 1, "must be on or before 2010-01-02")
|
||||
valid!(:birth_date, on_or_after)
|
||||
valid!(:birth_date, 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.validates_date :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
|
||||
invalid!(:birth_date, on_or_after - 1, "must be on or after 2010-01-01")
|
||||
invalid!(:birth_date, on_or_before + 1, "must be on or before 2010-01-02")
|
||||
valid!(:birth_date, on_or_after)
|
||||
valid!(:birth_date, on_or_before)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user