mongoid 7.0.3 → 7.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f9840f2a5bdcfd628358c56f70818857080118680059a6ca299c6de3b4554c2
4
- data.tar.gz: f8700656e769546f2c8d2555013aa601d10552e9e48faf37f24c66fded700b1d
3
+ metadata.gz: 97ae228df96e11fe59977a8d1af1bb0e86597fe5ee31d8cbe257a077d6e87d4f
4
+ data.tar.gz: b8face8e682359ca47c26c0dc168ab1a99762769176fd2f8796ae472a341cd76
5
5
  SHA512:
6
- metadata.gz: a05fb92510939cf2ccff55855219033db8a9a45399865f725e695af95a9501f72a0db72422766dd54fc9946854e0065b9beb870bfeb3a02b8ac9e605962419e0
7
- data.tar.gz: 267ff19b100ca5ef83f383ddd8d4ece8ce0e122a16cbc6c1605bc872e391ad775bd6336beb53af733ba8d7b47d9ec01d9842f5502c7f0c135cdc2fa258b80b47
6
+ metadata.gz: 1aafc53e49a0576a7bfb081bca208629ba7323c1a52468e0279644b0b9c2a9d4015c63d35cdf1f16b0967056ed976d015638fab512bce7a221acfeda75c867ed
7
+ data.tar.gz: 0c3e7557c424ccd5a95d3e5c4249e4a45a31f74577be2ba7cfac70d67d3226cd00b0b655e7f9d576086a0fc18c7b9d7bf37c57e8a06fb07131a3bec99e85fe8a
Binary file
Binary file
@@ -145,20 +145,19 @@ module Mongoid
145
145
  # @since 7.0
146
146
  def inverse_type; end
147
147
 
148
- # The class name of the relation object(s).
148
+ # The class name, possibly unqualified or :: prefixed, of the association
149
+ # object(s).
149
150
  #
150
- # The class name may be fully qualified or may be specified relative
151
- # to the class on which the association is defined (this class is
152
- # accessible as inverse_class). If :class_name option is given in the
153
- # association, the exact value of that option is returned here for
154
- # backwards compatibility reasons. If :class_name option is not given,
155
- # the name of the class computed by Mongoid to be the association target
156
- # is returned, and it will be fully qualified.
151
+ # This method returns the class name as it is used in the association
152
+ # definition. If :class_name option is given in the association, the
153
+ # exact value of that option is returned here. If :class_name option is
154
+ # not given, the name of the class is calculated from association name
155
+ # but is not resolved to the actual class.
157
156
  #
158
157
  # The class name returned by this method may not correspond to a defined
159
- # class. The return value of the method is the class name that Mongoid
160
- # would reference, relative to the host document class, when it needs to
161
- # perform operations on the association target.
158
+ # class, either because the corresponding class has not been loaded yet,
159
+ # or because the association references a non-existent class altogether.
160
+ # To obtain the association class, use +relation_class+ method.
162
161
  #
163
162
  # @note The return value of this method should not be used to determine
164
163
  # whether two associations have the same target class, because the
@@ -170,15 +169,7 @@ module Mongoid
170
169
  #
171
170
  # @since 7.0
172
171
  def relation_class_name
173
- @class_name ||= @options[:class_name] || begin
174
- cls_name = ActiveSupport::Inflector.classify(name)
175
- begin
176
- cls_name = resolve_name(inverse_class, cls_name).name
177
- rescue NameError
178
- # ignore
179
- end
180
- cls_name
181
- end
172
+ @class_name ||= @options[:class_name] || ActiveSupport::Inflector.classify(name)
182
173
  end
183
174
  alias :class_name :relation_class_name
184
175
 
@@ -478,10 +469,21 @@ module Mongoid
478
469
 
479
470
  # Resolves the given class/module name in the context of the specified
480
471
  # module, as Ruby would when a constant is referenced in the source.
472
+ #
473
+ # @note This method can swallow exceptions produced during class loading,
474
+ # because it rescues NameError internally. Since this method attempts
475
+ # to load classes, failure during the loading process may also lead to
476
+ # there being incomplete class definitions.
481
477
  def resolve_name(mod, name)
