mongo_mapper 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/Rakefile +3 -2
  2. data/lib/mongo_mapper.rb +2 -3
  3. data/lib/mongo_mapper/plugins/associations.rb +10 -1
  4. data/lib/mongo_mapper/plugins/associations/base.rb +2 -2
  5. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +12 -3
  6. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +41 -0
  7. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +1 -0
  8. data/lib/mongo_mapper/plugins/associations/proxy.rb +8 -2
  9. data/lib/mongo_mapper/plugins/callbacks.rb +7 -3
  10. data/lib/mongo_mapper/plugins/descendants.rb +2 -2
  11. data/lib/mongo_mapper/plugins/keys.rb +14 -7
  12. data/lib/mongo_mapper/plugins/modifiers.rb +30 -14
  13. data/lib/mongo_mapper/plugins/protected.rb +1 -1
  14. data/lib/mongo_mapper/plugins/serialization.rb +1 -1
  15. data/lib/mongo_mapper/query.rb +27 -19
  16. data/lib/mongo_mapper/support.rb +10 -6
  17. data/lib/mongo_mapper/version.rb +1 -1
  18. data/mongo_mapper.gemspec +14 -8
  19. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +1 -1
  20. data/test/functional/associations/test_belongs_to_proxy.rb +1 -1
  21. data/test/functional/associations/test_many_documents_proxy.rb +100 -17
  22. data/test/functional/associations/test_one_embedded_proxy.rb +68 -0
  23. data/test/functional/associations/test_one_proxy.rb +48 -13
  24. data/test/functional/test_binary.rb +1 -1
  25. data/test/functional/test_document.rb +7 -7
  26. data/test/functional/test_embedded_document.rb +8 -0
  27. data/test/functional/test_identity_map.rb +2 -2
  28. data/test/functional/test_modifiers.rb +249 -185
  29. data/test/functional/test_protected.rb +4 -0
  30. data/test/functional/test_string_id_compatibility.rb +1 -1
  31. data/test/support/custom_matchers.rb +0 -18
  32. data/test/test_helper.rb +6 -4
  33. data/test/unit/associations/test_base.rb +7 -2
  34. data/test/unit/test_document.rb +5 -5
  35. data/test/unit/test_embedded_document.rb +7 -7
  36. data/test/unit/test_query.rb +17 -7
  37. data/test/unit/test_support.rb +26 -14
  38. metadata +33 -16
@@ -69,6 +69,10 @@ class ProtectedTest < Test::Unit::TestCase
69
69
  @doc.name.should == 'Stimpson J. Cat'
70
70
  @doc.admin.should be_false
71
71
  end
72
+
73
+ should "accept nil as constructor's argument without raising exception" do
74
+ lambda { @doc_class.new(nil) }.should_not raise_error
75
+ end
72
76
  end
73
77
 
74
78
  context "Single collection inherited protected attributes" do
@@ -28,7 +28,7 @@ class StringIdCompatibilityTest < Test::Unit::TestCase
28
28
  project._id.should be_instance_of(String)
29
29
  project.id.size.should == 24
30
30
  lambda {
31
- Mongo::ObjectID.from_string(project.id)
31
+ BSON::ObjectID.from_string(project.id)
32
32
  }.should_not raise_error
33
33
  end
34
34
 
@@ -1,16 +1,4 @@
1
1
  module CustomMatchers
2
- custom_matcher :be_nil do |receiver, matcher, args|
3
- matcher.positive_failure_message = "Expected #{receiver} to be nil but it wasn't"
4
- matcher.negative_failure_message = "Expected #{receiver} not to be nil but it was"
5
- receiver.nil?
6
- end
7
-
8
- custom_matcher :be_blank do |receiver, matcher, args|
9
- matcher.positive_failure_message = "Expected #{receiver} to be blank but it wasn't"
10
- matcher.negative_failure_message = "Expected #{receiver} not to be blank but it was"
11
- receiver.blank?
12
- end
13
-
14
2
  custom_matcher :be_true do |receiver, matcher, args|
15
3
  matcher.positive_failure_message = "Expected #{receiver} to be true but it wasn't"
16
4
  matcher.negative_failure_message = "Expected #{receiver} not to be true but it was"
@@ -23,12 +11,6 @@ module CustomMatchers
23
11
  receiver.eql?(false)
24
12
  end
25
13
 
