mongo_mapper 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +1 -1
  3. data/{README.rdoc → README.md} +28 -20
  4. data/examples/keys.rb +1 -1
  5. data/examples/modifiers/set.rb +1 -1
  6. data/examples/querying.rb +1 -1
  7. data/examples/safe.rb +2 -2
  8. data/examples/scopes.rb +1 -1
  9. data/lib/mongo_mapper.rb +1 -0
  10. data/lib/mongo_mapper/connection.rb +16 -38
  11. data/lib/mongo_mapper/extensions/object_id.rb +5 -1
  12. data/lib/mongo_mapper/plugins/associations/belongs_to_association.rb +1 -1
  13. data/lib/mongo_mapper/plugins/dirty.rb +29 -37
  14. data/lib/mongo_mapper/plugins/document.rb +1 -1
  15. data/lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb +1 -1
  16. data/lib/mongo_mapper/plugins/embedded_callbacks.rb +1 -0
  17. data/lib/mongo_mapper/plugins/embedded_document.rb +1 -1
  18. data/lib/mongo_mapper/plugins/indexes.rb +13 -6
  19. data/lib/mongo_mapper/plugins/keys.rb +1 -2
  20. data/lib/mongo_mapper/plugins/modifiers.rb +27 -10
  21. data/lib/mongo_mapper/plugins/persistence.rb +6 -2
  22. data/lib/mongo_mapper/plugins/querying.rb +9 -3
  23. data/lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb +3 -4
  24. data/lib/mongo_mapper/plugins/safe.rb +10 -4
  25. data/lib/mongo_mapper/plugins/stats.rb +1 -3
  26. data/lib/mongo_mapper/utils.rb +2 -2
  27. data/lib/mongo_mapper/version.rb +1 -1
  28. data/spec/examples.txt +1643 -0
  29. data/spec/functional/accessible_spec.rb +1 -1
  30. data/spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb +2 -2
  31. data/spec/functional/associations/belongs_to_proxy_spec.rb +4 -4
  32. data/spec/functional/associations/in_array_proxy_spec.rb +14 -14
  33. data/spec/functional/associations/many_documents_as_proxy_spec.rb +6 -6
  34. data/spec/functional/associations/many_documents_proxy_spec.rb +22 -22
  35. data/spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb +2 -2
  36. data/spec/functional/associations/many_polymorphic_proxy_spec.rb +4 -4
  37. data/spec/functional/associations/one_as_proxy_spec.rb +8 -8
  38. data/spec/functional/associations/one_proxy_spec.rb +8 -8
  39. data/spec/functional/associations_spec.rb +3 -3
  40. data/spec/functional/binary_spec.rb +2 -2
  41. data/spec/functional/caching_spec.rb +15 -22
  42. data/spec/functional/callbacks_spec.rb +2 -2
  43. data/spec/functional/counter_cache_spec.rb +10 -10
  44. data/spec/functional/dirty_spec.rb +27 -10
  45. data/spec/functional/document_spec.rb +5 -5
  46. data/spec/functional/dumpable_spec.rb +1 -1
  47. data/spec/functional/embedded_document_spec.rb +5 -5
  48. data/spec/functional/identity_map_spec.rb +6 -6
  49. data/spec/functional/indexes_spec.rb +19 -18
  50. data/spec/functional/keys_spec.rb +22 -22
  51. data/spec/functional/logger_spec.rb +2 -2
  52. data/spec/functional/modifiers_spec.rb +67 -19
  53. data/spec/functional/partial_updates_spec.rb +8 -8
  54. data/spec/functional/protected_spec.rb +1 -1
  55. data/spec/functional/querying_spec.rb +48 -22
  56. data/spec/functional/safe_spec.rb +23 -27
  57. data/spec/functional/sci_spec.rb +7 -7
  58. data/spec/functional/scopes_spec.rb +1 -1
  59. data/spec/functional/static_keys_spec.rb +2 -2
  60. data/spec/functional/stats_spec.rb +28 -12
  61. data/spec/functional/validations_spec.rb +8 -16
  62. data/spec/quality_spec.rb +1 -1
  63. data/spec/spec_helper.rb +32 -8
  64. data/spec/support/matchers.rb +1 -1
  65. data/spec/unit/associations/proxy_spec.rb +1 -1
  66. data/spec/unit/clone_spec.rb +1 -1
  67. data/spec/unit/document_spec.rb +3 -3
  68. data/spec/unit/embedded_document_spec.rb +4 -5
  69. data/spec/unit/extensions_spec.rb +3 -4
  70. data/spec/unit/identity_map_middleware_spec.rb +65 -96
  71. data/spec/unit/key_spec.rb +16 -17
  72. data/spec/unit/keys_spec.rb +7 -7
  73. data/spec/unit/mongo_mapper_spec.rb +41 -88
  74. data/spec/unit/rails_spec.rb +2 -2
  75. metadata +37 -24
  76. data/lib/mongo_mapper/extensions/ordered_hash.rb +0 -23
