mongoid 8.1.6 → 8.1.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4218c578b31195178d4f2425bf42c70741f23e123832c9dcc0df9794b1bfbaa
4
- data.tar.gz: 24b7b07e571fff97c9c35cc4f2477f6def8202211a35fb205711f73492f8f68c
3
+ metadata.gz: 965ef60c6694e5d48b7edd1f16c9718b975f3b3969e27a3557e9913a87791e00
4
+ data.tar.gz: 28ea0535a075f4759ff40bb11dca76481b77e9d9cd00ce611b6e4d162e191532
5
5
  SHA512:
6
- metadata.gz: 4086af26408203774f2c4861ae84707adea2dd45fff821470a9517e9ec10c41fc4c80a3e566a25118806e2d89311f6eb1aa8a9e27953ba5784cb22d78025e0ea
7
- data.tar.gz: 1b50e4fff002cc80175aa6c8e489f79c37f5b2cfebdf9adfe6da316b38bab18540a96717d7f217ed2054f7022faf4ec9eb42129e0474b59d3266c3585d237184
6
+ metadata.gz: bd40308e934c907c54d05a8644ac104e1236887e80eaba812939ad9c2a9dca622a306be12a7cf35b9af217c6c9fe894d5794053970ab89c18f21933f59da2197
7
+ data.tar.gz: ba2aa5da4708302723c9170b57d6cfd9d760b63c2e1f3c33efcdcef33971c5720f07cd2f08d160160be675125981b8cab2b529b0a39d2100723de485e869b12f
@@ -35,11 +35,25 @@ module Mongoid
35
35
  # from and behaves identically to association traversal for the purposes
36
36
  # of, for example, subsequent array element retrieval.
37
37
  #
38
- # @param [ Document | Hash ] document The document to extract from.
38
+ # @param [ Document | Hash | String ] document The document to extract from.
39
39
  # @param [ String ] key The key path to extract.
40
40
  #
41
41
  # @return [ Object | Array ] Field value or values.
42
42
  module_function def extract_attribute(document, key)
43
+ # The matcher system will wind up sending atomic values to this as well,
44
+ # when attepting to match more complex types. If anything other than a
45
+ # Document or a Hash is given, we'll short-circuit the logic and just
46
+ # return an empty array.
47
+ return [] unless document.is_a?(Hash) || document.is_a?(Document)
48
+
49
+ # Performance optimization; if the key does not include a '.' character,
50
+ # it must reference an immediate attribute of the document.
51
+ unless key.include?('.')
52
+ hash = document.respond_to?(:attributes) ? document.attributes : document
53
+ key = find_exact_key(hash, key)
54
+ return key ? [ hash[key] ] : []
55
+ end
56
+
43
57
  if document.respond_to?(:as_attributes, true)
44
58
  # If a document has hash fields, as_attributes would keep those fields
45
59
  # as Hash instances which do not offer indifferent access.
@@ -12,13 +12,13 @@ module Mongoid
12
12
  included do
13
13
 
14
14
  class << self
15
- # Note that this intentionally only delegates :include_root_in_json
16
- # and not :include_root_in_json? - delegating the latter produces
17
- # wrong behavior.
18
- # Also note that this intentionally uses the ActiveSupport delegation
19
- # functionality and not the Ruby standard library one.
20
- # See https://jira.mongodb.org/browse/MONGOID-4849.
21
- delegate :include_root_in_json, to: ::Mongoid
15
+ def include_root_in_json
16
+ @include_root_in_json.nil? ? ::Mongoid.include_root_in_json : @include_root_in_json
17
+ end
18
+
19
+ def include_root_in_json=(new_value)
20
+ @include_root_in_json = new_value
21
+ end
22
22
  end
23
23
  end
24
24
 
@@ -30,7 +30,11 @@ module Mongoid
30
30
  if value
31
31
  Mongoid::Fields::Validators::Macro.validate_field_name(self, value)
32
32
  value = value.to_s
33
- super
33
+ if defined?(::ActiveSupport::ClassAttribute)
34
+ ::ActiveSupport::ClassAttribute.redefine(self, 'discriminator_key', value)
35
+ else
36
+ super
37
+ end
34
38
  else
35
39
  # When discriminator key is set to nil, replace the class's definition
36
40
  # of the discriminator key reader (provided by class_attribute earlier)
@@ -69,13 +69,16 @@ module Mongoid
69
69
  # Now, treating the target as an array, look at each element
70
70
  # and see if it is valid, but only if it has already been
71
71
  # persisted, or changed, and hasn't been flagged for destroy.
72
- list.all? do |value|
72
+ #
73
+ # use map.all? instead of just all?, because all? will do short-circuit
74
+ # evaluation and terminate on the first failed validation.
75
+ list.map do |value|
73
76
  if value && !value.flagged_for_destroy? && (!value.persisted? || value.changed?)
74
77
  value.validated? ? true : value.valid?
75
78
  else
76
79
  true
77
80
  end
78
- end
81
+ end.all?
79
82
  end
80
83
 
81
84
  document.errors.add(attribute, :invalid) unless valid
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mongoid
4
- VERSION = "8.1.6"
4
+ VERSION = "8.1.7"
5
5
  end
