mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
Fix multiparameter extension to work with ActiveRecord 3.1
This commit is contained in:
parent
2702ec3266
commit
64a7440de4
@ -39,6 +39,7 @@ module ValidatesTimeliness
|
||||
callstack.each do |name, values_with_empty_parameters|
|
||||
begin
|
||||
klass = (self.class.reflect_on_aggregation(name.to_sym) || column_for_attribute(name)).klass
|
||||
values_with_empty_parameters = values_with_empty_parameters.to_a.sort_by { |v| v.first }.map { |v| v.last } if Hash === values_with_empty_parameters
|
||||
values = values_with_empty_parameters.reject { |v| v.nil? }
|
||||
|
||||
if values.empty?
|
||||
|
||||
@ -4,26 +4,54 @@ describe ValidatesTimeliness::Extensions::MultiparameterHandler do
|
||||
let(:employee) { Employee.new }
|
||||
|
||||
context "time column" do
|
||||
it 'should return string value for invalid date portion' do
|
||||
multiparameter_attribute(:birth_datetime, [2000, 2, 31, 12, 0, 0])
|
||||
employee.birth_datetime_before_type_cast.should == '2000-02-31 12:00:00'
|
||||
context "given an array callstack as in Rails 3.0 and before" do
|
||||
it 'should return string value for invalid date portion' do
|
||||
multiparameter_attribute(:birth_datetime, [2000, 2, 31, 12, 0, 0])
|
||||
employee.birth_datetime_before_type_cast.should == '2000-02-31 12:00:00'
|
||||
end
|
||||
|
||||
it 'should return Time value for valid datetimes' do
|
||||
multiparameter_attribute(:birth_datetime, [2000, 2, 28, 12, 0, 0])
|
||||
employee.birth_datetime_before_type_cast.should be_kind_of(Time)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should return Time value for valid datetimes' do
|
||||
multiparameter_attribute(:birth_datetime, [2000, 2, 28, 12, 0, 0])
|
||||
employee.birth_datetime_before_type_cast.should be_kind_of(Time)
|
||||
|
||||
context "given a hash callstack as in Rails 3.1+" do
|
||||
it 'should return string value for invalid date portion' do
|
||||
multiparameter_attribute(:birth_datetime, { 1 => 2000, 2 => 2, 3 => 31, 4 => 12, 5 => 0, 6 => 0 })
|
||||
employee.birth_datetime_before_type_cast.should == '2000-02-31 12:00:00'
|
||||
end
|
||||
|
||||
it 'should return Time value for valid datetimes' do
|
||||
multiparameter_attribute(:birth_datetime, { 1 => 2000, 2 => 2, 3 => 28, 4 => 12, 5 => 0, 6 => 0 })
|
||||
employee.birth_datetime_before_type_cast.should be_kind_of(Time)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "date column" do
|
||||
it 'should return string value for invalid date' do
|
||||
multiparameter_attribute(:birth_date, [2000, 2, 31])
|
||||
employee.birth_date_before_type_cast.should == '2000-02-31'
|
||||
context "given an array callstack as in Rails 3.0 and before" do
|
||||
it 'should return string value for invalid date' do
|
||||
multiparameter_attribute(:birth_date, [2000, 2, 31])
|
||||
employee.birth_date_before_type_cast.should == '2000-02-31'
|
||||
end
|
||||
|
||||
it 'should return Date value for valid date' do
|
||||
multiparameter_attribute(:birth_date, [2000, 2, 28])
|
||||
employee.birth_date_before_type_cast.should be_kind_of(Date)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should return Date value for valid date' do
|
||||
multiparameter_attribute(:birth_date, [2000, 2, 28])
|
||||
employee.birth_date_before_type_cast.should be_kind_of(Date)
|
||||
context "given a hash callstack as in Rails 3.1+" do
|
||||
it 'should return string value for invalid date' do
|
||||
multiparameter_attribute(:birth_date, { 1 => 2000, 2 => 2, 3 => 31 })
|
||||
employee.birth_date_before_type_cast.should == '2000-02-31'
|
||||
end
|
||||
|
||||
it 'should return Date value for valid date' do
|
||||
multiparameter_attribute(:birth_date, { 1 => 2000, 2 => 2, 3 => 28 })
|
||||
employee.birth_date_before_type_cast.should be_kind_of(Date)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user