Sha256: dab15a4f833cdd73555f9681904b1e5276e3235fdce11b04d819c060d71ce329

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

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

describe "MongoDoc::Associations::DocumentProxy" do
  class Parent
    include MongoDoc::Document
  end

  class Child
    include MongoDoc::Document
  end

  let(:parent) { Parent.new }
  let(:name) {'association_name'}

  subject do
    MongoDoc::Associations::DocumentProxy.new(:assoc_name => name, :root => parent, :parent => parent, :assoc_class => Child)
  end

  describe "#build" do
    it "#build builds a new object" do
      Child.should === subject.build({})
    end
  end

  context "delegated to the document" do
    %w(id to_bson).each do |method|
      it "delegates #{method} to the document" do
        subject.stub(:document => stub)
        subject.document.should_receive(method)
        subject.send(method)
      end
    end
  end

  %w(_modifier_path= _selector_path=).each do |setter|
    describe "##{setter}" do
      it "delegates to the document with our assoc name" do
        subject.stub(:document => stub)
        subject.document.should_receive(setter).with("new.path.#{name}")
        MongoDoc::Associations::ProxyBase.stub(:is_document?).and_return(true)
        subject.send("#{setter}", 'new.path')
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
mongo_doc-0.6.1 spec/associations/document_proxy_spec.rb
mongo_doc-0.6.0 spec/associations/document_proxy_spec.rb
mongo_doc_rails2-0.6.1 spec/associations/document_proxy_spec.rb
mongo_doc-0.5.5 spec/associations/document_proxy_spec.rb