mongo_mapper 0.14.0 → 0.15.4
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.
- checksums.yaml +5 -5
- data/LICENSE +1 -1
- data/README.md +72 -0
- data/examples/keys.rb +1 -1
- data/examples/modifiers/set.rb +1 -1
- data/examples/querying.rb +1 -1
- data/examples/safe.rb +2 -2
- data/examples/scopes.rb +1 -1
- data/lib/mongo_mapper.rb +19 -17
- data/lib/mongo_mapper/connection.rb +16 -38
- data/lib/mongo_mapper/extensions/array.rb +1 -1
- data/lib/mongo_mapper/extensions/binary.rb +1 -1
- data/lib/mongo_mapper/extensions/date.rb +1 -1
- data/lib/mongo_mapper/extensions/float.rb +1 -1
- data/lib/mongo_mapper/extensions/hash.rb +1 -1
- data/lib/mongo_mapper/extensions/nil_class.rb +2 -2
- data/lib/mongo_mapper/extensions/object.rb +1 -1
- data/lib/mongo_mapper/extensions/object_id.rb +6 -2
- data/lib/mongo_mapper/extensions/set.rb +1 -1
- data/lib/mongo_mapper/extensions/string.rb +1 -1
- data/lib/mongo_mapper/plugins/accessible.rb +1 -1
- data/lib/mongo_mapper/plugins/associations/base.rb +10 -2
- data/lib/mongo_mapper/plugins/associations/belongs_to_association.rb +1 -1
- data/lib/mongo_mapper/plugins/associations/many_association.rb +6 -5
- data/lib/mongo_mapper/plugins/associations/{belongs_to_polymorphic_proxy.rb → proxy/belongs_to_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{belongs_to_proxy.rb → proxy/belongs_to_proxy.rb} +6 -0
- data/lib/mongo_mapper/plugins/associations/proxy/collection.rb +55 -0
- data/lib/mongo_mapper/plugins/associations/{embedded_collection.rb → proxy/embedded_collection.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{in_array_proxy.rb → proxy/in_array_proxy.rb} +36 -6
- data/lib/mongo_mapper/plugins/associations/proxy/in_foreign_array_proxy.rb +136 -0
- data/lib/mongo_mapper/plugins/associations/{many_documents_as_proxy.rb → proxy/many_documents_as_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{many_documents_proxy.rb → proxy/many_documents_proxy.rb} +0 -4
- data/lib/mongo_mapper/plugins/associations/{many_embedded_polymorphic_proxy.rb → proxy/many_embedded_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{many_embedded_proxy.rb → proxy/many_embedded_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{many_polymorphic_proxy.rb → proxy/many_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{one_as_proxy.rb → proxy/one_as_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{one_embedded_polymorphic_proxy.rb → proxy/one_embedded_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{one_embedded_proxy.rb → proxy/one_embedded_proxy.rb} +3 -1
- data/lib/mongo_mapper/plugins/associations/{one_proxy.rb → proxy/one_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/proxy/proxy.rb +164 -0
- data/lib/mongo_mapper/plugins/associations/single_association.rb +5 -13
- data/lib/mongo_mapper/plugins/dirty.rb +29 -37
- data/lib/mongo_mapper/plugins/document.rb +1 -1
- data/lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb +1 -1
- data/lib/mongo_mapper/plugins/embedded_callbacks.rb +1 -0
- data/lib/mongo_mapper/plugins/embedded_document.rb +2 -2
- data/lib/mongo_mapper/plugins/identity_map.rb +3 -1
- data/lib/mongo_mapper/plugins/indexes.rb +13 -6
- data/lib/mongo_mapper/plugins/keys.rb +12 -7
- data/lib/mongo_mapper/plugins/keys/key.rb +21 -13
- data/lib/mongo_mapper/plugins/modifiers.rb +39 -14
- data/lib/mongo_mapper/plugins/persistence.rb +6 -2
- data/lib/mongo_mapper/plugins/querying.rb +9 -3
- data/lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb +6 -6
- data/lib/mongo_mapper/plugins/safe.rb +10 -4
- data/lib/mongo_mapper/plugins/scopes.rb +19 -3
- data/lib/mongo_mapper/plugins/stats.rb +1 -3
- data/lib/mongo_mapper/plugins/strong_parameters.rb +26 -0
- data/lib/mongo_mapper/plugins/validations.rb +1 -1
- data/lib/mongo_mapper/railtie.rb +1 -0
- data/lib/mongo_mapper/utils.rb +2 -2
- data/lib/mongo_mapper/version.rb +1 -1
- data/spec/examples.txt +1731 -0
- data/spec/functional/accessible_spec.rb +7 -1
- data/spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb +2 -2
- data/spec/functional/associations/belongs_to_proxy_spec.rb +55 -5
- data/spec/functional/associations/in_array_proxy_spec.rb +149 -14
- data/spec/functional/associations/in_foreign_array_proxy_spec.rb +321 -0
- data/spec/functional/associations/many_documents_as_proxy_spec.rb +6 -6
- data/spec/functional/associations/many_documents_proxy_spec.rb +22 -22
- data/spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb +2 -2
- data/spec/functional/associations/many_polymorphic_proxy_spec.rb +4 -4
- data/spec/functional/associations/one_as_proxy_spec.rb +8 -8
- data/spec/functional/associations/one_embedded_proxy_spec.rb +28 -0
- data/spec/functional/associations/one_proxy_spec.rb +19 -9
- data/spec/functional/associations_spec.rb +3 -3
- data/spec/functional/binary_spec.rb +2 -2
- data/spec/functional/caching_spec.rb +15 -22
- data/spec/functional/callbacks_spec.rb +2 -2
- data/spec/functional/counter_cache_spec.rb +10 -10
- data/spec/functional/dirty_spec.rb +48 -10
- data/spec/functional/dirty_with_callbacks_spec.rb +59 -0
- data/spec/functional/document_spec.rb +5 -8
- data/spec/functional/dumpable_spec.rb +1 -1
- data/spec/functional/embedded_document_spec.rb +5 -5
- data/spec/functional/identity_map_spec.rb +8 -8
- data/spec/functional/indexes_spec.rb +19 -18
- data/spec/functional/keys_spec.rb +64 -33
- data/spec/functional/logger_spec.rb +2 -2
- data/spec/functional/modifiers_spec.rb +81 -19
- data/spec/functional/partial_updates_spec.rb +8 -8
- data/spec/functional/protected_spec.rb +1 -1
- data/spec/functional/querying_spec.rb +70 -22
- data/spec/functional/safe_spec.rb +23 -27
- data/spec/functional/sci_spec.rb +7 -7
- data/spec/functional/scopes_spec.rb +89 -1
- data/spec/functional/static_keys_spec.rb +2 -2
- data/spec/functional/stats_spec.rb +28 -12
- data/spec/functional/strong_parameters_spec.rb +49 -0
- data/spec/functional/validations_spec.rb +8 -16
- data/spec/quality_spec.rb +1 -1
- data/spec/spec_helper.rb +39 -8
- data/spec/support/matchers.rb +1 -1
- data/spec/unit/associations/proxy_spec.rb +18 -10
- data/spec/unit/clone_spec.rb +1 -1
- data/spec/unit/document_spec.rb +3 -3
- data/spec/unit/embedded_document_spec.rb +4 -5
- data/spec/unit/extensions_spec.rb +12 -7
- data/spec/unit/identity_map_middleware_spec.rb +65 -96
- data/spec/unit/inspect_spec.rb +1 -1
- data/spec/unit/key_spec.rb +23 -18
- data/spec/unit/keys_spec.rb +17 -8
- data/spec/unit/mongo_mapper_spec.rb +41 -88
- data/spec/unit/rails_spec.rb +2 -2
- data/spec/unit/validations_spec.rb +18 -18
- metadata +70 -38
- data/README.rdoc +0 -56
- data/lib/mongo_mapper/extensions/ordered_hash.rb +0 -23
- data/lib/mongo_mapper/plugins/associations/collection.rb +0 -29
- data/lib/mongo_mapper/plugins/associations/proxy.rb +0 -141
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "ManyDocumentsAsProxy" do
|
4
4
|
before do
|
5
|
-
Post.collection.
|
6
|
-
PostComment.collection.
|
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
|
-
|
158
|
+
lambda {
|
159
159
|
@post.comments.find!(@comment5._id)
|
160
|
-
}.
|
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
|
-
|
171
|
+
lambda {
|
172
172
|
@post.comments.find!(@comment1._id, @comment2._id, @comment4._id)
|
173
|
-
}.
|
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.
|
6
|
-
Status.collection.
|
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
|
-
|
175
|
-
|
176
|
-
|
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
|
-
|
188
|
-
|
189
|
-
|
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
|
-
|
209
|
-
|
210
|
-
|
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
|
-
|
222
|
-
|
223
|
-
|
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
|
-
|
433
|
+
lambda {
|
434
434
|
project.statuses.create!(:name => nil)
|
435
|
-
}.
|
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
|
-
|
757
|
+
lambda {
|
758
758
|
@project1.statuses.find!(@brand_new.id, @complete.id, @archived.id)
|
759
|
-
}.
|
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.
|
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.
|
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 "ManyPolymorphicProxy" do
|
4
4
|
before do
|
5
|
-
Room.collection.
|
6
|
-
Message.collection.
|
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
|
-
|
250
|
+
lambda {
|
251
251
|
@lounge.messages.find!(@lm1._id, @lm2._id, @hm2._id)
|
252
|
-
}.
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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,4 +97,32 @@ describe "OneEmbeddedProxy" do
|
|
97
97
|
post.author.address.id.should_not be_nil
|
98
98
|
end
|
99
99
|
|
100
|
+
it "should keep the reference to assigned document" do
|
101
|
+
@post_class.one(:author, :class => @author_class)
|
102
|
+
post = @post_class.new
|
103
|
+
new_author = @author_class.new
|
104
|
+
post.author = new_author
|
105
|
+
new_author.name = 'Frank'
|
106
|
+
|
107
|
+
post.author.name.should == 'Frank'
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should update references for parent and root" do
|
111
|
+
@post_class.key(:author_name, String)
|
112
|
+
@post_class.one(:author, :class => @author_class)
|
113
|
+
@post_class.before_save do
|
114
|
+
self.author_name = author.name
|
115
|
+
end
|
116
|
+
|
117
|
+
author = @author_class.new
|
118
|
+
@post_class.create!(author: author)
|
119
|
+
author.save!
|
120
|
+
|
121
|
+
post = @post_class.create!(author: author)
|
122
|
+
post.author.name = 'Frank'
|
123
|
+
post.author.save!
|
124
|
+
|
125
|
+
post.author.name.should == 'Frank'
|
126
|
+
post.author_name.should == 'Frank'
|
127
|
+
end
|
100
128
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
369
|
+
lambda {
|
370
370
|
post.create_author!
|
371
|
-
}.
|
371
|
+
}.should raise_error(MongoMapper::DocumentNotValid)
|
372
372
|
end
|
373
373
|
|
374
374
|
it "should work if valid" do
|
@@ -403,4 +403,14 @@ describe "OneProxy" do
|
|
403
403
|
article.paper_id.should == @paper.id
|
404
404
|
end
|
405
405
|
end
|
406
|
-
|
406
|
+
|
407
|
+
it "should keep the reference to assigned document" do
|
408
|
+
@post_class.one(:author, :class => @author_class)
|
409
|
+
post = @post_class.new
|
410
|
+
new_author = @author_class.new
|
411
|
+
post.author = new_author
|
412
|
+
new_author.name = 'Frank'
|
413
|
+
|
414
|
+
post.author.name.should == 'Frank'
|
415
|
+
end
|
416
|
+
end
|
@@ -9,7 +9,7 @@ module AssociationsSpec
|
|
9
9
|
|
10
10
|
many :posts, :class_name => 'AssociationsSpec::AwesomePost', :foreign_key => :creator_id
|
11
11
|
end
|
12
|
-
AwesomeUser.collection.
|
12
|
+
AwesomeUser.collection.drop
|
13
13
|
|
14
14
|
class AwesomeTag
|
15
15
|
include MongoMapper::EmbeddedDocument
|
@@ -29,8 +29,8 @@ module AssociationsSpec
|
|
29
29
|
many :tags, :class_name => 'AssociationsSpec::AwesomeTag', :foreign_key => :post_id
|
30
30
|
end
|
31
31
|
|
32
|
-
AwesomeUser.collection.
|
33
|
-
AwesomePost.collection.
|
32
|
+
AwesomeUser.collection.drop
|
33
|
+
AwesomePost.collection.drop
|
34
34
|
|
35
35
|
user = AwesomeUser.create
|
36
36
|
tag1 = AwesomeTag.new(:name => 'awesome')
|
@@ -10,7 +10,7 @@ describe "Binary" do
|
|
10
10
|
doc.save
|
11
11
|
|
12
12
|
doc = doc.reload
|
13
|
-
doc.contents.
|
13
|
+
doc.contents.data.should == BSON::Binary.new('010101').data
|
14
14
|
end
|
15
15
|
|
16
16
|
context "Saving a document with a blank binary value" do
|
@@ -21,7 +21,7 @@ describe "Binary" do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "not fail" do
|
24
|
-
|
24
|
+
lambda { @document.new(:file => nil).save }.should_not raise_error
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -6,16 +6,16 @@ describe "Caching" do
|
|
6
6
|
extend MongoMapper::Plugins
|
7
7
|
plugin MongoMapper::Plugins::Caching
|
8
8
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
@klass.stub(:name).and_return('Post')
|
10
|
+
@klass.any_instance.stub(:persisted?).and_return(true)
|
11
|
+
@klass.any_instance.stub(:[]).and_return(nil)
|
12
|
+
@klass.any_instance.stub(:[]=).and_return(nil)
|
13
13
|
end
|
14
14
|
|
15
15
|
context "new" do
|
16
16
|
before do
|
17
17
|
@doc = @klass.new
|
18
|
-
|
18
|
+
@doc.stub(:persisted?).and_return(false)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should be class/new" do
|
@@ -23,11 +23,9 @@ describe "Caching" do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should work with suffix" do
|
26
|
-
@doc.cache_key(:foo).
|
27
|
-
should == 'Post/new/foo'
|
26
|
+
@doc.cache_key(:foo).should == 'Post/new/foo'
|
28
27
|
|
29
|
-
@doc.cache_key(:foo, :bar).
|
30
|
-
should == 'Post/new/foo/bar'
|
28
|
+
@doc.cache_key(:foo, :bar).should == 'Post/new/foo/bar'
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
@@ -35,14 +33,14 @@ describe "Caching" do
|
|
35
33
|
before do
|
36
34
|
@object_id = BSON::ObjectId.new
|
37
35
|
@doc = @klass.new
|
38
|
-
|
39
|
-
|
36
|
+
@doc.stub(:persisted?).and_return(true)
|
37
|
+
@doc.stub(:id).and_return(@object_id)
|
40
38
|
end
|
41
39
|
|
42
40
|
context "with updated_at" do
|
43
41
|
before do
|
44
42
|
time = Time.utc(2010, 6, 20, 8, 10, 7)
|
45
|
-
|
43
|
+
@doc.stub(:[]).with(:updated_at).and_return(time)
|
46
44
|
end
|
47
45
|
|
48
46
|
it "should be class/id-timestamp" do
|
@@ -50,11 +48,9 @@ describe "Caching" do
|
|
50
48
|
end
|
51
49
|
|
52
50
|
it "should work with suffix" do
|
53
|
-
@doc.cache_key(:foo).
|
54
|
-
should == "Post/#{@object_id}-20100620081007/foo"
|
51
|
+
@doc.cache_key(:foo).should == "Post/#{@object_id}-20100620081007/foo"
|
55
52
|
|
56
|
-
@doc.cache_key(:foo, :bar).
|
57
|
-
should == "Post/#{@object_id}-20100620081007/foo/bar"
|
53
|
+
@doc.cache_key(:foo, :bar).should == "Post/#{@object_id}-20100620081007/foo/bar"
|
58
54
|
end
|
59
55
|
end
|
60
56
|
|
@@ -64,12 +60,9 @@ describe "Caching" do
|
|
64
60
|
end
|
65
61
|
|
66
62
|
it "should work with suffix" do
|
67
|
-
@doc.cache_key(:foo).
|
68
|
-
|
69
|
-
|
70
|
-
@doc.cache_key(:foo, :bar, :baz).
|
71
|
-
should == "Post/#{@object_id}/foo/bar/baz"
|
63
|
+
@doc.cache_key(:foo).should == "Post/#{@object_id}/foo"
|
64
|
+
@doc.cache_key(:foo, :bar, :baz).should == "Post/#{@object_id}/foo/bar/baz"
|
72
65
|
end
|
73
66
|
end
|
74
67
|
end
|
75
|
-
end
|
68
|
+
end
|