Skip to content

Instantly share code, notes, and snippets.

@mkocher
Created January 14, 2011 17:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkocher/779930 to your computer and use it in GitHub Desktop.
Save mkocher/779930 to your computer and use it in GitHub Desktop.
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