Sha256: 9a9bd0815c615936afa445530c498beb4c591d5113d3eadfea1237556b8a0f70

Contents?: true

Size: 1.53 KB

Versions: 18

Compression:

Stored size: 1.53 KB

Contents

RSpec.describe 'ValidatesTimeliness::Extensions::MultiparameterHandler' do

  context "time column" do
    it 'should be nil invalid date portion' do
      employee = record_with_multiparameter_attribute(:birth_datetime, [2000, 2, 31, 12, 0, 0])
      expect(employee.birth_datetime).to be_nil
    end
     
    it 'should assign a Time value for valid datetimes' do
      employee = record_with_multiparameter_attribute(:birth_datetime, [2000, 2, 28, 12, 0, 0])
      expect(employee.birth_datetime).to eq Time.zone.local(2000, 2, 28, 12, 0, 0)
    end

    it 'should be nil for incomplete date portion' do
      employee = record_with_multiparameter_attribute(:birth_datetime, [2000, nil, nil])
      expect(employee.birth_datetime).to be_nil
    end
  end

  context "date column" do
    it 'should assign nil for invalid date' do
      employee = record_with_multiparameter_attribute(:birth_date, [2000, 2, 31])
      expect(employee.birth_date).to be_nil
    end

    it 'should assign a Date value for valid date' do
      employee = record_with_multiparameter_attribute(:birth_date, [2000, 2, 28])
      expect(employee.birth_date).to eq Date.new(2000, 2, 28)
    end

    it 'should assign hash values for incomplete date' do
      employee = record_with_multiparameter_attribute(:birth_date, [2000, nil, nil])
      expect(employee.birth_date).to be_nil
    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

18 entries across 18 versions & 1 rubygems

Version Path
validates_timeliness-8.0.0.beta1 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-7.0.0 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-7.0.0.beta2 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-5.0.1 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-6.0.1 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-7.0.0.beta1 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-6.0.0 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-6.0.0.beta2 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-6.0.0.beta1 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-6.0.0.alpha1 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-5.0.0 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-5.0.0.beta2 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-5.0.0.beta1 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-5.0.0.alpha5 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-5.0.0.alpha4 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-5.0.0.alpha3 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-5.0.0.alpha2 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
validates_timeliness-5.0.0.alpha1 spec/validates_timeliness/extensions/multiparameter_handler_spec.rb