Skip to content

Commit da85ff7

Browse files
p-mongop
andauthored
MONGOID-5246 Flip feature flags for 8.0 (#5177)
* MONGOID-5246 Flip feature flags for 8.0 * legacy_pluck_distinct * show examples to change the values * legacy_pluck_distinct * legacy_pluck_distinct * pluck distinct * account for bigdecimal flag * RUBY-2928 * use config_override * fix findable spec Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent f119b04 commit da85ff7

File tree

11 files changed

+187
-112
lines changed

11 files changed

+187
-112
lines changed

docs/reference/configuration.txt

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,13 @@ for details on driver options.
282282
# Product.where(impossible_condition: true).sum(:price)
283283
#
284284
# ... return nil instead of 0.
285-
# (default: true in Mongoid 7, will change to false in Mongoid 8)
286-
broken_aggregables: true
285+
# (default: false)
286+
#broken_aggregables: true
287287

288288
# Ignore aliased fields in embedded documents when performing pluck and
289289
# distinct operations, for backwards compatibility.
290-
# (default: true in Mongoid 7, will change to false in Mongoid 8)
291-
broken_alias_handling: true
290+
# (default: false)
291+
#broken_alias_handling: true
292292

293293
# Maintain broken `and' method behavior that existed in Mongoid 7.3
294294
# and earlier for backwards compatibility: in some situations, conditions
@@ -310,13 +310,13 @@ for details on driver options.
310310
# This is obviously incorrect as the {"$in"=>[2021]} clause is lost.
311311
# Notice that the clause is only lost when both clauses are added using
312312
# the #and method.
313-
# (default: true in Mongoid 7, will change to false in Mongoid 8)
314-
broken_and: true
313+
# (default: false)
314+
#broken_and: true
315315

316316
# When exiting a nested `with_scope' block, set the current scope to
317317
# nil instead of the parent scope for backwards compatibility.
318-
# (default: true in Mongoid 7, will change to false in Mongoid 8)
319-
broken_scoping: true
318+
# (default: false)
319+
#broken_scoping: true
320320

321321
# Maintain broken update behavior in some cases for backwards
322322
# compatibility.
@@ -335,8 +335,8 @@ for details on driver options.
335335
# In Mongoid 7.3 and earlier, canvas.palette would be nil when we would
336336
# expect it to be palette. Set this option to true to keep this behavior,
337337
# set the option to false to perform the second update correctly.
338-
# (default: true in Mongoid 7, will change to false in Mongoid 8)
339-
broken_updates: true
338+
# (default: false)
339+
#broken_updates: true
340340

341341
# Time objects in Ruby have nanosecond precision, whereas MongoDB server
342342
# can only store times with millisecond precision. Set this option to
@@ -347,9 +347,8 @@ for details on driver options.
347347
# which documents are being queried. Setting this option to false will
348348
# produce different results for queries on embedded associations that
349349
# are already loaded into memory vs queries on unloaded associations and
350-
# top-level models. (default: false in Mongoid 7, will change to true
351-
# in Mongoid 8).
352-
compare_time_by_ms: false
350+
# top-level models. (default: true)
351+
#compare_time_by_ms: false
353352

354353
# Set the global discriminator key. (default: "_type")
355354
discriminator_key: "_type"
@@ -370,17 +369,17 @@ for details on driver options.
370369
# Maintain legacy behavior of pluck and distinct, which does not demongoize
371370
# values on returning them. Setting this option to false will cause
372371
# pluck and distinct to return demongoized values.
373-
# (default: true in Mongoid 7, will change to false in Mongoid 8)
374-
legacy_pluck_distinct: true
372+
# (default: false)
373+
#legacy_pluck_distinct: true
375374

376375
# Maintain legacy behavior of === on Mongoid document classes, which
377376
# returns true in a number of cases where Ruby's === implementation would
378377
# return false. Note that the behavior of === on Mongoid document
379378
# instances differs from both the behavior of === on document classes
380379
# and from Ruby's behavior of === on simple object instances regardless
381380
# of the value of this option.
382-
# (default: true in Mongoid 7, will change to false in Mongoid 8)
383-
legacy_triple_equals: true
381+
# (default: false)
382+
#legacy_triple_equals: true
384383

385384
# Set the Mongoid and Ruby driver log levels when Mongoid is not using
386385
# Ruby on Rails logger instance. (default: :info)
@@ -393,8 +392,8 @@ for details on driver options.
393392
# Force ``BSON::ObjectId#as_json`` method to return the hash
394393
# { "$oid" => id.to_s }. When this option is false, and bson-ruby 5
395394
# is used, the return value will be the hexadecimal ObjectId string only.
396-
# (default: true in Mongoid 7, will change to false in Mongoid 8)
397-
object_id_as_json_oid: true
395+
# (default: false)
396+
#object_id_as_json_oid: true
398397

399398
# Preload all models in development, needed when models use
400399
# inheritance. (default: false)

docs/release-notes/mongoid-7.5.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,27 @@ please consult GitHub releases for detailed release notes and JIRA for
1818
the complete list of issues fixed in each release, including bug fixes.
1919

2020

21+
Default Option Values Changed
22+
-----------------------------
23+
24+
**Breaking change:** The following options have had their default values
25+
changed in Mongoid 7.5:
26+
27+
- ``:broken_aggregables`` => ``false``
28+
- ``:broken_alias_handling`` => ``false``
29+
- ``:broken_and`` => ``false``
30+
- ``:broken_scoping`` => ``false``
31+
- ``:broken_updates`` => ``false``
32+
- ``:compare_time_by_ms`` => ``true``
33+
- ``:legacy_pluck_distinct`` => ``false``
34+
- ``:legacy_triple_equals`` => ``false``
35+
- ``:map_big_decimal_to_decimal128`` => ``true``
36+
- ``:object_id_as_json_oid`` => ``false``
37+
38+
Please refer to :ref:`configuration option <configuration-options>` for
39+
the description and effects of each of these options.
40+
41+
2142
Order of Callback Invocation
2243
----------------------------
2344

lib/mongoid/config.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,44 +75,44 @@ module Config
7575
option :use_utc, default: false
7676

7777
# Store BigDecimals as Decimal128s instead of strings in the db.
78-
option :map_big_decimal_to_decimal128, default: false
78+
option :map_big_decimal_to_decimal128, default: true
7979

8080
# Update embedded documents correctly when setting it, unsetting it
8181
# and resetting it. See MONGOID-5206 and MONGOID-5240 for more details.
82-
option :broken_updates, default: true
82+
option :broken_updates, default: false
8383

8484
# Maintain legacy behavior of === on Mongoid documents, which returns
8585
# true in a number of cases where Ruby's === implementation would
8686
# return false.
87-
option :legacy_triple_equals, default: true
87+
option :legacy_triple_equals, default: false
8888

8989
# When exiting a nested `with_scope' block, set the current scope to
9090
# nil instead of the parent scope for backwards compatibility.
91-
option :broken_scoping, default: true
91+
option :broken_scoping, default: false
9292

9393
# Maintain broken behavior of sum over empty result sets for backwards
9494
# compatibility.
95-
option :broken_aggregables, default: true
95+
option :broken_aggregables, default: false
9696

9797
# Ignore aliased fields in embedded documents when performing pluck and
9898
# distinct operations, for backwards compatibility.
99-
option :broken_alias_handling, default: true
99+
option :broken_alias_handling, default: false
100100

101101
# Maintain broken `and' behavior when using the same operator on the same
102102
# field multiple times for backwards compatibility.
103-
option :broken_and, default: true
103+
option :broken_and, default: false
104104

105105
# Use millisecond precision when comparing Time objects with the _matches?
106106
# function.
107-
option :compare_time_by_ms, default: false
107+
option :compare_time_by_ms, default: true
108108

109109
# Use bson-ruby's implementation of as_json for BSON::ObjectId instead of
110110
# the one monkey-patched into Mongoid.
111-
option :object_id_as_json_oid, default: true
111+
option :object_id_as_json_oid, default: false
112112

113113
# Maintain legacy behavior of pluck and distinct, which does not
114114
# demongoize the values on returning them.
115-
option :legacy_pluck_distinct, default: true
115+
option :legacy_pluck_distinct, default: false
116116

117117
# Has Mongoid been configured? This is checking that at least a valid
118118
# client config exists.

spec/integration/matcher_operator_data/type_decimal.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@
2929
matches: false
3030
min_server_version: 3.4
3131

32-
- name: BigDecimal field - does not match
32+
# Requires :map_big_decimal_to_decimal128 option to be true.
33+
- name: BigDecimal field - matches
3334
document:
3435
big_decimal_field: !ruby/object:BigDecimal
3536
18:0.42e2
3637
query:
3738
big_decimal_field:
3839
$type: 19
39-
matches: false
40+
matches: true
4041
min_server_version: 3.4

spec/mongoid/config_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,70 +267,70 @@
267267

268268
context 'when setting the map_big_decimal_to_decimal128 option in the config' do
269269
let(:option) { :map_big_decimal_to_decimal128 }
270-
let(:default) { false }
270+
let(:default) { true }
271271

272272
it_behaves_like "a config option"
273273
end
274274

275275
context 'when setting the broken_updates option in the config' do
276276
let(:option) { :broken_updates }
277-
let(:default) { true }
277+
let(:default) { false }
278278

279279
it_behaves_like "a config option"
280280
end
281281

282282
context 'when setting the legacy_triple_equals option in the config' do
283283
let(:option) { :legacy_triple_equals }
284-
let(:default) { true }
284+
let(:default) { false }
285285

286286
it_behaves_like "a config option"
287287
end
288288

289289
context 'when setting the broken_scoping option in the config' do
290290
let(:option) { :broken_scoping }
291-
let(:default) { true }
291+
let(:default) { false }
292292

293293
it_behaves_like "a config option"
294294
end
295295

296296
context 'when setting the broken_aggregables option in the config' do
297297
let(:option) { :broken_aggregables }
298-
let(:default) { true }
298+
let(:default) { false }
299299

300300
it_behaves_like "a config option"
301301
end
302302

303303
context 'when setting the broken_alias_handling option in the config' do
304304
let(:option) { :broken_alias_handling }
305-
let(:default) { true }
305+
let(:default) { false }
306306

307307
it_behaves_like "a config option"
308308
end
309309

310310
context 'when setting the broken_and option in the config' do
311311
let(:option) { :broken_and }
312-
let(:default) { true }
312+
let(:default) { false }
313313

314314
it_behaves_like "a config option"
315315
end
316316

317317
context 'when setting the compare_time_by_ms option in the config' do
318318
let(:option) { :compare_time_by_ms }
319-
let(:default) { false }
319+
let(:default) { true }
320320

321321
it_behaves_like "a config option"
322322
end
323323

324324
context 'when setting the object_id_as_json_oid option in the config' do
325325
let(:option) { :object_id_as_json_oid }
326-
let(:default) { true }
326+
let(:default) { false }
327327

328328
it_behaves_like "a config option"
329329
end
330330

331331
context 'when setting the legacy_pluck_distinct option in the config' do
332332
let(:option) { :legacy_pluck_distinct }
333-
let(:default) { true }
333+
let(:default) { false }
334334

335335
it_behaves_like "a config option"
336336
end

spec/mongoid/contextual/mongo_spec.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,22 @@
559559
context "when legacy_pluck_distinct is set" do
560560
config_override :legacy_pluck_distinct, true
561561

562-
it "returns the non-demongoized distinct field values" do
563-
expect(context.distinct(:sales).sort).to eq([ "1E2", "2E3" ])
562+
context 'when storing BigDecimal as string' do
563+
config_override :map_big_decimal_to_decimal128, false
564+
565+
it "returns the non-demongoized distinct field values" do
566+
expect(context.distinct(:sales).sort).to eq([ "1E2", "2E3" ])
567+
end
568+
end
569+
570+
context 'when storing BigDecimal as decimal128' do
571+
config_override :map_big_decimal_to_decimal128, true
572+
573+
it "returns the non-demongoized distinct field values" do
574+
pending 'RUBY-2928'
575+
576+
expect(context.distinct(:sales).sort).to eq([ BSON::Decimal128.new("1E2"), BSON::Decimal128.new("2E3") ])
577+
end
564578
end
565579
end
566580

spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
describe ".evolve" do
88

99
context 'when map_big_decimal_to_decimal128 is false' do
10+
config_override :map_big_decimal_to_decimal128, false
1011

1112
context "when provided a big decimal" do
1213

@@ -62,14 +63,7 @@
6263
end
6364

6465
context 'when map_big_decimal_to_decimal128 is true' do
65-
66-
before do
67-
Mongoid.map_big_decimal_to_decimal128 = true
68-
end
69-
70-
after do
71-
Mongoid.map_big_decimal_to_decimal128 = false
72-
end
66+
config_override :map_big_decimal_to_decimal128, true
7367

7468
context "when provided a big decimal" do
7569

spec/mongoid/criteria/queryable/selector_spec.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,20 @@ def localized?
387387
selector.send(method, "key", array)
388388
end
389389

390-
it "serializes each element in the array" do
391-
expect(selector["key"]).to eq([ big_one.to_s, big_two.to_s ])
390+
context 'when serializing bigdecimal to string' do
391+
config_override :map_big_decimal_to_decimal128, false
392+
393+
it "serializes each element in the array" do
394+
expect(selector["key"]).to eq([ big_one.to_s, big_two.to_s ])
395+
end
396+
end
397+
398+
context 'when serializing bigdecimal to decimal128' do
399+
config_override :map_big_decimal_to_decimal128, true
400+
401+
it "serializes each element in the array" do
402+
expect(selector["key"]).to eq([ BSON::Decimal128.new(big_one), BSON::Decimal128.new(big_two)])
403+
end
392404
end
393405
end
394406
end

0 commit comments

Comments
 (0)