mongoid 8.1.1 → 8.1.2

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: 7c8aee259f97121ac5d253787ffef62a4be73f599715f05b85f3aa9db0cbdbeb
4
- data.tar.gz: 91dd81468f04ba196460275f315767e6c291b3299272416f45591168937330d6
3
+ metadata.gz: 2100bfc3ff5a707914028bbcca16fe61db68cfc271f2603b79a9f420baccdd3a
4
+ data.tar.gz: c1147f2941f122d45a5678ed2c9d95ab840a65e1f8883970384f846f979bfb9f
5
5
  SHA512:
6
- metadata.gz: 77f061a14a9b65420c977d2df0b9fd0c5a00f96e0f0be996c8c08e469ed89b458ac50079a3cf0aa9997550ea858cb3b55931418ad12330dd454daa7f8105daed
7
- data.tar.gz: 8844008ccaf7b53a964029e39fcbe626fbe62c0c1a890c331c65a853f518a4dcd9a9415a748281c541b4c8f7970816f57727a30899dc2af144a38c4696e0ef18
6
+ metadata.gz: 4710b315e359d87807dc3b882b39d929eb52bf53612bf2d37e6bbf409309b3116773eab6e810b8b7dbbbfc33f24e135758c757b3de43dca4c591881b39d1e2df
7
+ data.tar.gz: 758af68d937986c4a01963ff9e8c6f106276fc40805c1133966d88461eabd19ca7b41e412b50566fe962b180525a925bae529ff5b58846fa8433336d8880a6ad
checksums.yaml.gz.sig CHANGED
Binary file
@@ -35,10 +35,15 @@ module Mongoid
35
35
  # @api private
36
36
  class_attribute :aliased_associations
37
37
 
38
+ # @return [ Set<String> ] The set of associations that are configured
39
+ # with :store_as parameter.
40
+ class_attribute :stored_as_associations
41
+
38
42
  self.embedded = false
39
43
  self.embedded_relations = BSON::Document.new
40
44
  self.relations = BSON::Document.new
41
45
  self.aliased_associations = {}
46
+ self.stored_as_associations = Set.new
42
47
  end
43
48
 
44
49
  # This is convenience for libraries still on the old API.
@@ -219,6 +224,7 @@ module Mongoid
219
224
  self.relations = self.relations.merge(name => assoc)
220
225
  if assoc.embedded? && assoc.respond_to?(:store_as) && assoc.store_as != name
221
226
  self.aliased_associations[assoc.store_as] = name
227
+ self.stored_as_associations << assoc.store_as
222
228
  end
223
229
  end
224
230
  end
@@ -43,22 +43,46 @@ module Mongoid
43
43
  # @return [ true | false ] True if pending, false if not.
44
44
  def pending_attribute?(key, value)
45
45
  name = key.to_s
46
-
47
46
  aliased = if aliased_associations.key?(name)
48
47
  aliased_associations[name]
49
48
  else
50
49
  name
51
50
  end
52
-
53
51
  if relations.has_key?(aliased)
54
- pending_relations[name] = value
52
+ set_pending_relation(name, aliased, value)
55
53
  return true
56
54
  end
57
55
  if nested_attributes.has_key?(aliased)
58
- pending_nested[name] = value
56
+ set_pending_nested(name, aliased, value)
59
57
  return true
60
58
  end
61
- return false
59
+ false
60
+ end
61
+
62
+ # Set value of the pending relation.
63
+ #
64
+ # @param [ Symbol ] name The name of the relation.
65
+ # @param [ Symbol ] aliased The aliased name of the relation.
66
+ # @param [ Object ] value The value of the relation.
67
+ def set_pending_relation(name, aliased, value)
68
+ if stored_as_associations.include?(name)
69
+ pending_relations[aliased] = value
70
+ else
71
+ pending_relations[name] = value
72
+ end
73
+ end
74
+
75
+ # Set value of the pending nested attribute.
76
+ #
77
+ # @param [ Symbol ] name The name of the nested attribute.
78
+ # @param [ Symbol ] aliased The aliased name of the nested attribute.
79
+ # @param [ Object ] value The value of the nested attribute.
80
+ def set_pending_nested(name, aliased, value)
81
+ if stored_as_associations.include?(name)
82
+ pending_nested[aliased] = value
83
+ else
84
+ pending_nested[name] = value
85
+ end
62
86
  end
63
87
 
64
88
  # Get all the pending associations that need to be set.
@@ -25,6 +25,8 @@ module Mongoid
25
25
  # @param [ Hash ] options Extras for the option.
26
26
  #
27
27
  # @option options [ Object ] :default The default value.
28
+ # @option options [ Proc | nil ] :on_change The callback to invoke when the
29
+ # setter is invoked.
28
30
  def option(name, options = {})
29
31
  defaults[name] = settings[name] = options[:default]
30
32
 
@@ -38,6 +40,7 @@ module Mongoid
38
40
 
39
41
  define_method("#{name}=") do |value|
40
42
  settings[name] = value
43
+ options[:on_change]&.call(value)
41
44
  end
42
45
 
43
46
  define_method("#{name}?") do
@@ -128,6 +128,23 @@ module Mongoid
128
128
  # always return a Hash.
129
129
  option :legacy_attributes, default: false
130
130
 
131
+ # Allow BSON::Decimal128 to be parsed and returned directly in
132
+ # field values. When BSON 5 is present and the this option is set to false
133
+ # (the default), BSON::Decimal128 values in the database will be returned
134
+ # as BigDecimal.
135
+ #
136
+ # @note this option only has effect when BSON 5+ is present. Otherwise,
137
+ # the setting is ignored.
138
+ option :allow_bson5_decimal128, default: false, on_change: -> (allow) do
139
+ if BSON::VERSION >= '5.0.0'
140
+ if allow
141
+ BSON::Registry.register(BSON::Decimal128::BSON_TYPE, BSON::Decimal128)
142
+ else
143
+ BSON::Registry.register(BSON::Decimal128::BSON_TYPE, BigDecimal)
144
+ end
145
+ end
146
+ end
147
+
131
148
  # Sets the async_query_executor for the application. By default the thread pool executor
132
149
  # is set to `:immediate. Options are:
133
150
  #
@@ -20,7 +20,7 @@ module Mongoid
20
20
  other.each_pair do |key, value|
21
21
  if value.is_a?(Hash) && self[key.to_s].is_a?(Hash)
22
22
  value = self[key.to_s].merge(value) do |_key, old_val, new_val|
23
- case _key
23
+ case _key.to_s
24
24
  when '$in'
25
25
  new_val & old_val
26
26
  when '$nin'
@@ -47,7 +47,7 @@ module Mongoid
47
47
  if value.is_a?(Hash) && selector[field].is_a?(Hash) &&
48
48
  value.keys.all? { |key|
49
49
  key_s = key.to_s
50
- key_s.start_with?('$') && !selector[field].key?(key_s)
50
+ key_s.start_with?('$') && !selector[field].keys.map(&:to_s).include?(key_s)
51
51
  }
52
52
  then
53
53
  # Multiple operators can be combined on the same field by
@@ -38,8 +38,12 @@ module Mongoid
38
38
  consolidated = {}
39
39
  each_pair do |key, value|
40
40
  if key =~ /\$/
41
- value.each_pair do |_key, _value|
42
- value[_key] = (key == "$rename") ? _value.to_s : mongoize_for(key, klass, _key, _value)
41
+ value.keys.each do |key2|
42
+ value2 = value[key2]
43
+ real_key = klass.database_field_name(key2)
44
+
45
+ value.delete(key2) if real_key != key2
46
+ value[real_key] = (key == "$rename") ? value2.to_s : mongoize_for(key, klass, real_key, value2)
43
47
  end
44
48
  consolidated[key] ||= {}
45
49
  consolidated[key].update(value)
@@ -814,21 +814,19 @@ module Mongoid
814
814
  #
815
815
  # @api private
816
816
  def retrieve_and_validate_type(name, type)
817
- type_mapping = TYPE_MAPPINGS[type]
818
- result = type_mapping || unmapped_type(type)
819
- if !result.is_a?(Class)
820
- raise Errors::InvalidFieldType.new(self, name, type)
821
- else
822
- if INVALID_BSON_CLASSES.include?(result)
823
- warn_message = "Using #{result} as the field type is not supported. "
824
- if result == BSON::Decimal128
825
- warn_message += "In BSON <= 4, the BSON::Decimal128 type will work as expected for both storing and querying, but will return a BigDecimal on query in BSON 5+."
826
- else
827
- warn_message += "Saving values of this type to the database will work as expected, however, querying them will return a value of the native Ruby Integer type."
828
- end
829
- Mongoid.logger.warn(warn_message)
817
+ result = TYPE_MAPPINGS[type] || unmapped_type(type)
818
+ raise Errors::InvalidFieldType.new(self, name, type) if !result.is_a?(Class)
819
+
820
+ if unsupported_type?(result)
821
+ warn_message = "Using #{result} as the field type is not supported. "
822
+ if result == BSON::Decimal128
823
+ warn_message += 'In BSON <= 4, the BSON::Decimal128 type will work as expected for both storing and querying, but will return a BigDecimal on query in BSON 5+. To use literal BSON::Decimal128 fields with BSON 5, set Mongoid.allow_bson5_decimal128 to true.'
824
+ else
825
+ warn_message += 'Saving values of this type to the database will work as expected, however, querying them will return a value of the native Ruby Integer type.'
830
826
  end
827
+ Mongoid.logger.warn(warn_message)
831
828
  end
829
+
832
830
  result
833
831
  end
834
832
 
@@ -847,6 +845,19 @@ module Mongoid
847
845
  type || Object
848
846
  end
849
847
  end
848
+
849
+ # Queries whether or not the given type is permitted as a declared field
850
+ # type.
851
+ #
852
+ # @param [ Class ] type The type to query
853
+ #
854
+ # @return [ true | false ] whether or not the type is supported
855
+ #
856
+ # @api private
857
+ def unsupported_type?(type)
858
+ return !Mongoid::Config.allow_bson5_decimal128? if type == BSON::Decimal128
859
+ INVALID_BSON_CLASSES.include?(type)
860
+ end
850
861
  end
851
862
  end
852
863
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mongoid
4
- VERSION = "8.1.1"
4
+ VERSION = "8.1.2"
5
5
  end
@@ -2708,4 +2708,31 @@ describe Mongoid::Attributes do
2708
2708
  catalog.set_field.should == Set.new([ 1, 2 ])
2709
2709
  end
2710
2710
  end
2711
+
2712
+ context 'when an embedded field has a capitalized store_as name' do
2713
+ let(:person) { Person.new(Purse: { brand: 'Gucci' }) }
2714
+
2715
+ it 'sets the value' do
2716
+ expect(person.purse.brand).to eq('Gucci')
2717
+ end
2718
+
2719
+ it 'saves successfully' do
2720
+ expect(person.save!).to eq(true)
2721
+ end
2722
+
2723
+ context 'when persisted' do
2724
+ before do
2725
+ person.save!
2726
+ person.reload
2727
+ end
2728
+
2729
+ it 'persists the value' do
2730
+ expect(person.reload.purse.brand).to eq('Gucci')
2731
+ end
2732
+
2733
+ it 'uses the correct key in the database' do
2734
+ expect(person.collection.find(_id: person.id).first['Purse']['_id']).to eq(person.purse.id)
2735
+ end
2736
+ end
2737
+ end
2711
2738
  end
