mongoid 7.2.0 → 7.2.1

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/mongoid/criteria/queryable/selector.rb +0 -4
  5. data/lib/mongoid/document.rb +3 -2
  6. data/lib/mongoid/interceptable.rb +3 -1
  7. data/lib/mongoid/matcher/field_operator.rb +7 -11
  8. data/lib/mongoid/version.rb +1 -1
  9. data/spec/integration/app_spec.rb +35 -2
  10. data/spec/integration/callbacks_models.rb +49 -0
  11. data/spec/integration/callbacks_spec.rb +216 -0
  12. data/spec/integration/matcher_operator_data/gt_types.yml +63 -0
  13. data/spec/integration/matcher_operator_data/gte_types.yml +15 -0
  14. data/spec/integration/matcher_operator_data/lt_types.yml +15 -0
  15. data/spec/integration/matcher_operator_data/lte_types.yml +15 -0
  16. data/spec/integration/matcher_operator_data/ne_types.yml +15 -0
  17. data/spec/lite_spec_helper.rb +1 -1
  18. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +50 -0
  19. data/spec/mongoid/atomic/paths_spec.rb +41 -0
  20. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +36 -0
  21. data/spec/shared/lib/mrss/cluster_config.rb +211 -0
  22. data/spec/shared/lib/mrss/constraints.rb +27 -0
  23. data/spec/shared/lib/mrss/docker_runner.rb +262 -0
  24. data/spec/shared/lib/mrss/server_version_registry.rb +69 -0
  25. data/spec/shared/share/Dockerfile.erb +229 -0
  26. data/spec/shared/shlib/distro.sh +73 -0
  27. data/spec/shared/shlib/server.sh +270 -0
  28. data/spec/shared/shlib/set_env.sh +128 -0
  29. data/spec/support/models/customer.rb +11 -0
  30. data/spec/support/models/customer_address.rb +12 -0
  31. data/spec/support/models/dictionary.rb +6 -0
  32. metadata +44 -12
  33. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a81d403f49ffcc37e06200c91ab90a6205604730f7169ceb4a07d057ae61193
4
- data.tar.gz: 045ce8ed60ab931f1406e52f25f9e486d670ec1c76dff86ee3b299cbeca0adfe
3
+ metadata.gz: bb2c430462ea474d889d41fa20a7011b5ddfeeac215cddc762c2e2a4324e8ef9
4
+ data.tar.gz: 002a48e7013981c8c12f45edca4f5c9a5c75c9b99ac5f2fd46422532871ae775
5
5
  SHA512:
6
- metadata.gz: bebd7b18d65049cd7d0793319a65bf1868f3c9addf09c21c7b4dbf315deb2fda27cf1a8f27be5288245ab2b1c830d21752de9042d01fb9b31579cab7536ccdcf
7
- data.tar.gz: 4a4b231ce42eb8b5bf07eca5131ff4b9e5c838a0965996adcf9a529ad6c398f11e0c9e4e5d7cc005fe969e4851a50a2d6aab7c436af433a809c6090ff1927b9c
6
+ metadata.gz: 6985ec8a658d859e3a8f863eca20326d11aba2249488f10cff0bb6c01c8a4de759ab6726b1573e7e6a845ccf5b72213b8fe0374d699761e13608121216bafe98
7
+ data.tar.gz: fb681e64b86e56203d0029452b71f197bcadfb86b56ccadd514edc6bac416c68490ed708db5a09bc84cf638a43fb359d6ec977f31ca226429c0ca99de0af3120
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -123,10 +123,6 @@ module Mongoid
123
123
  # {'foo' => {'$lt' => 5}}. This step should be done after all
124
124
  # value-based processing is complete.
125
125
  if key.is_a?(Key)
126
- if serializer && evolved_value != value
127
- raise NotImplementedError, "This method is not prepared to handle key being a Key and serializer being not nil"
128
- end
129
-
130
126
  evolved_value = key.transform_value(evolved_value)
131
127
  end
132
128
 
@@ -229,8 +229,9 @@ module Mongoid
229
229
  became = klass.new(clone_document)
230
230
  became._id = _id
231
231
  became.instance_variable_set(:@changed_attributes, changed_attributes)
232
- became.instance_variable_set(:@errors, ActiveModel::Errors.new(became))
233
- became.errors.instance_variable_set(:@messages, errors.instance_variable_get(:@messages))
232
+ new_errors = ActiveModel::Errors.new(became)
233
+ new_errors.copy!(errors)
234
+ became.instance_variable_set(:@errors, new_errors)
234
235
  became.instance_variable_set(:@new_record, new_record?)
