mongo_mapper 0.12.0 → 0.13.0.beta1

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.
Files changed (154) hide show
  1. checksums.yaml +7 -0
  2. data/README.rdoc +35 -13
  3. data/bin/mmconsole +1 -1
  4. data/lib/mongo_mapper.rb +4 -0
  5. data/lib/mongo_mapper/connection.rb +17 -6
  6. data/lib/mongo_mapper/document.rb +1 -0
  7. data/lib/mongo_mapper/exceptions.rb +4 -1
  8. data/lib/mongo_mapper/extensions/binary.rb +1 -1
  9. data/lib/mongo_mapper/extensions/boolean.rb +20 -23
  10. data/lib/mongo_mapper/extensions/date.rb +3 -3
  11. data/lib/mongo_mapper/extensions/integer.rb +5 -1
  12. data/lib/mongo_mapper/extensions/kernel.rb +2 -0
  13. data/lib/mongo_mapper/extensions/ordered_hash.rb +23 -0
  14. data/lib/mongo_mapper/extensions/string.rb +2 -2
  15. data/lib/mongo_mapper/extensions/time.rb +7 -5
  16. data/lib/mongo_mapper/middleware/identity_map.rb +3 -4
  17. data/lib/mongo_mapper/plugins.rb +1 -1
  18. data/lib/mongo_mapper/plugins/associations.rb +11 -5
  19. data/lib/mongo_mapper/plugins/associations/base.rb +5 -3
  20. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +0 -0
  21. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +8 -8
  22. data/lib/mongo_mapper/plugins/associations/collection.rb +2 -0
  23. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +32 -7
  24. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +2 -2
  25. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +12 -12
  26. data/lib/mongo_mapper/plugins/associations/proxy.rb +5 -1
  27. data/lib/mongo_mapper/plugins/associations/single_association.rb +6 -6
  28. data/lib/mongo_mapper/plugins/clone.rb +4 -2
  29. data/lib/mongo_mapper/plugins/dirty.rb +22 -21
  30. data/lib/mongo_mapper/plugins/document.rb +4 -4
  31. data/lib/mongo_mapper/plugins/dumpable.rb +22 -0
  32. data/lib/mongo_mapper/plugins/embedded_callbacks.rb +58 -9
  33. data/lib/mongo_mapper/plugins/identity_map.rb +42 -32
  34. data/lib/mongo_mapper/plugins/keys.rb +133 -54
  35. data/lib/mongo_mapper/plugins/keys/key.rb +68 -22
  36. data/lib/mongo_mapper/plugins/modifiers.rb +26 -19
  37. data/lib/mongo_mapper/plugins/persistence.rb +15 -5
  38. data/lib/mongo_mapper/plugins/querying.rb +15 -40
  39. data/lib/mongo_mapper/plugins/querying/{decorator.rb → decorated_plucky_query.rb} +24 -4
  40. data/lib/mongo_mapper/plugins/rails.rb +22 -2
  41. data/lib/mongo_mapper/plugins/safe.rb +8 -5
  42. data/lib/mongo_mapper/plugins/sci.rb +26 -4
  43. data/lib/mongo_mapper/plugins/scopes.rb +5 -4
  44. data/lib/mongo_mapper/plugins/timestamps.rb +11 -4
  45. data/lib/mongo_mapper/plugins/validations.rb +1 -1
  46. data/lib/mongo_mapper/utils.rb +12 -0
  47. data/lib/mongo_mapper/version.rb +1 -1
  48. data/lib/rails/generators/mongo_mapper/config/config_generator.rb +20 -7
  49. data/lib/rails/generators/mongo_mapper/config/templates/mongo.yml +6 -0
  50. data/lib/rails/generators/mongo_mapper/model/model_generator.rb +18 -1
  51. data/lib/rails/generators/mongo_mapper/model/templates/model.rb +9 -5
  52. data/{test/functional/test_accessible.rb → spec/functional/accessible_spec.rb} +29 -29
  53. data/{test/functional/associations/test_belongs_to_polymorphic_proxy.rb → spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb} +10 -10
  54. data/{test/functional/associations/test_belongs_to_proxy.rb → spec/functional/associations/belongs_to_proxy_spec.rb} +82 -64
  55. data/{test/functional/associations/test_in_array_proxy.rb → spec/functional/associations/in_array_proxy_spec.rb} +68 -68
  56. data/{test/functional/associations/test_many_documents_as_proxy.rb → spec/functional/associations/many_documents_as_proxy_spec.rb} +37 -38
  57. data/{test/functional/associations/test_many_documents_proxy.rb → spec/functional/associations/many_documents_proxy_spec.rb} +233 -146
  58. data/{test/functional/associations/test_many_embedded_polymorphic_proxy.rb → spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb} +19 -20
  59. data/{test/functional/associations/test_many_embedded_proxy.rb → spec/functional/associations/many_embedded_proxy_spec.rb} +23 -24
  60. data/{test/functional/associations/test_many_polymorphic_proxy.rb → spec/functional/associations/many_polymorphic_proxy_spec.rb} +45 -46
  61. data/{test/functional/associations/test_one_as_proxy.rb → spec/functional/associations/one_as_proxy_spec.rb} +75 -77
  62. data/{test/functional/associations/test_one_embedded_polymorphic_proxy.rb → spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb} +31 -32
  63. data/{test/functional/associations/test_one_embedded_proxy.rb → spec/functional/associations/one_embedded_proxy_spec.rb} +10 -10
  64. data/{test/functional/associations/test_one_proxy.rb → spec/functional/associations/one_proxy_spec.rb} +125 -102
  65. data/spec/functional/associations_spec.rb +48 -0
  66. data/{test/functional/test_binary.rb → spec/functional/binary_spec.rb} +6 -6
  67. data/spec/functional/caching_spec.rb +75 -0
  68. data/{test/functional/test_callbacks.rb → spec/functional/callbacks_spec.rb} +84 -26
  69. data/{test/functional/test_dirty.rb → spec/functional/dirty_spec.rb} +57 -42
  70. data/{test/functional/test_document.rb → spec/functional/document_spec.rb} +52 -52
  71. data/spec/functional/dumpable_spec.rb +24 -0
  72. data/{test/functional/test_dynamic_querying.rb → spec/functional/dynamic_querying_spec.rb} +14 -14
  73. data/{test/functional/test_embedded_document.rb → spec/functional/embedded_document_spec.rb} +51 -42
  74. data/{test/functional/test_equality.rb → spec/functional/equality_spec.rb} +4 -4
  75. data/spec/functional/extensions_spec.rb +16 -0
  76. data/{test/functional/test_identity_map.rb → spec/functional/identity_map_spec.rb} +73 -61
  77. data/spec/functional/indexes_spec.rb +48 -0
  78. data/spec/functional/keys_spec.rb +224 -0
  79. data/{test/functional/test_logger.rb → spec/functional/logger_spec.rb} +6 -6
  80. data/spec/functional/modifiers_spec.rb +550 -0
  81. data/spec/functional/pagination_spec.rb +89 -0
  82. data/spec/functional/protected_spec.rb +199 -0
  83. data/spec/functional/querying_spec.rb +1003 -0
  84. data/spec/functional/rails_spec.rb +55 -0
  85. data/spec/functional/safe_spec.rb +163 -0
  86. data/{test/functional/test_sci.rb → spec/functional/sci_spec.rb} +123 -34
  87. data/{test/functional/test_scopes.rb → spec/functional/scopes_spec.rb} +59 -26
  88. data/spec/functional/timestamps_spec.rb +97 -0
  89. data/{test/functional/test_touch.rb → spec/functional/touch_spec.rb} +13 -13
  90. data/spec/functional/userstamps_spec.rb +46 -0
  91. data/{test/functional/test_validations.rb → spec/functional/validations_spec.rb} +64 -64
  92. data/spec/spec_helper.rb +81 -0
  93. data/spec/support/matchers.rb +24 -0
  94. data/{test → spec/support}/models.rb +1 -6
  95. data/spec/unit/associations/base_spec.rb +146 -0
  96. data/spec/unit/associations/belongs_to_association_spec.rb +30 -0
  97. data/spec/unit/associations/many_association_spec.rb +64 -0
  98. data/spec/unit/associations/one_association_spec.rb +48 -0
  99. data/{test/unit/associations/test_proxy.rb → spec/unit/associations/proxy_spec.rb} +21 -21
  100. data/{test/unit/test_clone.rb → spec/unit/clone_spec.rb} +21 -11
  101. data/spec/unit/config_generator_spec.rb +24 -0
  102. data/{test/unit/test_document.rb → spec/unit/document_spec.rb} +42 -42
  103. data/{test/unit/test_dynamic_finder.rb → spec/unit/dynamic_finder_spec.rb} +28 -28
  104. data/{test/unit/test_embedded_document.rb → spec/unit/embedded_document_spec.rb} +102 -108
  105. data/{test/unit/test_equality.rb → spec/unit/equality_spec.rb} +7 -7
  106. data/{test/unit/test_exceptions.rb → spec/unit/exceptions_spec.rb} +3 -3
  107. data/{test/unit/test_extensions.rb → spec/unit/extensions_spec.rb} +85 -71
  108. data/spec/unit/identity_map_middleware_spec.rb +134 -0
  109. data/{test/unit/test_inspect.rb → spec/unit/inspect_spec.rb} +8 -8
  110. data/{test/unit/test_key.rb → spec/unit/key_spec.rb} +82 -52
  111. data/spec/unit/keys_spec.rb +155 -0
  112. data/spec/unit/model_generator_spec.rb +47 -0
  113. data/spec/unit/mongo_mapper_spec.rb +184 -0
  114. data/spec/unit/pagination_spec.rb +11 -0
  115. data/{test/unit/test_plugins.rb → spec/unit/plugins_spec.rb} +14 -14
  116. data/spec/unit/rails_compatibility_spec.rb +40 -0
  117. data/{test/unit/test_rails_reflect_on_association.rb → spec/unit/rails_reflect_on_association_spec.rb} +9 -9
  118. data/{test/unit/test_rails.rb → spec/unit/rails_spec.rb} +31 -31
  119. data/spec/unit/serialization_spec.rb +169 -0
  120. data/spec/unit/serializers/json_serializer_spec.rb +218 -0
  121. data/spec/unit/serializers/xml_serializer_spec.rb +198 -0
  122. data/{test/unit/test_time_zones.rb → spec/unit/time_zones_spec.rb} +8 -8
  123. data/{test/unit/test_translation.rb → spec/unit/translation_spec.rb} +6 -6
  124. data/{test/unit/test_validations.rb → spec/unit/validations_spec.rb} +72 -59
  125. metadata +199 -179
  126. data/test/_NOTE_ON_TESTING +0 -1
  127. data/test/functional/test_associations.rb +0 -46
  128. data/test/functional/test_caching.rb +0 -77
  129. data/test/functional/test_indexes.rb +0 -50
  130. data/test/functional/test_modifiers.rb +0 -537
  131. data/test/functional/test_pagination.rb +0 -91
  132. data/test/functional/test_protected.rb +0 -201
  133. data/test/functional/test_querying.rb +0 -935
  134. data/test/functional/test_safe.rb +0 -76
  135. data/test/functional/test_timestamps.rb +0 -62
  136. data/test/functional/test_userstamps.rb +0 -44
  137. data/test/support/railtie.rb +0 -4
  138. data/test/support/railtie/autoloaded.rb +0 -2
  139. data/test/support/railtie/not_autoloaded.rb +0 -3
  140. data/test/support/railtie/parent.rb +0 -3
  141. data/test/test_active_model_lint.rb +0 -18
  142. data/test/test_helper.rb +0 -93
  143. data/test/unit/associations/test_base.rb +0 -146
  144. data/test/unit/associations/test_belongs_to_association.rb +0 -29
  145. data/test/unit/associations/test_many_association.rb +0 -63
  146. data/test/unit/associations/test_one_association.rb +0 -47
  147. data/test/unit/serializers/test_json_serializer.rb +0 -216
  148. data/test/unit/serializers/test_xml_serializer.rb +0 -196
  149. data/test/unit/test_identity_map_middleware.rb +0 -132
  150. data/test/unit/test_keys.rb +0 -65
  151. data/test/unit/test_mongo_mapper.rb +0 -157
  152. data/test/unit/test_pagination.rb +0 -11
  153. data/test/unit/test_rails_compatibility.rb +0 -38
  154. data/test/unit/test_serialization.rb +0 -166