@@ -345,6 +345,15 @@ describe Mongoid::Config do
345
345
  it_behaves_like "a config option"
346
346
  end
347
347
 
348
+ context 'when setting the allow_bson5_decimal128 option in the config' do
349
+ min_bson_version '5.0'
350
+
351
+ let(:option) { :allow_bson5_decimal128 }
352
+ let(:default) { false }
353
+
354
+ it_behaves_like "a config option"
355
+ end
356
+
348
357
  context 'when setting the broken_updates option in the config' do
349
358
  let(:option) { :broken_updates }
350
359
  let(:default) { false }
@@ -1184,33 +1184,49 @@ describe Mongoid::Contextual::Mongo do
1184
1184
  let!(:person2) { Person.create!(ssn: BSON::Decimal128.new("1")) }
1185
1185
  let(:tally) { Person.tally("ssn") }
1186
1186
 
1187
+ let(:tallied_classes) do
1188
+ tally.keys.map(&:class).sort do |a, b|
1189
+ a.to_s.casecmp(b.to_s)
1190
+ end
1191
+ end
1192
+
1187
1193
  context "< BSON 5" do
1188
1194
  max_bson_version '4.99.99'
1189
1195
 
1190
1196
  it "stores the correct types in the database" do
1191
- Person.find(person1.id).attributes["ssn"].should be_a BSON::Regexp::Raw
1192
- Person.find(person2.id).attributes["ssn"].should be_a BSON::Decimal128
1197
+ expect(Person.find(person1.id).attributes["ssn"]).to be_a BSON::Regexp::Raw
1198
+ expect(Person.find(person2.id).attributes["ssn"]).to be_a BSON::Decimal128
1199
+ end
1200
+
1201
+ it "tallies the correct type" do
1202
+ expect(tallied_classes).to be == [ BSON::Decimal128, BSON::Regexp::Raw ]
1203
+ end
1204
+ end
1205
+
1206
+ context '>= BSON 5' do
1207
+ min_bson_version "5.0"
1208
+
1209
+ it "stores the correct types in the database" do
1210
+ expect(Person.find(person1.id).ssn).to be_a BSON::Regexp::Raw
1211
+ expect(Person.find(person2.id).ssn).to be_a BigDecimal
1193
1212
  end
1194
1213
 
1195
1214
  it "tallies the correct type" do
1196
- tally.keys.map(&:class).sort do |a,b|
1197
- a.to_s <=> b.to_s
1198
- end.should == [BSON::Decimal128, BSON::Regexp::Raw]
1215
+ expect(tallied_classes).to be == [ BigDecimal, BSON::Regexp::Raw ]
1199
1216
  end
1200
1217
  end
1201
1218
 
1202
- context ">= BSON 5" do
1219
+ context '>= BSON 5 with decimal128 allowed' do
1203
1220
  min_bson_version "5.0"
1221
+ config_override :allow_bson5_decimal128, true
1204
1222
 
1205
1223
  it "stores the correct types in the database" do
1206
- Person.find(person1.id).ssn.should be_a BSON::Regexp::Raw
1207
- Person.find(person2.id).ssn.should be_a BigDeimal
1224
+ expect(Person.find(person1.id).ssn).to be_a BSON::Regexp::Raw
1225
+ expect(Person.find(person2.id).ssn).to be_a BSON::Decimal128
1208
1226
  end
1209
1227
 
1210
1228
  it "tallies the correct type" do
1211
- tally.keys.map(&:class).sort do |a,b|
1212
- a.to_s <=> b.to_s
1213
- end.should == [BigDecimal, BSON::Regexp::Raw]
1229
+ expect(tallied_classes).to be == [ BSON::Decimal128, BSON::Regexp::Raw ]
1214
1230
  end
1215
1231
  end
1216
1232
  end
@@ -3687,6 +3703,20 @@ describe Mongoid::Contextual::Mongo do
3687
3703
  end
3688
3704
  end
3689
3705
 
3706
+ context 'when using aliased field names' do
3707
+ before do
3708
+ context.update_all('$set' => { years: 100 })
3709
+ end
3710
+
3711
+ it "updates the first matching document" do
3712
+ expect(depeche_mode.reload.years).to eq(100)
3713
+ end
3714
+
3715
+ it "updates the last matching document" do
3716
+ expect(new_order.reload.years).to eq(100)
3717
+ end
3718
+ end
3719
+
3690
3720
  context "when the attributes must be mongoized" do
3691
3721
 
3692
3722
  before do
@@ -44,7 +44,7 @@ describe Mongoid::Criteria::Queryable::Selector do
44
44
  end
45
45
  end
46
46
 
47
- context "when selector contains a $nin" do
47
+ context "when selector contains a $nin string" do
48
48
 
49
49
  let(:initial) do
50
50
  { "$nin" => ["foo"] }
@@ -72,7 +72,35 @@ describe Mongoid::Criteria::Queryable::Selector do
72
72
  end
73
73
  end
74
74
 
75
- context "when selector contains a $in" do
75
+ context "when selector contains a $nin symbol" do
76
+
77
+ let(:initial) do
78
+ { :$nin => ["foo"] }
79
+ end
80
+
81
+ before do
82
+ selector["field"] = initial
83
+ end
84
+
85
+ context "when merging in a new $nin" do
86
+
87
+ let(:other) do
88
+ { "field" => { :$nin => ["bar"] } }
89
+ end
90
+
91
+ before do
92
+ selector.merge!(other)
93
+ end
94
+
95
+ it "combines the two $nin queries into one" do
96
+ expect(selector).to eq({
97
+ "field" => { :$nin => ["foo", "bar"] }
98
+ })
99
+ end
100
+ end
101
+ end
102
+
103
+ context "when selector contains a $in string" do
76
104
 
77
105
  let(:initial) do
78
106
  { "$in" => [1, 2] }
@@ -117,6 +145,51 @@ describe Mongoid::Criteria::Queryable::Selector do
117
145
  end
118
146
  end
119
147
 
148
+ context "when selector contains a $in symbol" do
149
+
150
+ let(:initial) do
151
+ { :$in => [1, 2] }
152
+ end
153
+
154
+ before do
155
+ selector["field"] = initial
156
+ end
157
+
158
+ context "when merging in a new $in with an intersecting value" do
159
+
160
+ let(:other) do
161
+ { "field" => { :$in => [1] } }
162
+ end
163
+
164
+ before do
165
+ selector.merge!(other)
166
+ end
167
+
168
+ it "intersects the $in values" do
169
+ expect(selector).to eq({
170
+ "field" => { :$in => [1] }
171
+ })
172
+ end
173
+ end
174
+
175
+ context "when merging in a new $in with no intersecting values" do
176
+
177
+ let(:other) do
178
+ { "field" => { :$in => [3] } }
179
+ end
180
+
181
+ before do
182
+ selector.merge!(other)
183
+ end
184
+
185
+ it "intersects the $in values" do
186
+ expect(selector).to eq({
187
+ "field" => { :$in => [] }
188
+ })
189
+ end
190
+ end
191
+ end
192
+
120
193
  context "when selector is not nested" do
121
194
 
122
195
  before do
@@ -210,7 +210,79 @@ describe Mongoid::Criteria::Queryable::Storable do
210
210
  }
211
211
  end
212
212
  end
213
+
214
+ context 'when value is a hash combine values with different operator keys' do
215
+ let(:base) do
216
+ query.add_field_expression('foo', {'$in' => ['bar']})
217
+ end
218
+
219
+ let(:modified) do
220
+ base.add_field_expression('foo', {'$nin' => ['zoom']})
221
+ end
222
+
223
+ it 'combines the conditions using $and' do
224
+ modified.selector.should == {
225
+ 'foo' => {
226
+ '$in' => ['bar'],
227
+ '$nin' => ['zoom']
228
+ }
229
+ }
230
+ end
231
+ end
232
+
233
+ context 'when value is a hash with symbol operator key combine values with different operator keys' do
234
+ let(:base) do
235
+ query.add_field_expression('foo', {:$in => ['bar']})
236
+ end
237
+
238
+ let(:modified) do
239
+ base.add_field_expression('foo', {:$nin => ['zoom']})
240
+ end
241
+
242
+ it 'combines the conditions using $and' do
243
+ modified.selector.should == {
244
+ 'foo' => {
245
+ :$in => ['bar'],
246
+ :$nin => ['zoom']
247
+ }
248
+ }
249
+ end
250
+ end
251
+
252
+ context 'when value is a hash add values with same operator keys using $and' do
253
+ let(:base) do
254
+ query.add_field_expression('foo', {'$in' => ['bar']})
255
+ end
256
+
257
+ let(:modified) do
258
+ base.add_field_expression('foo', {'$in' => ['zoom']})
259
+ end
260
+
261
+ it 'adds the new condition using $and' do
262
+ modified.selector.should == {
263
+ 'foo' => {'$in' => ['bar']},
264
+ '$and' => ['foo' => {'$in' => ['zoom']}]
265
+ }
266
+ end
267
+ end
268
+
269
+ context 'when value is a hash with symbol operator key add values with same operator keys using $and' do
270
+ let(:base) do
271
+ query.add_field_expression('foo', {:$in => ['bar']})
272
+ end
273
+
274
+ let(:modified) do
275
+ base.add_field_expression('foo', {:$in => ['zoom']})
276
+ end
277
+
278
+ it 'adds the new condition using $and' do
279
+ modified.selector.should == {
280
+ 'foo' => {:$in => ['bar']},
281
+ '$and' => ['foo' => {:$in => ['zoom']}]
282
+ }
283
+ end
213
284
  end
285
+ end
214
286
 
215
287
  describe '#add_operator_expression' do
216
288
  let(:query_method) { :add_operator_expression }
@@ -178,7 +178,7 @@ describe Mongoid::Extensions::Hash do
178
178
 
179
179
  it "moves the non hash values under the provided key" do
180
180
  expect(consolidated).to eq({
181
- "$set" => { name: "Tool", likes: 10 }, "$inc" => { plays: 1 }
181
+ "$set" => { 'name' => "Tool", likes: 10 }, "$inc" => { 'plays' => 1 }
182
182
  })
183
183
  end
184
184
  end
@@ -195,7 +195,7 @@ describe Mongoid::Extensions::Hash do
195
195
 
196
196
  it "moves the non hash values under the provided key" do
197
197
  expect(consolidated).to eq({
198
- "$set" => { likes: 10, name: "Tool" }, "$inc" => { plays: 1 }
198
+ "$set" => { likes: 10, 'name' => "Tool" }, "$inc" => { 'plays' => 1 }
199
199
  })
200
200
  end
201
201
  end
@@ -213,7 +213,7 @@ describe Mongoid::Extensions::Hash do
213
213
 
214
214
  it "moves the non hash values under the provided key" do
215
215
  expect(consolidated).to eq({
216
- "$set" => { likes: 10, name: "Tool" }, "$inc" => { plays: 1 }
216
+ "$set" => { likes: 10, name: "Tool" }, "$inc" => { 'plays' => 1 }
217
217
  })
218
218
  end
219
219
  end
@@ -559,6 +559,49 @@ describe Mongoid::Fields do
559
559
  end
560
560
  end
561
561
  end
