Sha256: 4b7bbb64cb8818c5d000bb2f5d8ce36bf2ef8605c95993e12c5e34a4d08c4bc3

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 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'}

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

  it "has the association name" do
    subject.assoc_name.should == name
  end

  it "has the parent" do
    subject._parent.should == parent
  end

  it "has the root" do
    subject._root.should == parent
  end

  it "has the association class" do
    subject.assoc_class.should == Child
  end

  it "inserts the association name the _path_to_root" do
    subject._path_to_root(Child.new, :name1 => 'value1', :name2 => 'value2').should == {"#{name}.name1" => 'value1', "#{name}.name2" => "value2"}
  end

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

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
mongo_doc-0.4.2 spec/associations/document_proxy_spec.rb
mongo_doc-0.4.1 spec/associations/document_proxy_spec.rb
mongo_doc-0.4.0 spec/associations/document_proxy_spec.rb
mongo_doc-0.3.2 spec/associations/document_proxy_spec.rb
mongo_doc-0.3.1 spec/associations/document_proxy_spec.rb
mongo_doc-0.3.0 spec/associations/document_proxy_spec.rb
mongodoc-0.2.4 spec/associations/document_proxy_spec.rb
mongodoc-0.2.2 spec/associations/document_proxy_spec.rb