Create a gist now

Instantly share code, notes, and snippets.

require 'spec_helper'
class ::ParentDoc
include MongoMapper::Document
many :embedded_docs
many :child_docs
key :name, String
end
class ::EmbeddedDoc
include MongoMapper::EmbeddedDocument
key :name, String
end
class ::ChildDoc
include MongoMapper::Document
key :name, String
end
describe "mongo mapper defaulting of embeded documents" do
before do
ParentDoc.collection.drop
Movie.collection.drop
end
it "defaults the list to empty if the key doesn't exist" do
parent = ParentDoc.new(:name => "The Parent")
parent.save!
parent.embedded_docs.should == []
end
describe "mongo mapper has problems if the key exists" do
context "with an embedded document proxy " do
it "blows up" do
ParentDoc.collection.insert("name" => "Nully", "embedded_docs" => nil)
lambda {ParentDoc.find_by_name("Nully") }.should raise_error # current (correct?) behavior...
end
end
context "with a non-embedded document proxy" do
it "blows up" do
ParentDoc.collection.insert("name" => "Nully", "child_docs" => nil)
lambda { ParentDoc.find_by_name("Nully") }.should raise_error # current (correct?) behavior
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment