test/unit/test_document.rb in mongo_mapper-unstable-2010.1.6 vs test/unit/test_document.rb in mongo_mapper-unstable-2010.1.12
- old
+ new
@@ -5,18 +5,18 @@
context "The Document Class" do
setup do
@document = Doc()
end
+ should "return false for embeddable" do
+ Doc().embeddable?.should be_false
+ end
+
should "have logger method" do
@document.logger.should == MongoMapper.logger
@document.logger.should be_instance_of(Logger)
end
-
- should "track its descendants" do
- MongoMapper::Document.descendants.should include(@document)
- end
should "use default database by default" do
@document.database.should == MongoMapper.database
end
@@ -63,68 +63,56 @@
should "allow setting the collection name" do
@document.set_collection_name('foobar')
@document.collection.should be_instance_of(Mongo::Collection)
@document.collection.name.should == 'foobar'
end
-
- should 'allow extensions to Document to be appended' do
- module Extension; def test_this_extension; end end
- MongoMapper::Document.append_extensions(Extension)
- article = Doc()
- article.should respond_to(:test_this_extension)
- end
-
- should 'add appended extensions to classes that include Document before they are added' do
- module Extension; def test_this_extension; end end
- article = Doc()
- MongoMapper::Document.append_extensions(Extension)
- article.should respond_to(:test_this_extension)
- end
-
- should 'allow inclusions to Document to be appended' do
- module Inclusion; def test_this_inclusion; end end
- MongoMapper::Document.append_inclusions(Inclusion)
- article = Doc()
- article.new.should respond_to(:test_this_inclusion)
- end
-
- should 'add appended inclusions to classes that include Document before they are added' do
- module Inclusion; def test_this_inclusion; end end
- article = Doc()
- MongoMapper::Document.append_inclusions(Inclusion)
- article.new.should respond_to(:test_this_inclusion)
- end
end # Document class
context "Documents that inherit from other documents" do
should "default collection name to inherited class" do
Message.collection_name.should == 'messages'
Enter.collection_name.should == 'messages'
Exit.collection_name.should == 'messages'
Chat.collection_name.should == 'messages'
end
-
+
should "default associations to inherited class" do
- Message.associations.keys.should include("room")
- Enter.associations.keys.should include("room")
- Exit.associations.keys.should include("room")
- Chat.associations.keys.should include("room")
- end
-
- should "track subclasses" do
- Message.subclasses.should == [Enter, Exit, Chat]
+ Message.associations.keys.should include("room")
+ Enter.associations.keys.should include("room")
+ Exit.associations.keys.should include("room")
+ Chat.associations.keys.should include("room")
end
end
+
+ context "descendants" do
+ should "default to nil" do
+ Enter.descendants.should be_nil
+ end
+ should "be recorded" do
+ Message.descendants.should == [Enter, Exit, Chat]
+ end
+ end
+
context "An instance of a document" do
setup do
@document = Doc do
key :name, String
key :age, Integer
end
end
+ should "create id during initialization" do
+ @document.new._id.should be_instance_of(Mongo::ObjectID)
+ end
+
+ should "have to_param that is string representation of id" do
+ doc = @document.new(:id => Mongo::ObjectID.new)
+ doc.to_param.should == doc.id.to_s
+ doc.to_param.should be_instance_of(String)
+ end
+
should "have access to logger" do
doc = @document.new
doc.logger.should == @document.logger
doc.logger.should be_instance_of(Logger)
end
@@ -147,14 +135,10 @@
doc = @document.new
doc.window.should == WindowSize.new(600, 480)
end
context "root document" do
- should "have a nil _root_document" do
- @document.new._root_document.should be_nil
- end
-
should "set self to the root document on embedded documents" do
klass = Doc()
pets = EDoc()
klass.many :pets, :class => pets
@@ -176,11 +160,11 @@
doc.new?.should be_true
end
end
context "clone" do
- should "not set the id" do
+ should "be new" do
doc = @document.create(:name => "foo", :age => 27)
clone = doc.clone
clone.should be_new
end
@@ -188,9 +172,14 @@
doc = @document.create(:name => "foo", :age => 27)
clone = doc.clone
clone.name.should == "foo"
clone.age.should == 27
end
+ end
+
+ should "call inspect on the document's attributes instead of to_s when inspecting the document" do
+ doc = @document.new(:animals => %w(dog cat))
+ doc.inspect.should include(%(animals: ["dog", "cat"]))
end
context "equality" do
setup do
@oid = Mongo::ObjectID.new