Sha256: 815b1a92729b93c89f291793c0f6aa449801bb234ac303a813a76bb77ff11468

Contents?: true

Size: 1.34 KB

Versions: 14

Compression:

Stored size: 1.34 KB

Contents

require 'spec_helper'

describe Ardm::Property::DateTime do
  let(:name)          { :created_at }
  let(:type)          { described_class }
  let(:options)       { {} }
  let(:value)         { DateTime.now }
  let(:other_value)   { DateTime.now + 15 }
  let(:invalid_value) { 1 }
  let(:model) { Blog::Article }
  let(:property) { type.new(model, name, options) }

  it_should_behave_like 'A semipublic Property'

  describe '#typecast' do
    describe 'and value given as a hash with keys like :year, :month, etc' do
      it 'builds a DateTime instance from hash values' do
        result = property.typecast(
          :year  => '2006',
          :month => '11',
          :day   => '23',
          :hour  => '12',
          :min   => '0',
          :sec   => '0'
        )

        expect(result).to be_kind_of(DateTime)
        expect(result.year).to eql(2006)
        expect(result.month).to eql(11)
        expect(result.day).to eql(23)
        expect(result.hour).to eql(12)
        expect(result.min).to eql(0)
        expect(result.sec).to eql(0)
      end
    end

    describe 'and value is a string' do
      it 'parses the string' do
        expect(property.typecast('Dec, 2006').month).to eq(12)
      end
    end

    it 'does not typecast non-datetime values' do
      expect(property.typecast('not-datetime')).to eql('not-datetime')
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ardm-0.4.0.ar427 spec/semipublic/property/date_time_spec.rb
ardm-0.4.0 spec/semipublic/property/date_time_spec.rb
ardm-0.3.2 spec/semipublic/property/date_time_spec.rb
ardm-0.3.1 spec/semipublic/property/date_time_spec.rb
ardm-0.3.0 spec/semipublic/property/date_time_spec.rb
ardm-0.2.7 spec/semipublic/property/date_time_spec.rb
ardm-0.2.6 spec/semipublic/property/date_time_spec.rb
ardm-0.2.5 spec/semipublic/property/date_time_spec.rb
ardm-0.2.4 spec/semipublic/property/date_time_spec.rb
ardm-0.2.3 spec/semipublic/property/date_time_spec.rb
ardm-0.2.2 spec/semipublic/property/date_time_spec.rb
ardm-0.2.1 spec/semipublic/property/date_time_spec.rb
ardm-0.2.0 spec/semipublic/property/date_time_spec.rb
ardm-0.1.0 spec/semipublic/property/date_time_spec.rb