Sha256: ffa4d176d2db68c5158a23d430668f31ab58cb4bb770ff8f48cc614bf3b20b3f

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

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

describe DataMapper::Property::Date do
  before :all do
    @name  = :created_on
    @type  = DataMapper::Property::Date
    @value = Date.today
    @other_value = Date.today+1
    @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 Date instance from hash values' do
        result = @property.typecast(
          'year'  => '2007',
          'month' => '3',
          'day'   => '25'
        )

        result.should be_kind_of(Date)
        result.year.should eql(2007)
        result.month.should eql(3)
        result.day.should eql(25)
      end
    end

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

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