Fix multiparameter extension to work with ActiveRecord 3.1

This commit is contained in:
Chris Griego 2011-12-29 21:49:58 -06:00 committed by Adam Meehan
parent 2702ec3266
commit 64a7440de4
2 changed files with 42 additions and 13 deletions

View File

@ -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?

View File

@ -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