Skip to content

Commit

Permalink
Minor: Reordered and renamed several of the document tests. Also move…
Browse files Browse the repository at this point in the history
…d some stuff into their proper home.
  • Loading branch information
jnunemaker committed Dec 31, 2009
1 parent df3c5d6 commit 96f1752
Show file tree
Hide file tree
Showing 4 changed files with 628 additions and 630 deletions.
43 changes: 43 additions & 0 deletions test/functional/associations/test_belongs_to_proxy.rb
Expand Up @@ -45,4 +45,47 @@ def setup
id = Mongo::ObjectID.new
@comment_class.new(:name => 'Foo', :post_id => id).post.nil?.should be_true
end

context ":dependent" do
setup do
# FIXME: make use of already defined models
class ::Property
include MongoMapper::Document
end
Property.collection.remove

class ::Thing
include MongoMapper::Document
key :name, String
end
Thing.collection.remove
end

teardown do
Object.send :remove_const, 'Property' if defined?(::Property)
Object.send :remove_const, 'Thing' if defined?(::Thing)
end

context "=> destroy" do
setup do
Property.key :thing_id, ObjectId
Property.belongs_to :thing, :dependent => :destroy
Thing.has_many :properties

@thing = Thing.create(:name => "Tree")
@property1 = Property.create
@property2 = Property.create
@property3 = Property.create
@thing.properties << @property1
@thing.properties << @property2
@thing.properties << @property3
end

should "not execute on a belongs_to association" do
Thing.count.should == 1
@property1.destroy
Thing.count.should == 1
end
end
end
end
90 changes: 90 additions & 0 deletions test/functional/associations/test_many_documents_proxy.rb
Expand Up @@ -384,4 +384,94 @@ def setup
project.collaborators.top.should == collaborator1
end
end

context ":dependent" do
setup do
# FIXME: make use of already defined models
class ::Property
include MongoMapper::Document
end
Property.collection.remove

class ::Thing
include MongoMapper::Document
key :name, String
end
Thing.collection.remove
end

teardown do
Object.send :remove_const, 'Property' if defined?(::Property)
Object.send :remove_const, 'Thing' if defined?(::Thing)
end

context "=> destroy" do
setup do
Property.key :thing_id, ObjectId
Property.belongs_to :thing, :dependent => :destroy
Thing.many :properties, :dependent => :destroy

@thing = Thing.create(:name => "Tree")
@property1 = Property.create
@property2 = Property.create
@property3 = Property.create
@thing.properties << @property1
@thing.properties << @property2
@thing.properties << @property3
end

should "should destroy the associated documents" do
@thing.properties.count.should == 3
@thing.destroy
@thing.properties.count.should == 0
Property.count.should == 0
end
end

context "=> delete_all" do
setup do
Property.key :thing_id, ObjectId
Property.belongs_to :thing
Thing.has_many :properties, :dependent => :delete_all

@thing = Thing.create(:name => "Tree")
@property1 = Property.create
@property2 = Property.create
@property3 = Property.create
@thing.properties << @property1
@thing.properties << @property2
@thing.properties << @property3
end

should "should delete associated documents" do
@thing.properties.count.should == 3
@thing.destroy
@thing.properties.count.should == 0
Property.count.should == 0
end
end

context "=> nullify" do
setup do
Property.key :thing_id, ObjectId
Property.belongs_to :thing
Thing.has_many :properties, :dependent => :nullify

@thing = Thing.create(:name => "Tree")
@property1 = Property.create
@property2 = Property.create
@property3 = Property.create
@thing.properties << @property1
@thing.properties << @property2
@thing.properties << @property3
end

should "should nullify relationship but not destroy associated documents" do
@thing.properties.count.should == 3
@thing.destroy
@thing.properties.count.should == 0
Property.count.should == 3
end
end
end
end
15 changes: 15 additions & 0 deletions test/functional/test_binary.rb
Expand Up @@ -15,4 +15,19 @@ class BinaryTest < Test::Unit::TestCase
doc = doc.reload
doc.contents.to_s.should == ByteBuffer.new('010101').to_s
end

context "Saving a document with a blank binary value" do
setup do
@document = Class.new do
include MongoMapper::Document
set_collection_name 'test'
key :file, Binary
end
@document.collection.remove
end

should "not fail" do
assert_nothing_raised { @document.new(:file => nil).save }
end
end
end

0 comments on commit 96f1752

Please sign in to comment.