482
478
  cls = exc = nil
483
479
  parts = name.to_s.split('::')
484
- namespace_hierarchy(mod).each do |ns|
480
+ if parts.first == ''
481
+ parts.shift
482
+ hierarchy = [Object]
483
+ else
484
+ hierarchy = namespace_hierarchy(mod)
485
+ end
486
+ hierarchy.each do |ns|
485
487
  begin
486
488
  parts.each do |part|
487
489
  # Simple const_get sometimes pulls names out of weird scopes,
@@ -74,7 +74,11 @@ module Mongoid
74
74
 
75
75
  if association.is_a?(Association::Embedded::EmbedsMany)
76
76
  attrs[association.key].each do |attr|
77
- embedded_klass = attr.fetch('_type', association.relation_class_name).constantize
77
+ embedded_klass = if type = attr['_type']
78
+ type.constantize
79
+ else
80
+ association.relation_class
81
+ end
78
82
  process_localized_attributes(embedded_klass, attr)
79
83
  end
80
84
  else
@@ -82,7 +82,9 @@ module Mongoid
82
82
  #
83
83
  # @since 3.0.0
84
84
  def numeric?
85
- true if Float(self) rescue (self =~ /^NaN|\-?Infinity$/)
85
+ !!Float(self)
86
+ rescue ArgumentError
87
+ (self =~ /\A(?:NaN|-?Infinity)\z/) == 0
86
88
  end
87
89
 
88
90
  # Get the string as a getter string.
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
- VERSION = "7.0.3"
3
+ VERSION = "7.0.4"
4
4
  end
@@ -0,0 +1,2 @@
1
+ class OtherOwnerObject
2
+ end
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ require_relative './embeds_one_models'
2
3
 
3
4
  describe Mongoid::Association::Embedded::EmbeddedIn do
4
5
 
@@ -313,6 +314,42 @@ describe Mongoid::Association::Embedded::EmbeddedIn do
313
314
  it 'returns nil' do
314
315
  expect(association.inverses).to eq(nil)
315
316
  end
317
+
318
+ context 'when class_name is given and is a plain string' do
319
+ let(:association) do
320
+ EomParent.relations['child']
321
+ end
322
+
323
+ it 'returns the inverse in an array' do
324
+ inverses = association.inverses
325
+ expect(inverses).to eq([:parent])
326
+ end
327
+ end
328
+
329
+ context 'when class_name is given and is a :: prefixed string' do
330
+ let(:association) do
331
+ EomCcChild.relations['parent']
332
+ end
333
+
334
+ it 'returns the inverse in an array' do
335
+ pending 'MONGOID-4751'
336
+
337
+ inverses = association.inverses
338
+ expect(inverses).to eq([:child])
339
+ end
340
+
341
+ context 'when other associations referencing unloaded classes exist' do
342
+ let(:association) do
343
+ EomDnlChild.relations['parent']
344
+ end
345
+
346
+ it 'does not load other classes' do
347
+ inverses = association.inverses
348
+ expect(inverses).to eq([:child])
349
+ expect(Object.const_defined?(:EoDnlMarker)).to be false
350
+ end
351
+ end
352
+ end
316
353
  end
317
354
  end
318
355
  end
@@ -549,6 +586,16 @@ describe Mongoid::Association::Embedded::EmbeddedIn do
549
586
  it 'returns the class name option' do
550
587
  expect(association.relation_class_name).to eq('OtherContainer')
551
588
  end
589
+
590
+ context ':class_name is a :: prefixed string' do
591
+ let(:association) do
592
+ EomCcChild.relations['parent']
593
+ end
594
+
595
+ it 'returns the :: prefixed string' do
596
+ expect(association.relation_class_name).to eq('::EomCcParent')
597
+ end
598
+ end
552
599
  end
553
600
 
554
601
  context 'when the class_name option is not specified' do
