Sha256: ac17d6ccbec5fc86bb21d28cc65cd1ca420c577e1a38c5265f04c4b49aee2828

Contents?: true

Size: 1.77 KB

Versions: 12

Compression:

Stored size: 1.77 KB

Contents

require 'spec_helper'

describe MongoDoc::References do
  class Address
    include MongoDoc::Document

    attr_accessor :state
  end

  context "Simple Reference" do
    class Person
      include MongoDoc::Document

      references :address
    end

    subject { Person.new }

    context "Object accessor" do
      it { should respond_to(:address) }
      it { should respond_to(:address=) }

      it "is not part of the persistent key set" do
        Person._keys.should_not include(:address)
      end
    end

    context "Object Id accessor" do
      it { should respond_to(:address_id) }
      it { should respond_to(:address_id=) }

      it "is part of the persistent key set" do
        Person._keys.should include(:address_id)
      end
    end
  end

  context "Named Reference" do
    class Person
      include MongoDoc::Document

      references :address, :as => :work_address
    end

    subject { Person.new }

    context "Object accessor" do
      it { should respond_to(:work_address) }
      it { should respond_to(:work_address=) }

      it "is not part of the persistent key set" do
        Person._keys.should_not include(:work_address)
      end
    end

    context "Object Id accessor" do
      it { should respond_to(:work_address_id) }
      it { should respond_to(:work_address_id=) }

      it "is part of the persistent key set" do
        Person._keys.should include(:work_address_id)
      end
    end
  end

  describe "setting the id" do
    class Person
      include MongoDoc::Document

      references :address
    end

    let(:address) { Address.new(:_id => BSON::ObjectID.new) }
    let(:person) { Person.new }

    it "resets the object to nil" do
      person.address = address
      person.address_id = nil
      person.address.should be_nil
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
mongo_doc-0.6.17 spec/references_spec.rb
mongo_doc-0.6.16 spec/references_spec.rb
mongo_doc-0.6.15 spec/references_spec.rb
mongo_doc-0.6.14 spec/references_spec.rb
mongo_doc-0.6.13 spec/references_spec.rb
mongo_doc-0.6.12 spec/references_spec.rb
mongo_doc-0.6.11 spec/references_spec.rb
mongo_doc-0.6.10 spec/references_spec.rb
mongo_doc-0.6.9 spec/references_spec.rb
mongo_doc-0.6.8 spec/references_spec.rb
mongo_doc-0.6.7 spec/references_spec.rb
mongo_doc-0.6.6 spec/references_spec.rb