@@ -119,7 +119,7 @@ describe "Accessible" do
119
119
  key :name, String
120
120
  key :site_id, ObjectId
121
121
  end
122
- GrandParent.collection.remove
122
+ GrandParent.collection.drop
123
123
 
124
124
  class ::Child < ::GrandParent
125
125
  attr_accessible :position
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
 
4
4
  describe "BelongsToPolymorphicProxy" do
5
5
  before do
6
- Status.collection.remove
7
- Project.collection.remove
6
+ Status.collection.drop
7
+ Project.collection.drop
8
8
  end
9
9
 
10
10
  it "should default to nil" do
@@ -121,13 +121,13 @@ describe "BelongsToProxy" do
121
121
  class ::Property
122
122
  include MongoMapper::Document
123
123
  end
124
- Property.collection.remove
124
+ Property.collection.drop
125
125
 
126
126
  class ::Thing
127
127
  include MongoMapper::Document
128
128
  key :name, String
129
129
  end
130
- Thing.collection.remove
130
+ Thing.collection.drop
131
131
  end
132
132
 
133
133
  after do
@@ -211,7 +211,7 @@ describe "BelongsToProxy" do
211
211
  end
212
212
 
213
213
  it "should raise exception if invalid" do
214
- expect { comment.create_post! }.to raise_error(MongoMapper::DocumentNotValid)
214
+ lambda { comment.create_post! }.should raise_error(MongoMapper::DocumentNotValid)
215
215
  end
216
216
 
217
217
  it "should work if valid" do
@@ -252,4 +252,4 @@ describe "BelongsToProxy" do
252
252
  post.reload.title.should == 'Hello, world!'
253
253
  end
254
254
  end
255
- end
255
+ end
@@ -14,8 +14,8 @@ describe "InArrayProxy" do
14
14
  key :list_ids, Array
15
15
  many :lists, :in => :list_ids
16
16
  end
17
- User.collection.remove
18
- List.collection.remove
17
+ User.collection.drop
18
+ List.collection.drop
19
19
  end
20
20
 
21
21
  after do
@@ -112,9 +112,9 @@ describe "InArrayProxy" do
112
112
  end
113
113
 
114
114
  it "should raise exception if invalid" do
115
- expect {
115
+ lambda {
116
116
  @user.lists.create!
117
- }.to raise_error(MongoMapper::DocumentNotValid)
117
+ }.should raise_error(MongoMapper::DocumentNotValid)
118
118
  end
119
119
 
120
120
  it "should reset cache" do
@@ -144,7 +144,7 @@ describe "InArrayProxy" do
144
144
 
145
145
  it "should not hit the database if ids key is empty" do
146
146
  @user.list_ids = []
147
- expect(@user.lists).to receive(:query).never
147
+ @user.lists.should_receive(:query).never
148
148
  @user.lists.all.should == []