235
236
  became.instance_variable_set(:@destroyed, destroyed?)
236
237
  became.changed_attributes[klass.discriminator_key] = self.class.discriminator_value
@@ -234,9 +234,11 @@ module Mongoid
234
234
  # document.halted_callback_hook(filter)
235
235
  #
236
236
  # @param [ Symbol ] filter The callback that halted.
237
+ # @param [ Symbol ] name The name of the callback that was halted
238
+ # (requires Rails 6.1+)
237
239
  #
238
240
  # @since 3.0.3
239
- def halted_callback_hook(filter)
241
+ def halted_callback_hook(filter, name = nil)
240
242
  @before_callback_halted = true
241
243
  end
242
244
 
@@ -35,17 +35,13 @@ module Mongoid
35
35
  end
36
36
 
37
37
  module_function def apply_comparison_operator(operator, left, right)
38
- case left
39
- when Numeric
40
- case right
41
- when Numeric
42
- left.send(operator, right)
43
- else
44
- false
45
- end
46
- else
47
- false
48
- end
38
+ left.send(operator, right)
39
+ rescue ArgumentError, NoMethodError, TypeError
40
+ # We silence bogus comparison attempts, e.g. number to string
41
+ # comparisons.
42
+ # Several different exceptions may be produced depending on the types
43
+ # involved.
44
+ false
49
45
  end
50
46
  end
51
47
  end
@@ -2,5 +2,5 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  module Mongoid
5
- VERSION = "7.2.0"
5
+ VERSION = "7.2.1"
6
6
  end
@@ -150,7 +150,7 @@ describe 'Mongoid application tests' do
150
150
  end
151
151
  index.should be nil
152
152
 