@@ -557,6 +604,17 @@ describe Mongoid::Association::Embedded::EmbeddedIn do
557
604
  expect(association.relation_class_name).to eq('Container')
558
605
  end
559
606
  end
607
+
608
+ context 'when another association in the model is referencing a third model class' do
609
+ let(:association) do
610
+ EomDnlChild.relations['parent']
611
+ end
612
+
613
+ it 'does not attempt to load the third class' do
614
+ expect(association.relation_class_name).to eq('EomDnlParent')
615
+ expect(Object.const_defined?(:EoDnlMarker)).to be false
616
+ end
617
+ end
560
618
  end
561
619
 
562
620
  describe '#klass' do
@@ -0,0 +1,6 @@
1
+ # This file is added as an autoload target, but should never be actually
2
+ # processed.
3
+
4
+ # Marker class - if this class exists, this file was attempted to be required.
5
+ class EoDnlMarker
6
+ end
@@ -0,0 +1,51 @@
1
+ class EomParent
2
+ include Mongoid::Document
3
+
4
+ embeds_one :child, class_name: 'EomChild'
5
+
6
+ field :name, type: String
7
+ end
8
+
9
+ class EomChild
10
+ include Mongoid::Document
11
+
12
+ embedded_in :parent, class_name: 'EomParent'
13
+
14
+ field :a, type: Integer, default: 0
15
+ field :b, type: Integer, default: 0
16
+ end
17
+
18
+ # Models with associations with :class_name as a :: prefixed string
19
+
20
+ class EomCcParent
21
+ include Mongoid::Document
22
+
23
+ embeds_one :child, class_name: '::EomCcChild'
24
+ end
25
+
26
+ class EomCcChild
27
+ include Mongoid::Document
28
+
29
+ embedded_in :parent, class_name: '::EomCcParent'
30
+ end
31
+
32
+ # Models referencing other models which should not be loaded unless the
33
+ # respective association is referenced
34
+
35
+ autoload :EomDnlMissingChild, 'mongoid/association/embedded/embeds_one_dnl_models'
36
+
37
+ class EomDnlParent
38
+ include Mongoid::Document
39
+
40
+ embeds_one :child, class_name: 'EomDnlChild'
41
+ embeds_one :missing_child, class_name: 'EomDnlMissingChild'
42
+ end
43
+
44
+ autoload :EomDnlMissingParent, 'mongoid/association/embedded/embeds_one_dnl_models'
45
+
46
+ class EomDnlChild
47
+ include Mongoid::Document
48
+
49
+ embedded_in :parent, class_name: 'EomDnlParent'
50
+ embedded_in :missing_parent, class_name: 'EomDnlMissingParent'
51
+ end
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ require_relative './embeds_one_models'
2
3
 
3
4
  describe Mongoid::Association::Embedded::EmbedsOne do
4
5
 
@@ -444,6 +445,32 @@ describe Mongoid::Association::Embedded::EmbedsOne do
444
445
  it 'returns the :as attribute' do
445
446
  expect(association.inverses).to eq([ :containable ])
446
447
  end
448
+
449
+ context 'when class_name is given and is a :: prefixed string' do
450
+
451
+ let(:association) do
452
+ EomCcParent.relations['child']
453
+ end
454
+
455
+ it 'returns the inverse in an array' do
456
+ pending 'MONGOID-4751'
457
+
458
+ inverses = association.inverses
459
+ expect(inverses).to eq([:parent])
460
+ end
461
+
462
+ context 'when other associations referencing unloaded classes exist' do
463
+ let(:association) do
464
+ EomDnlParent.relations['child']
465
+ end
466
+
467
+ it 'does not load other classes' do
468
+ inverses = association.inverses
469
+ expect(inverses).to eq([:parent])
470
+ expect(Object.const_defined?(:EoDnlMarker)).to be false
471
+ end
472
+ end
473
+ end
447
474
  end
448
475
  end
449
476
  end
@@ -604,6 +631,16 @@ describe Mongoid::Association::Embedded::EmbedsOne do
604
631
  it 'returns the class name option' do
605
632
  expect(association.relation_class_name).to eq('OtherEmbeddedObject')