@@ -1,8 +1,8 @@
1
- require 'test_helper'
1
+ require 'spec_helper'
2
2
 
3
- class EqualityTest < Test::Unit::TestCase
3
+ describe "Equality" do
4
4
  context "Case equality" do
5
- setup do
5
+ before do
6
6
  @person = Doc()
7
7
  @address = Doc()
8
8
 
@@ -10,7 +10,7 @@ class EqualityTest < Test::Unit::TestCase
10
10
  @address.belongs_to :person, :class => @person
11
11
  end
12
12
 
13
- should "work with proxies" do
13
+ it "should work with proxies" do
14
14
  person = @person.create!
15
15
  address = @address.create!(:person => person)
16
16
  @person.should === address.person
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Core Extensions" do
4
+ describe "Time" do
5
+ let(:doc) do
6
+ Doc do
7
+ key :created_at, Time
8
+ end
9
+ end
10
+
11
+ it "should match the precision of Time types stored in the database" do
12
+ d = doc.create(:created_at => Time.now)
13
+ d.created_at.should == d.reload.created_at
14
+ end
15
+ end
16
+ end
@@ -1,6 +1,6 @@
1
- require 'test_helper'
1
+ require 'spec_helper'
2
2
 
3
- class IdentityMapTest < Test::Unit::TestCase
3
+ describe "IdentityMap" do
4
4
  def assert_in_map(*resources)
5
5
  [resources].flatten.each do |resource|
6
6
  MongoMapper::Plugins::IdentityMap.include?(resource).should be_true
@@ -14,24 +14,24 @@ class IdentityMapTest < Test::Unit::TestCase
14
14
  end
15
15
 
16
16
  def expect_no_queries
17
- Mongo::Collection.any_instance.expects(:find_one).never
18
- Mongo::Collection.any_instance.expects(:find).never
17
+ Mongo::Collection.any_instance.should_receive(:find_one).never
18
+ Mongo::Collection.any_instance.should_receive(:find).never
19
19
  end
20
20
 
21
21
  def expects_one_query
22
- Mongo::Collection.any_instance.expects(:find_one).once.returns({})
22
+ Mongo::Collection.any_instance.should_receive(:find_one).once.and_return({})
23
23
  end
24
24
 
25
25
  def clear_identity_map
26
26
  MongoMapper::Plugins::IdentityMap.clear
27
27
  end
28
28
 
29
- should "default identity map to off" do
29
+ it "should default identity map to off" do
30
30
  MongoMapper::Plugins::IdentityMap.enabled?.should be_false
31
31
  end
32
32
 
33
33
  context "Document" do
34
- setup do
34
+ before do
35
35
  @original_identity_map_enabled = MongoMapper::Plugins::IdentityMap.enabled
36
36
  MongoMapper::Plugins::IdentityMap.enabled = true
37
37
 
@@ -50,11 +50,11 @@ class IdentityMapTest < Test::Unit::TestCase
50
50
  clear_identity_map
51
51
  end
52
52
 
53
- teardown do
53
+ after do
54
54
  MongoMapper::Plugins::IdentityMap.enabled = @original_identity_map_enabled
55
55
  end
56
56
 
57
- should "be able to clear the map of all models" do
57
+ it "should be able to clear the map of all models" do
58
58
  person = @person_class.create(:name => 'John')
59
59
  post = @post_class.create(:title => 'IM 4eva')
60
60
 
@@ -66,19 +66,19 @@ class IdentityMapTest < Test::Unit::TestCase
66
66
  end
67
67
 
68
68
  context ".use" do
69
- setup do
69
+ before do
70
70
  @person = @person_class.create
71
71
  clear_identity_map
72
72
  end
73
73
 
74
- should "use the identity map" do
74
+ it "should use the identity map" do
75
75
  MongoMapper::Plugins::IdentityMap.enabled = false
76
76
  MongoMapper::Plugins::IdentityMap.use do
77
77
  @person_class.find(@person.id).should equal(@person_class.find(@person.id))
78
78
  end
79
79
  end
80
80
 
81
- should "clear the map" do
81
+ it "should clear the map" do
82
82
  MongoMapper::Plugins::IdentityMap.enabled = false
83
83
  MongoMapper::Plugins::IdentityMap.repository['hello'] = 'world'
84
84
  MongoMapper::Plugins::IdentityMap.use do
@@ -87,7 +87,7 @@ class IdentityMapTest < Test::Unit::TestCase
87
87
  MongoMapper::Plugins::IdentityMap.repository.empty?.should be_true
88
88
  end
89
89
 
90
- should "set enabled back to original status" do
90
+ it "should set enabled back to original status" do
91
91
  MongoMapper::Plugins::IdentityMap.enabled = false
92
92
  MongoMapper::Plugins::IdentityMap.enabled?.should be_false
93
93
  MongoMapper::Plugins::IdentityMap.use do
@@ -98,18 +98,18 @@ class IdentityMapTest < Test::Unit::TestCase
98
98
  end
99
99
 
100
100
  context ".without" do
101
- setup do
101
+ before do
102
102
  @person = @person_class.create
103
103
  clear_identity_map
104
104
  end
105
105
 
106
- should "skip the map" do
106
+ it "should skip the map" do
107
107
  MongoMapper::Plugins::IdentityMap.without do
108
108
  @person_class.find(@person.id).should_not equal(@person_class.find(@person.id))
109
109
  end
110
110
  end
111
111
 
112
- should "set enabled back to original value" do
112
+ it "should set enabled back to original value" do
113
113
  MongoMapper::Plugins::IdentityMap.enabled = true
114
114
  MongoMapper::Plugins::IdentityMap.enabled?.should be_true
115
115
  MongoMapper::Plugins::IdentityMap.without do
@@ -119,32 +119,32 @@ class IdentityMapTest < Test::Unit::TestCase
119
119
  end
120
120
  end
121
121
 
122
- should "default identity map to hash" do
122
+ it "should default identity map to hash" do
123
123
  MongoMapper::Plugins::IdentityMap.repository.should == {}
124
124
  end
125
125
 
126
- should "add key to map when saved" do
126
+ it "should add key to map when saved" do
127
127
  person = @person_class.new
128
128
  assert_not_in_map(person)
129
129
  person.save.should be_true
130
130
  assert_in_map(person)
131
131
  end
132
132
 
133
- should "allow saving with options" do
133
+ it "should allow saving with options" do
134
134
  person = @person_class.new
135
135
  assert_not_in_map(person)
136
136
  person.save(:validate => false).should be_true
137
137
  assert_in_map(person)
138
138
  end
139
139
 
140
- should "remove key from map when deleted" do
140
+ it "should remove key from map when deleted" do
141
141
  person = @person_class.create(:name => 'Fred')
142
142
  assert_in_map(person)
143
143
  person.delete
144
144
  assert_not_in_map(person)
145
145
  end
146
146
 
147
- should "remove key from map when destroyed" do
147
+ it "should remove key from map when destroyed" do
148
148
  person = @person_class.create(:name => 'Fred')
149
149
  assert_in_map(person)
150
150
  person.destroy
@@ -152,11 +152,11 @@ class IdentityMapTest < Test::Unit::TestCase
152
152
  end
153
153
 
154
154
  context "#reload" do
155
- setup do
155
+ before do
156
156
  @person = @person_class.create(:name => 'Fred')
157
157
  end
158
158
 
159
- should "re-query the object" do
159
+ it "should re-query the object" do
160
160
  assert_in_map(@person)
161
161
  expects_one_query
162
162
  @person.reload
@@ -164,16 +164,16 @@ class IdentityMapTest < Test::Unit::TestCase
164
164
  end
165
165
 
166
166
  context "#load" do
167
- setup do
167
+ before do
168
168
  @id = BSON::ObjectId.new
169
169
  end
170
170
 
171
- should "add document to map" do
171
+ it "should add document to map" do
172
172
  loaded = @person_class.load('_id' => @id, 'name' => 'Frank')
173
173
  assert_in_map(loaded)
174
174
  end
175
175
 
176
- should "return document if already in map" do
176
+ it "should return document if already in map" do
177
177
  first_load = @person_class.load('_id' => @id, 'name' => 'Frank')
178
178
  second_load = @person_class.load('_id' => @id, 'name' => 'Frank')
179
179
  first_load.should equal(second_load)
@@ -181,22 +181,22 @@ class IdentityMapTest < Test::Unit::TestCase
181
181
  end
182
182
 
183
183
  context "#find (with one id)" do
184
- should "return nil if not found " do
184
+ it "should return nil if not found " do
185
185
  @person_class.find(1234).should be_nil
186
186
  end
187
187
 
188
188
  context "for object not in map" do
189
- setup do
189
+ before do
190
190
  @person = @person_class.create(:name => 'Fred')
191
191
  clear_identity_map
192
192
  end
193
193
 
194
- should "query the database" do
194
+ it "should query the database" do
195
195
  expects_one_query
196
196
  @person_class.find(@person.id)
197
197
  end
198
198
 
199
- should "add object to map" do
199
+ it "should add object to map" do
200
200
  assert_not_in_map(@person)
201
201
  found_person = @person_class.find(@person.id)
202
202
  assert_in_map(found_person)
@@ -204,16 +204,16 @@ class IdentityMapTest < Test::Unit::TestCase
204
204
  end
205
205
 
206
206
  context "for object in map" do
207
- setup do
207
+ before do
208
208
  @person = @person_class.create(:name => 'Fred')
209
209
  end
210
210
 
211
- should "not query database" do
211
+ it "should not query database" do
212
212
  expect_no_queries
213
213
  @person_class.find(@person.id)
214
214
  end
215
215
 
216
- should "return exact object" do
216
+ it "should return exact object" do
217
217
  assert_in_map(@person)
218
218
  found_person = @person_class.find(@person.id)
219
219
  found_person.should equal(@person)
@@ -222,7 +222,7 @@ class IdentityMapTest < Test::Unit::TestCase
222
222
  end
223
223
 
224
224
  context "#find (with one id and options)" do
225
- setup do
225
+ before do
226
226
  @person = @person_class.create(:name => 'Fred')
227
227
  @post1 = @person.posts.create(:title => 'I Love Mongo')
228
228
  @post2 = @person.posts.create(:title => 'Migrations Suck!')
@@ -234,25 +234,25 @@ class IdentityMapTest < Test::Unit::TestCase
234
234
  #
235
235
  # I'm open to not making this query if someone can figure out reliable
236
236
  # way to check if document matches criteria without querying.
237
- should "query the database" do
237
+ it "should query the database" do
238
238
  assert_in_map(@post1)
239
239
  expects_one_query
240
240
  @person.posts.find(@post1.id)
241
241
  end
242
242
 
243
- should "return exact object" do
243
+ it "should return exact object" do
244
244
  assert_in_map(@post1)
245
245
  post = @person.posts.find(@post1.id)
246
246
  post.should equal(@post1)
247
247
  end
248
248
 
249
- should "return nil if not found " do
249
+ it "should return nil if not found " do
250
250
  @person.posts.find(1234).should be_nil
251
251
  end
252
252
  end
253
253
 
254
254
  context "#find (with multiple ids)" do
255
- should "add all documents to map" do
255
+ it "should add all documents to map" do
256
256
  person1 = @person_class.create(:name => 'Fred')
257
257
  person2 = @person_class.create(:name => 'Bill')
258
258
  person3 = @person_class.create(:name => 'Jesse')
@@ -262,7 +262,7 @@ class IdentityMapTest < Test::Unit::TestCase
262
262
  assert_in_map(people)
263
263
  end
264
264
 
265
- should "add missing documents to map and return existing ones" do
265
+ it "should add missing documents to map and return existing ones" do
266
266
  person1 = @person_class.create(:name => 'Fred')
267
267
  clear_identity_map
268
268
  person2 = @person_class.create(:name => 'Bill')
@@ -280,38 +280,38 @@ class IdentityMapTest < Test::Unit::TestCase
280
280
 
281
281
  context "#first" do
282
282
  context "for object not in map" do
283
- setup do
283
+ before do
284
284
  @person = @person_class.create(:name => 'Fred')
285
285
  clear_identity_map
286
286
  end
287
287
 
288
- should "query the database" do
288
+ it "should query the database" do
289
289
  expects_one_query
290
290
  @person_class.first(:_id => @person.id)
291
291
  end
292
292
 
293
- should "add object to map" do
293
+ it "should add object to map" do
294
294
  assert_not_in_map(@person)
295
295
  found_person = @person_class.first(:_id => @person.id)
296
296
  assert_in_map(found_person)
297
297
  end
298
298
 
299
- should "return nil if not found" do
299
+ it "should return nil if not found" do
300
300
  @person_class.first(:name => 'Bill').should be_nil
301
301
  end
302
302
  end
303
303
 
304
304
  context "for object in map" do
305
- setup do
305
+ before do
306
306
  @person = @person_class.create(:name => 'Fred')
307
307
  end
308
308
 
309
- should "not query database" do
309
+ it "should not query database" do
310
310
  expect_no_queries
311
311
  @person_class.first(:_id => @person.id)
312
312
  end
313
313
 
314
- should "return exact object" do
314
+ it "should return exact object" do
315
315
  assert_in_map(@person)
316
316
  found_person = @person_class.first(:_id => @person.id)
317
317
  found_person.should equal(@person)
@@ -320,7 +320,7 @@ class IdentityMapTest < Test::Unit::TestCase
320
320
  end
321
321
 
322
322
  context "#all" do
323
- should "add all documents to map" do
323
+ it "should add all documents to map" do
324
324
  person1 = @person_class.create(:name => 'Fred')
325
325
  person2 = @person_class.create(:name => 'Bill')
326
326
  person3 = @person_class.create(:name => 'Jesse')
@@ -330,7 +330,7 @@ class IdentityMapTest < Test::Unit::TestCase
330
330
  assert_in_map(people)
331
331
  end
332
332
 
333
- should "add missing documents to map and return existing ones" do
333
+ it "should add missing documents to map and return existing ones" do
334
334
  person1 = @person_class.create(:name => 'Fred')
335
335
  clear_identity_map
336
336
  person2 = @person_class.create(:name => 'Bill')
@@ -346,23 +346,35 @@ class IdentityMapTest < Test::Unit::TestCase
346
346
  end
347
347
 
348
348
  context "#find_by_id" do
349
- setup do
349
+ before do
350
350
  @person = @person_class.create(:name => 'Bill')
351
351
  end
352
352
 
353
- should "return nil for document id not found in collection" do
353
+ it "should return nil for document id not found in collection" do
354
354
  assert_in_map(@person)
355
355
  @person_class.find_by_id(BSON::ObjectId.new).should be_nil
356
356
  end
357
357
  end
358
358
 