153
- Mrss::ChildProcessHelper.check_call(%w(rake db:mongoid:create_indexes),
153
+ Mrss::ChildProcessHelper.check_call(%w(bundle exec rake db:mongoid:create_indexes),
154
154
  cwd: APP_PATH, env: env)
155
155
 
156
156
  index = client['posts'].indexes.detect do |index|
@@ -181,11 +181,44 @@ describe 'Mongoid application tests' do
181
181
  end
182
182
  end
183
183
 
184
+ def parse_mongodb_uri(uri)
185
+ pre, query = uri.split('?', 2)
186
+ if pre =~ %r,\A(mongodb(?:.*?))://([^/]+)(?:/(.*))?\z,
187
+ protocol = $1
188
+ hosts = $2
189
+ database = $3
190
+ if database == ''
191
+ database = nil
192
+ end
193
+ else
194
+ raise ArgumentError, "Invalid MongoDB URI: #{uri}"
195
+ end
196
+ if query == ''
197
+ query = nil
198
+ end
199
+ {
200
+ protocol: protocol,
201
+ hosts: hosts,
202
+ database: database,
203
+ query: query,
204
+ }
205
+ end
206
+
207
+ def build_mongodb_uri(parts)
208
+ "#{parts.fetch(:protocol)}://#{parts.fetch(:hosts)}/#{parts[:database]}?#{parts[:query]}"
209
+ end
210
+
184
211
  def write_mongoid_yml
212
+ # HACK: the driver does not provide a MongoDB URI parser and assembler,
213
+ # and the Ruby standard library URI module doesn't handle multiple hosts.
214
+ parts = parse_mongodb_uri(SpecConfig.instance.uri_str)
215
+ parts[:database] = 'mongoid_test'
216
+ uri = build_mongodb_uri(parts)
217
+ p uri
185
218
  env_config = {'clients' => {'default' => {
186
219
  # TODO massive hack, will fail if uri specifies a database name or
187
220
  # any uri options
188
- 'uri' => "#{SpecConfig.instance.uri_str}/mongoid_test",
221
+ 'uri' => uri,
189
222
  }}}
190
223
  config = {'development' => env_config, 'production' => env_config}
191
224
  File.open('config/mongoid.yml', 'w') do |f|
@@ -0,0 +1,49 @@
1
+ class Galaxy
2
+ include Mongoid::Document
3
+
4
+ field :age, type: Integer
5
+
6
+ before_validation :set_age
7
+
8
+ embeds_many :stars
9
+
10
+ private
11
+
12
+ def set_age
13
+ self.age ||= 100_000
14
+ end
15
+ end
16
+
17
+ class Star
18
+ include Mongoid::Document
19
+
20
+ embedded_in :galaxy
21
+
22
+ field :age, type: Integer
23
+
24
+ before_validation :set_age
25
+
26
+ embeds_many :planets
27
+
28
+ private
29
+
30
+ def set_age
31
+ self.age ||= 42_000
32
+ end
33
+ end
34
+
35
+ class Planet
36
+ include Mongoid::Document
37
+
38
+ embedded_in :star
39
+
40
+ field :age, type: Integer
41
+
42
+ before_validation :set_age
43
+
44
+ private
45
+
46
+ def set_age
47
+ self.age ||= 2_000
48
+ end
49
+ end
@@ -0,0 +1,216 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require 'spec_helper'
5
+ require_relative './callbacks_models'
6
+
7
+ describe 'callbacks integration tests' do
8
+ context 'when modifying attributes in a callback' do
9
+
10
+ context 'when creating top-level document' do
11
+ context 'top level document' do
12
+ let(:instance) do
13
+ Galaxy.create!
14
+ end
15
+
16
+ it 'writes the attribute value into the model' do
17
+ instance.age.should == 100_000
18
+ end
19
+
20
+ it 'persists the attribute value' do
21
+ Galaxy.find(instance.id).age.should == 100_000
22
+ end
23
+ end
24
+
25
+ context 'embedded document' do
26
+ shared_examples 'persists the attribute value' do
27
+ it 'writes the attribute value into the model' do
28
+ instance.stars.first.age.should == 42_000
29
+ end
30
+
31
+ it 'persists the attribute value' do
32
+ Galaxy.find(instance.id).stars.first.age.should == 42_000
33
+ end
34
+ end
35
+
36
+ context 'set as a document instance' do
37
+ let(:instance) do
38
+ Galaxy.create!(stars: [Star.new])
39
+ end
40
+
41
+ include_examples 'persists the attribute value'
42
+ end
43
+
44
+ context 'set as attributes on parent' do
45
+ let(:instance) do
46
+ Galaxy.create!(stars: [{}])
47
+ end
48
+
49
+ include_examples 'persists the attribute value'
50
+ end
51
+ end
52
+
53
+ context 'nested embedded document' do
54
+ shared_examples 'persists the attribute value' do
55
+ it 'writes the attribute value into the model' do
56
+ instance.stars.first.planets.first.age.should == 2_000
57
+ end
58
+
59
+ it 'persists the attribute value' do
60
+ Galaxy.find(instance.id).stars.first.planets.first.age.should == 2_000
61
+ end
62
+ end
63
+
64
+ context 'set as a document instance' do
65
+ let(:instance) do
66
+ Galaxy.create!(stars: [Star.new(
67
+ planets: [Planet.new],
68
+ )])
69
+ end
70
+
71
+ include_examples 'persists the attribute value'
72
+ end
73
+
74
+ context 'set as attributes on parent' do
75
+ let(:instance) do
76
+ Galaxy.create!(stars: [
77
+ planets: [{}],
78
+ ])
79
+ end
80
+
81
+ include_examples 'persists the attribute value'
82
+ end
83
+ end
84
+ end
85
+
86
+ context 'when updating top-level document via #save' do
87
+ let!(:instance) do
88
+ Galaxy.create!
89
+ end
90
+
91
+ context 'embedded document' do
92
+ shared_examples 'persists the attribute value' do
93
+ it 'writes the attribute value into the model' do
94
+ instance.stars.first.age.should == 42_000
95
+ end
96
+
97
+ it 'persists the attribute value' do
98
+ Galaxy.find(instance.id).stars.first.age.should == 42_000
99
+ end
100
+ end
101
+
102
+ context 'set as a document instance' do
103
+ before do
104
+ instance.stars = [Star.new]
105
+ instance.save!
106
+ end
107
+
108
+ include_examples 'persists the attribute value'
109
+ end
110
+
111
+ context 'set as attributes on parent' do
112
+ before do
113
+ instance.stars = [{}]
114
+ instance.save!
115
+ end
116
+
117
+ include_examples 'persists the attribute value'
118
+ end
119
+ end
120
+
121
+ context 'nested embedded document' do
122
+ shared_examples 'persists the attribute value' do
123
+ it 'writes the attribute value into the model' do
124
+ instance.stars.first.planets.first.age.should == 2_000
125
+ end
126
+
127
+ it 'persists the attribute value' do
128
+ Galaxy.find(instance.id).stars.first.planets.first.age.should == 2_000
129
+ end
130
+ end
131
+
132
+ context 'set as a document instance' do
133
+ before do
134
+ instance.stars = [Star.new(planets: [Planet.new])]
135
+ instance.save!
136
+ end
137
+
138
+ include_examples 'persists the attribute value'
139
+ end
140
+
141
+ context 'set as attributes on parent' do
142
+ before do
143
+ instance.stars = [planets: [{}]]
144
+ instance.save!
145
+ end
146
+
147
+ include_examples 'persists the attribute value'
148
+ end
149
+ end
150
+ end
151
+
152
+ context 'when updating top-level document via #update_attributes' do
153
+ let!(:instance) do
154
+ Galaxy.create!
155
+ end
156
+
157
+ context 'embedded document' do
158
+ shared_examples 'persists the attribute value' do
159
+ it 'writes the attribute value into the model' do
160
+ instance.stars.first.age.should == 42_000
161
+ end
162
+
163
+ it 'persists the attribute value' do
164
+ Galaxy.find(instance.id).stars.first.age.should == 42_000
165
+ end
166
+ end
167
+
168
+ context 'set as a document instance' do
169
+ before do
170
+ instance.update_attributes(stars: [Star.new])
171
+ end
172
+
173
+ include_examples 'persists the attribute value'
174
+ end
175
+
176
+ context 'set as attributes on parent' do
177
+ before do
178
+ instance.update_attributes(stars: [{}])
179
+ end
180
+
181
+ include_examples 'persists the attribute value'
182
+ end
183
+ end
184
+
185
+ context 'nested embedded document' do
186
+ shared_examples 'persists the attribute value' do
187
+ it 'writes the attribute value into the model' do
188
+ instance.stars.first.planets.first.age.should == 2_000
189
+ end
190
+
191
+ it 'persists the attribute value' do
192
+ pending 'MONGOID-4476'
193
+
194
+ Galaxy.find(instance.id).stars.first.planets.first.age.should == 2_000
195
+ end
196
+ end
197
+
198
+ context 'set as a document instance' do
199
+ before do
200
+ instance.update_attributes(stars: [Star.new(planets: [Planet.new])])
201
+ end
202
+
203
+ include_examples 'persists the attribute value'
204
+ end
205
+
206
+ context 'set as attributes on parent' do
207
+ before do
208
+ instance.update_attributes(stars: [planets: [{}]])
209
+ end
210
+
211
+ include_examples 'persists the attribute value'
212
+ end
213
+ end
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,63 @@
1
+ - name: Date field - matches
2
+ document:
3
+ date_field: 2020-12-22
4
+ query:
5
+ date_field:
6
+ $gt: 2020-12-21
7
+ matches: true
8
+
9
+ - name: Date field - does not match
10
+ document:
11
+ date_field: 2020-12-21
12
+ query:
13
+ date_field:
14
+ $gt: 2020-12-21
15
+ matches: false
16
+
17
+ - name: Date value in generic field - matches
18
+ document:
19
+ field: 2020-12-22
20
+ query:
21
+ field:
22
+ $gt: 2020-12-21
23
+ matches: true
24
+
25
+ - name: Date field - does not match
26
+ document:
27
+ field: 2020-12-21
28
+ query:
29
+ field:
30
+ $gt: 2020-12-21
31
+ matches: false
32
+
33
+ - name: Time value in generic field queried by date - matches
34
+ document:
35
+ field: 2020-12-22 00:00:00
36
+ query:
37
+ field:
38
+ $gt: 2020-12-21
39
+ matches: true
40
+
41
+ - name: Time value in generic field queried by date - does not match
42
+ document:
43
+ field: 2020-12-21 00:00:00
44
+ query:
45
+ field:
46
+ $gt: 2020-12-21
47
+ matches: false
48
+
49
+ - name: Time value in generic field - matches
50
+ document:
51
+ field: 2020-12-22 00:00:00
52
+ query:
53
+ field:
54
+ $gt: 2020-12-21 00:00:00
55
+ matches: true
56
+
57
+ - name: Time value in generic field - does not match
58
+ document:
59
+ field: 2020-12-21 00:00:00
60
+ query:
61
+ field:
62
+ $gt: 2020-12-21 00:00:00
63
+ matches: false