public
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.