Sha256: 0acd84e031ab8978ebaf41a1e66c518273f7743d48ea618fd691a3a436e5fe6f

Contents?: true

Size: 1012 Bytes

Versions: 1

Compression:

Stored size: 1012 Bytes

Contents

share_examples_for 'An ObjectId Type' do
  describe '#typecast' do
    it 'should return nil when given nil' do
      @property.typecast(nil).should be_nil
    end

    it 'should return BSON::ObjectId when given a valid string' do
      value = '4d7b57618f9f1f12bd000002'
      loaded = @property.typecast(value)
      loaded.should == ::BSON::ObjectId.from_string(value)
    end

    it 'should raise BSON::InvalidObjectId when give an invalid string' do
      lambda {
        @property.typecast('#invalid#')
      }.should raise_error(::BSON::InvalidObjectId)
    end

    it 'should return the argument when given a BSON::ObjectId' do
      mongo_id = ::BSON::ObjectId.new
      loaded = @property.typecast(mongo_id)
      loaded.should be(mongo_id)
    end

    it 'should raise an error when given anything else' do
      [ 0, 1, Object.new, true, false, [], {} ].each do |value|
        lambda {
          @property.typecast(value)
        }.should raise_error(ArgumentError)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dm-mongo-adapter-0.6.0 spec/public/shared/object_id_shared_spec.rb