mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
Changed multiparameter implementation to be more like AR 3.1 but backwards compatible
Specs improved to not make direct call to multiparameter method.
This commit is contained in:
@@ -1,61 +1,34 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ValidatesTimeliness::Extensions::MultiparameterHandler do
|
||||
let(:employee) { Employee.new }
|
||||
|
||||
context "time column" do
|
||||
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
|
||||
it 'should return string value for invalid date portion' do
|
||||
employee = record_with_multiparameter_attribute(:birth_datetime, [2000, 2, 31, 12, 0, 0])
|
||||
employee.birth_datetime_before_type_cast.should == '2000-02-31 12:00:00'
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
it 'should return Time value for valid datetimes' do
|
||||
employee = record_with_multiparameter_attribute(:birth_datetime, [2000, 2, 28, 12, 0, 0])
|
||||
employee.birth_datetime_before_type_cast.should be_kind_of(Time)
|
||||
end
|
||||
end
|
||||
|
||||
context "date column" do
|
||||
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
|
||||
it 'should return string value for invalid date' do
|
||||
employee = record_with_multiparameter_attribute(:birth_date, [2000, 2, 31])
|
||||
employee.birth_date_before_type_cast.should == '2000-02-31'
|
||||
end
|
||||
|
||||
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
|
||||
it 'should return Date value for valid date' do
|
||||
employee = record_with_multiparameter_attribute(:birth_date, [2000, 2, 28])
|
||||
employee.birth_date_before_type_cast.should be_kind_of(Date)
|
||||
end
|
||||
end
|
||||
|
||||
def multiparameter_attribute(name, values)
|
||||
employee.send(:execute_callstack_for_multiparameter_attributes, name.to_s => values)
|
||||
def record_with_multiparameter_attribute(name, values)
|
||||
hash = {}
|
||||
values.each_with_index {|value, index| hash["#{name}(#{index+1}i)"] = value.to_s }
|
||||
Employee.new(hash)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user