Sha256: 9e20b64fac5a0cd34bb5aafcff9c2b0cf7de3e63a43bbf9d531ebefed13cc1f5

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

Contents

require 'helper'

describe Toy::Identity::ObjectIdKeyFactory do
  uses_constants('User')

  it "should use BSON::ObjectId as key_type" do
    Toy::Identity::ObjectIdKeyFactory.new.key_type.should be(BSON::ObjectId)
  end

  it "should use object id for next key" do
    key = Toy::Identity::ObjectIdKeyFactory.new.next_key(nil)
    key.should be_instance_of(BSON::ObjectId)
  end

  describe "Declaring key to be object_id" do
    before(:each) do
      User.key(Toy::Identity::ObjectIdKeyFactory.new)
      User.attribute(:name, String)
    end

    it "returns BSON::ObjectId as .key_type" do
      User.key_type.should be(BSON::ObjectId)
    end

    it "sets id attribute to BSON::ObjectId type" do
      User.attributes['id'].type.should be(BSON::ObjectId)
    end

    it "correctly stores id in database" do
      user = User.create(:name => 'John')
      user.id.should be_instance_of(BSON::ObjectId)
      key = user.adapter.client.find_one(user.id)['_id']
      key.should be_instance_of(BSON::ObjectId)
      user.id.should == key
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
toystore-mongo-0.12.0 spec/toy/identity/object_id_key_factory_spec.rb
toystore-mongo-0.11.0 spec/toy/identity/object_id_key_factory_spec.rb
toystore-mongo-0.10.0 spec/toy/identity/object_id_key_factory_spec.rb
toystore-mongo-0.9.0 spec/toy/identity/object_id_key_factory_spec.rb