mongo_mapper 0.15.3 → 0.15.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -6
  3. data/lib/mongo_mapper.rb +17 -18
  4. data/lib/mongo_mapper/extensions/array.rb +1 -1
  5. data/lib/mongo_mapper/extensions/binary.rb +1 -1
  6. data/lib/mongo_mapper/extensions/date.rb +1 -1
  7. data/lib/mongo_mapper/extensions/float.rb +1 -1
  8. data/lib/mongo_mapper/extensions/hash.rb +1 -1
  9. data/lib/mongo_mapper/extensions/nil_class.rb +2 -2
  10. data/lib/mongo_mapper/extensions/object.rb +1 -1
  11. data/lib/mongo_mapper/extensions/object_id.rb +1 -1
  12. data/lib/mongo_mapper/extensions/set.rb +1 -1
  13. data/lib/mongo_mapper/extensions/string.rb +1 -1
  14. data/lib/mongo_mapper/plugins/associations/many_association.rb +2 -3
  15. data/lib/mongo_mapper/plugins/associations/{belongs_to_polymorphic_proxy.rb → proxy/belongs_to_polymorphic_proxy.rb} +0 -0
  16. data/lib/mongo_mapper/plugins/associations/{belongs_to_proxy.rb → proxy/belongs_to_proxy.rb} +0 -0
  17. data/lib/mongo_mapper/plugins/associations/proxy/collection.rb +55 -0
  18. data/lib/mongo_mapper/plugins/associations/{embedded_collection.rb → proxy/embedded_collection.rb} +0 -0
  19. data/lib/mongo_mapper/plugins/associations/{in_array_proxy.rb → proxy/in_array_proxy.rb} +0 -0
  20. data/lib/mongo_mapper/plugins/associations/{in_foreign_array_proxy.rb → proxy/in_foreign_array_proxy.rb} +0 -0
  21. data/lib/mongo_mapper/plugins/associations/{many_documents_as_proxy.rb → proxy/many_documents_as_proxy.rb} +0 -0
  22. data/lib/mongo_mapper/plugins/associations/{many_documents_proxy.rb → proxy/many_documents_proxy.rb} +0 -4
  23. data/lib/mongo_mapper/plugins/associations/{many_embedded_polymorphic_proxy.rb → proxy/many_embedded_polymorphic_proxy.rb} +0 -0
  24. data/lib/mongo_mapper/plugins/associations/{many_embedded_proxy.rb → proxy/many_embedded_proxy.rb} +0 -0
  25. data/lib/mongo_mapper/plugins/associations/{many_polymorphic_proxy.rb → proxy/many_polymorphic_proxy.rb} +0 -0
  26. data/lib/mongo_mapper/plugins/associations/{one_as_proxy.rb → proxy/one_as_proxy.rb} +0 -0
  27. data/lib/mongo_mapper/plugins/associations/{one_embedded_polymorphic_proxy.rb → proxy/one_embedded_polymorphic_proxy.rb} +0 -0
  28. data/lib/mongo_mapper/plugins/associations/{one_embedded_proxy.rb → proxy/one_embedded_proxy.rb} +0 -0
  29. data/lib/mongo_mapper/plugins/associations/{one_proxy.rb → proxy/one_proxy.rb} +0 -0
  30. data/lib/mongo_mapper/plugins/associations/{proxy.rb → proxy/proxy.rb} +63 -48
  31. data/lib/mongo_mapper/plugins/associations/single_association.rb +2 -11
  32. data/lib/mongo_mapper/plugins/dirty.rb +1 -1
  33. data/lib/mongo_mapper/plugins/keys/key.rb +9 -6
  34. data/lib/mongo_mapper/plugins/validations.rb +1 -1
  35. data/lib/mongo_mapper/version.rb +1 -1
  36. data/spec/examples.txt +1706 -1704
  37. data/spec/functional/keys_spec.rb +13 -0
  38. data/spec/unit/associations/proxy_spec.rb +5 -5
  39. data/spec/unit/extensions_spec.rb +9 -3
  40. data/spec/unit/inspect_spec.rb +1 -1
  41. data/spec/unit/key_spec.rb +7 -1
  42. metadata +33 -19
  43. data/lib/mongo_mapper/plugins/associations/collection.rb +0 -29
@@ -352,6 +352,19 @@ describe "Keys" do
352
352
  it 'should remove the key' do
