Sha256: 0850d94d6efd18e48ea514f0a7c865b32bbf48160c5f3db40cbd7c6f0520cbd2

Contents?: true

Size: 1.7 KB

Versions: 7

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'

describe ValidatesTimeliness::Extensions::MultiparameterHandler do

  context "time column" 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 eq '2000-02-31 12:00:00'
    end
     
    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 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 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 eq '2000-02-31'
    end

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

  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

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/validates_timeliness-3.0.14/spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-3.0.14 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-3.0.13 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-3.0.12 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-3.0.11 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-3.0.10 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-3.0.9 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb