mongo_mapper 0.12.0 → 0.13.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +35 -13
- data/bin/mmconsole +1 -1
- data/lib/mongo_mapper.rb +4 -0
- data/lib/mongo_mapper/connection.rb +17 -6
- data/lib/mongo_mapper/document.rb +1 -0
- data/lib/mongo_mapper/exceptions.rb +4 -1
- data/lib/mongo_mapper/extensions/binary.rb +1 -1
- data/lib/mongo_mapper/extensions/boolean.rb +20 -23
- data/lib/mongo_mapper/extensions/date.rb +3 -3
- data/lib/mongo_mapper/extensions/integer.rb +5 -1
- data/lib/mongo_mapper/extensions/kernel.rb +2 -0
- data/lib/mongo_mapper/extensions/ordered_hash.rb +23 -0
- data/lib/mongo_mapper/extensions/string.rb +2 -2
- data/lib/mongo_mapper/extensions/time.rb +7 -5
- data/lib/mongo_mapper/middleware/identity_map.rb +3 -4
- data/lib/mongo_mapper/plugins.rb +1 -1
- data/lib/mongo_mapper/plugins/associations.rb +11 -5
- data/lib/mongo_mapper/plugins/associations/base.rb +5 -3
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +0 -0
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +8 -8
- data/lib/mongo_mapper/plugins/associations/collection.rb +2 -0
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +32 -7
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +2 -2
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +12 -12
- data/lib/mongo_mapper/plugins/associations/proxy.rb +5 -1
- data/lib/mongo_mapper/plugins/associations/single_association.rb +6 -6
- data/lib/mongo_mapper/plugins/clone.rb +4 -2
- data/lib/mongo_mapper/plugins/dirty.rb +22 -21
- data/lib/mongo_mapper/plugins/document.rb +4 -4
- data/lib/mongo_mapper/plugins/dumpable.rb +22 -0
- data/lib/mongo_mapper/plugins/embedded_callbacks.rb +58 -9
- data/lib/mongo_mapper/plugins/identity_map.rb +42 -32
- data/lib/mongo_mapper/plugins/keys.rb +133 -54
- data/lib/mongo_mapper/plugins/keys/key.rb +68 -22
- data/lib/mongo_mapper/plugins/modifiers.rb +26 -19
- data/lib/mongo_mapper/plugins/persistence.rb +15 -5
- data/lib/mongo_mapper/plugins/querying.rb +15 -40
- data/lib/mongo_mapper/plugins/querying/{decorator.rb → decorated_plucky_query.rb} +24 -4
- data/lib/mongo_mapper/plugins/rails.rb +22 -2
- data/lib/mongo_mapper/plugins/safe.rb +8 -5
- data/lib/mongo_mapper/plugins/sci.rb +26 -4
- data/lib/mongo_mapper/plugins/scopes.rb +5 -4
- data/lib/mongo_mapper/plugins/timestamps.rb +11 -4
- data/lib/mongo_mapper/plugins/validations.rb +1 -1
- data/lib/mongo_mapper/utils.rb +12 -0
- data/lib/mongo_mapper/version.rb +1 -1
- data/lib/rails/generators/mongo_mapper/config/config_generator.rb +20 -7
- data/lib/rails/generators/mongo_mapper/config/templates/mongo.yml +6 -0
- data/lib/rails/generators/mongo_mapper/model/model_generator.rb +18 -1
- data/lib/rails/generators/mongo_mapper/model/templates/model.rb +9 -5
- data/{test/functional/test_accessible.rb → spec/functional/accessible_spec.rb} +29 -29
- data/{test/functional/associations/test_belongs_to_polymorphic_proxy.rb → spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb} +10 -10
- data/{test/functional/associations/test_belongs_to_proxy.rb → spec/functional/associations/belongs_to_proxy_spec.rb} +82 -64
- data/{test/functional/associations/test_in_array_proxy.rb → spec/functional/associations/in_array_proxy_spec.rb} +68 -68
- data/{test/functional/associations/test_many_documents_as_proxy.rb → spec/functional/associations/many_documents_as_proxy_spec.rb} +37 -38
- data/{test/functional/associations/test_many_documents_proxy.rb → spec/functional/associations/many_documents_proxy_spec.rb} +233 -146
- data/{test/functional/associations/test_many_embedded_polymorphic_proxy.rb → spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb} +19 -20
- data/{test/functional/associations/test_many_embedded_proxy.rb → spec/functional/associations/many_embedded_proxy_spec.rb} +23 -24
- data/{test/functional/associations/test_many_polymorphic_proxy.rb → spec/functional/associations/many_polymorphic_proxy_spec.rb} +45 -46
- data/{test/functional/associations/test_one_as_proxy.rb → spec/functional/associations/one_as_proxy_spec.rb} +75 -77
- data/{test/functional/associations/test_one_embedded_polymorphic_proxy.rb → spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb} +31 -32
- data/{test/functional/associations/test_one_embedded_proxy.rb → spec/functional/associations/one_embedded_proxy_spec.rb} +10 -10
- data/{test/functional/associations/test_one_proxy.rb → spec/functional/associations/one_proxy_spec.rb} +125 -102
- data/spec/functional/associations_spec.rb +48 -0
- data/{test/functional/test_binary.rb → spec/functional/binary_spec.rb} +6 -6
- data/spec/functional/caching_spec.rb +75 -0
- data/{test/functional/test_callbacks.rb → spec/functional/callbacks_spec.rb} +84 -26
- data/{test/functional/test_dirty.rb → spec/functional/dirty_spec.rb} +57 -42
- data/{test/functional/test_document.rb → spec/functional/document_spec.rb} +52 -52
- data/spec/functional/dumpable_spec.rb +24 -0
- data/{test/functional/test_dynamic_querying.rb → spec/functional/dynamic_querying_spec.rb} +14 -14
- data/{test/functional/test_embedded_document.rb → spec/functional/embedded_document_spec.rb} +51 -42
- data/{test/functional/test_equality.rb → spec/functional/equality_spec.rb} +4 -4
- data/spec/functional/extensions_spec.rb +16 -0
- data/{test/functional/test_identity_map.rb → spec/functional/identity_map_spec.rb} +73 -61
- data/spec/functional/indexes_spec.rb +48 -0
- data/spec/functional/keys_spec.rb +224 -0
- data/{test/functional/test_logger.rb → spec/functional/logger_spec.rb} +6 -6
- data/spec/functional/modifiers_spec.rb +550 -0
- data/spec/functional/pagination_spec.rb +89 -0
- data/spec/functional/protected_spec.rb +199 -0
- data/spec/functional/querying_spec.rb +1003 -0
- data/spec/functional/rails_spec.rb +55 -0
- data/spec/functional/safe_spec.rb +163 -0
- data/{test/functional/test_sci.rb → spec/functional/sci_spec.rb} +123 -34
- data/{test/functional/test_scopes.rb → spec/functional/scopes_spec.rb} +59 -26
- data/spec/functional/timestamps_spec.rb +97 -0
- data/{test/functional/test_touch.rb → spec/functional/touch_spec.rb} +13 -13
- data/spec/functional/userstamps_spec.rb +46 -0
- data/{test/functional/test_validations.rb → spec/functional/validations_spec.rb} +64 -64
- data/spec/spec_helper.rb +81 -0
- data/spec/support/matchers.rb +24 -0
- data/{test → spec/support}/models.rb +1 -6
- data/spec/unit/associations/base_spec.rb +146 -0
- data/spec/unit/associations/belongs_to_association_spec.rb +30 -0
- data/spec/unit/associations/many_association_spec.rb +64 -0
- data/spec/unit/associations/one_association_spec.rb +48 -0
- data/{test/unit/associations/test_proxy.rb → spec/unit/associations/proxy_spec.rb} +21 -21
- data/{test/unit/test_clone.rb → spec/unit/clone_spec.rb} +21 -11
- data/spec/unit/config_generator_spec.rb +24 -0
- data/{test/unit/test_document.rb → spec/unit/document_spec.rb} +42 -42
- data/{test/unit/test_dynamic_finder.rb → spec/unit/dynamic_finder_spec.rb} +28 -28
- data/{test/unit/test_embedded_document.rb → spec/unit/embedded_document_spec.rb} +102 -108
- data/{test/unit/test_equality.rb → spec/unit/equality_spec.rb} +7 -7
- data/{test/unit/test_exceptions.rb → spec/unit/exceptions_spec.rb} +3 -3
- data/{test/unit/test_extensions.rb → spec/unit/extensions_spec.rb} +85 -71
- data/spec/unit/identity_map_middleware_spec.rb +134 -0
- data/{test/unit/test_inspect.rb → spec/unit/inspect_spec.rb} +8 -8
- data/{test/unit/test_key.rb → spec/unit/key_spec.rb} +82 -52
- data/spec/unit/keys_spec.rb +155 -0
- data/spec/unit/model_generator_spec.rb +47 -0
- data/spec/unit/mongo_mapper_spec.rb +184 -0
- data/spec/unit/pagination_spec.rb +11 -0
- data/{test/unit/test_plugins.rb → spec/unit/plugins_spec.rb} +14 -14
- data/spec/unit/rails_compatibility_spec.rb +40 -0
- data/{test/unit/test_rails_reflect_on_association.rb → spec/unit/rails_reflect_on_association_spec.rb} +9 -9
- data/{test/unit/test_rails.rb → spec/unit/rails_spec.rb} +31 -31
- data/spec/unit/serialization_spec.rb +169 -0
- data/spec/unit/serializers/json_serializer_spec.rb +218 -0
- data/spec/unit/serializers/xml_serializer_spec.rb +198 -0
- data/{test/unit/test_time_zones.rb → spec/unit/time_zones_spec.rb} +8 -8
- data/{test/unit/test_translation.rb → spec/unit/translation_spec.rb} +6 -6
- data/{test/unit/test_validations.rb → spec/unit/validations_spec.rb} +72 -59
- metadata +199 -179
- data/test/_NOTE_ON_TESTING +0 -1
- data/test/functional/test_associations.rb +0 -46
- data/test/functional/test_caching.rb +0 -77
- data/test/functional/test_indexes.rb +0 -50
- data/test/functional/test_modifiers.rb +0 -537
- data/test/functional/test_pagination.rb +0 -91
- data/test/functional/test_protected.rb +0 -201
- data/test/functional/test_querying.rb +0 -935
- data/test/functional/test_safe.rb +0 -76
- data/test/functional/test_timestamps.rb +0 -62
- data/test/functional/test_userstamps.rb +0 -44
- data/test/support/railtie.rb +0 -4
- data/test/support/railtie/autoloaded.rb +0 -2
- data/test/support/railtie/not_autoloaded.rb +0 -3
- data/test/support/railtie/parent.rb +0 -3
- data/test/test_active_model_lint.rb +0 -18
- data/test/test_helper.rb +0 -93
- data/test/unit/associations/test_base.rb +0 -146
- data/test/unit/associations/test_belongs_to_association.rb +0 -29
- data/test/unit/associations/test_many_association.rb +0 -63
- data/test/unit/associations/test_one_association.rb +0 -47
- data/test/unit/serializers/test_json_serializer.rb +0 -216
- data/test/unit/serializers/test_xml_serializer.rb +0 -196
- data/test/unit/test_identity_map_middleware.rb +0 -132
- data/test/unit/test_keys.rb +0 -65
- data/test/unit/test_mongo_mapper.rb +0 -157
- data/test/unit/test_pagination.rb +0 -11
- data/test/unit/test_rails_compatibility.rb +0 -38
- data/test/unit/test_serialization.rb +0 -166
@@ -1,8 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe "Equality" do
|
4
4
|
context "Case equality" do
|
5
|
-
|
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
|
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 '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
|
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.
|
18
|
-
Mongo::Collection.any_instance.
|
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.
|
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
|
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
|
-
|
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
|
-
|
53
|
+
after do
|
54
54
|
MongoMapper::Plugins::IdentityMap.enabled = @original_identity_map_enabled
|
55
55
|
end
|
56
56
|
|
57
|
-
should
|
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
|
-
|
69
|
+
before do
|
70
70
|
@person = @person_class.create
|
71
71
|
clear_identity_map
|
72
72
|
end
|
73
73
|
|
74
|
-
should
|
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
|
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
|
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
|
-
|
101
|
+
before do
|
102
102
|
@person = @person_class.create
|
103
103
|
clear_identity_map
|
104
104
|
end
|
105
105
|
|
106
|
-
should
|
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
|
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
|
122
|
+
it "should default identity map to hash" do
|
123
123
|
MongoMapper::Plugins::IdentityMap.repository.should == {}
|
124
124
|
end
|
125
125
|
|
126
|
-
should
|
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
|
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
|
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
|
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
|
-
|
155
|
+
before do
|
156
156
|
@person = @person_class.create(:name => 'Fred')
|
157
157
|
end
|
158
158
|
|
159
|
-
should
|
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
|
-
|
167
|
+
before do
|
168
168
|
@id = BSON::ObjectId.new
|
169
169
|
end
|
170
170
|
|
171
|
-
should
|
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
|
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
|
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
|
-
|
189
|
+
before do
|
190
190
|
@person = @person_class.create(:name => 'Fred')
|
191
191
|
clear_identity_map
|
192
192
|
end
|
193
193
|
|
194
|
-
should
|
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
|
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
|
-
|
207
|
+
before do
|
208
208
|
@person = @person_class.create(:name => 'Fred')
|
209
209
|
end
|
210
210
|
|
211
|
-
should
|
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
|
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
|
-
|
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
|
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
|
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
|
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
|
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
|
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
|
-
|
283
|
+
before do
|
284
284
|
@person = @person_class.create(:name => 'Fred')
|
285
285
|
clear_identity_map
|
286
286
|
end
|
287
287
|
|
288
|
-
should
|
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
|
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
|
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
|
-
|
305
|
+
before do
|
306
306
|
@person = @person_class.create(:name => 'Fred')
|
307
307
|
end
|
308
308
|
|
309
|
-
should
|
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
|
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
|
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
|
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
|
-
|
349
|
+
before do
|
350
350
|
@person = @person_class.create(:name => 'Bill')
|
351
351
|
end
|
352
352
|
|
353
|
-
should
|
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
|
-
|
372
|
+
before do
|
361
373
|
@person = @person_class.create(:name => 'Bill')
|
362
374
|
clear_identity_map
|
363
375
|
end
|
364
376
|
|
365
|
-
should
|
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
|
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
|
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
|
-
|
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
|
-
|
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
|
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
|
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
|
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
|
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
|
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)
|