353
353
  DocWithRemovedKey.keys.should_not have_key "_something"
354
354
  end
355
+ end
356
+
357
+ describe "default with no type" do
358
+ it "should work (regression)" do
359
+ doc = Doc do
360
+ key :a_num, default: 0
361
+ end
355
362
 
363
+ instance = doc.new
364
+ instance.a_num.should == 0
365
+
366
+ instance = doc.new(a_num: 10)
367
+ instance.a_num.should == 10
368
+ end
356
369
  end
357
370
  end
@@ -1,19 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  class FakeNilProxy < MongoMapper::Plugins::Associations::Proxy
4
- def find_target; nil end
4
+ def load_target; @target ||= nil end
5
5
  end
6
6
 
7
7
  class FakeBlankProxy < MongoMapper::Plugins::Associations::Proxy
8
- def find_target; '' end
8
+ def load_target; @target ||= '' end
9
9
  end
10
10
 
11
11
  class FakeNumberProxy < MongoMapper::Plugins::Associations::Proxy
12
- def find_target; 17 end
12
+ def load_target; @target ||= 17 end
13
13
  end
14
14
 
15
15
  class FakeProxy < MongoMapper::Plugins::Associations::Proxy
16
- def find_target; [1, 2] end
16
+ def load_target; @target ||= [1, 2] end
17
17
  end
18
18
 
19
19
  describe "Proxy" do
@@ -32,7 +32,7 @@ describe "Proxy" do
32
32
  end
33
33
 
34
34
  it "should be able to inspect the proxy" do
35
- @proxy.inspect.should == '[1, 2]'
35
+ @proxy.inspect.should == "#<FakeProxy:#{@proxy.object_id} [1, 2]>"
36
36
  end
37
37
 
38
38
  context "nil?" do
@@ -192,15 +192,21 @@ describe "Support" do
192
192
  end
193
193
  end
194
194
 
195
- context "NilClass#from_mongo" do
195
+ context "NilClass.from_mongo" do
196
196
  it "should return nil" do
197
- nil.from_mongo(nil).should be_nil
197
+ NilClass.from_mongo(nil).should be_nil
198
+ end
199
+ end
200
+
201
+ context "NilClass.to_mongo" do
202
+ it "should return nil" do
203
+ NilClass.to_mongo(nil).should be_nil
198
204
  end
199
205
  end
200
206
 
201
207
  context "NilClass#to_mongo" do
202
208
  it "should return nil" do
203
- nil.to_mongo(nil).should be_nil
209
+ nil.to_mongo.should be_nil
204
210
  end
205
211
  end
206
212
 
@@ -31,7 +31,7 @@ describe "Inspect" do
31
31
  klass.many :pets, :class => pets
32
32
 
33
33
  doc = klass.new(:pets => [{:name => "Kitten"}])
34
- doc.inspect.should =~ /_id:.*, pets: \[.*_id.*, name: "Kitten".*\]/
34
+ doc.inspect.should =~ /_id:.*, pets: .*\[.*_id.*, name: "Kitten".*\]/
35
35
  end
36
36
 
37
37
  it "should include embedded document" do
@@ -55,6 +55,7 @@ describe "Key" do
55
55
  it "should work with name and options" do
56
56
  key = Key.new(:foo, :required => true)
57
57
  key.name.should == 'foo'
58
+ key.type.should be_nil
58
59
  key.options[:required].should be_truthy
59
60
  end
60
61
 
@@ -111,7 +112,12 @@ describe "Key" do
111
112
  subject { @key }
112
113
 
113
114
  it "should cast each element correctly" do
114
- ids = [BSON::ObjectId.new, BSON::ObjectId.new, BSON::ObjectId.new.to_s, BSON::ObjectId.new.to_s]
115
+ ids = [
116
+ BSON::ObjectId.new,
117
+ BSON::ObjectId.new,
118
+ BSON::ObjectId.new.to_s,
119
+ BSON::ObjectId.new.to_s
120
+ ]
115
121
  subject.set(ids).should == ids.map { |id| ObjectId.to_mongo(id) }
116
122
  end
117
123
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.3
4
+ version: 0.15.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-02-11 00:00:00.000000000 Z
13
+ date: 2021-06-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mongo
@@ -82,6 +82,20 @@ dependencies:
82
82
  - - "~>"
