Sha256: 7329f1ec55629cc425a8c5d99ebc36cc08a40373710a6f90370aa1b1a12bbbea

Contents?: true

Size: 1.26 KB

Versions: 6

Compression:

Stored size: 1.26 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'spec_helper'))

describe DataMapper::Property::DateTime do
  before :all do
    @name  = :created_at
    @type  = DataMapper::Property::DateTime
    @value = DateTime.now
    @other_value = DateTime.now+15
    @invalid_value = 1
  end

  it_should_behave_like "A semipublic Property"

  describe '#typecast_to_primitive' 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'
        )

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

    describe 'and value is a string' do
      it 'parses the string' do
        @property.typecast('Dec, 2006').month.should == 12
      end
    end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dm-core-1.0.2 spec/semipublic/property/date_time_spec.rb
dm-core-1.0.1 spec/semipublic/property/date_time_spec.rb
dm-core-1.0.0 spec/semipublic/property/date_time_spec.rb
dm-core-1.0.0.rc3 spec/semipublic/property/date_time_spec.rb
dm-core-1.0.0.rc2 spec/semipublic/property/date_time_spec.rb
dm-core-1.0.0.rc1 spec/semipublic/property/date_time_spec.rb