606
633
  end
634
+
635
+ context ':class_name is a :: prefixed string' do
636
+ let(:association) do
637
+ EomCcParent.relations['child']
638
+ end
639
+
640
+ it 'returns the :: prefixed string' do
641
+ expect(association.relation_class_name).to eq('::EomCcChild')
642
+ end
643
+ end
607
644
  end
608
645
 
609
646
  context 'when the class_name option is not specified' do
@@ -612,6 +649,17 @@ describe Mongoid::Association::Embedded::EmbedsOne do
612
649
  expect(association.relation_class_name).to eq('EmbeddedObject')
613
650
  end
614
651
  end
652
+
653
+ context 'when another association in the model is referencing a third model class' do
654
+ let(:association) do
655
+ EomDnlParent.relations['child']
656
+ end
657
+
658
+ it 'does not attempt to load the third class' do
659
+ expect(association.relation_class_name).to eq('EomDnlChild')
660
+ expect(Object.const_defined?(:EoDnlMarker)).to be false
661
+ end
662
+ end
615
663
  end
616
664
 
617
665
  describe '#klass' do
@@ -1622,6 +1622,17 @@ describe Mongoid::Association::Referenced::BelongsTo do
1622
1622
  end
1623
1623
  end
1624
1624
 
1625
+ context 'when the :class_name option is scoped with ::' do
1626
+
1627
+ let(:options) do
1628
+ { class_name: '::OtherOwnerObject' }
1629
+ end
1630
+
1631
+ it 'returns the class name option' do
1632
+ expect(association.relation_class_name).to eq('::OtherOwnerObject')
1633
+ end
1634
+ end
1635
+
1625
1636
  context 'when the class_name option is not specified' do
1626
1637
 
1627
1638
  it 'uses the name of the relation to deduce the class name' do
@@ -1644,17 +1655,23 @@ describe Mongoid::Association::Referenced::BelongsTo do
1644
1655
 
1645
1656
  context 'when the :class_name option is specified' do
1646
1657
 
1647
- let!(:_class) do
1648
- class OtherOwnerObject; end
1649
- OtherOwnerObject
1658
+ let(:options) do
1659
+ { class_name: 'OtherOwnerObject' }
1660
+ end
1661
+
1662
+ it 'returns the named class' do
1663
+ expect(association.relation_class).to eq(OtherOwnerObject)
1650
1664
  end
1665
+ end
1666
+
1667
+ context 'when the :class_name option is scoped with ::' do
1651
1668
 
1652
1669
  let(:options) do
1653
- { class_name: 'OtherOwnerObject' }
1670
+ { class_name: '::OtherOwnerObject' }
1654
1671
  end
1655
1672
 
1656
- it 'returns the class name option' do
1657
- expect(association.relation_class).to eq(_class)
1673
+ it 'returns the named class' do
1674
+ expect(association.relation_class).to eq(OtherOwnerObject)
1658
1675
  end
1659
1676
  end
1660
1677
 
@@ -909,12 +909,12 @@ describe Mongoid::Association::Referenced::HasOne do
909
909
  end
910
910
  end
911
911
 
912
- it 'returns the proper namespaced class name' do
912
+ it 'returns the inferred unqualified class name' do
913
913
  define_classes
914
914
 
915
915
  expect(
916
916
  HasOneAssociationClassName::OwnedClass.relations['owner_class'].relation_class_name
917
- ).to eq('HasOneAssociationClassName::OwnerClass')
917
+ ).to eq('OwnerClass')
918
918
  end
919
919
  end
920
920
 
@@ -945,6 +945,16 @@ describe Mongoid::Association::Referenced::HasOne do
945
945
  expect(association.relation_class_name).to eq('BelongingObject')
946
946
  end
947
947
  end
948
+
949
+ context "when the class is not defined" do
950
+ let(:name) do
951
+ :undefined_class
952
+ end
953
+
954
+ it 'does not trigger autoloading' do
955
+ expect(association.relation_class_name).to eq('UndefinedClass')
956
+ end
957
+ end
948
958
  end
