mongo_mapper-unstable 2010.3.8 → 2010.06.23
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.
- data/README.rdoc +4 -8
- data/bin/mmconsole +1 -1
- data/examples/keys.rb +37 -0
- data/examples/plugins.rb +41 -0
- data/examples/querying.rb +35 -0
- data/examples/scopes.rb +52 -0
- data/lib/mongo_mapper/connection.rb +83 -0
- data/lib/mongo_mapper/document.rb +11 -329
- data/lib/mongo_mapper/embedded_document.rb +9 -38
- data/lib/mongo_mapper/exceptions.rb +30 -0
- data/lib/mongo_mapper/extensions/array.rb +19 -0
- data/lib/mongo_mapper/extensions/binary.rb +22 -0
- data/lib/mongo_mapper/extensions/boolean.rb +44 -0
- data/lib/mongo_mapper/extensions/date.rb +25 -0
- data/lib/mongo_mapper/extensions/float.rb +14 -0
- data/lib/mongo_mapper/extensions/hash.rb +14 -0
- data/lib/mongo_mapper/extensions/integer.rb +19 -0
- data/lib/mongo_mapper/extensions/kernel.rb +9 -0
- data/lib/mongo_mapper/extensions/nil_class.rb +18 -0
- data/lib/mongo_mapper/extensions/object.rb +27 -0
- data/lib/mongo_mapper/extensions/object_id.rb +30 -0
- data/lib/mongo_mapper/extensions/set.rb +20 -0
- data/lib/mongo_mapper/extensions/string.rb +18 -0
- data/lib/mongo_mapper/extensions/time.rb +29 -0
- data/lib/mongo_mapper/plugins/accessible.rb +44 -0
- data/lib/mongo_mapper/plugins/associations/base.rb +7 -6
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +5 -6
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +5 -6
- data/lib/mongo_mapper/plugins/associations/collection.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +2 -1
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +25 -39
- data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +4 -4
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +36 -46
- data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +5 -4
- data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +40 -0
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +7 -7
- data/lib/mongo_mapper/plugins/associations/proxy.rb +16 -8
- data/lib/mongo_mapper/plugins/associations.rb +14 -22
- data/lib/mongo_mapper/plugins/caching.rb +21 -0
- data/lib/mongo_mapper/plugins/callbacks.rb +17 -5
- data/lib/mongo_mapper/plugins/clone.rb +10 -4
- data/lib/mongo_mapper/plugins/descendants.rb +3 -2
- data/lib/mongo_mapper/plugins/dirty.rb +1 -0
- data/lib/mongo_mapper/plugins/document.rb +41 -0
- data/lib/mongo_mapper/{support/find.rb → plugins/dynamic_querying/dynamic_finder.rb} +3 -36
- data/lib/mongo_mapper/plugins/dynamic_querying.rb +43 -0
- data/lib/mongo_mapper/plugins/embedded_document.rb +49 -0
- data/lib/mongo_mapper/plugins/equality.rb +4 -10
- data/lib/mongo_mapper/plugins/identity_map.rb +29 -23
- data/lib/mongo_mapper/plugins/indexes.rb +12 -0
- data/lib/mongo_mapper/plugins/inspect.rb +1 -0
- data/lib/mongo_mapper/plugins/keys/key.rb +55 -0
- data/lib/mongo_mapper/plugins/keys.rb +85 -110
- data/lib/mongo_mapper/plugins/logger.rb +1 -0
- data/lib/mongo_mapper/plugins/modifiers.rb +41 -16
- data/lib/mongo_mapper/plugins/pagination.rb +5 -15
- data/lib/mongo_mapper/plugins/persistence.rb +69 -0
- data/lib/mongo_mapper/plugins/protected.rb +9 -1
- data/lib/mongo_mapper/plugins/querying/decorator.rb +46 -0
- data/lib/mongo_mapper/plugins/querying/plucky_methods.rb +15 -0
- data/lib/mongo_mapper/plugins/querying.rb +176 -0
- data/lib/mongo_mapper/plugins/rails.rb +6 -1
- data/lib/mongo_mapper/plugins/safe.rb +28 -0
- data/lib/mongo_mapper/plugins/sci.rb +32 -0
- data/lib/mongo_mapper/plugins/scopes.rb +21 -0
- data/lib/mongo_mapper/plugins/serialization.rb +5 -4
- data/lib/mongo_mapper/plugins/timestamps.rb +2 -1
- data/lib/mongo_mapper/plugins/userstamps.rb +1 -0
- data/lib/mongo_mapper/plugins/validations.rb +9 -5
- data/lib/mongo_mapper/plugins.rb +1 -20
- data/lib/mongo_mapper/support/descendant_appends.rb +5 -6
- data/lib/mongo_mapper/version.rb +4 -0
- data/lib/mongo_mapper.rb +71 -128
- data/test/{NOTE_ON_TESTING → _NOTE_ON_TESTING} +0 -0
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +5 -5
- data/test/functional/associations/test_belongs_to_proxy.rb +13 -21
- data/test/functional/associations/test_in_array_proxy.rb +7 -9
- data/test/functional/associations/test_many_documents_as_proxy.rb +5 -5
- data/test/functional/associations/test_many_documents_proxy.rb +186 -64
- data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +22 -22
- data/test/functional/associations/test_many_embedded_proxy.rb +32 -32
- data/test/functional/associations/test_many_polymorphic_proxy.rb +47 -47
- data/test/functional/associations/test_one_embedded_proxy.rb +67 -0
- data/test/functional/associations/test_one_proxy.rb +70 -49
- data/test/functional/test_accessible.rb +168 -0
- data/test/functional/test_associations.rb +11 -11
- data/test/functional/test_binary.rb +5 -5
- data/test/functional/test_caching.rb +76 -0
- data/test/functional/test_callbacks.rb +104 -34
- data/test/functional/test_dirty.rb +16 -16
- data/test/functional/test_document.rb +12 -924
- data/test/functional/test_dynamic_querying.rb +75 -0
- data/test/functional/test_embedded_document.rb +88 -8
- data/test/functional/test_identity_map.rb +41 -43
- data/test/functional/{test_indexing.rb → test_indexes.rb} +3 -5
- data/test/functional/test_logger.rb +1 -1
- data/test/functional/test_modifiers.rb +275 -181
- data/test/functional/test_pagination.rb +13 -15
- data/test/functional/test_protected.rb +25 -11
- data/test/functional/test_querying.rb +873 -0
- data/test/functional/test_safe.rb +76 -0
- data/test/functional/test_sci.rb +230 -0
- data/test/functional/test_scopes.rb +171 -0
- data/test/functional/test_string_id_compatibility.rb +11 -11
- data/test/functional/test_timestamps.rb +0 -2
- data/test/functional/test_userstamps.rb +0 -1
- data/test/functional/test_validations.rb +44 -31
- data/test/models.rb +18 -17
- data/test/{active_model_lint_test.rb → test_active_model_lint.rb} +3 -1
- data/test/test_helper.rb +59 -16
- data/test/unit/associations/test_base.rb +47 -42
- data/test/unit/associations/test_proxy.rb +15 -15
- data/test/unit/serializers/test_json_serializer.rb +29 -29
- data/test/unit/test_clone.rb +69 -0
- data/test/unit/test_descendant_appends.rb +3 -3
- data/test/unit/test_document.rb +49 -67
- data/test/unit/test_dynamic_finder.rb +53 -51
- data/test/unit/test_embedded_document.rb +19 -38
- data/test/unit/{test_support.rb → test_extensions.rb} +136 -122
- data/test/unit/test_key.rb +185 -0
- data/test/unit/test_keys.rb +29 -147
- data/test/unit/test_mongo_mapper.rb +3 -48
- data/test/unit/test_pagination.rb +1 -150
- data/test/unit/test_rails.rb +77 -19
- data/test/unit/test_rails_compatibility.rb +12 -12
- data/test/unit/test_serialization.rb +5 -5
- data/test/unit/test_time_zones.rb +9 -9
- data/test/unit/test_validations.rb +46 -46
- metadata +157 -155
- data/.gitignore +0 -10
- data/Rakefile +0 -55
- data/VERSION +0 -1
- data/lib/mongo_mapper/plugins/pagination/proxy.rb +0 -72
- data/lib/mongo_mapper/query.rb +0 -130
- data/lib/mongo_mapper/support.rb +0 -215
- data/mongo_mapper.gemspec +0 -196
- data/performance/read_write.rb +0 -52
- data/specs.watchr +0 -51
- data/test/support/custom_matchers.rb +0 -55
- data/test/support/timing.rb +0 -16
- data/test/unit/test_query.rb +0 -340
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DynamicQueryingTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@document = Doc do
|
6
|
+
scope :nunes, where(:last_name => 'Nunemaker')
|
7
|
+
|
8
|
+
key :first_name, String
|
9
|
+
key :last_name, String
|
10
|
+
key :age, Integer
|
11
|
+
key :date, Date
|
12
|
+
end
|
13
|
+
|
14
|
+
@doc1 = @document.create(:first_name => 'John', :last_name => 'Nunemaker', :age => 27)
|
15
|
+
@doc2 = @document.create(:first_name => 'Steve', :last_name => 'Smith', :age => 28)
|
16
|
+
@doc3 = @document.create(:first_name => 'Steph', :last_name => 'Nunemaker', :age => 26)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "find document based on argument" do
|
20
|
+
@document.find_by_first_name('John').should == @doc1
|
21
|
+
@document.find_by_last_name('Nunemaker', :order => 'age desc').should == @doc1
|
22
|
+
@document.find_by_age(27).should == @doc1
|
23
|
+
end
|
24
|
+
|
25
|
+
should "not raise error" do
|
26
|
+
@document.find_by_first_name('Mongo').should be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
should "define a method for each key" do
|
30
|
+
@document.methods(false).select { |e| e =~ /^find_by_/ }.size == @document.keys.size
|
31
|
+
end
|
32
|
+
|
33
|
+
should "find document based on all arguments" do
|
34
|
+
@document.find_by_first_name_and_last_name_and_age('John', 'Nunemaker', 27).should == @doc1
|
35
|
+
end
|
36
|
+
|
37
|
+
should "not find the document if an argument is wrong" do
|
38
|
+
@document.find_by_first_name_and_last_name_and_age('John', 'Nunemaker', 28).should be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
should "find all documents based on arguments" do
|
42
|
+
docs = @document.find_all_by_last_name('Nunemaker')
|
43
|
+
docs.should be_kind_of(Array)
|
44
|
+
docs.should include(@doc1)
|
45
|
+
docs.should include(@doc3)
|
46
|
+
end
|
47
|
+
|
48
|
+
should "initialize document with given arguments" do
|
49
|
+
doc = @document.find_or_initialize_by_first_name_and_last_name('David', 'Cuadrado')
|
50
|
+
doc.should be_new
|
51
|
+
doc.first_name.should == 'David'
|
52
|
+
end
|
53
|
+
|
54
|
+
should "not initialize document if document is found" do
|
55
|
+
doc = @document.find_or_initialize_by_first_name('John')
|
56
|
+
doc.should_not be_new
|
57
|
+
end
|
58
|
+
|
59
|
+
should "create document with given arguments" do
|
60
|
+
doc = @document.find_or_create_by_first_name_and_last_name('David', 'Cuadrado')
|
61
|
+
doc.should_not be_new
|
62
|
+
doc.first_name.should == 'David'
|
63
|
+
end
|
64
|
+
|
65
|
+
should "raise error if document is not found when using !" do
|
66
|
+
lambda {
|
67
|
+
@document.find_by_first_name_and_last_name!(1,2)
|
68
|
+
}.should raise_error(MongoMapper::DocumentNotFound)
|
69
|
+
end
|
70
|
+
|
71
|
+
should "work on scopes" do
|
72
|
+
@document.nunes.find_by_first_name('Steph').should == @doc3
|
73
|
+
@document.nunes.find_all_by_first_name('Steph').should == [@doc3]
|
74
|
+
end
|
75
|
+
end
|
@@ -42,6 +42,14 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
42
42
|
address._parent_document.should be(doc)
|
43
43
|
address._root_document.should be(doc)
|
44
44
|
end
|
45
|
+
|
46
|
+
should "assign _parent_document and _root_document when loading" do
|
47
|
+
address = @address_class.new(:city => 'South Bend', :state => 'IN')
|
48
|
+
doc = @klass.create(:foo => address)
|
49
|
+
doc.reload
|
50
|
+
doc.foo._parent_document.should be(doc)
|
51
|
+
doc.foo._root_document.should be(doc)
|
52
|
+
end
|
45
53
|
end
|
46
54
|
|
47
55
|
should "correctly instantiate single collection inherited embedded documents" do
|
@@ -53,31 +61,93 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
53
61
|
doc1.reload.message.class.should be(Enter)
|
54
62
|
end
|
55
63
|
|
56
|
-
context "new?" do
|
64
|
+
context "new? (embedded key)" do
|
57
65
|
setup do
|
58
66
|
@klass.key :foo, @address_class
|
59
67
|
end
|
60
68
|
|
61
|
-
should "be
|
69
|
+
should "be true until document is saved" do
|
62
70
|
address = @address_class.new(:city => 'South Bend', :state => 'IN')
|
63
71
|
doc = @klass.new(:foo => address)
|
64
|
-
address.new?.should
|
72
|
+
address.new?.should be_true
|
65
73
|
end
|
66
74
|
|
67
|
-
should "
|
75
|
+
should "be false after document is saved" do
|
68
76
|
address = @address_class.new(:city => 'South Bend', :state => 'IN')
|
69
77
|
doc = @klass.new(:foo => address)
|
70
78
|
doc.save
|
71
|
-
doc.foo.new?.should
|
79
|
+
doc.foo.new?.should be_false
|
72
80
|
end
|
73
81
|
|
74
|
-
should "
|
82
|
+
should "be false when loaded from database" do
|
75
83
|
address = @address_class.new(:city => 'South Bend', :state => 'IN')
|
76
84
|
doc = @klass.new(:foo => address)
|
77
85
|
doc.save
|
78
86
|
|
79
|
-
doc
|
80
|
-
doc.foo.new?.should
|
87
|
+
doc.reload
|
88
|
+
doc.foo.new?.should be_false
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "new? (embedded association)" do
|
93
|
+
setup do
|
94
|
+
@doc = @klass.new(:pets => [{:name => 'poo bear'}])
|
95
|
+
end
|
96
|
+
|
97
|
+
should "be true until document is saved" do
|
98
|
+
@doc.should be_new
|
99
|
+
@doc.pets.first.should be_new
|
100
|
+
end
|
101
|
+
|
102
|
+
should "be false after document is saved" do
|
103
|
+
@doc.save
|
104
|
+
@doc.pets.first.should_not be_new
|
105
|
+
end
|
106
|
+
|
107
|
+
should "be false when loaded from database" do
|
108
|
+
@doc.save
|
109
|
+
@doc.pets.first.should_not be_new
|
110
|
+
@doc.reload
|
111
|
+
@doc.pets.first.should_not be_new
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "#destroyed?" do
|
116
|
+
setup do
|
117
|
+
@doc = @klass.create(:pets => [@pet_klass.new(:name => 'sparky')])
|
118
|
+
end
|
119
|
+
|
120
|
+
should "be false if root document is not destroyed" do
|
121
|
+
@doc.should_not be_destroyed
|
122
|
+
@doc.pets.first.should_not be_destroyed
|
123
|
+
end
|
124
|
+
|
125
|
+
should "be true if root document is destroyed" do
|
126
|
+
@doc.destroy
|
127
|
+
@doc.should be_destroyed
|
128
|
+
@doc.pets.first.should be_destroyed
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "#persisted?" do
|
133
|
+
setup do
|
134
|
+
@doc = @klass.new(:name => 'persisted doc', :pets => [@pet_klass.new(:name => 'persisted pet')])
|
135
|
+
end
|
136
|
+
|
137
|
+
should "be false if new" do
|
138
|
+
@doc.pets.first.should_not be_persisted
|
139
|
+
end
|
140
|
+
|
141
|
+
should "be false if destroyed" do
|
142
|
+
@doc.save
|
143
|
+
@doc.destroy
|
144
|
+
@doc.pets.first.should be_destroyed
|
145
|
+
@doc.pets.first.should_not be_persisted
|
146
|
+
end
|
147
|
+
|
148
|
+
should "be true if not new or destroyed" do
|
149
|
+
@doc.save
|
150
|
+
@doc.pets.first.should be_persisted
|
81
151
|
end
|
82
152
|
end
|
83
153
|
|
@@ -127,4 +197,14 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
127
197
|
pet.expects(:save!)
|
128
198
|
pet.update_attributes!(attributes)
|
129
199
|
end
|
200
|
+
|
201
|
+
should "have database instance method that is equal to root document" do
|
202
|
+
person = @klass.create(:pets => [@pet_klass.new(:name => 'sparky')])
|
203
|
+
person.pets.first.database.should == person.database
|
204
|
+
end
|
205
|
+
|
206
|
+
should "have collection instance method that is equal to root document" do
|
207
|
+
person = @klass.create(:pets => [@pet_klass.new(:name => 'sparky')])
|
208
|
+
person.pets.first.collection.name.should == person.collection.name
|
209
|
+
end
|
130
210
|
end
|
@@ -29,16 +29,14 @@ class IdentityMapTest < Test::Unit::TestCase
|
|
29
29
|
MongoMapper::Plugins::IdentityMap.models.clear
|
30
30
|
|
31
31
|
@person_class = Doc('Person') do
|
32
|
-
set_collection_name 'people'
|
33
32
|
plugin MongoMapper::Plugins::IdentityMap
|
34
|
-
|
33
|
+
|
35
34
|
key :name, String
|
36
35
|
end
|
37
36
|
|
38
37
|
@post_class = Doc('Post') do
|
39
|
-
set_collection_name 'posts'
|
40
38
|
plugin MongoMapper::Plugins::IdentityMap
|
41
|
-
|
39
|
+
|
42
40
|
key :title, String
|
43
41
|
key :person_id, ObjectId
|
44
42
|
end
|
@@ -66,7 +64,7 @@ class IdentityMapTest < Test::Unit::TestCase
|
|
66
64
|
|
67
65
|
[@person_class, @post_class].each { |klass| klass.identity_map.should == {} }
|
68
66
|
end
|
69
|
-
|
67
|
+
|
70
68
|
context "IM on off status" do
|
71
69
|
teardown do
|
72
70
|
@post_class.identity_map_on
|
@@ -131,7 +129,7 @@ class IdentityMapTest < Test::Unit::TestCase
|
|
131
129
|
expects_one_query
|
132
130
|
@person.reload
|
133
131
|
end
|
134
|
-
|
132
|
+
|
135
133
|
should "add object back into map" do
|
136
134
|
assert_in_map(@person)
|
137
135
|
before_reload = @person
|
@@ -142,7 +140,7 @@ class IdentityMapTest < Test::Unit::TestCase
|
|
142
140
|
|
143
141
|
context "#load" do
|
144
142
|
setup do
|
145
|
-
@id =
|
143
|
+
@id = BSON::ObjectID.new
|
146
144
|
end
|
147
145
|
|
148
146
|
should "add document to map" do
|
@@ -208,7 +206,7 @@ class IdentityMapTest < Test::Unit::TestCase
|
|
208
206
|
|
209
207
|
# There are times when even though the id matches, other criteria doesn't
|
210
208
|
# so we need to do the query to ensure that when criteria doesn't match
|
211
|
-
# the document is in fact not found.
|
209
|
+
# the document is in fact not found.
|
212
210
|
#
|
213
211
|
# I'm open to not making this query if someone can figure out reliable
|
214
212
|
# way to check if document matches criteria without querying.
|
@@ -217,13 +215,13 @@ class IdentityMapTest < Test::Unit::TestCase
|
|
217
215
|
expects_one_query
|
218
216
|
@person.posts.find(@post1.id)
|
219
217
|
end
|
220
|
-
|
218
|
+
|
221
219
|
should "return exact object" do
|
222
220
|
assert_in_map(@post1)
|
223
221
|
@person.posts.find(@post1.id)
|
224
222
|
assert_in_map(@post1)
|
225
223
|
end
|
226
|
-
|
224
|
+
|
227
225
|
should "return nil if not found " do
|
228
226
|
@person.posts.find(1234).should be_nil
|
229
227
|
end
|
@@ -272,7 +270,7 @@ class IdentityMapTest < Test::Unit::TestCase
|
|
272
270
|
found_person = @person_class.first(:_id => @person.id)
|
273
271
|
assert_in_map(found_person)
|
274
272
|
end
|
275
|
-
|
273
|
+
|
276
274
|
should "return nil if not found" do
|
277
275
|
@person_class.first(:name => 'Bill').should be_nil
|
278
276
|
end
|
@@ -321,15 +319,15 @@ class IdentityMapTest < Test::Unit::TestCase
|
|
321
319
|
assert_in_map(people.first, person2, person3)
|
322
320
|
end
|
323
321
|
end
|
324
|
-
|
322
|
+
|
325
323
|
context "#find_by_id" do
|
326
324
|
setup do
|
327
325
|
@person = @person_class.create(:name => 'Bill')
|
328
326
|
end
|
329
|
-
|
327
|
+
|
330
328
|
should "return nil for document id not found in collection" do
|
331
329
|
assert_in_map(@person)
|
332
|
-
@person_class.find_by_id(
|
330
|
+
@person_class.find_by_id(BSON::ObjectID.new).should be_nil
|
333
331
|
end
|
334
332
|
end
|
335
333
|
|
@@ -344,13 +342,13 @@ class IdentityMapTest < Test::Unit::TestCase
|
|
344
342
|
@person_class.first(:_id => @person.id, :select => 'name').should == @person
|
345
343
|
@person_class.first(:_id => @person.id, 'fields' => ['name']).should == @person
|
346
344
|
@person_class.last(:_id => @person.id, :select => 'name', :order => 'name').should == @person
|
347
|
-
@person_class.find(@person.id
|
345
|
+
@person_class.fields(:name).find(@person.id).should == @person
|
348
346
|
@person_class.all(:_id => @person.id, :select => 'name').should == [@person]
|
349
347
|
assert_not_in_map(@person)
|
350
348
|
end
|
351
|
-
|
349
|
+
|
352
350
|
should "return nil if not found" do
|
353
|
-
@person_class.
|
351
|
+
@person_class.fields(:name).find(BSON::ObjectID.new).should be_nil
|
354
352
|
end
|
355
353
|
end
|
356
354
|
|
@@ -359,11 +357,10 @@ class IdentityMapTest < Test::Unit::TestCase
|
|
359
357
|
class ::Item
|
360
358
|
include MongoMapper::Document
|
361
359
|
plugin MongoMapper::Plugins::IdentityMap
|
362
|
-
|
363
|
-
key :_type, String
|
360
|
+
|
364
361
|
key :title, String
|
365
362
|
key :parent_id, ObjectId
|
366
|
-
|
363
|
+
|
367
364
|
belongs_to :parent, :class_name => 'Item'
|
368
365
|
one :blog, :class_name => 'Blog', :foreign_key => 'parent_id'
|
369
366
|
end
|
@@ -388,44 +385,45 @@ class IdentityMapTest < Test::Unit::TestCase
|
|
388
385
|
assert_in_map(blog)
|
389
386
|
Item.identity_map.should equal(Blog.identity_map)
|
390
387
|
end
|
391
|
-
|
388
|
+
|
392
389
|
should "not query when finding by _id and _type" do
|
393
390
|
blog = Blog.create(:title => 'Blog')
|
394
391
|
post = BlogPost.create(:title => 'Mongo Rocks', :blog => blog)
|
395
392
|
Item.identity_map.clear
|
396
|
-
|
393
|
+
|
397
394
|
blog = Item.find(blog.id)
|
398
395
|
post = Item.find(post.id)
|
399
396
|
assert_in_map(blog, post)
|
400
|
-
|
397
|
+
|
401
398
|
expect_no_queries
|
402
399
|
post.blog
|
403
400
|
Blog.find(blog.id)
|
404
401
|
end
|
405
|
-
|
402
|
+
|
406
403
|
should "load from map when using parent collection inherited class" do
|
407
404
|
blog = Blog.create(:title => 'Jill')
|
408
405
|
Item.find(blog.id).should equal(blog)
|
409
406
|
end
|
410
|
-
|
407
|
+
|
411
408
|
should "work correctly with belongs to proxy" do
|
412
409
|
root = Item.create(:title => 'Root')
|
413
410
|
assert_in_map(root)
|
414
|
-
|
411
|
+
|
415
412
|
blog = Blog.create(:title => 'Jill', :parent => root)
|
413
|
+
blog.parent.inspect
|
416
414
|
assert_in_map(blog)
|
417
|
-
root.should equal(blog.parent)
|
415
|
+
root.should equal(blog.parent.target)
|
418
416
|
end
|
419
|
-
|
417
|
+
|
420
418
|
should "work correctly with one proxy" do
|
421
419
|
blog = Blog.create(:title => 'Jill')
|
422
420
|
assert_in_map(blog)
|
423
421
|
|
424
422
|
root = Item.create(:title => 'Root', :blog => blog)
|
425
423
|
assert_in_map(root)
|
426
|
-
|
424
|
+
blog.should equal(root.blog.target)
|
427
425
|
end
|
428
|
-
|
426
|
+
|
429
427
|
should "work correctly with one proxy create" do
|
430
428
|
root = Item.create(:title => 'Root')
|
431
429
|
blog = root.blog.create(:title => 'Blog')
|
@@ -440,65 +438,65 @@ class IdentityMapTest < Test::Unit::TestCase
|
|
440
438
|
assert_not_in_map(post)
|
441
439
|
end
|
442
440
|
end
|
443
|
-
|
441
|
+
|
444
442
|
should "not remove from map on delete" do
|
445
443
|
post = @post_class.create(:title => 'Bill')
|
446
444
|
assert_in_map(post)
|
447
|
-
|
445
|
+
|
448
446
|
@post_class.without_identity_map do
|
449
447
|
post.destroy
|
450
448
|
end
|
451
|
-
|
449
|
+
|
452
450
|
assert_in_map(post)
|
453
451
|
end
|
454
|
-
|
452
|
+
|
455
453
|
should "not add to map when loading" do
|
456
454
|
@post_class.without_identity_map do
|
457
|
-
post = @post_class.load({'_id' =>
|
455
|
+
post = @post_class.load({'_id' => BSON::ObjectID.new, 'title' => 'Awesome!'})
|
458
456
|
assert_not_in_map(post)
|
459
457
|
end
|
460
458
|
end
|
461
|
-
|
459
|
+
|
462
460
|
should "not load from map when loading" do
|
463
461
|
post = @post_class.create(:title => 'Awesome!')
|
464
|
-
|
462
|
+
|
465
463
|
@post_class.without_identity_map do
|
466
464
|
loaded = @post_class.load('_id' => post._id, 'title' => 'Awesome!')
|
467
465
|
loaded.should_not equal(post)
|
468
466
|
end
|
469
467
|
end
|
470
|
-
|
468
|
+
|
471
469
|
context "all" do
|
472
470
|
should "not add to map" do
|
473
471
|
@post_class.without_identity_map do
|
474
472
|
post1 = @post_class.create(:title => 'Foo')
|
475
473
|
post2 = @post_class.create(:title => 'Bar')
|
476
474
|
@post_class.identity_map.clear
|
477
|
-
|
475
|
+
|
478
476
|
assert_not_in_map(@post_class.all)
|
479
477
|
end
|
480
478
|
end
|
481
479
|
end
|
482
|
-
|
480
|
+
|
483
481
|
context "first" do
|
484
482
|
should "not add to map" do
|
485
483
|
@post_class.without_identity_map do
|
486
484
|
post1 = @post_class.create(:title => 'Foo')
|
487
485
|
post2 = @post_class.create(:title => 'Bar')
|
488
486
|
@post_class.identity_map.clear
|
489
|
-
|
487
|
+
|
490
488
|
assert_not_in_map(@post_class.first)
|
491
489
|
end
|
492
490
|
end
|
493
491
|
end
|
494
|
-
|
492
|
+
|
495
493
|
context "last" do
|
496
494
|
should "not add to map" do
|
497
495
|
@post_class.without_identity_map do
|
498
496
|
post1 = @post_class.create(:title => 'Foo')
|
499
497
|
post2 = @post_class.create(:title => 'Bar')
|
500
498
|
@post_class.identity_map.clear
|
501
|
-
|
499
|
+
|
502
500
|
assert_not_in_map(@post_class.last(:order => 'title'))
|
503
501
|
end
|
504
502
|
end
|
@@ -4,15 +4,13 @@ class IndexingTest < Test::Unit::TestCase
|
|
4
4
|
context "Indexing" do
|
5
5
|
setup do
|
6
6
|
@document = Doc do
|
7
|
-
set_collection_name 'users'
|
8
|
-
|
9
7
|
key :first_name, String
|
10
8
|
key :last_name, String
|
11
9
|
key :age, Integer
|
12
10
|
key :date, Date
|
13
11
|
end
|
14
|
-
drop_indexes(@document)
|
15
12
|
end
|
13
|
+
teardown { drop_indexes(@document) }
|
16
14
|
|
17
15
|
should "allow creating index for a key" do
|
18
16
|
@document.ensure_index :first_name
|
@@ -31,8 +29,8 @@ class IndexingTest < Test::Unit::TestCase
|
|
31
29
|
# just checking have_index('first_name_1_last_name_-1') I'm checking
|
32
30
|
# the values of the indexes to make sure the index creation was successful
|
33
31
|
@document.collection.index_information.detect do |index|
|
34
|
-
keys = index[
|
35
|
-
keys.include?(
|
32
|
+
keys = index[0]
|
33
|
+
keys.include?('first_name_1') && keys.include?('last_name_-1')
|
36
34
|
end.should_not be_nil
|
37
35
|
end
|
38
36
|
|
@@ -11,7 +11,7 @@ class LoggerTest < Test::Unit::TestCase
|
|
11
11
|
should "be able to get access to that logger" do
|
12
12
|
MongoMapper.logger.should == @logger
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
should "be able to log messages" do
|
16
16
|
MongoMapper.logger.debug 'testing'
|
17
17
|
@output.string.include?('testing').should be_true
|