83
83
  - !ruby/object:Gem::Version
84
84
  version: '1.0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: rexml
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :runtime
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
85
99
  description: MongoMapper is a Object-Document Mapper for Ruby and Rails
86
100
  email:
87
101
  - nunemaker@gmail.com
@@ -137,24 +151,24 @@ files:
137
151
  - lib/mongo_mapper/plugins/associations.rb
138
152
  - lib/mongo_mapper/plugins/associations/base.rb
139
153
  - lib/mongo_mapper/plugins/associations/belongs_to_association.rb
140
- - lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb
141
- - lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb
142
- - lib/mongo_mapper/plugins/associations/collection.rb
143
- - lib/mongo_mapper/plugins/associations/embedded_collection.rb
144
- - lib/mongo_mapper/plugins/associations/in_array_proxy.rb
145
- - lib/mongo_mapper/plugins/associations/in_foreign_array_proxy.rb
146
154
  - lib/mongo_mapper/plugins/associations/many_association.rb
147
- - lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb
148
- - lib/mongo_mapper/plugins/associations/many_documents_proxy.rb
149
- - lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
150
- - lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb
151
- - lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb
152
- - lib/mongo_mapper/plugins/associations/one_as_proxy.rb
153
155
  - lib/mongo_mapper/plugins/associations/one_association.rb
154
- - lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb
155
- - lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb
156
- - lib/mongo_mapper/plugins/associations/one_proxy.rb
157
- - lib/mongo_mapper/plugins/associations/proxy.rb
156
+ - lib/mongo_mapper/plugins/associations/proxy/belongs_to_polymorphic_proxy.rb
157
+ - lib/mongo_mapper/plugins/associations/proxy/belongs_to_proxy.rb
158
+ - lib/mongo_mapper/plugins/associations/proxy/collection.rb
159
+ - lib/mongo_mapper/plugins/associations/proxy/embedded_collection.rb
160
+ - lib/mongo_mapper/plugins/associations/proxy/in_array_proxy.rb
161
+ - lib/mongo_mapper/plugins/associations/proxy/in_foreign_array_proxy.rb
162
+ - lib/mongo_mapper/plugins/associations/proxy/many_documents_as_proxy.rb
163
+ - lib/mongo_mapper/plugins/associations/proxy/many_documents_proxy.rb
164
+ - lib/mongo_mapper/plugins/associations/proxy/many_embedded_polymorphic_proxy.rb
165
+ - lib/mongo_mapper/plugins/associations/proxy/many_embedded_proxy.rb
166
+ - lib/mongo_mapper/plugins/associations/proxy/many_polymorphic_proxy.rb
167
+ - lib/mongo_mapper/plugins/associations/proxy/one_as_proxy.rb
168
+ - lib/mongo_mapper/plugins/associations/proxy/one_embedded_polymorphic_proxy.rb
169
+ - lib/mongo_mapper/plugins/associations/proxy/one_embedded_proxy.rb
170
+ - lib/mongo_mapper/plugins/associations/proxy/one_proxy.rb
171
+ - lib/mongo_mapper/plugins/associations/proxy/proxy.rb
158
172
  - lib/mongo_mapper/plugins/associations/single_association.rb
159
173
  - lib/mongo_mapper/plugins/caching.rb
160
174
  - lib/mongo_mapper/plugins/callbacks.rb
@@ -304,7 +318,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
304
318
  - !ruby/object:Gem::Version
305
319
  version: '0'
306
320
  requirements: []
307
- rubygems_version: 3.1.4
321
+ rubygems_version: 3.1.6
308
322
  signing_key:
309
323
  specification_version: 4
310
324
  summary: A Ruby Object Mapper for Mongo
@@ -1,29 +0,0 @@
1
- # encoding: UTF-8
2
- module MongoMapper
3
- module Plugins
4
- module Associations
5
- class Collection < Proxy
6
- def to_ary
7
- load_target
8
- if target.is_a?(Array)
9
- target.to_ary
10
- else
11
- Array(target)
12
- end
13
- end
14
-
15
- alias_method :to_a, :to_ary
16
-
17
- def include?(*args)
18
- load_target
19
- target.include?(*args)
20
- end
21
-
22
- def reset
23
- super
24
- target = []
25
- end
26
- end
27
- end
28
- end
29
- end