26
- custom_matcher :be_valid do |receiver, matcher, args|
27
- matcher.positive_failure_message = "Expected to be valid but it was invalid #{receiver.errors.inspect}"
28
- matcher.negative_failure_message = "Expected to be invalid but it was valid #{receiver.errors.inspect}"
29
- receiver.valid?
30
- end
31
-
32
14
  custom_matcher :have_error_on do |receiver, matcher, args|
33
15
  receiver.valid?
34
16
  attribute = args[0]
@@ -2,14 +2,16 @@ require File.expand_path(File.dirname(__FILE__) + '/../lib/mongo_mapper')
2
2
  require 'fileutils'
3
3
 
4
4
  gem 'jnunemaker-matchy', '0.4.0'
5
- gem 'shoulda', '2.10.2'
6
- gem 'timecop', '0.3.1'
7
- gem 'mocha', '0.9.8'
5
+ gem 'shoulda', '2.10.2'
6
+ gem 'json', '>= 1.2.3'
7
+ gem 'timecop', '0.3.1'
8
+ gem 'mocha', '0.9.8'
8
9
 
9
- require 'matchy'
10
10
  require 'shoulda'
11
11
  require 'timecop'
12
+ require 'matchy'
12
13
  require 'mocha'
14
+ require 'json'
13
15
  require 'pp'
14
16
 
15
17
  require 'support/custom_matchers'
@@ -194,9 +194,14 @@ class AssociationBaseTest < Test::Unit::TestCase
194
194
  end
195
195
 
196
196
  should "be OneProxy for one" do
197
- base = Base.new(:one, :target, :polymorphic => true)
197
+ base = Base.new(:one, :status, :polymorphic => true)
198
198
  base.proxy_class.should == OneProxy
199
199
  end
200
+
201
+ should "be OneEmbeddedProxy for one embedded" do
202
+ base = Base.new(:one, :media)
203
+ base.proxy_class.should == OneEmbeddedProxy
204
+ end
200
205
 
201
206
  should "be InArrayProxy for many with :in option" do
202
207
  base = Base.new(:many, :messages, :in => :message_ids)
@@ -204,4 +209,4 @@ class AssociationBaseTest < Test::Unit::TestCase
204
209
  end
205
210
  end
206
211
 
207
- end
212
+ end
@@ -84,8 +84,8 @@ class DocumentTest < Test::Unit::TestCase
84
84
  end
85
85
 
86
86
  context "descendants" do
87
- should "default to nil" do
88
- Enter.descendants.should be_nil
87
+ should "default to an empty array" do
88
+ Enter.descendants.should == []
89
89
  end
90
90
 
91
91
  should "be recorded" do
@@ -102,7 +102,7 @@ class DocumentTest < Test::Unit::TestCase
102
102
  end
103
103
 
104
104
  should "create id during initialization" do
105
- @document.new._id.should be_instance_of(Mongo::ObjectID)
105
+ @document.new._id.should be_instance_of(BSON::ObjectID)
106
106
  end
107
107
 
108
108
  should "have access to logger" do
@@ -177,7 +177,7 @@ class DocumentTest < Test::Unit::TestCase
177
177
 
178
178
  context "equality" do
179
179
  setup do
180
- @oid = Mongo::ObjectID.new
180
+ @oid = BSON::ObjectID.new
181
181
  end
182
182
 
183
183
  should "delegate hash to _id" do
@@ -213,7 +213,7 @@ class DocumentTest < Test::Unit::TestCase
213
213
  end
214
214
 
215
215
  should "not be equal if class same but id different" do
216
- (@document.new('_id' => @oid) == @document.new('_id' => Mongo::ObjectID.new)).should be(false)
216
+ (@document.new('_id' => @oid) == @document.new('_id' => BSON::ObjectID.new)).should be(false)
217
217
  end
218
218
 
219
219
  should "not be equal if id same but class different" do
@@ -202,8 +202,8 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
202
202
  end
203
203
 
204
204
  context "descendants" do
205
- should "default to nil" do
206
- Child.descendants.should be_nil
205
+ should "default to an empty array" do
206
+ Child.descendants.should == []
207
207
  end
208
208
 
209
209
  should "be recorded" do
@@ -232,17 +232,17 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
232
232
  end
233
233
 
234
234
  should "create id during initialization" do