562
+
563
+ context 'when the field is declared as BSON::Decimal128' do
564
+ let(:document) { Mop.create!(decimal128_field: BSON::Decimal128.new(Math::PI.to_s)).reload }
565
+
566
+ shared_context 'BSON::Decimal128 is BigDecimal' do
567
+ it 'should return a BigDecimal' do
568
+ expect(document.decimal128_field).to be_a BigDecimal
569
+ end
570
+ end
571
+
572
+ shared_context 'BSON::Decimal128 is BSON::Decimal128' do
573
+ it 'should return a BSON::Decimal128' do
574
+ expect(document.decimal128_field).to be_a BSON::Decimal128
575
+ end
576
+ end
577
+
578
+ it 'is declared as BSON::Decimal128' do
579
+ expect(Mop.fields['decimal128_field'].type).to be == BSON::Decimal128
580
+ end
581
+
582
+ context 'when BSON version <= 4' do
583
+ max_bson_version '4.99.99'
584
+ it_behaves_like 'BSON::Decimal128 is BSON::Decimal128'
585
+ end
586
+
587
+ context 'when BSON version >= 5' do
588
+ min_bson_version '5.0.0'
589
+
590
+ context 'when allow_bson5_decimal128 is false' do
591
+ config_override :allow_bson5_decimal128, false
592
+ it_behaves_like 'BSON::Decimal128 is BigDecimal'
593
+ end
594
+
595
+ context 'when allow_bson5_decimal128 is true' do
596
+ config_override :allow_bson5_decimal128, true
597
+ it_behaves_like 'BSON::Decimal128 is BSON::Decimal128'
598
+ end
599
+
600
+ context 'when allow_bson5_decimal128 is default' do
601
+ it_behaves_like 'BSON::Decimal128 is BigDecimal'
602
+ end
603
+ end
604
+ end
562
605
  end
563
606
 
564
607
  describe "#getter_before_type_cast" do
@@ -195,15 +195,12 @@ module Mrss
195
195
  'debian81' => 'debian:jessie',
196
196
  'debian92' => 'debian:stretch',
197
197
  'debian10' => 'debian:buster',
198
- 'debian11' => 'debian:bullseye',
199
198
  'ubuntu1404' => 'ubuntu:trusty',
200
199
  'ubuntu1604' => 'ubuntu:xenial',
201
200
  'ubuntu1804' => 'ubuntu:bionic',
202
201
  'ubuntu2004' => 'ubuntu:focal',
203
- 'ubuntu2204' => 'ubuntu:jammy',
204
202
  'rhel62' => 'centos:6',
205
203
  'rhel70' => 'centos:7',
206
- 'rhel80' => 'rockylinux:8',
207
204
  }.freeze
208
205
 
209
206
  def base_image
@@ -234,10 +231,6 @@ module Mrss
234
231
  distro =~ /debian|ubuntu/
235
232
  end
236
233
 
237
- def ubuntu?
238
- distro=~ /ubuntu/
239
- end
240
-
241
234
  def preload?
242
235
  !!@options[:preload]
243
236
  end
@@ -98,8 +98,8 @@ module Mrss
98
98
  def min_libmongocrypt_version(version)
99
99
  require_libmongocrypt
100
100
  before(:all) do
101
- actual_version = Utils.parse_version(Mongo::Crypt::Binding.mongocrypt_version(nil))
102
- min_version = Utils.parse_version(version)
101
+ actual_version = Gem::Version.new(Mongo::Crypt::Binding.mongocrypt_version(nil))
102
+ min_version = Gem::Version.new(version)
103
103
  unless actual_version >= min_version
104
104
  skip "libmongocrypt version #{min_version} required, but version #{actual_version} is available"
105
105
  end
@@ -24,21 +24,6 @@ module Mrss
24
24
 
25
25
  attr_reader :desired_version, :arch
26
26
 
27
- def target_arch
28
- # can't use RbConfig::CONFIG["arch"] because JRuby doesn't
29
- # return anything meaningful there.
30
- #
31
- # also, need to use `uname -a` instead of (e.g.) `uname -p`
32
- # because debian (at least) does not return anything meaningful
33
- # for `uname -p`.
34
- uname = `uname -a`.strip
35
- @target_arch ||= case uname
36
- when /aarch/ then "aarch64"
37
- when /x86/ then "x86_64"
38
- else raise "unsupported architecture #{uname.inspect}"
39
- end
40
- end
41
-
42
27
  def download_url
43
28
  @download_url ||= begin
44
29
  version, version_ok = detect_version(current_catalog)
@@ -55,13 +40,35 @@ module Mrss
55
40
  end
56
41
  dl = version['downloads'].detect do |dl|
57
42
  dl['archive']['url'].index("enterprise-#{arch}") &&
58
- dl['arch'] == target_arch
43
+ dl['arch'] == 'x86_64'
59
44
  end
60
45
  unless dl
61
46
  raise MissingDownloadUrl, "No download for #{arch} for #{version['version']}"
62
47
  end
63
48
  url = dl['archive']['url']
64
49
  end
50
+ rescue MissingDownloadUrl
51
+ if %w(2.6 3.0).include?(desired_version) && arch == 'ubuntu1604'
52
+ # 2.6 and 3.0 are only available for ubuntu1204 and ubuntu1404.
53
+ # Those ubuntus have ancient Pythons that don't work due to not
54
+ # implementing recent TLS protocols.
55
+ # Because of this we test on ubuntu1604 which has a newer Python.
56
+ # But we still need to retrieve ubuntu1404-targeting builds.
57
+ url = self.class.new('3.2', arch).download_url
58
+ unless url.include?('3.2.')
59
+ raise 'URL not in expected format'
60
+ end
61
+ url = case desired_version
62
+ when '2.6'
63
+ url.sub(/\b3\.2\.\d+/, '2.6.12')
64
+ when '3.0'
65
+ url.sub(/\b3\.2\.\d+/, '3.0.15')
66
+ else
67
+ raise NotImplementedError
68
+ end.sub('ubuntu1604', 'ubuntu1404')
69
+ else
70
+ raise
71
+ end
65
72
  end
