Created
January 14, 2011 17:34
-
-
Save mkocher/779930 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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