235
- @document.new._id.should be_instance_of(Mongo::ObjectID)
235
+ @document.new._id.should be_instance_of(BSON::ObjectID)
236
236
  end
237
237
 
238
238
  should "have id method returns _id" do
239
- id = Mongo::ObjectID.new
239
+ id = BSON::ObjectID.new
240
240
  doc = @document.new(:_id => id)
241
241
  doc.id.should == id
242
242
  end
243
243
 
244
244
  should "convert string object id to mongo object id when assigning id with _id object id type" do
245
- id = Mongo::ObjectID.new
245
+ id = BSON::ObjectID.new
246
246
  doc = @document.new(:id => id.to_s)
247
247
  doc._id.should == id
248
248
  doc.id.should == id
@@ -568,7 +568,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
568
568
 
569
569
  context "equality" do
570
570
  setup do
571
- @oid = Mongo::ObjectID.new
571
+ @oid = BSON::ObjectID.new
572
572
  end
573
573
 
574
574
  should "delegate hash to _id" do
@@ -599,7 +599,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
599
599
  end
600
600
 
601
601
  should "not be equal if class same but id different" do
602
- (@document.new('_id' => @oid) == @document.new('_id' => Mongo::ObjectID.new)).should be_false
602
+ (@document.new('_id' => @oid) == @document.new('_id' => BSON::ObjectID.new)).should be_false
603
603
  end
604
604
 
605
605
  should "not be equal if id same but class different" do
@@ -53,6 +53,12 @@ class QueryTest < Test::Unit::TestCase
53
53
  criteria[:created_at]['$gt'].should be_utc
54
54
  end
55
55
 
56
+ should "work with multiple symbol operators on the same field" do
57
+ Query.new(Message, :position.gt => 0, :position.lte => 10).criteria.should == {
58
+ :position => {"$gt" => 0, "$lte" => 10}
59
+ }
60
+ end
61
+
56
62
  should "work with simple criteria" do
