tpitale-mongo_mapper 0.6.9 → 0.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +2 -17
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/mongo_mapper/associations/base.rb +19 -10
- data/lib/mongo_mapper/associations/in_array_proxy.rb +137 -0
- data/lib/mongo_mapper/associations/one_proxy.rb +64 -0
- data/lib/mongo_mapper/associations/proxy.rb +7 -4
- data/lib/mongo_mapper/associations.rb +11 -3
- data/lib/mongo_mapper/callbacks.rb +30 -78
- data/lib/mongo_mapper/dirty.rb +5 -24
- data/lib/mongo_mapper/document.rb +117 -144
- data/lib/mongo_mapper/embedded_document.rb +7 -11
- data/lib/mongo_mapper/finder_options.rb +42 -30
- data/lib/mongo_mapper/mongo_mapper.rb +125 -0
- data/lib/mongo_mapper/pagination.rb +12 -1
- data/lib/mongo_mapper/rails_compatibility/embedded_document.rb +1 -0
- data/lib/mongo_mapper/serialization.rb +2 -2
- data/lib/mongo_mapper/serializers/json_serializer.rb +2 -46
- data/lib/mongo_mapper/support.rb +5 -2
- data/lib/mongo_mapper/validations.rb +1 -3
- data/lib/mongo_mapper.rb +8 -2
- data/mongo_mapper.gemspec +14 -8
- data/specs.watchr +3 -5
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +8 -0
- data/test/functional/associations/test_belongs_to_proxy.rb +54 -9
- data/test/functional/associations/test_in_array_proxy.rb +309 -0
- data/test/functional/associations/test_many_documents_proxy.rb +103 -53
- data/test/functional/associations/test_many_embedded_proxy.rb +4 -14
- data/test/functional/associations/test_many_polymorphic_proxy.rb +4 -3
- data/test/functional/associations/test_one_proxy.rb +149 -0
- data/test/functional/test_binary.rb +13 -4
- data/test/functional/test_callbacks.rb +1 -5
- data/test/functional/test_dirty.rb +1 -4
- data/test/functional/test_document.rb +576 -640
- data/test/functional/test_embedded_document.rb +7 -20
- data/test/functional/test_modifiers.rb +238 -0
- data/test/functional/test_pagination.rb +1 -3
- data/test/functional/test_string_id_compatibility.rb +3 -8
- data/test/functional/test_validations.rb +13 -75
- data/test/models.rb +1 -1
- data/test/support/timing.rb +1 -1
- data/test/test_helper.rb +28 -0
- data/test/unit/associations/test_base.rb +54 -13
- data/test/unit/associations/test_proxy.rb +12 -0
- data/test/unit/test_document.rb +36 -26
- data/test/unit/test_embedded_document.rb +14 -51
- data/test/unit/test_finder_options.rb +36 -7
- data/test/unit/test_key.rb +1 -4
- data/test/unit/test_pagination.rb +6 -0
- data/test/unit/test_rails_compatibility.rb +4 -1
- data/test/unit/test_serializations.rb +1 -2
- data/test/unit/test_support.rb +4 -0
- data/test/unit/test_time_zones.rb +1 -2
- data/test/unit/test_validations.rb +3 -14
- metadata +12 -6
- data/lib/mongo_mapper/observing.rb +0 -50
- data/test/unit/test_observing.rb +0 -101
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OneProxyTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@post_class = Doc('Post')
|
6
|
+
@author_class = Doc do
|
7
|
+
key :post_id, ObjectId
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
should "default to nil" do
|
12
|
+
@post_class.one :author, :class => @author_class
|
13
|
+
@post_class.new.author.nil?.should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
should "be able to replace the association" do
|
17
|
+
@post_class.one :author, :class => @author_class
|
18
|
+
|
19
|
+
post = @post_class.new
|
20
|
+
author = @author_class.new(:name => 'Frank')
|
21
|
+
post.author = author
|
22
|
+
post.reload
|
23
|
+
|
24
|
+
post.author.should == author
|
25
|
+
post.author.nil?.should be_false
|
26
|
+
|
27
|
+
new_author = @author_class.new(:name => 'Emily')
|
28
|
+
post.author = new_author
|
29
|
+
post.author.should == new_author
|
30
|
+
end
|
31
|
+
|
32
|
+
should "have boolean method for testing presence" do
|
33
|
+
@post_class.one :author, :class => @author_class
|
34
|
+
|
35
|
+
post = @post_class.new
|
36
|
+
post.author?.should be_false
|
37
|
+
|
38
|
+
post.author = @author_class.new(:name => 'Frank')
|
39
|
+
post.author?.should be_true
|
40
|
+
end
|
41
|
+
|
42
|
+
should "work with criteria" do
|
43
|
+
@post_class.one :primary_author, :class => @author_class, :primary => true
|
44
|
+
@post_class.one :author, :class => @author_class
|
45
|
+
|
46
|
+
post = @post_class.create
|
47
|
+
author = @author_class.create(:name => 'Frank', :primary => false, :post_id => post.id)
|
48
|
+
primary = @author_class.create(:name => 'Bill', :primary => true, :post_id => post.id)
|
49
|
+
post.author.should == author
|
50
|
+
post.primary_author.should == primary
|
51
|
+
end
|
52
|
+
|
53
|
+
should "unset the association" do
|
54
|
+
@post_class.one :author, :class => @author_class
|
55
|
+
post = @post_class.new
|
56
|
+
author = @author_class.new
|
57
|
+
post.author = author
|
58
|
+
post.reload
|
59
|
+
|
60
|
+
post.author = nil
|
61
|
+
post.author.nil?.should be_false
|
62
|
+
end
|
63
|
+
|
64
|
+
should "work with :dependent delete" do
|
65
|
+
@post_class.one :author, :class => @author_class, :dependent => :delete
|
66
|
+
|
67
|
+
post = @post_class.create
|
68
|
+
author = @author_class.new
|
69
|
+
post.author = author
|
70
|
+
post.reload
|
71
|
+
|
72
|
+
@author_class.any_instance.expects(:delete).once
|
73
|
+
post.author = @author_class.new
|
74
|
+
end
|
75
|
+
|
76
|
+
should "work with :dependent destroy" do
|
77
|
+
@post_class.one :author, :class => @author_class, :dependent => :destroy
|
78
|
+
|
79
|
+
post = @post_class.create
|
80
|
+
author = @author_class.new
|
81
|
+
post.author = author
|
82
|
+
post.reload
|
83
|
+
|
84
|
+
@author_class.any_instance.expects(:destroy).once
|
85
|
+
post.author = @author_class.new
|
86
|
+
end
|
87
|
+
|
88
|
+
should "work with :dependent nullify" do
|
89
|
+
@post_class.one :author, :class => @author_class, :dependent => :nullify
|
90
|
+
|
91
|
+
post = @post_class.create
|
92
|
+
author = @author_class.new
|
93
|
+
post.author = author
|
94
|
+
post.reload
|
95
|
+
|
96
|
+
post.author = @author_class.new
|
97
|
+
|
98
|
+
author.reload
|
99
|
+
author.post_id.should be_nil
|
100
|
+
end
|
101
|
+
|
102
|
+
should "be able to build" do
|
103
|
+
@post_class.one :author, :class => @author_class
|
104
|
+
|
105
|
+
post = @post_class.create
|
106
|
+
author = post.author.build(:name => 'John')
|
107
|
+
post.author.should be_instance_of(@author_class)
|
108
|
+
post.author.should be_new
|
109
|
+
post.author.name.should == 'John'
|
110
|
+
post.author.should == author
|
111
|
+
post.author.post_id.should == post.id
|
112
|
+
end
|
113
|
+
|
114
|
+
should "be able to create" do
|
115
|
+
@post_class.one :author, :class => @author_class
|
116
|
+
|
117
|
+
post = @post_class.create
|
118
|
+
author = post.author.create(:name => 'John')
|
119
|
+
post.author.should be_instance_of(@author_class)
|
120
|
+
post.author.should_not be_new
|
121
|
+
post.author.name.should == 'John'
|
122
|
+
post.author.should == author
|
123
|
+
post.author.post_id.should == post.id
|
124
|
+
end
|
125
|
+
|
126
|
+
context "#create!" do
|
127
|
+
setup do
|
128
|
+
@author_class.key :name, String, :required => true
|
129
|
+
@post_class.one :author, :class => @author_class
|
130
|
+
end
|
131
|
+
|
132
|
+
should "raise exception if invalid" do
|
133
|
+
post = @post_class.create
|
134
|
+
assert_raises(MongoMapper::DocumentNotValid) do
|
135
|
+
post.author.create!
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
should "work if valid" do
|
140
|
+
post = @post_class.create
|
141
|
+
author = post.author.create!(:name => 'John')
|
142
|
+
post.author.should be_instance_of(@author_class)
|
143
|
+
post.author.should_not be_new
|
144
|
+
post.author.name.should == 'John'
|
145
|
+
post.author.should == author
|
146
|
+
post.author.post_id.should == post.id
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -2,12 +2,9 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class BinaryTest < Test::Unit::TestCase
|
4
4
|
should "serialize and deserialize correctly" do
|
5
|
-
klass =
|
6
|
-
include MongoMapper::Document
|
7
|
-
set_collection_name 'test'
|
5
|
+
klass = Doc do
|
8
6
|
key :contents, Binary
|
9
7
|
end
|
10
|
-
klass.collection.remove
|
11
8
|
|
12
9
|
doc = klass.new(:contents => '010101')
|
13
10
|
doc.save
|
@@ -15,4 +12,16 @@ class BinaryTest < Test::Unit::TestCase
|
|
15
12
|
doc = doc.reload
|
16
13
|
doc.contents.to_s.should == ByteBuffer.new('010101').to_s
|
17
14
|
end
|
15
|
+
|
16
|
+
context "Saving a document with a blank binary value" do
|
17
|
+
setup do
|
18
|
+
@document = Doc do
|
19
|
+
key :file, Binary
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
should "not fail" do
|
24
|
+
assert_nothing_raised { @document.new(:file => nil).save }
|
25
|
+
end
|
26
|
+
end
|
18
27
|
end
|
@@ -3,10 +3,7 @@ require 'test_helper'
|
|
3
3
|
class CallbacksTest < Test::Unit::TestCase
|
4
4
|
context "Defining and running callbacks" do
|
5
5
|
setup do
|
6
|
-
@document =
|
7
|
-
include MongoMapper::Document
|
8
|
-
set_collection_name 'test'
|
9
|
-
|
6
|
+
@document = Doc do
|
10
7
|
key :name, String
|
11
8
|
|
12
9
|
[ :before_validation_on_create, :before_validation_on_update,
|
@@ -30,7 +27,6 @@ class CallbacksTest < Test::Unit::TestCase
|
|
30
27
|
@history = nil
|
31
28
|
end
|
32
29
|
end
|
33
|
-
@document.collection.remove
|
34
30
|
end
|
35
31
|
|
36
32
|
should "get the order right for creating documents" do
|
@@ -3,12 +3,9 @@ require 'models'
|
|
3
3
|
|
4
4
|
class DirtyTest < Test::Unit::TestCase
|
5
5
|
def setup
|
6
|
-
@document =
|
7
|
-
include MongoMapper::Document
|
8
|
-
set_collection_name 'test'
|
6
|
+
@document = Doc do
|
9
7
|
key :phrase, String
|
10
8
|
end
|
11
|
-
@document.collection.remove
|
12
9
|
|
13
10
|
Status.collection.remove
|
14
11
|
Project.collection.remove
|