Sha256: def65d459d3325768a6da13824be8e7ba1084c4f52abb33f084690a9f3bd8fdd

Contents?: true

Size: 981 Bytes

Versions: 2

Compression:

Stored size: 981 Bytes

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "MongoDoc::ParentProxy" do
  class Parent
    include MongoDoc::Document
  end

  class Child
    include MongoDoc::Document
  end

  before do
    @parent = Parent.new
    @assoc_name = 'association'
  end

  subject do
    MongoDoc::ParentProxy.new(@parent, @assoc_name)
  end

  it "has the association name" do
    should respond_to(:assoc_name)
  end

  it "has a parent" do
    should respond_to(:_parent)
  end

  it "requires a parent" do
    expect do
      MongoDoc::ParentProxy.new(nil, @assoc_name)
    end.should raise_error
  end

  it "requires an association name" do
    expect do
      MongoDoc::ParentProxy.new(@parent, nil)
    end.should raise_error
  end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongodoc-0.2.1 spec/parent_proxy_spec.rb
mongodoc-0.2.0 spec/parent_proxy_spec.rb