949
959
 
950
960
  describe '#relation_class' do
@@ -277,49 +277,77 @@ describe Mongoid::Extensions::String do
277
277
  context "when the string is an integer" do
278
278
 
279
279
  it "returns true" do
280
- expect("1234").to be_numeric
280
+ expect("1234".numeric?).to eq(true)
281
281
  end
282
282
  end
283
283
 
284
284
  context "when string is a float" do
285
285
 
286
286
  it "returns true" do
287
- expect("1234.123").to be_numeric
287
+ expect("1234.123".numeric?).to eq(true)
288
288
  end
289
289
  end
290
290
 
291
291
  context "when the string is has exponents" do
292
292
 
293
293
  it "returns true" do
294
- expect("1234.123123E4").to be_numeric
294
+ expect("1234.123123E4".numeric?).to eq(true)
295
295
  end
296
296
  end
297
297
 
298
298
  context "when the string is non numeric" do
299
299
 
300
300
  it "returns false" do
301
- expect("blah").to_not be_numeric
301
+ expect("blah".numeric?).to eq(false)
302
302
  end
303
303
  end
304
304
 
305
305
  context "when the string is NaN" do
306
306
 
307
307
  it "returns true" do
308
- expect("NaN").to be_numeric
308
+ expect("NaN".numeric?).to eq(true)
309
+ end
310
+ end
311
+
312
+ context "when the string is NaN and junk in front" do
313
+
314
+ it "returns false" do
315
+ expect("a\nNaN".numeric?).to eq(false)
316
+ end
317
+ end
318
+
319
+ context "when the string is NaN and whitespace at end" do
320
+
321
+ it "returns false" do
322
+ expect("NaN\n".numeric?).to eq(false)
309
323
  end
310
324
  end
311
325
 
312
326
  context "when the string is Infinity" do
313
327
 
314
328
  it "returns true" do
315
- expect("Infinity").to be_numeric
329
+ expect("Infinity".numeric?).to eq(true)
330
+ end
331
+ end
332
+
333
+ context "when the string contains Infinity and junk in front" do
334
+
335
+ it "returns false" do
336
+ expect("a\nInfinity".numeric?).to eq(false)
337
+ end
338
+ end
339
+
340
+ context "when the string contains Infinity and whitespace at end" do
341
+
342
+ it "returns false" do
343
+ expect("Infinity\n".numeric?).to eq(false)
316
344
  end
317
345
  end
318
346
 
319
347
  context "when the string is -Infinity" do
320
348
 
321
349
  it "returns true" do
322
- expect("-Infinity").to be_numeric
350
+ expect("-Infinity".numeric?).to eq(true)
323
351
  end
324
352
  end
325
353
  end