149
149
  end
150
150
  end
@@ -160,7 +160,7 @@ describe "InArrayProxy" do
160
160
 
161
161
  it "should not hit the database if ids key is empty" do
162
162
  @user.list_ids = []
163
- expect(@user.lists).to receive(:query).never
163
+ @user.lists.should_receive(:query).never
164
164
  @user.lists.first.should be_nil
165
165
  end
166
166
  end
@@ -176,7 +176,7 @@ describe "InArrayProxy" do
176
176
 
177
177
  it "should not hit the database if ids key is empty" do
178
178
  @user.list_ids = []
179
- expect(@user.lists).to receive(:query).never
179
+ @user.lists.should_receive(:query).never
180
180
  @user.lists.last.should be_nil
181
181
  end
182
182
  end
@@ -195,9 +195,9 @@ describe "InArrayProxy" do
195
195
  end
196
196
 
197
197
  it "should raise error when using ! and not found" do
198
- expect {
198
+ lambda {
199
199
  @user.lists.find!(@list3.id)
200
- }.to raise_error(MongoMapper::DocumentNotFound)
200
+ }.should raise_error(MongoMapper::DocumentNotFound)
201
201
  end
202
202
  end
203
203
 
@@ -230,7 +230,7 @@ describe "InArrayProxy" do
230
230
 
231
231
  it "should not hit the database if ids key is empty" do
232
232
  @user.list_ids = []
233
- expect(@user.lists).to receive(:query).never
233
+ @user.lists.should_receive(:query).never
234
234
  @user.lists.paginate(:page => 1).should == []
235
235
  end
236
236
  end
@@ -249,9 +249,9 @@ describe "InArrayProxy" do
249
249
  end
250
250
 
251
251
  it "should raise error when using ! and not found" do
252
- expect {
252
+ lambda {
253
253
  @user.lists.find_by_name!('Foo 3')
254
- }.to raise_error(MongoMapper::DocumentNotFound)
254
+ }.should raise_error(MongoMapper::DocumentNotFound)
255
255
  end
256
256
 
257
257
  context "find_or_create_by" do
@@ -293,7 +293,7 @@ describe "InArrayProxy" do
293
293
 
294
294
  it "should not hit the database if ids key is empty" do
295
295
  @user.list_ids = []
296
- expect(@user.lists).to receive(:query).never
296
+ @user.lists.should_receive(:query).never
297
297
  @user.lists.count(:name => 'Foo 1').should == 0
298
298
  end
299
299
  end
@@ -346,4 +346,4 @@ describe "InArrayProxy" do
346
346
  end
347
347
  end
348
348
  end
349
- end
349
+ end
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe "ManyDocumentsAsProxy" do
4
4
  before do
5
- Post.collection.remove
6
- PostComment.collection.remove
5
+ Post.collection.drop
6
+ PostComment.collection.drop
7
7
  end
8
8
 
9
9
  it "should default reader to empty array" do
@@ -155,9 +155,9 @@ describe "ManyDocumentsAsProxy" do
155
155
  end
156
156
 
157
157
  it "should not work for id not in association" do
158
- expect {
158
+ lambda {
159
159
  @post.comments.find!(@comment5._id)
160
- }.to raise_error(MongoMapper::DocumentNotFound)
160
+ }.should raise_error(MongoMapper::DocumentNotFound)
161
161
  end
162
162
  end
163
163
 
@@ -168,9 +168,9 @@ describe "ManyDocumentsAsProxy" do
168
168
  end
169
169
 
170
170
  it "should not work for ids not in association" do
171
- expect {
171
+ lambda {
172
172
  @post.comments.find!(@comment1._id, @comment2._id, @comment4._id)
173
- }.to raise_error(MongoMapper::DocumentNotFound)
173
+ }.should raise_error(MongoMapper::DocumentNotFound)
174
174
  end
