mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 07:16:41 +00:00
Fix multiparameter extension to not allow partial dates as per ActiveRecord implementation.
This commit is contained in:
@@ -3,26 +3,36 @@ require 'spec_helper'
|
||||
describe ValidatesTimeliness::Extensions::MultiparameterHandler do
|
||||
|
||||
context "time column" do
|
||||
it 'should return string value for invalid date portion' do
|
||||
it 'should assign a 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'
|
||||
employee.birth_datetime_before_type_cast.should eq '2000-02-31 12:00:00'
|
||||
end
|
||||
|
||||
it 'should return Time value for valid datetimes' do
|
||||
it 'should assign a 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)
|
||||
employee.birth_datetime_before_type_cast.should eq Time.local(2000, 2, 28, 12, 0, 0)
|
||||
end
|
||||
|
||||
it 'should assign a string value for incomplete time' do
|
||||
employee = record_with_multiparameter_attribute(:birth_datetime, [2000, nil, nil])
|
||||
employee.birth_datetime_before_type_cast.should eq '2000-00-00'
|
||||
end
|
||||
end
|
||||
|
||||
context "date column" do
|
||||
it 'should return string value for invalid date' do
|
||||
it 'should assign a 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'
|
||||
employee.birth_date_before_type_cast.should eq '2000-02-31'
|
||||
end
|
||||
|
||||
it 'should return Date value for valid date' do
|
||||
it 'should assign a 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)
|
||||
employee.birth_date_before_type_cast.should eq Date.new(2000, 2, 28)
|
||||
end
|
||||
|
||||
it 'should assign a string value for incomplete date' do
|
||||
employee = record_with_multiparameter_attribute(:birth_date, [2000, nil, nil])
|
||||
employee.birth_date_before_type_cast.should eq '2000-00-00'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user