66
73
 
67
74
  private
@@ -3,35 +3,13 @@
3
3
 
4
4
  module Mrss
5
5
  module Utils
6
- extend self
7
6
 
8
- def print_backtrace(dest=STDERR)
9
- raise
10
- rescue => e
11
- dest.puts e.backtrace.join("\n")
12
- end
13
-
14
- # Parses the given version string, accounting for suffix information that
15
- # Gem::Version cannot successfully parse.
16
- #
17
- # @param [ String ] version the version to parse
18
- #
19
- # @return [ Gem::Version ] the parsed version
20
- #
21
- # @raise [ ArgumentError ] if the string cannot be parsed.
22
- def parse_version(version)
23
- Gem::Version.new(version)
24
- rescue ArgumentError
25
- match = version.match(/\A(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)?(-[A-Za-z\+\d]+)?\z/)
26
- raise ArgumentError.new("Malformed version number string #{version}") if match.nil?
27
-
28
- Gem::Version.new(
29
- [
30
- match[:major],
31
- match[:minor],
32
- match[:patch]
33
- ].join('.')
34
- )
7
+ module_function def print_backtrace(dest=STDERR)
8
+ begin
9
+ hello world
10
+ rescue => e
11
+ dest.puts e.backtrace.join("\n")
12
+ end
35
13
  end
36
14
  end
37
15
  end
@@ -7,13 +7,13 @@
7
7
  <%
8
8
 
9
9
  python_toolchain_url = "https://s3.amazonaws.com//mciuploads/mongo-python-driver-toolchain/#{distro}/ba92de2700c04ee2d4f82c3ffdfc33105140cb04/mongo_python_driver_toolchain_#{distro.gsub('-', '_')}_ba92de2700c04ee2d4f82c3ffdfc33105140cb04_19_11_14_15_33_33.tar.gz"
10
- # server_version = '4.3.3'
10
+ server_version = '4.3.3'
11
11
  server_url = "http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-#{distro}-#{server_version}.tgz"
12
12
  server_archive_basename = File.basename(server_url)
13
13
  server_extracted_dir = server_archive_basename.sub(/\.(tar\.gz|tgz)$/, '')
14
14
 
15
15
  # When changing, also update the hash in shlib/set_env.sh.
16
- TOOLCHAIN_VERSION='e8c60866f54bed7e336a37df3a97d6ae1b971b7d'
16
+ TOOLCHAIN_VERSION='219833abad4d9d3bf43c0fef101a8ca082ac4ae9'
17
17
 
18
18
  def ruby_toolchain_url(ruby)
19
19
  "http://boxes.10gen.com/build/toolchain-drivers/mongo-ruby-driver/#{TOOLCHAIN_VERSION}/#{distro}/#{ruby}.tar.xz"
@@ -77,31 +77,25 @@ ENV DOCKER=1
77
77
  # therefore install python-pip in all configurations here.
78
78
 
79
79
  <% packages = %w(
80
- procps lsb-release bzip2 curl wget gpg zsh
80
+ procps lsb-release bzip2 curl zsh
81
81
  git make gcc libyaml-0-2 libgmp-dev zlib1g-dev libsnappy-dev
82
82
  krb5-user krb5-kdc krb5-admin-server libsasl2-dev libsasl2-modules-gssapi-mit
83
83
  haproxy
84
84
  python3-pip
85
- tzdata shared-mime-info software-properties-common
85
+ tzdata shared-mime-info
86
86
  ) %>
87
87
 
88
88
  <% if distro =~ /ubuntu2004/ %>
89
89
  <% packages << 'libsnmp35' %>
90
- <% elsif distro =~ /ubuntu2204|debian11/ %>
91
- <% packages << 'libsnmp40' %>
92
90
  <% else %>
93
91
  <% packages << 'libsnmp30' %>
94
92
  <% end %>
95
93
 
96
- <% if distro !~ /ubuntu2004|ubuntu2204|debian11/ %>
94
+ <% if distro !~ /ubuntu2004/ %>
97
95
  <% packages << 'python-pip' %>
98
96
  <% end %>
99
97
 
100
- <% if distro =~ /ubuntu2204|debian11/ %>
101
- <% packages << 'python3-venv' %>
102
- <% end %>
103
-
104
- <% if distro =~ /debian10|ubuntu2204|debian11/ %>
98
+ <% if distro =~ /debian10/ %>
105
99
  <% packages << 'openjdk-11-jdk-headless' %>
106
100
  <% elsif distro =~ /ubuntu1404/ %>
107
101
  # Ubuntu 14.04 only has openjdk 7, this is too old to be useful
@@ -111,37 +105,31 @@ ENV DOCKER=1
111
105
 
112
106
  # ubuntu1404, ubuntu1604: libcurl3
113
107
  # ubuntu1804, ubuntu2004, debian10: libcurl4
114
- <% if distro =~ /ubuntu1804|ubuntu2004|ubuntu2204|debian10|debian11/ %>
108
+ <% if distro =~ /ubuntu1804|ubuntu2004|debian10/ %>
115
109
  <% packages << 'libcurl4' %>
116
110
  <% else %>
117
111
  <% packages << 'libcurl3' %>
118
112
  <% end %>
119
113
 
120
- <% if distro =~ /ubuntu1804|ubuntu2004|ubuntu2204/ %>
114
+ <% if distro =~ /ubuntu1804|ubuntu2004/ %>
121
115
  <% packages << 'nodejs' %>
122
116
  <% end %>
123
117
 
124
- <% if distro =~ /ubuntu2004|ubuntu2204/ %>
125
- <% packages += %w(ruby bundler) %>
118
+ <% if distro =~ /ubuntu2004/ %>
119
+ <% packages += %w(ruby ruby2.7 bundler) %>
126
120
  <% end %>