175
175
  end
176
176
 
@@ -2,8 +2,8 @@ require 'spec_helper.rb'
2
2
 
3
3
  describe "ManyDocumentsProxy" do
4
4
  before do
5
- Project.collection.remove
6
- Status.collection.remove
5
+ Project.collection.drop
6
+ Status.collection.drop
7
7
 
8
8
  @pet_class = Doc do
9
9
  key :name, String
@@ -171,9 +171,9 @@ describe "ManyDocumentsProxy" do
171
171
  end
172
172
 
173
173
  it "should call destroy the existing documents" do
174
- expect(@broker.properties[0]).to receive(:destroy).once
175
- expect(@broker.properties[1]).to receive(:destroy).once
176
- expect(@broker.properties[2]).to receive(:destroy).once
174
+ @broker.properties[0].should_receive(:destroy).once
175
+ @broker.properties[1].should_receive(:destroy).once
176
+ @broker.properties[2].should_receive(:destroy).once
177
177
  @broker.properties = [@property_class.new]
178
178
  end
179
179
 
@@ -184,9 +184,9 @@ describe "ManyDocumentsProxy" do
184
184
  end
185
185
 
186
186
  it "should skip over documents that are the same" do
187
- expect(@broker.properties[0]).to receive(:destroy).never
188
- expect(@broker.properties[1]).to receive(:destroy).once
189
- expect(@broker.properties[2]).to receive(:destroy).never
187
+ @broker.properties[0].should_receive(:destroy).never
188
+ @broker.properties[1].should_receive(:destroy).once
189
+ @broker.properties[2].should_receive(:destroy).never
190
190
  @broker.properties = [@property3, @property1]
191
191
  end
192
192
  end
@@ -205,9 +205,9 @@ describe "ManyDocumentsProxy" do
205
205
  end
206
206
 
207
207
  it "should call delete the existing documents" do
208
- expect(@broker.properties[0]).to receive(:delete).once
209
- expect(@broker.properties[1]).to receive(:delete).once
210
- expect(@broker.properties[2]).to receive(:delete).once
208
+ @broker.properties[0].should_receive(:delete).once
209
+ @broker.properties[1].should_receive(:delete).once
210
+ @broker.properties[2].should_receive(:delete).once
211
211
  @broker.properties = [@property_class.new]
212
212
  end
213
213
 
@@ -218,9 +218,9 @@ describe "ManyDocumentsProxy" do
218
218
  end
219
219
 
220
220
  it "should skip over documents that are the same" do
221
- expect(@broker.properties[0]).to receive(:delete).never
222
- expect(@broker.properties[1]).to receive(:delete).once
223
- expect(@broker.properties[2]).to receive(:delete).never
221
+ @broker.properties[0].should_receive(:delete).never
222
+ @broker.properties[1].should_receive(:delete).once
223
+ @broker.properties[2].should_receive(:delete).never
224
224
  @broker.properties = [@property3, @property1]
225
225
  end
226
226
  end
@@ -430,9 +430,9 @@ describe "ManyDocumentsProxy" do
430
430
 
431
431
  it "should raise exception if not valid" do
432
432
  project = Project.create
433
- expect {
433
+ lambda {
434
434
  project.statuses.create!(:name => nil)
435
- }.to raise_error(MongoMapper::DocumentNotValid)
435
+ }.should raise_error(MongoMapper::DocumentNotValid)
436
436
  end
437
437
 
438
438
  it "should reset cache" do
@@ -754,9 +754,9 @@ describe "ManyDocumentsProxy" do
754
754
  end
755
755
 
756
756
  it "should not work for ids not in association" do
757
- expect {
757
+ lambda {
758
758
  @project1.statuses.find!(@brand_new.id, @complete.id, @archived.id)
759
- }.to raise_error(MongoMapper::DocumentNotFound)
759
+ }.should raise_error(MongoMapper::DocumentNotFound)
760
760
  end