metadata CHANGED
@@ -1,14 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.3
4
+ version: 7.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
- date: 2019-05-24 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDRDCCAiygAwIBAgIBATANBgkqhkiG9w0BAQsFADAmMSQwIgYDVQQDDBtkcml2
14
+ ZXItcnVieS9EQz0xMGdlbi9EQz1jb20wHhcNMTkwMTE3MjIzMDE1WhcNMjAwMTE3
15
+ MjIzMDE1WjAmMSQwIgYDVQQDDBtkcml2ZXItcnVieS9EQz0xMGdlbi9EQz1jb20w
16
+ ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDRXUgGvH0ZtWwDPc2umdHw
17
+ B+INNm6jNTRp8PMyUKxPzxaxX2OiBQk9gLC3zsK9ZmlZu4lNfpHVSCEPoiP/fhPg
18
+ Kyfq2xld3Qz0Pki5d5i0/r14343MTKiNiFulLlbbdlN0cXeEFNJHUycZnD2LOXwz
19
+ egYGHOl14FI8t5visIWtqRnLXXIlDsBHzmeEZjUZRGSgjC0R3RT/I+Fk5yUhn1w4
20
+ rqFyAiW+cjjzmT7mmqT0jV6fd0JFHbKnSgt9iPijKSimBgUOsorHwOTMlTzwsy0d
21
+ ZT+al1RiT5zqlAJLxFHwmoYOxD/bSNtKsYl60ek0hK2mISBVy9BBmLvCgHDx5uSp
22
+ AgMBAAGjfTB7MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBRbd1mx
23
+ fvSaVIwKI+tnEAYDW/B81zAgBgNVHREEGTAXgRVkcml2ZXItcnVieUAxMGdlbi5j
24
+ b20wIAYDVR0SBBkwF4EVZHJpdmVyLXJ1YnlAMTBnZW4uY29tMA0GCSqGSIb3DQEB
25
+ CwUAA4IBAQBtXpljL+EXFgH2YRSkYTNn9WKurclJKqaMTJvJoEm2mX1IbAg+BX+i
26
+ Eb+rKelkjezRqVkurzRjif8RI9aGBpAyfobQfHHJNzHQzSFwhEmwlGDQRgQzrDhN
27
+ cbkRB2wDgGJNjnjMKLXfeZX+SjWAsHDrOc+Ue9nHs2AdJxCTDgB1MMNGZ1UjLL9/
28
+ HhO93otEnxwCVijD9ruORb0bT9LlNKosQQEzrhXtOtNK9k7s7G6Gi0BFMOIJDVyq
29
+ bMYVwXXhV8czdzgkQB/ZPWHSbEWXnmkze1mzvqWBCPOVXYrcnL9cnEl/RoxtS1hr
30
+ Db6Ac6mCUSYfYHBWpWqxjc45n70i5Xi1
31
+ -----END CERTIFICATE-----
32
+ date: 2019-06-13 00:00:00.000000000 Z
12
33
  dependencies:
13
34
  - !ruby/object:Gem::Dependency
14
35
  name: activemodel
@@ -493,6 +514,7 @@ files:
493
514
  - spec/app/models/ordered_post.rb
494
515
  - spec/app/models/ordered_preference.rb
495
516
  - spec/app/models/oscar.rb
517
+ - spec/app/models/other_owner_object.rb
496
518
  - spec/app/models/override.rb
497
519
  - spec/app/models/ownable.rb
498
520
  - spec/app/models/owner.rb
@@ -607,6 +629,8 @@ files:
607
629
  - spec/mongoid/association/embedded/embeds_one/binding_spec.rb
608
630
  - spec/mongoid/association/embedded/embeds_one/buildable_spec.rb
609
631
  - spec/mongoid/association/embedded/embeds_one/proxy_spec.rb
632
+ - spec/mongoid/association/embedded/embeds_one_dnl_models.rb
633
+ - spec/mongoid/association/embedded/embeds_one_models.rb
610
634
  - spec/mongoid/association/embedded/embeds_one_spec.rb
611
635
  - spec/mongoid/association/macros_spec.rb
612
636
  - spec/mongoid/association/nested/many_spec.rb
@@ -1041,6 +1065,8 @@ test_files:
1041
1065
  - spec/mongoid/association/embedded/embedded_in/buildable_spec.rb
1042
1066
  - spec/mongoid/association/embedded/embedded_in/binding_spec.rb
1043
1067
  - spec/mongoid/association/embedded/embeds_many_spec.rb
1068
+ - spec/mongoid/association/embedded/embeds_one_dnl_models.rb
1069
+ - spec/mongoid/association/embedded/embeds_one_models.rb
1044
1070
  - spec/mongoid/association/embedded/dirty_spec.rb
1045
1071
  - spec/mongoid/association/embedded/embedded_in_spec.rb
1046
1072
  - spec/mongoid/association/syncable_spec.rb
@@ -1205,6 +1231,7 @@ test_files:
1205
1231
  - spec/app/models/artist.rb
1206
1232
  - spec/app/models/my_hash.rb
1207
1233
  - spec/app/models/post.rb
1234
+ - spec/app/models/other_owner_object.rb
1208
1235
  - spec/app/models/track.rb
1209
1236
  - spec/app/models/tool.rb
1210
1237
  - spec/app/models/movie.rb
Binary file