mongo_mapper 0.13.0.beta2 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +1 -1
- data/README.md +64 -0
- data/examples/keys.rb +3 -3
- data/examples/modifiers/set.rb +2 -2
- data/examples/querying.rb +3 -3
- data/examples/safe.rb +2 -2
- data/examples/scopes.rb +1 -1
- data/lib/mongo_mapper.rb +5 -0
- data/lib/mongo_mapper/connection.rb +16 -37
- data/lib/mongo_mapper/document.rb +4 -0
- data/lib/mongo_mapper/extensions/array.rb +14 -6
- data/lib/mongo_mapper/extensions/hash.rb +15 -3
- data/lib/mongo_mapper/extensions/object.rb +4 -0
- data/lib/mongo_mapper/extensions/object_id.rb +5 -1
- data/lib/mongo_mapper/extensions/string.rb +13 -5
- data/lib/mongo_mapper/extensions/symbol.rb +18 -0
- data/lib/mongo_mapper/plugins/accessible.rb +14 -4
- data/lib/mongo_mapper/plugins/associations.rb +7 -6
- data/lib/mongo_mapper/plugins/associations/base.rb +18 -13
- data/lib/mongo_mapper/plugins/associations/belongs_to_association.rb +10 -1
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +9 -8
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +12 -11
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +4 -4
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +24 -23
- data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +18 -16
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +55 -48
- data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +14 -13
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +7 -6
- data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +7 -5
- data/lib/mongo_mapper/plugins/associations/one_as_proxy.rb +17 -14
- data/lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb +14 -13
- data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +9 -9
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +27 -26
- data/lib/mongo_mapper/plugins/associations/proxy.rb +31 -28
- data/lib/mongo_mapper/plugins/callbacks.rb +14 -1
- data/lib/mongo_mapper/plugins/counter_cache.rb +97 -0
- 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.rb +10 -9
- data/lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb +18 -17
- data/lib/mongo_mapper/plugins/embedded_callbacks.rb +2 -1
- data/lib/mongo_mapper/plugins/embedded_document.rb +1 -1
- data/lib/mongo_mapper/plugins/identity_map.rb +1 -1
- data/lib/mongo_mapper/plugins/indexes.rb +37 -2
- data/lib/mongo_mapper/plugins/keys.rb +202 -142
- data/lib/mongo_mapper/plugins/keys/key.rb +22 -13
- data/lib/mongo_mapper/plugins/keys/static.rb +45 -0
- data/lib/mongo_mapper/plugins/modifiers.rb +59 -28
- data/lib/mongo_mapper/plugins/partial_updates.rb +86 -0
- data/lib/mongo_mapper/plugins/persistence.rb +13 -8
- data/lib/mongo_mapper/plugins/protected.rb +6 -5
- data/lib/mongo_mapper/plugins/querying.rb +85 -42
- data/lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb +32 -9
- data/lib/mongo_mapper/plugins/rails.rb +1 -0
- data/lib/mongo_mapper/plugins/safe.rb +10 -4
- data/lib/mongo_mapper/plugins/sci.rb +4 -1
- data/lib/mongo_mapper/plugins/scopes.rb +78 -7
- data/lib/mongo_mapper/plugins/stats.rb +17 -0
- data/lib/mongo_mapper/plugins/timestamps.rb +1 -0
- data/lib/mongo_mapper/plugins/touch.rb +1 -1
- data/lib/mongo_mapper/plugins/validations.rb +7 -2
- data/lib/mongo_mapper/railtie.rb +20 -0
- data/lib/mongo_mapper/railtie/database.rake +1 -1
- data/lib/mongo_mapper/utils.rb +2 -2
- data/lib/mongo_mapper/version.rb +1 -1
- data/lib/rails/generators/mongo_mapper/config/config_generator.rb +12 -13
- data/lib/rails/generators/mongo_mapper/model/model_generator.rb +9 -9
- data/spec/examples.txt +1643 -0
- data/spec/functional/accessible_spec.rb +13 -13
- data/spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb +13 -13
- data/spec/functional/associations/belongs_to_proxy_spec.rb +18 -19
- data/spec/functional/associations/in_array_proxy_spec.rb +10 -10
- data/spec/functional/associations/many_documents_as_proxy_spec.rb +6 -6
- data/spec/functional/associations/many_documents_proxy_spec.rb +85 -14
- data/spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb +13 -13
- data/spec/functional/associations/many_embedded_proxy_spec.rb +1 -1
- data/spec/functional/associations/many_polymorphic_proxy_spec.rb +4 -4
- data/spec/functional/associations/one_as_proxy_spec.rb +10 -10
- data/spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb +9 -9
- data/spec/functional/associations/one_embedded_proxy_spec.rb +3 -3
- data/spec/functional/associations/one_proxy_spec.rb +10 -10
- data/spec/functional/associations_spec.rb +3 -3
- data/spec/functional/binary_spec.rb +2 -2
- data/spec/functional/caching_spec.rb +8 -15
- data/spec/functional/callbacks_spec.rb +89 -2
- data/spec/functional/counter_cache_spec.rb +235 -0
- data/spec/functional/dirty_spec.rb +63 -46
- data/spec/functional/document_spec.rb +30 -2
- data/spec/functional/dumpable_spec.rb +1 -1
- data/spec/functional/embedded_document_spec.rb +18 -18
- data/spec/functional/identity_map_spec.rb +27 -14
- data/spec/functional/indexes_spec.rb +44 -19
- data/spec/functional/keys_spec.rb +117 -15
- data/spec/functional/logger_spec.rb +3 -3
- data/spec/functional/modifiers_spec.rb +67 -19
- data/spec/functional/partial_updates_spec.rb +577 -0
- data/spec/functional/protected_spec.rb +14 -14
- data/spec/functional/querying_spec.rb +55 -28
- data/spec/functional/safe_spec.rb +23 -27
- data/spec/functional/sci_spec.rb +49 -14
- data/spec/functional/scopes_spec.rb +235 -2
- data/spec/functional/static_keys_spec.rb +153 -0
- data/spec/functional/stats_spec.rb +86 -0
- data/spec/functional/touch_spec.rb +6 -6
- data/spec/functional/validations_spec.rb +51 -57
- data/spec/quality_spec.rb +51 -0
- data/spec/spec_helper.rb +37 -9
- data/spec/support/matchers.rb +5 -14
- data/spec/unit/associations/base_spec.rb +12 -12
- data/spec/unit/associations/belongs_to_association_spec.rb +2 -2
- data/spec/unit/associations/many_association_spec.rb +2 -2
- data/spec/unit/associations/one_association_spec.rb +2 -2
- data/spec/unit/associations/proxy_spec.rb +19 -16
- data/spec/unit/clone_spec.rb +1 -1
- data/spec/unit/document_spec.rb +8 -8
- data/spec/unit/dynamic_finder_spec.rb +8 -8
- data/spec/unit/embedded_document_spec.rb +18 -19
- data/spec/unit/extensions_spec.rb +41 -17
- data/spec/unit/identity_map_middleware_spec.rb +65 -96
- data/spec/unit/inspect_spec.rb +4 -4
- data/spec/unit/key_spec.rb +28 -26
- data/spec/unit/keys_spec.rb +10 -10
- data/spec/unit/model_generator_spec.rb +2 -4
- data/spec/unit/mongo_mapper_spec.rb +38 -85
- data/spec/unit/rails_spec.rb +5 -0
- data/spec/unit/serialization_spec.rb +1 -1
- data/spec/unit/time_zones_spec.rb +2 -2
- data/spec/unit/validations_spec.rb +28 -15
- metadata +188 -161
- data/README.rdoc +0 -55
- data/lib/mongo_mapper/extensions/ordered_hash.rb +0 -23
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "ManyEmbeddedPolymorphicProxy" do
|
4
4
|
before do
|
5
|
-
Catalog.collection.
|
6
|
-
TrModels::Fleet.collection.
|
5
|
+
Catalog.collection.drop
|
6
|
+
TrModels::Fleet.collection.drop
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should default reader to empty array" do
|
@@ -21,7 +21,7 @@ describe "ManyEmbeddedPolymorphicProxy" do
|
|
21
21
|
it "should be able to replace the association" do
|
22
22
|
catalog = Catalog.new
|
23
23
|
catalog.medias = [Video.new('file' => 'video.mpg', 'length' => 3600)]
|
24
|
-
catalog.save.should
|
24
|
+
catalog.save.should be_truthy
|
25
25
|
|
26
26
|
catalog = catalog.reload
|
27
27
|
catalog.medias.size.should == 1
|
@@ -40,7 +40,7 @@ describe "ManyEmbeddedPolymorphicProxy" do
|
|
40
40
|
catalog.medias[1].serial_number.should == '1B'
|
41
41
|
catalog.medias[1].class.should == Robot
|
42
42
|
|
43
|
-
catalog.save.should
|
43
|
+
catalog.save.should be_truthy
|
44
44
|
catalog.reload
|
45
45
|
|
46
46
|
catalog.medias.size.should == 2
|
@@ -60,7 +60,7 @@ describe "ManyEmbeddedPolymorphicProxy" do
|
|
60
60
|
catalog.medias[1].serial_number.should == '1B'
|
61
61
|
catalog.medias[1].class.should == Robot
|
62
62
|
|
63
|
-
catalog.save.should
|
63
|
+
catalog.save.should be_truthy
|
64
64
|
catalog.reload
|
65
65
|
|
66
66
|
catalog.medias.size.should == 2
|
@@ -81,7 +81,7 @@ describe "ManyEmbeddedPolymorphicProxy" do
|
|
81
81
|
catalog.medias[1].serial_number.should == '1B'
|
82
82
|
catalog.medias[1].class.should == Robot
|
83
83
|
|
84
|
-
catalog.save.should
|
84
|
+
catalog.save.should be_truthy
|
85
85
|
catalog.reload
|
86
86
|
|
87
87
|
catalog.medias.size.should == 2
|
@@ -105,7 +105,7 @@ describe "ManyEmbeddedPolymorphicProxy" do
|
|
105
105
|
Image.new('file' => 'image.png', 'width' => 800, 'height' => 600)
|
106
106
|
]
|
107
107
|
catalog.medias.count.should == 3
|
108
|
-
catalog.save.should
|
108
|
+
catalog.save.should be_truthy
|
109
109
|
catalog.reload
|
110
110
|
catalog.medias.count.should == 3
|
111
111
|
end
|
@@ -118,7 +118,7 @@ describe "ManyEmbeddedPolymorphicProxy" do
|
|
118
118
|
Music.new('file' => 'music.mp3', 'bitrate' => '128kbps'),
|
119
119
|
Image.new('file' => 'image.png', 'width' => 800, 'height' => 600)
|
120
120
|
]
|
121
|
-
catalog.save.should
|
121
|
+
catalog.save.should be_truthy
|
122
122
|
|
123
123
|
catalog = catalog.reload
|
124
124
|
catalog.medias.size.should == 3
|
@@ -146,7 +146,7 @@ describe "ManyEmbeddedPolymorphicProxy" do
|
|
146
146
|
fleet.transports.size.should == 3
|
147
147
|
fleet.transports[0].class.should == TrModels::Ambulance
|
148
148
|
fleet.transports[0].license_plate.should == 'GGG123'
|
149
|
-
fleet.transports[0].icu.should
|
149
|
+
fleet.transports[0].icu.should be_truthy
|
150
150
|
fleet.transports[1].class.should == TrModels::Car
|
151
151
|
fleet.transports[1].license_plate.should == 'ABC123'
|
152
152
|
fleet.transports[1].model.should == 'VW Golf'
|
@@ -155,12 +155,12 @@ describe "ManyEmbeddedPolymorphicProxy" do
|
|
155
155
|
fleet.transports[2].license_plate.should == 'DEF123'
|
156
156
|
fleet.transports[2].model.should == 'Honda Accord'
|
157
157
|
fleet.transports[2].year.should == 2008
|
158
|
-
fleet.save.should
|
158
|
+
fleet.save.should be_truthy
|
159
159
|
|
160
160
|
fleet = fleet.reload
|
161
161
|
fleet.transports.size.should == 3
|
162
162
|
fleet.transports[0].license_plate.should == 'GGG123'
|
163
|
-
fleet.transports[0].icu.should
|
163
|
+
fleet.transports[0].icu.should be_truthy
|
164
164
|
fleet.transports[1].license_plate.should == 'ABC123'
|
165
165
|
fleet.transports[1].model.should == 'VW Golf'
|
166
166
|
fleet.transports[1].year.should == 2001
|
@@ -184,7 +184,7 @@ describe "ManyEmbeddedPolymorphicProxy" do
|
|
184
184
|
it "should be able to replace the association" do
|
185
185
|
fleet = TrModels::Fleet.new
|
186
186
|
fleet.transports = [TrModels::Car.new('license_plate' => 'DCU2013', 'model' => 'Honda Civic')]
|
187
|
-
fleet.save.should
|
187
|
+
fleet.save.should be_truthy
|
188
188
|
|
189
189
|
fleet = fleet.reload
|
190
190
|
fleet.transports.size.should == 1
|
@@ -198,7 +198,7 @@ describe "ManyEmbeddedPolymorphicProxy" do
|
|
198
198
|
TrModels::Bus.new('license_plate' => 'XYZ9090', 'max_passengers' => 51),
|
199
199
|
TrModels::Ambulance.new('license_plate' => 'HDD3030', 'icu' => true)
|
200
200
|
]
|
201
|
-
fleet.save.should
|
201
|
+
fleet.save.should be_truthy
|
202
202
|
|
203
203
|
fleet = fleet.reload
|
204
204
|
fleet.transports.size.should == 3
|
@@ -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
|
|
@@ -9,7 +9,7 @@ describe "OneAsProxy" do
|
|
9
9
|
|
10
10
|
it "should default to nil" do
|
11
11
|
@post_class.one :author, :as => :authorable, :class => @author_class
|
12
|
-
@post_class.new.author.nil?.should
|
12
|
+
@post_class.new.author.nil?.should be_truthy
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should return nil instead of a proxy" do
|
@@ -29,7 +29,7 @@ describe "OneAsProxy" do
|
|
29
29
|
post = @post_class.new('author' => { 'name' => 'Frank' })
|
30
30
|
post.author.name.should == 'Frank'
|
31
31
|
|
32
|
-
post.save.should
|
32
|
+
post.save.should be_truthy
|
33
33
|
post.reload
|
34
34
|
|
35
35
|
post.author.name.should == 'Frank'
|
@@ -59,7 +59,7 @@ describe "OneAsProxy" do
|
|
59
59
|
@post.reload
|
60
60
|
|
61
61
|
@post.author.should == @author
|
62
|
-
@post.author.nil?.should
|
62
|
+
@post.author.nil?.should be_falsey
|
63
63
|
|
64
64
|
new_author = @author_class.new(:name => 'Emily')
|
65
65
|
@post.author = new_author
|
@@ -71,7 +71,7 @@ describe "OneAsProxy" do
|
|
71
71
|
@post.reload
|
72
72
|
|
73
73
|
@post.author.should == @author
|
74
|
-
@post.author.nil?.should
|
74
|
+
@post.author.nil?.should be_falsey
|
75
75
|
|
76
76
|
original_author = @post.author
|
77
77
|
original_author.name.should == 'Frank'
|
@@ -104,7 +104,7 @@ describe "OneAsProxy" do
|
|
104
104
|
@post.reload
|
105
105
|
|
106
106
|
@post.author.name.should == 'Frank'
|
107
|
-
@post.author.nil?.should
|
107
|
+
@post.author.nil?.should be_falsey
|
108
108
|
|
109
109
|
@post.author = {'name' => 'Emily'}
|
110
110
|
@post.author.name.should == 'Emily'
|
@@ -263,10 +263,10 @@ describe "OneAsProxy" do
|
|
263
263
|
@post_class.one :author, :as => :authorable, :class => @author_class
|
264
264
|
|
265
265
|
post = @post_class.new
|
266
|
-
post.author?.should
|
266
|
+
post.author?.should be_falsey
|
267
267
|
|
268
268
|
post.author = @author_class.new(:name => 'Frank')
|
269
|
-
post.author?.should
|
269
|
+
post.author?.should be_truthy
|
270
270
|
end
|
271
271
|
|
272
272
|
it "should work with criteria" do
|
@@ -288,7 +288,7 @@ describe "OneAsProxy" do
|
|
288
288
|
post.update_attributes!(:author => author)
|
289
289
|
post.reload
|
290
290
|
post.author = nil
|
291
|
-
post.author.nil?.should
|
291
|
+
post.author.nil?.should be_truthy
|
292
292
|
end
|
293
293
|
|
294
294
|
context "destroying parent with :dependent" do
|
@@ -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
|
@@ -35,7 +35,7 @@ describe "OneEmbeddedPolymorhpicProxy" do
|
|
35
35
|
post.author.name.should == 'Frank'
|
36
36
|
post.author.class.should == Human
|
37
37
|
|
38
|
-
post.save.should
|
38
|
+
post.save.should be_truthy
|
39
39
|
post.reload
|
40
40
|
|
41
41
|
post.author.name.should == 'Frank'
|
@@ -56,7 +56,7 @@ describe "OneEmbeddedPolymorhpicProxy" do
|
|
56
56
|
@post.reload
|
57
57
|
|
58
58
|
@post.author.should == @human
|
59
|
-
@post.author.nil?.should
|
59
|
+
@post.author.nil?.should be_falsey
|
60
60
|
@post.author.class.should == Human
|
61
61
|
|
62
62
|
new_human = Human.new(:name => 'Emily')
|
@@ -70,7 +70,7 @@ describe "OneEmbeddedPolymorhpicProxy" do
|
|
70
70
|
@post.reload
|
71
71
|
|
72
72
|
@post.author.should == @human
|
73
|
-
@post.author.nil?.should
|
73
|
+
@post.author.nil?.should be_falsey
|
74
74
|
|
75
75
|
original_author = @post.author
|
76
76
|
original_author.name.should == 'Frank'
|
@@ -99,7 +99,7 @@ describe "OneEmbeddedPolymorhpicProxy" do
|
|
99
99
|
@post.reload
|
100
100
|
|
101
101
|
@post.author.serial_number.should == '1B'
|
102
|
-
@post.author.nil?.should
|
102
|
+
@post.author.nil?.should be_falsey
|
103
103
|
|
104
104
|
@post.author = {'serial_number' => '2C'}
|
105
105
|
@post.author.serial_number.should == '2C'
|
@@ -142,13 +142,13 @@ describe "OneEmbeddedPolymorhpicProxy" do
|
|
142
142
|
|
143
143
|
post.author.class.should == TrModels::Ambulance
|
144
144
|
post.author.license_plate.should == 'GGG123'
|
145
|
-
post.author.icu.should
|
146
|
-
post.save.should
|
145
|
+
post.author.icu.should be_truthy
|
146
|
+
post.save.should be_truthy
|
147
147
|
|
148
148
|
post = post.reload
|
149
149
|
post.author.class.should == TrModels::Ambulance
|
150
150
|
post.author.license_plate.should == 'GGG123'
|
151
|
-
post.author.icu.should
|
151
|
+
post.author.icu.should be_truthy
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should not have problem loading root document if embedded one is nil" do
|
@@ -179,10 +179,10 @@ describe "OneEmbeddedPolymorhpicProxy" do
|
|
179
179
|
@post_class.one :author, :polymorphic => true, :class => Robot
|
180
180
|
|
181
181
|
post = @post_class.new
|
182
|
-
post.author?.should
|
182
|
+
post.author?.should be_falsey
|
183
183
|
|
184
184
|
post.author = Human.new(:name => 'Frank')
|
185
|
-
post.author?.should
|
185
|
+
post.author?.should be_truthy
|
186
186
|
end
|
187
187
|
|
188
188
|
it "should initialize id for nested embedded document created from hash" do
|
@@ -38,7 +38,7 @@ describe "OneEmbeddedProxy" do
|
|
38
38
|
post.reload
|
39
39
|
|
40
40
|
post.author.should == author
|
41
|
-
post.author.nil?.should
|
41
|
+
post.author.nil?.should be_falsey
|
42
42
|
|
43
43
|
new_author = @author_class.new(:name => 'Emily')
|
44
44
|
post.author = new_author
|
@@ -72,10 +72,10 @@ describe "OneEmbeddedProxy" do
|
|
72
72
|
@post_class.one :author, :class => @author_class
|
73
73
|
|
74
74
|
post = @post_class.new
|
75
|
-
post.author?.should
|
75
|
+
post.author?.should be_falsey
|
76
76
|
|
77
77
|
post.author = @author_class.new(:name => 'Frank')
|
78
|
-
post.author?.should
|
78
|
+
post.author?.should be_truthy
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should initialize id for nested embedded document created from hash" do
|
@@ -11,7 +11,7 @@ describe "OneProxy" do
|
|
11
11
|
|
12
12
|
it "should default to nil" do
|
13
13
|
@post_class.one :author, :class => @author_class
|
14
|
-
@post_class.new.author.nil?.should
|
14
|
+
@post_class.new.author.nil?.should be_truthy
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should return nil instead of a proxy" do
|
@@ -25,7 +25,7 @@ describe "OneProxy" do
|
|
25
25
|
post = @post_class.new('author' => { 'name' => 'Frank' })
|
26
26
|
post.author.name.should == 'Frank'
|
27
27
|
|
28
|
-
post.save.should
|
28
|
+
post.save.should be_truthy
|
29
29
|
post.reload
|
30
30
|
|
31
31
|
post.author.name.should == 'Frank'
|
@@ -42,7 +42,7 @@ describe "OneProxy" do
|
|
42
42
|
post.reload
|
43
43
|
|
44
44
|
post.author.should == author
|
45
|
-
post.author.nil?.should
|
45
|
+
post.author.nil?.should be_falsey
|
46
46
|
|
47
47
|
new_author = @author_class.new(:name => 'Emily')
|
48
48
|
post.author = new_author
|
@@ -58,7 +58,7 @@ describe "OneProxy" do
|
|
58
58
|
post.reload
|
59
59
|
|
60
60
|
post.author.should == author
|
61
|
-
post.author.nil?.should
|
61
|
+
post.author.nil?.should be_falsey
|
62
62
|
|
63
63
|
original_author = post.author
|
64
64
|
original_author.name.should == 'Frank'
|
@@ -79,7 +79,7 @@ describe "OneProxy" do
|
|
79
79
|
post.reload
|
80
80
|
|
81
81
|
post.author.name.should == 'Frank'
|
82
|
-
post.author.nil?.should
|
82
|
+
post.author.nil?.should be_falsey
|
83
83
|
|
84
84
|
post.author = {'name' => 'Emily'}
|
85
85
|
post.author.name.should == 'Emily'
|
@@ -207,10 +207,10 @@ describe "OneProxy" do
|
|
207
207
|
@post_class.one :author, :class => @author_class
|
208
208
|
|
209
209
|
post = @post_class.new
|
210
|
-
post.author?.should
|
210
|
+
post.author?.should be_falsey
|
211
211
|
|
212
212
|
post.author = @author_class.new(:name => 'Frank')
|
213
|
-
post.author?.should
|
213
|
+
post.author?.should be_truthy
|
214
214
|
end
|
215
215
|
|
216
216
|
it "should work with criteria" do
|
@@ -232,7 +232,7 @@ describe "OneProxy" do
|
|
232
232
|
post.update_attributes!(:author => author)
|
233
233
|
post.reload
|
234
234
|
post.author = nil
|
235
|
-
post.author.nil?.should
|
235
|
+
post.author.nil?.should be_truthy
|
236
236
|
end
|
237
237
|
|
238
238
|
context "destroying parent with :dependent" do
|
@@ -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
|
@@ -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
|
@@ -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,7 +33,7 @@ describe "Caching" do
|
|
35
33
|
before do
|
36
34
|
@object_id = BSON::ObjectId.new
|
37
35
|
@doc = @klass.new
|
38
|
-
@doc.stub(:persisted).and_return(true)
|
36
|
+
@doc.stub(:persisted?).and_return(true)
|
39
37
|
@doc.stub(:id).and_return(@object_id)
|
40
38
|
end
|
41
39
|
|
@@ -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
|