761
761
  end
762
762
 
@@ -810,13 +810,13 @@ describe "ManyDocumentsProxy" do
810
810
  class ::Property
811
811
  include MongoMapper::Document
812
812
  end
813
- Property.collection.remove
813
+ Property.collection.drop
814
814
 
815
815
  class ::Thing
816
816
  include MongoMapper::Document
817
817
  key :name, String
818
818
  end
819
- Thing.collection.remove
819
+ Thing.collection.drop
820
820
  end
821
821
 
822
822
  after do
@@ -997,7 +997,7 @@ describe "ManyDocumentsProxy" do
997
997
 
998
998
  lambda do
999
999
  @job_title_2.trainings.find_by_slug!('bar')
1000
- end.should raise_error
1000
+ end.should raise_error(RuntimeError)
1001
1001
  end
1002
1002
 
1003
1003
  it "should scope with an extra where clause on the proxy (regression #2)" do
@@ -1018,7 +1018,7 @@ describe "ManyDocumentsProxy" do
1018
1018
 
1019
1019
  lambda do
1020
1020
  @job_title_2.trainings.find_by_slug!('bar')
1021
- end.should raise_error
1021
+ end.should raise_error(RuntimeError)
1022
1022
  end
1023
1023
  end
1024
1024
  end
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe "ManyEmbeddedPolymorphicProxy" do
4
4
  before do
5
- Catalog.collection.remove
6
- TrModels::Fleet.collection.remove
5
+ Catalog.collection.drop
6
+ TrModels::Fleet.collection.drop
7
7
  end
8
8
 
9
9
  it "should default reader to empty array" do
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe "ManyPolymorphicProxy" do
4
4
  before do
5
- Room.collection.remove
6
- Message.collection.remove
5
+ Room.collection.drop
6
+ Message.collection.drop
7
7
  end
8
8
 
9
9
  it "should default reader to empty array" do
@@ -247,9 +247,9 @@ describe "ManyPolymorphicProxy" do
247
247
  end
248
248
 
249
249
  it "should not work for ids not in association" do
250
- expect {
250
+ lambda {
251
251
  @lounge.messages.find!(@lm1._id, @lm2._id, @hm2._id)
252
- }.to raise_error(MongoMapper::DocumentNotFound)
252
+ }.should raise_error(MongoMapper::DocumentNotFound)
253
253
  end
254
254
  end
255
255
 
@@ -132,7 +132,7 @@ describe "OneAsProxy" do
132
132
  end
133
133
 
134
134
  it "should call delete on the existing document" do
135
- expect_any_instance_of(@author_class).to receive(:delete).once
135
+ @author_class.any_instance.should_receive(:delete).once
136
136
  @post.author = @author_class.new
137
137
  end
138
138
 
@@ -142,7 +142,7 @@ describe "OneAsProxy" do
142
142
  end
143
143
 
144
144
  it "should do nothing if it's the same document" do
145
- expect_any_instance_of(@author_class).to receive(:delete).never
145
+ @author_class.any_instance.should_receive(:delete).never
146
146
  @post.author = @author
147
147
  end
148
148
  end
@@ -157,7 +157,7 @@ describe "OneAsProxy" do
157
157
  end
158
158
 
159
159
  it "should call destroy the existing document" do
160
- expect_any_instance_of(@author_class).to receive(:destroy).once
160
+ @author_class.any_instance.should_receive(:destroy).once
161
161
  @post.author = @author_class.new
162
162
  end
163
163
 
@@ -167,7 +167,7 @@ describe "OneAsProxy" do
167
167
  end
168
168
 
169
169
  it "should do nothing if it's the same document" do
170
- expect_any_instance_of(@author_class).to receive(:destroy).never
170
+ @author_class.any_instance.should_receive(:destroy).never
171
171
  @post.author = @author
172
172
  end
173
173
  end