57
63
  Query.new(Room, :foo => 'bar').criteria.should == {
58
64
  :foo => 'bar'
@@ -65,34 +71,34 @@ class QueryTest < Test::Unit::TestCase
65
71
  end
66
72
 
67
73
  should "convert id to _id" do
68
- id = Mongo::ObjectID.new
74
+ id = BSON::ObjectID.new
69
75
  Query.new(Room, :id => id).criteria.should == {:_id => id}
70
76
  end
71
77
 
72
78
  should "convert id with symbol operator to _id with modifier" do
73
- id = Mongo::ObjectID.new
79
+ id = BSON::ObjectID.new
74
80
  Query.new(Room, :id.ne => id).criteria.should == {
75
81
  :_id => {'$ne' => id}
76
82
  }
77
83
  end
78
84
 
79
85
  should "make sure that _id's are object ids" do
80
- id = Mongo::ObjectID.new
86
+ id = BSON::ObjectID.new
81
87
  Query.new(Room, :_id => id.to_s).criteria.should == {:_id => id}
82
88
  end
83
89
 
84
90
  should "work fine with _id's that are object ids" do
85
- id = Mongo::ObjectID.new
91
+ id = BSON::ObjectID.new
86
92
  Query.new(Room, :_id => id).criteria.should == {:_id => id}
87
93
  end
88
94
 
89
95
  should "make sure other object id typed keys get converted" do
90
- id = Mongo::ObjectID.new
96
+ id = BSON::ObjectID.new
91
97
  Query.new(Message, :room_id => id.to_s).criteria.should == {:room_id => id}
92
98
  end
93
99
 
94
100
  should "work fine with object ids for object id typed keys" do
95
- id = Mongo::ObjectID.new
101
+ id = BSON::ObjectID.new
96
102
  Query.new(Message, :room_id => id).criteria.should == {:room_id => id}
97
103
  end
98
104
 
@@ -152,7 +158,7 @@ class QueryTest < Test::Unit::TestCase
152
158
  end
153
159
 
154
160
  should "make sure that ids in array are object ids" do
155
- id1, id2, id3 = Mongo::ObjectID.new, Mongo::ObjectID.new, Mongo::ObjectID.new
161
+ id1, id2, id3 = BSON::ObjectID.new, BSON::ObjectID.new, BSON::ObjectID.new
156
162
 
157
163
  Query.new(Room, :_id => [id1.to_s, id2.to_s, id3.to_s]).criteria.should == {
158
164
  :_id => {'$in' => [id1, id2, id3]}
@@ -282,6 +288,10 @@ class QueryTest < Test::Unit::TestCase
282
288
  should "also work with select as array of symbols" do
283
289
  Query.new(Room, :select => [:a, :b]).options[:fields].should == [:a, :b]
284
290
  end
291
+
292
+ should "work with select as hash" do
293
+ Query.new(Room, :select => {:a => 0, :b => 1}).options[:fields].should == {:a => 0, :b => 1}
294
+ end
285
295
  end
286
296
 
287
297
  context "Condition auto-detection" do
@@ -21,11 +21,11 @@ class SupportTest < Test::Unit::TestCase
21
21
 
22
22
  context "Binary#to_mongo" do
23
23
  should "convert to byte buffer if not byte buffer" do
24
- Binary.to_mongo('asdfsadasdfs').is_a?(ByteBuffer).should be_true
24
+ Binary.to_mongo('asdfsadasdfs').is_a?(BSON::ByteBuffer).should be_true
25
25
  end
26
26
 
27
27
  should "be byte buffer if byte buffer" do
28
- Binary.to_mongo(ByteBuffer.new('asdfsadasdfs')).is_a?(ByteBuffer).should be_true
28
+ Binary.to_mongo(BSON::ByteBuffer.new('asdfsadasdfs')).is_a?(BSON::ByteBuffer).should be_true
29
29
  end
30
30
 
31
31
  should "be nil if nil" do
@@ -35,7 +35,7 @@ class SupportTest < Test::Unit::TestCase
35
35
 
36
36
  context "Binary#from_mongo" do
37
37
  should "return value" do
38
- buffer = ByteBuffer.new('asdfasdfasdf')
38
+ buffer = BSON::ByteBuffer.new('asdfasdfasdf')
39
39
  Binary.from_mongo(buffer).to_s.should == buffer.to_s
40
40
  end
41
41
  end
@@ -180,19 +180,19 @@ class SupportTest < Test::Unit::TestCase
180
180
  end
181
181
 
182
182
  should "return value if object id" do
183
- id = Mongo::ObjectID.new
183
+ id = BSON::ObjectID.new
184
184
  ObjectId.to_mongo(id).should be(id)
185
185
  end
186
186
 
187
187
  should "return object id if string" do
188
- id = Mongo::ObjectID.new
188
+ id = BSON::ObjectID.new
189
189
  ObjectId.to_mongo(id.to_s).should be(id)
190
190
  end
191
191
  end
192
192
 
193
193
  context "ObjectId#from_mongo" do
194
194
  should "return value" do
195
- id = Mongo::ObjectID.new
195
+ id = BSON::ObjectID.new
196
196
  ObjectId.from_mongo(id).should == id
197
197
  end
198
198
  end
@@ -356,15 +356,27 @@ class SupportTest < Test::Unit::TestCase
356
356
  end
357
357
  end
358
358
 
359
- context "Mongo::ObjectID.to_json" do
360
- should "convert object id to string" do
361
- id = Mongo::ObjectID.new
362
- id.to_json.should == %Q("#{id}")
359
+ context "BSON::ObjectID" do
360
+ context "#as_json" do
361
+ should "convert object id to string" do
362
+ id = BSON::ObjectID.new
363
+ id.as_json.should == id.to_s
364
+ end
363
365
  end
364
-
365
- should "support ruby driver syntax also" do
366
- id = Mongo::ObjectID.new
367
- id.original_to_json.should == %Q({"$oid": "#{id}"})
366
+ context "#to_json" do
367
+ should "convert object id to string" do
368
+ id = BSON::ObjectID.new
369
+ id.to_json.should == %Q("#{id}")
370
+ end
371
+
372
+ should "support ruby driver syntax also" do
373
+ id = BSON::ObjectID.new
374
+ id.original_to_json.should == %Q({"$oid": "#{id}"})
375
+ end
368
376
  end
369
377
  end
378
+
379
+ context "BSON::ObjectID.to_json" do
380
+
381
+ end
370
382
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 3
9
- version: 0.7.3
8
+ - 4
9
+ version: 0.7.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Nunemaker
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-05 00:00:00 -04:00
17
+ date: 2010-04-18 00:00:00 -04:00
18
18
  default_executable: mmconsole
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -40,9 +40,9 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  segments:
42
42
  - 0
43
- - 19
44
- - 3
45
- version: 0.19.3
43
+ - 20
44
+ - 1
45
+ version: 0.20.1
46
46
  type: :runtime
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
@@ -55,14 +55,28 @@ dependencies:
55
55
  segments:
56
56
  - 1
57
57
  - 8
58
- - 3
59
- version: 1.8.3
58
+ - 4
59
+ version: 1.8.4
60
60
  type: :runtime
61
61
  version_requirements: *id003
62
62
  - !ruby/object:Gem::Dependency
63
- name: jnunemaker-matchy
63
+ name: json
64
64
  prerelease: false
65
65
  requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 1
71
+ - 2
72
+ - 3
73
+ version: 1.2.3
74
+ type: :development
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: jnunemaker-matchy
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
66
80
  requirements:
67
81
  - - "="
68
82
  - !ruby/object:Gem::Version
@@ -72,11 +86,11 @@ dependencies:
72
86
  - 0
73
87
  version: 0.4.0
74
88
  type: :development
75
- version_requirements: *id004
89
+ version_requirements: *id005
76
90
  - !ruby/object:Gem::Dependency
77
91
  name: shoulda
78
92
  prerelease: false
79
- requirement: &id005 !ruby/object:Gem::Requirement
93
+ requirement: &id006 !ruby/object:Gem::Requirement
80
94
  requirements:
81
95
  - - "="
82
96
  - !ruby/object:Gem::Version
@@ -86,11 +100,11 @@ dependencies:
86
100
  - 2
87
101
  version: 2.10.2
88
102
  type: :development
89
- version_requirements: *id005
103
+ version_requirements: *id006
90
104
  - !ruby/object:Gem::Dependency
91
105
  name: timecop
92
106
  prerelease: false
93
- requirement: &id006 !ruby/object:Gem::Requirement
107
+ requirement: &id007 !ruby/object:Gem::Requirement
94
108
  requirements:
95
109
  - - "="
96
110
  - !ruby/object:Gem::Version
@@ -100,11 +114,11 @@ dependencies:
100
114
  - 1
101
115
  version: 0.3.1
102
116
  type: :development
103
- version_requirements: *id006
117
+ version_requirements: *id007
104
118
  - !ruby/object:Gem::Dependency
105
119
  name: mocha
106
120
  prerelease: false
107
- requirement: &id007 !ruby/object:Gem::Requirement
121
+ requirement: &id008 !ruby/object:Gem::Requirement
108
122
  requirements:
109
123
  - - "="
110
124
  - !ruby/object:Gem::Version
@@ -114,7 +128,7 @@ dependencies:
114
128
  - 8
115
129
  version: 0.9.8
116
130
  type: :development
117
- version_requirements: *id007
131
+ version_requirements: *id008
118
132
  description:
119
133
  email: nunemaker@gmail.com
120
134
  executables:
@@ -146,6 +160,7 @@ files:
146
160
  - lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
147
161
  - lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb
148
162
  - lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb
163
+ - lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
149
164
  - lib/mongo_mapper/plugins/associations/one_proxy.rb
150
165
  - lib/mongo_mapper/plugins/associations/proxy.rb
151
166
  - lib/mongo_mapper/plugins/callbacks.rb
@@ -185,6 +200,7 @@ files:
185
200
  - test/functional/associations/test_many_embedded_polymorphic_proxy.rb
186
201
  - test/functional/associations/test_many_embedded_proxy.rb
187
202
  - test/functional/associations/test_many_polymorphic_proxy.rb
203
+ - test/functional/associations/test_one_embedded_proxy.rb
188
204
  - test/functional/associations/test_one_proxy.rb
189
205
  - test/functional/test_associations.rb
190
206
  - test/functional/test_binary.rb
@@ -264,6 +280,7 @@ test_files:
264
280
  - test/functional/associations/test_many_embedded_polymorphic_proxy.rb
265
281
  - test/functional/associations/test_many_embedded_proxy.rb
266
282
  - test/functional/associations/test_many_polymorphic_proxy.rb
283
+ - test/functional/associations/test_one_embedded_proxy.rb
267
284
  - test/functional/associations/test_one_proxy.rb
268
285
  - test/functional/test_associations.rb
269
286
  - test/functional/test_binary.rb