@@ -26,6 +26,8 @@ describe 'Mongoid application tests' do
26
26
  context 'demo application' do
27
27
  context 'sinatra' do
28
28
  it 'runs' do
29
+ skip 'https://jira.mongodb.org/browse/MONGOID-5826'
30
+
29
31
  clone_application(
30
32
  'https://github.com/mongoid/mongoid-demo',
31
33
  subdir: 'sinatra-minimal',
@@ -45,6 +47,8 @@ describe 'Mongoid application tests' do
45
47
 
46
48
  context 'rails-api' do
47
49
  it 'runs' do
50
+ skip 'https://jira.mongodb.org/browse/MONGOID-5826'
51
+
48
52
  clone_application(
49
53
  'https://github.com/mongoid/mongoid-demo',
50
54
  subdir: 'rails-api',
@@ -95,7 +99,7 @@ describe 'Mongoid application tests' do
95
99
  check_call(%w(rails new mongoid-test --skip-spring --skip-active-record), env: clean_env)
96
100
 
97
101
  Dir.chdir('mongoid-test') do
98
- adjust_app_gemfile
102
+ adjust_app_gemfile(add_sprockets: SpecConfig.instance.rails_version != '8.0')
99
103
  check_call(%w(bundle install), env: clean_env)
100
104
 
101
105
  check_call(%w(rails g model post), env: clean_env)
@@ -117,7 +121,7 @@ describe 'Mongoid application tests' do
117
121
  check_call(%w(rails new mongoid-test-config --skip-spring --skip-active-record), env: clean_env)
118
122
 
119
123
  Dir.chdir('mongoid-test-config') do
120
- adjust_app_gemfile
124
+ adjust_app_gemfile(add_sprockets: SpecConfig.instance.rails_version != '8.0')
121
125
  check_call(%w(bundle install), env: clean_env)
122
126
 
123
127
  mongoid_config_file = File.join(TMP_BASE,'mongoid-test-config/config/mongoid.yml')
@@ -139,7 +143,7 @@ describe 'Mongoid application tests' do
139
143
  if (rails_version = SpecConfig.instance.rails_version) == 'master'
140
144
  else
141
145
  check_call(%w(gem list))
142
- check_call(%w(gem install rails --no-document -v) + ["~> #{rails_version}.0"])
146
+ check_call(%w(gem install rails --no-document --force -v) + ["~> #{rails_version}.0"])
143
147
  end
144
148
  end
145
149
 
@@ -287,6 +291,10 @@ describe 'Mongoid application tests' do
287
291
  end
288
292
 
289
293
  def adjust_rails_defaults(rails_version: SpecConfig.instance.rails_version)
294
+ if !rails_version.match?(/^\d+\.\d+$/)
295
+ # This must be pre-release version, we trim it
296
+ rails_version = rails_version.split('.')[0..1].join('.')
297
+ end
290
298
  if File.exist?('config/application.rb')
291
299
  lines = IO.readlines('config/application.rb')
292
300
  lines.each do |line|
@@ -749,6 +749,10 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
749
749
  person.save!
750
750
  end
751
751
 
752
+ # NOTE: there as a bad interdependency here, with the auto_save_spec.rb
753
+ # file. If auto_save_spec.rb runs before this, the following specs fail
754
+ # with "undefined method `nullify' for an instance of Person".
755
+
752
756
  context "when parent exists" do
753
757
 
754
758
  context "when child is destroyed" do
@@ -37,12 +37,18 @@ describe Mongoid::Validatable::AssociatedValidator do
37
37
  User.new(name: "test")
38
38
  end
39
39
 
40
- let(:description) do
40
+ let(:description1) do
41
+ Description.new
42
+ end
43
+
44
+ let(:description2) do
41
45
  Description.new
42
46
  end
43
47
 
44
48
  before do
45
- user.descriptions << description
49
+ user.descriptions << description1
50
+ user.descriptions << description2
51
+ user.valid?
46
52
  end
47
53
 
48
54
  it "only validates the parent once" do
@@ -50,12 +56,16 @@ describe Mongoid::Validatable::AssociatedValidator do
50
56
  end
51
57
 
52
58
  it "adds the errors from the relation" do
53
- user.valid?
54
59
  expect(user.errors[:descriptions]).to_not be_nil
55
60
  end
56
61
 
62
+ it 'reports all failed validations' do
63
+ errors = user.descriptions.flat_map { |d| d.errors[:details] }
64
+ expect(errors.length).to be == 2
65
+ end
66
+
57
67
  it "only validates the child once" do
58
- expect(description).to_not be_valid
68
+ expect(description1).to_not be_valid
59
69
  end
60
70
  end
61
71
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.6
4
+ version: 8.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - The MongoDB Ruby Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-20 00:00:00.000000000 Z
11
+ date: 2024-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '5.1'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.3'
22
+ version: '8.1'
23
23
  - - "!="
24
24
  - !ruby/object:Gem::Version
25
25
  version: 7.0.0
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '5.1'
33
33
  - - "<"
34
34
  - !ruby/object:Gem::Version
35
- version: '7.3'
35
+ version: '8.1'
36
36
  - - "!="
37
37
  - !ruby/object:Gem::Version
38
38
  version: 7.0.0