127
121
 
128
122
  RUN apt-get update && apt-get install -y <%= packages.join(' ') %>
129
-
130
- <% if ubuntu? %>
131
- RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
132
- RUN echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/kitware.list >/dev/null
133
- <% end %>
134
- RUN apt-get update && apt-get install -y cmake
135
-
123
+
136
124
  <% else %>
137
125
 
138
126
  <% if distro =~ /rhel6/ %>
139
-
127
+
140
128
  # CentOS 6 is dead - to use it retrieve the packages from vault:
141
129
  # https://stackoverflow.com/questions/53562691/error-cannot-retrieve-repository-metadata-repomd-xml-for-repository-base-pl
142
-
130
+
143
131
  <%
144
-
132
+
145
133
  cfg = <<-CFG
146
134
  [base]
147
135
  name=CentOS-$releasever - Base
@@ -153,11 +141,11 @@ gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
153
141
  CFG
154
142
 
155
143
  %>
156
-
144
+
157
145
  RUN printf "<%= cfg.gsub("\n", "\\n") %>" >/etc/yum.repos.d/CentOS-Base.repo
158
-
146
+
159
147
  <% end %>
160
-
148
+
161
149
  # Enterprise server: net-snmp
162
150
  # lsb_release: redhat-lsb-core
163
151
  # our runner scripts: which
@@ -174,8 +162,23 @@ CFG
174
162
 
175
163
  RUN yum install -y redhat-lsb-core which git gcc libyaml krb5-server \
176
164
  krb5-workstation cyrus-sasl-devel cyrus-sasl-gssapi java-1.8.0-openjdk \
177
- net-snmp python38 python38-devel cmake nodejs
165
+ net-snmp python3
178
166
 
167
+ <% if distro =~ /rhel6/ %>
168
+
169
+ # RHEL 6 ships with Python 2.6.
170
+
171
+ RUN yum install -y centos-release-scl && \
172
+ yum install -y python27-python python27-python-devel
173
+ ENV PATH=/opt/rh/python27/root/usr/bin:$PATH \
174
+ LD_LIBRARY_PATH=/opt/rh/python27/root/usr/lib64
175
+
176
+ <% else %>
177
+
178
+ RUN yum install -y python-devel
179
+
180
+ <% end %>
181
+
179
182
  <% end %>
180
183
 
181
184
  <% if preload? %>
@@ -217,7 +220,7 @@ CFG
217
220
  <% when 'git' %>
218
221
  # dateutil dependency is missing in mtools: https://github.com/rueckstiess/mtools/issues/864
219
222
  RUN python3 -m pip install virtualenv 'pymongo>=4' python-dateutil psutil
220
-
223
+
221
224
  # Install mtools from git because released versions do not work with pymongo 4.0
222
225
  RUN git clone https://github.com/p-mongodb/mtools && \
223
226
  cd mtools && \
@@ -231,7 +234,7 @@ CFG
231
234
  <% if @env.fetch('MONGODB_VERSION') >= '4.4' %>
232
235
  # ubuntu1604 installs MarkupSafe 0.0.0 here instead of 2.0.0+
233
236
  # as specified by dependencies, causing OCSP mock to not work.
234
- RUN python3 -mpip install asn1crypto oscrypto flask --upgrade --ignore-installed
237
+ RUN python3 -mpip install asn1crypto oscrypto flask --upgrade
235
238
  <% end %>
236
239
 
237
240
  # FLE is tested against 4.0+ servers.
@@ -240,7 +243,7 @@ CFG
240
243
  # boto3~=1.19 cryptography~=3.4.8 pykmip~=0.10.0
241
244
  # cryptography does not install due to lacking setuptools_rust
242
245
  # (either that version or anything that isn't part of system packages)
243
- RUN python3 -mpip install boto3~=1.19 cryptography pykmip~=0.10.0 'sqlalchemy<2.0.0'
246
+ RUN python3 -mpip install boto3~=1.19 cryptography pykmip~=0.10.0
244
247
  <% end %>
245
248
 
246
249
  <% unless ruby_head? || system_ruby? %>
@@ -252,6 +255,10 @@ CFG
252
255
 
253
256
  <% end %>
254
257
 
258
+ RUN curl --retry 3 -fL <%= server_download_url %> |tar xzf - && \
259
+ mv mongo*/ /opt/mongodb
260
+ ENV USE_OPT_MONGODB=1 USE_SYSTEM_PYTHON_PACKAGES=1
261
+
255
262
  <% end %>
256
263
 
257
264
  <% if distro =~ /debian|ubuntu/ %>
@@ -301,9 +308,6 @@ ENV MONGO_ORCHESTRATION_HOME=/tmpfs \
301
308
 
302
309
  COPY . .
303
310
 
304
- RUN bash -c '. .evergreen/download-mongodb.sh && get_distro && get_mongodb_download_url_for "$DISTRO" "<%= server_version %>" && curl --retry 3 -fL $MONGODB_DOWNLOAD_URL |tar xzf - && mv mongo*/ /opt/mongodb'
305
- ENV USE_OPT_MONGODB=1 USE_SYSTEM_PYTHON_PACKAGES=1
306
-
307
311
  <% if expose? %>
308
312
 
309
313
  <% ports = [] %>
