jnunemaker-mongomapper 0.3.2 → 0.3.3
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/History +10 -0
- data/Rakefile +5 -3
- data/VERSION +1 -1
- data/lib/mongomapper/associations/belongs_to_polymorphic_proxy.rb +3 -1
- data/lib/mongomapper/associations/belongs_to_proxy.rb +2 -2
- data/lib/mongomapper/associations/many_documents_proxy.rb +32 -14
- data/lib/mongomapper/associations/proxy.rb +2 -6
- data/lib/mongomapper/associations.rb +44 -9
- data/lib/mongomapper/document.rb +142 -89
- data/lib/mongomapper/dynamic_finder.rb +38 -0
- data/lib/mongomapper/embedded_document.rb +102 -85
- data/lib/mongomapper/finder_options.rb +3 -14
- data/lib/mongomapper/key.rb +10 -15
- data/lib/mongomapper/support.rb +30 -0
- data/lib/mongomapper.rb +4 -31
- data/mongomapper.gemspec +12 -10
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +14 -0
- data/test/functional/associations/test_belongs_to_proxy.rb +10 -0
- data/test/functional/associations/test_many_proxy.rb +63 -4
- data/test/functional/test_document.rb +371 -120
- data/test/functional/test_rails_compatibility.rb +2 -3
- data/test/models.rb +10 -6
- data/test/unit/serializers/test_json_serializer.rb +1 -1
- data/test/unit/test_document.rb +7 -1
- data/test/unit/test_embedded_document.rb +115 -24
- data/test/unit/test_finder_options.rb +7 -38
- data/test/unit/test_key.rb +46 -23
- metadata +7 -7
- data/test/unit/test_mongo_id.rb +0 -35
@@ -98,6 +98,65 @@ class ManyProxyTest < Test::Unit::TestCase
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
+
context "Unassociating documents" do
|
102
|
+
setup do
|
103
|
+
@project = Project.create
|
104
|
+
@project.statuses << Status.create(:name => '1')
|
105
|
+
@project.statuses << Status.create(:name => '2')
|
106
|
+
|
107
|
+
@project2 = Project.create
|
108
|
+
@project2.statuses << Status.create(:name => '1')
|
109
|
+
@project2.statuses << Status.create(:name => '2')
|
110
|
+
end
|
111
|
+
|
112
|
+
should "work with destroy all" do
|
113
|
+
@project.statuses.count.should == 2
|
114
|
+
@project.statuses.destroy_all
|
115
|
+
@project.statuses.count.should == 0
|
116
|
+
|
117
|
+
@project2.statuses.count.should == 2
|
118
|
+
Status.count.should == 2
|
119
|
+
end
|
120
|
+
|
121
|
+
should "work with destroy all and conditions" do
|
122
|
+
@project.statuses.count.should == 2
|
123
|
+
@project.statuses.destroy_all(:name => '1')
|
124
|
+
@project.statuses.count.should == 1
|
125
|
+
|
126
|
+
@project2.statuses.count.should == 2
|
127
|
+
Status.count.should == 3
|
128
|
+
end
|
129
|
+
|
130
|
+
should "work with delete all" do
|
131
|
+
@project.statuses.count.should == 2
|
132
|
+
@project.statuses.delete_all
|
133
|
+
@project.statuses.count.should == 0
|
134
|
+
|
135
|
+
@project2.statuses.count.should == 2
|
136
|
+
Status.count.should == 2
|
137
|
+
end
|
138
|
+
|
139
|
+
should "work with delete all and conditions" do
|
140
|
+
@project.statuses.count.should == 2
|
141
|
+
@project.statuses.delete_all(:name => '1')
|
142
|
+
@project.statuses.count.should == 1
|
143
|
+
|
144
|
+
@project2.statuses.count.should == 2
|
145
|
+
Status.count.should == 3
|
146
|
+
end
|
147
|
+
|
148
|
+
should "work with nullify" do
|
149
|
+
@project.statuses.count.should == 2
|
150
|
+
@project.statuses.nullify
|
151
|
+
@project.statuses.count.should == 0
|
152
|
+
|
153
|
+
@project2.statuses.count.should == 2
|
154
|
+
Status.count.should == 4
|
155
|
+
Status.count(:name => '1').should == 2
|
156
|
+
Status.count(:name => '2').should == 2
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
101
160
|
context "Finding scoped to association" do
|
102
161
|
setup do
|
103
162
|
@project1 = Project.new(:name => 'Project 1')
|
@@ -148,7 +207,7 @@ class ManyProxyTest < Test::Unit::TestCase
|
|
148
207
|
|
149
208
|
context "with :first" do
|
150
209
|
should "work" do
|
151
|
-
@project1.statuses.find(:first).should == @
|
210
|
+
@project1.statuses.find(:first, :order => 'name').should == @complete
|
152
211
|
end
|
153
212
|
|
154
213
|
should "work with conditions" do
|
@@ -159,7 +218,7 @@ class ManyProxyTest < Test::Unit::TestCase
|
|
159
218
|
|
160
219
|
context "with #first" do
|
161
220
|
should "work" do
|
162
|
-
@project1.statuses.first.should == @
|
221
|
+
@project1.statuses.first(:order => 'name').should == @complete
|
163
222
|
end
|
164
223
|
|
165
224
|
should "work with conditions" do
|
@@ -217,7 +276,7 @@ class ManyProxyTest < Test::Unit::TestCase
|
|
217
276
|
|
218
277
|
context "with #paginate" do
|
219
278
|
setup do
|
220
|
-
@statuses = @project2.statuses.paginate(:per_page => 2, :page => 1, :order => '
|
279
|
+
@statuses = @project2.statuses.paginate(:per_page => 2, :page => 1, :order => 'name asc')
|
221
280
|
end
|
222
281
|
|
223
282
|
should "return total pages" do
|
@@ -229,7 +288,7 @@ class ManyProxyTest < Test::Unit::TestCase
|
|
229
288
|
end
|
230
289
|
|
231
290
|
should "return the subject" do
|
232
|
-
@statuses.should ==
|
291
|
+
@statuses.collect(&:name).should == %w(Archived Complete)
|
233
292
|
end
|
234
293
|
end
|
235
294
|
end
|