@@ -302,7 +302,7 @@ describe "OneAsProxy" do
302
302
  end
303
303
 
304
304
  it "should should call destroy on the associated documents" do
305
- expect_any_instance_of(@author_class).to receive(:destroy).once
305
+ @author_class.any_instance.should_receive(:destroy).once
306
306
  @post.destroy
307
307
  end
308
308
 
@@ -324,7 +324,7 @@ describe "OneAsProxy" do
324
324
  end
325
325
 
326
326
  it "should should call delete the associated documents" do
327
- expect_any_instance_of(@author_class).to receive(:delete).once
327
+ @author_class.any_instance.should_receive(:delete).once
328
328
  @post.destroy
329
329
  end
330
330
 
@@ -445,7 +445,7 @@ describe "OneAsProxy" do
445
445
  end
446
446
 
447
447
  it "should raise exception if invalid" do
448
- expect { @post.create_author! }.to raise_error(MongoMapper::DocumentNotValid)
448
+ lambda { @post.create_author! }.should raise_error(MongoMapper::DocumentNotValid)
449
449
  end
450
450
 
451
451
  it "should work if valid" do
@@ -486,4 +486,4 @@ describe "OneAsProxy" do
486
486
  article.articleable_id.should == @paper.id
487
487
  end
488
488
  end
489
- end
489
+ end
@@ -97,7 +97,7 @@ describe "OneProxy" do
97
97
  end
98
98
 
99
99
  it "should call delete on the existing document" do
100
- expect_any_instance_of(@author_class).to receive(:delete).once
100
+ @author_class.any_instance.should_receive(:delete).once
101
101
  @post.author = @author_class.new
102
102
  end
103
103
 
@@ -107,7 +107,7 @@ describe "OneProxy" do
107
107
  end
108
108
 
109
109
  it "should do nothing if it's the same document" do
110
- expect_any_instance_of(@author_class).to receive(:delete).never
110
+ @author_class.any_instance.should_receive(:delete).never
111
111
  @post.author = @author
112
112
  end
113
113
  end
@@ -122,7 +122,7 @@ describe "OneProxy" do
122
122
  end
123
123
 
124
124
  it "should call destroy the existing document" do
125
- expect_any_instance_of(@author_class).to receive(:destroy).once
125
+ @author_class.any_instance.should_receive(:destroy).once
126
126
  @post.author = @author_class.new
127
127
  end
128
128
 
@@ -132,7 +132,7 @@ describe "OneProxy" do
132
132
  end
133
133
 
134
134
  it "should do nothing if it's the same document" do
135
- expect_any_instance_of(@author_class).to receive(:destroy).never
135
+ @author_class.any_instance.should_receive(:destroy).never
136
136
  @post.author = @author
137
137
  end
138
138
  end
@@ -246,7 +246,7 @@ describe "OneProxy" do
246
246
  end
247
247
 
248
248
  it "should should call destroy on the associated documents" do
249
- expect_any_instance_of(@author_class).to receive(:destroy).once
249
+ @author_class.any_instance.should_receive(:destroy).once
250
250
  @post.destroy
251
251
  end
252
252
 
@@ -268,7 +268,7 @@ describe "OneProxy" do
268
268
  end
269
269
 
270
270
  it "should should call delete the associated documents" do
271
- expect_any_instance_of(@author_class).to receive(:delete).once
271
+ @author_class.any_instance.should_receive(:delete).once
272
272
  @post.destroy
273
273
  end
274
274
 
@@ -366,9 +366,9 @@ describe "OneProxy" do
366
366
  end
367
367
 
368
368
  it "should raise exception if invalid" do
369
- expect {
369
+ lambda {
370
370
  post.create_author!
371
- }.to raise_error(MongoMapper::DocumentNotValid)
371
+ }.should raise_error(MongoMapper::DocumentNotValid)
372
372
  end
373
373
 
374
374
  it "should work if valid" do