@@ -78,26 +78,15 @@ install_mlaunch_venv() {
78
78
  # https://github.com/pypa/virtualenv/issues/1630
79
79
  python3 -m pip install venv --user
80
80
  fi
81
- if ! python3 -m ensurepip -h > /dev/null; then
82
- # Debian11/Ubuntu2204 have venv installed, but it is nonfunctional unless
83
- # the python3-venv package is also installed (it lacks the ensurepip
84
- # module).
85
- sudo apt-get install --yes python3-venv
86
- fi
87
81
  if test "$USE_SYSTEM_PYTHON_PACKAGES" = 1 &&
88
82
  python3 -m pip list |grep mtools
89
83
  then
90
84
  # Use the existing mtools-legacy
91
85
  :
92
86
  else
93
- # Spawn a virtual environment, but only if one is not already
94
- # active...
95
- if test -z "$VIRTUAL_ENV"; then
96
- venvpath="$MONGO_ORCHESTRATION_HOME"/venv
97
- python3 -m venv $venvpath
98
- . $venvpath/bin/activate
99
- fi
100
-
87
+ venvpath="$MONGO_ORCHESTRATION_HOME"/venv
88
+ python3 -m venv $venvpath
89
+ . $venvpath/bin/activate
101
90
  # [mlaunch] does not work:
102
91
  # https://github.com/rueckstiess/mtools/issues/856
103
92
  # dateutil dependency is missing in mtools: https://github.com/rueckstiess/mtools/issues/864
@@ -169,19 +158,6 @@ install_mlaunch_git() {
169
158
  fi
170
159
  }
171
160
 
172
- install_cmake() {
173
- if ! command -v cmake &> /dev/null; then
174
- if ! command -v apt-get &> /dev/null; then
175
- # no apt-get; assume RHEL
176
- sudo yum -y install cmake libarchive
177
- else
178
- sudo apt-get install --yes cmake
179
- fi
180
- else
181
- echo 'cmake is present'
182
- fi
183
- }
184
-
185
161
  # This function sets followong global variables:
186
162
  # server_cert_path
187
163
  # server_ca_path
@@ -197,7 +173,7 @@ calculate_server_args() {
197
173
  fi
198
174
 
199
175
  if test $mongo_version = latest; then
200
- mongo_version=70
176
+ mongo_version=60
201
177
  fi
202
178
 
203
179
  local args="--setParameter enableTestCommands=1"
@@ -1,5 +1,5 @@
1
1
  # When changing, also update the hash in share/Dockerfile.
2
- TOOLCHAIN_VERSION=e8c60866f54bed7e336a37df3a97d6ae1b971b7d
2
+ TOOLCHAIN_VERSION=219833abad4d9d3bf43c0fef101a8ca082ac4ae9
3
3
 
4
4
  set_env_java() {
5
5
  ls -l /opt || true
@@ -53,7 +53,7 @@ set_env_python() {
53
53
  curl -fL --retry 3 https://github.com/p-mongodb/deps/raw/main/"$arch"-python37.tar.xz | \
54
54
  tar xfJ - -C /opt
55
55
  fi
56
-
56
+
57
57
  if test -d /opt/python/3.7/bin; then
58
58
  # Most Evergreen configurations.
59
59
  export PATH=/opt/python/3.7/bin:$PATH
@@ -61,7 +61,7 @@ set_env_python() {
61
61
  # Configurations that use Docker in Evergreen - these don't preload.
62
62
  export PATH=/opt/python37/bin:$PATH
63
63
  fi
64
-
64
+
65
65
  python3 -V
66
66
  fi
67
67
  }
@@ -78,7 +78,7 @@ set_env_node() {
78
78
  # Node from toolchain in Evergreen
79
79
  export PATH=/opt/node/bin:$PATH
80
80
  fi
81
-
81
+
82
82
  node -v
83
83
  }
84
84
 
@@ -70,6 +70,7 @@ class Person
70
70
  embeds_many :messages, validate: false
71
71
 
72
72
  embeds_one :passport, autobuild: true, store_as: :pass, validate: false
73
+ embeds_one :purse, store_as: "Purse"
73
74
  embeds_one :pet, class_name: "Animal", validate: false
74
75
  embeds_one :name, as: :namable, validate: false do
75
76
  def extension
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Purse
4
+ include Mongoid::Document
5
+
6
+ field :brand, type: String
7
+
8
+ embedded_in :person
9
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.1
4
+ version: 8.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - The MongoDB Ruby Team
@@ -35,7 +35,7 @@ cert_chain:
35
35
  wkeAWhd5b+5JS0zgDL4SvGB8/W2IY+y0zELkojBMgJPyrpAWHL/WSsSBMuhyI2Pv
36
36
  xxaBVLklnJJ/qCCOZ3lG2MyVc/Nb0Mmq8ygWNsfwHmKKYuuWcviit0D0Tek=
37
37
  -----END CERTIFICATE-----
38
- date: 2023-07-11 00:00:00.000000000 Z
38
+ date: 2023-08-24 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: activemodel
@@ -1100,6 +1100,7 @@ files:
1100
1100
  - spec/support/models/publication/review.rb
1101
1101
  - spec/support/models/purchase.rb
1102
1102
  - spec/support/models/purchased_item.rb
1103
+ - spec/support/models/purse.rb
1103
1104
  - spec/support/models/question.rb
1104
1105
  - spec/support/models/quiz.rb
1105
1106
  - spec/support/models/rating.rb
@@ -1210,7 +1211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1210
1211
  - !ruby/object:Gem::Version
1211
1212
  version: 1.3.6
1212
1213
  requirements: []
1213
- rubygems_version: 3.4.12
1214
+ rubygems_version: 3.4.17
1214
1215
  signing_key:
1215
1216
  specification_version: 4
1216
1217
  summary: Elegant Persistence in Ruby for MongoDB.
@@ -1817,6 +1818,7 @@ test_files:
1817
1818
  - spec/support/models/publication.rb
1818
1819
  - spec/support/models/purchase.rb
1819
1820
  - spec/support/models/purchased_item.rb
1821
+ - spec/support/models/purse.rb
1820
1822
  - spec/support/models/question.rb
1821
1823
  - spec/support/models/quiz.rb
1822
1824
  - spec/support/models/rating.rb
metadata.gz.sig CHANGED
Binary file