359
+ context "#remove_documents_from_map" do
360
+ before do
361
+ @person = @person_class.create(:name => 'Fred')
362
+ end
363
+
364
+ it "should remove documents from the map" do
365
+ assert_in_map @person
366
+ @person_class.remove_documents_from_map(@person)
367
+ assert_not_in_map @person
368
+ end
369
+ end
370
+
359
371
  context "querying and selecting certain fields" do
360
- setup do
372
+ before do
361
373
  @person = @person_class.create(:name => 'Bill')
362
374
  clear_identity_map
363
375
  end
364
376
 
365
- should "not add to map" do
377
+ it "should not add to map" do
366
378
  assert_not_in_map(@person)
367
379
  @person_class.first(:_id => @person.id, :select => 'name').should == @person
368
380
  @person_class.first(:_id => @person.id, 'fields' => ['name']).should == @person
@@ -372,20 +384,20 @@ class IdentityMapTest < Test::Unit::TestCase
372
384
  assert_not_in_map(@person)
373
385
  end
374
386
 
375
- should "not add to map using where and each" do
387
+ it "should not add to map using where and each" do
376
388
  @person_class.where(:id => @person.id).each{|_|}
377
389
  assert_in_map(@person)
378
390
  @person_class.where(:id => @person.id).only(:id).each{|_|}
379
391
  assert_not_in_map(@person)
380
392
  end
381
393
 
382
- should "return nil if not found" do
394
+ it "should return nil if not found" do
383
395
  @person_class.fields(:name).find(BSON::ObjectId.new).should be_nil
384
396
  end
385
397
  end
386
398
 
387
399
  context "single collection inherited models" do
388
- setup do
400
+ before do
389
401
  class ::Item
390
402
  include MongoMapper::Document
391
403
 
@@ -405,13 +417,13 @@ class IdentityMapTest < Test::Unit::TestCase
405
417
  end
406
418
  end
407
419
 
408
- teardown do
420
+ after do
409
421
  Object.send :remove_const, 'Item' if defined?(::Item)
410
422
  Object.send :remove_const, 'Blog' if defined?(::Blog)
411
423
  Object.send :remove_const, 'BlogPost' if defined?(::BlogPost)
412
424
  end
413
425
 
414
- should "not query when finding by _id and _type" do
426
+ it "should not query when finding by _id and _type" do
415
427
  blog = Blog.create(:title => 'Blog')
416
428
  post = BlogPost.create(:title => 'Mongo Rocks', :blog => blog)
417
429
  clear_identity_map
@@ -425,12 +437,12 @@ class IdentityMapTest < Test::Unit::TestCase
425
437
  Blog.find(blog.id)
426
438
  end
427
439
 
428
- should "load from map when using parent collection inherited class" do
440
+ it "should load from map when using parent collection inherited class" do
429
441
  blog = Blog.create(:title => 'Jill')
430
442
  Item.find(blog.id).should equal(blog)
431
443
  end
432
444
 
433
- should "work correctly with belongs to proxy" do
445
+ it "should work correctly with belongs to proxy" do
434
446
  root = Item.create(:title => 'Root')
435
447
  assert_in_map(root)
436
448
 
@@ -439,7 +451,7 @@ class IdentityMapTest < Test::Unit::TestCase
439
451
  root.should equal(blog.parent.target)
440
452
  end
441
453
 
442
- should "work correctly with one proxy" do
454
+ it "should work correctly with one proxy" do
443
455
  blog = Blog.create(:title => 'Jill')
444
456
  assert_in_map(blog)
445
457
 
@@ -448,7 +460,7 @@ class IdentityMapTest < Test::Unit::TestCase
448
460
  blog.should equal(root.blog.target)
449
461
  end
450
462
 
451
- should "work correctly with one proxy create" do
463
+ it "should work correctly with one proxy create" do
452
464
  root = Item.create(:title => 'Root')
453
465
  blog = root.create_blog(:title => 'Blog')
454
466
  blog.parent.should equal(root)