Skip to content

Commit 2a0fbaf

Browse files
MONGOID-5509: Deprecate all feature flags which were introduced in Mongoid 7.x (#5489)
* Deprecate the use_activesupport_time_zone_deprecated config option. * Typo * Mongoid 8.1 should deprecate all feature flags which were introduced in the 7.x series, with intent to remove them in Mongoid 9.0. --------- Co-authored-by: shields <[email protected]>
1 parent 1a97bc7 commit 2a0fbaf

File tree

4 files changed

+78
-36
lines changed

4 files changed

+78
-36
lines changed

docs/reference/configuration.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ for details on driver options.
280280
# error. (default: true)
281281
belongs_to_required_by_default: true
282282

283-
# Maintain broken behavior of sum over empty result sets for backwards
283+
# (Deprecated) Maintain broken behavior of sum over empty result sets for backwards
284284
# compatibility. When calculating a sum on a field with a null context,
285285
# for example:
286286
#
@@ -297,12 +297,12 @@ for details on driver options.
297297
# (default: false)
298298
#broken_aggregables: true
299299

300-
# Ignore aliased fields in embedded documents when performing pluck and
300+
# (Deprecated) Ignore aliased fields in embedded documents when performing pluck and
301301
# distinct operations, for backwards compatibility.
302302
# (default: false)
303303
#broken_alias_handling: true
304304

305-
# Maintain broken `and' method behavior that existed in Mongoid 7.3
305+
# (Deprecated) Maintain broken `and' method behavior that existed in Mongoid 7.3
306306
# and earlier for backwards compatibility: in some situations, conditions
307307
# already present in a Criteria object would be replaced by newer
308308
# conditions when `and' method is used instead of the new conditions
@@ -325,12 +325,12 @@ for details on driver options.
325325
# (default: false)
326326
#broken_and: true
327327

328-
# When exiting a nested `with_scope' block, set the current scope to
328+
# (Deprecated) When exiting a nested `with_scope' block, set the current scope to
329329
# nil instead of the parent scope for backwards compatibility.
330330
# (default: false)
331331
#broken_scoping: true
332332

333-
# Maintain broken update behavior in some cases for backwards
333+
# (Deprecated) Maintain broken update behavior in some cases for backwards
334334
# compatibility.
335335
#
336336
# In Mongoid 7.3 and earlier, when assigning a value to an embedded
@@ -350,7 +350,7 @@ for details on driver options.
350350
# (default: false)
351351
#broken_updates: true
352352

353-
# Time objects in Ruby have nanosecond precision, whereas MongoDB server
353+
# (Deprecated) Time objects in Ruby have nanosecond precision, whereas MongoDB server
354354
# can only store times with millisecond precision. Set this option to
355355
# true to truncate times to millisecond precision when performing
356356
# queries on already loaded embedded associations (this is also called
@@ -383,13 +383,13 @@ for details on driver options.
383383
# to parent contexts by default. (default: false)
384384
join_contexts: false
385385

386-
# When this flag is true, the attributes method on a document will return
386+
# (Deprecated) When this flag is true, the attributes method on a document will return
387387
# a BSON::Document when that document is retrieved from the database, and
388388
# a Hash otherwise. When this flag is false, the attributes method will
389389
# always return a Hash. (default: false)
390390
#legacy_attributes: true
391391

392-
# Maintain legacy behavior of pluck and distinct, which does not demongoize
392+
# (Deprecated) Maintain legacy behavior of pluck and distinct, which does not demongoize
393393
# values on returning them. Setting this option to false will cause
394394
# pluck and distinct to return demongoized values. Setting this option to
395395
# false will also allow retrieving *_translations fields from pluck and
@@ -409,7 +409,7 @@ for details on driver options.
409409
# (default: false)
410410
#legacy_readonly: true
411411

412-
# Maintain legacy behavior of === on Mongoid document classes, which
412+
# (Deprecated) Maintain legacy behavior of === on Mongoid document classes, which
413413
# returns true in a number of cases where Ruby's === implementation would
414414
# return false. Note that the behavior of === on Mongoid document
415415
# instances differs from both the behavior of === on document classes
@@ -426,13 +426,13 @@ for details on driver options.
426426
# as a BSON::Decimal128 instead of a string. (default: true)
427427
#map_big_decimal_to_decimal128: true
428428

429-
# Force ``BSON::ObjectId#as_json`` method to return the hash
429+
# (Deprecated) Force ``BSON::ObjectId#as_json`` method to return the hash
430430
# { "$oid" => id.to_s }. When this option is false, and bson-ruby 5
431431
# is used, the return value will be the hexadecimal ObjectId string only.
432432
# (default: false)
433433
#object_id_as_json_oid: true
434434

435-
# When chaining the same operators that use the same field, setting this
435+
# (Deprecated) When chaining the same operators that use the same field, setting this
436436
# feature flag to false will cause those operators to be combined using an
437437
# and. Setting this feature flag to true will cause the later chained
438438
# operators to overwrite the earlier ones. (default: false)

lib/mongoid/config.rb

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,28 @@ def global_client
398398
end
399399
end
400400

401-
module DeprecateUseActivesupportTimeZone
402-
def use_activesupport_time_zone=(value)
403-
Mongoid::Warnings.warn_use_activesupport_time_zone_deprecated
404-
super
401+
module DeprecatedOptions
402+
OPTIONS = %i[ use_activesupport_time_zone
403+
broken_aggregables
404+
broken_alias_handling
405+
broken_and
406+
broken_scoping
407+
broken_updates
408+
compare_time_by_ms
409+
legacy_attributes
410+
legacy_pluck_distinct
411+
legacy_triple_equals
412+
object_id_as_json_oid
413+
overwrite_chained_operators ]
414+
415+
OPTIONS.each do |option|
416+
define_method(:"#{option}=") do |value|
417+
Mongoid::Warnings.send(:"warn_#{option}_deprecated")
418+
super(value)
419+
end
405420
end
406421
end
407422

408-
prepend DeprecateUseActivesupportTimeZone
423+
prepend DeprecatedOptions
409424
end
410425
end

lib/mongoid/warnings.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,18 @@ def warning(id, message)
2525
warning :as_json_compact_deprecated, '#as_json :compact option is deprecated. Please call #compact on the returned Hash object instead.'
2626
warning :symbol_type_deprecated, 'The BSON Symbol type is deprecated by MongoDB. Please use String or StringifiedSymbol field types instead of the Symbol field type.'
2727
warning :legacy_readonly, 'The readonly! method will only mark the document readonly when the legacy_readonly feature flag is switched off.'
28-
warning :use_activesupport_time_zone_deprecated, 'Config option :use_activesupport_time_zone is deprecated and should be removed from your config. It will be always true beginning in Mongoid 9.0.'
28+
warning :use_activesupport_time_zone_deprecated, 'Config option :use_activesupport_time_zone is deprecated and should be removed from your config. It will always be true beginning in Mongoid 9.0.'
29+
warning :broken_aggregables_deprecated, 'Config option :broken_aggregables is deprecated. It will always be false beginning in Mongoid 9.0. Please use load_defaults for Mongoid 8.0 or later, then remove it from your config.'
30+
warning :broken_alias_handling_deprecated, 'Config option :broken_alias_handling is deprecated. It will always be false beginning in Mongoid 9.0. Please use load_defaults for Mongoid 8.0 or later, then remove it from your config.'
31+
warning :broken_and_deprecated, 'Config option :broken_and is deprecated. It will always be false beginning in Mongoid 9.0. Please use load_defaults for Mongoid 8.0 or later, then remove it from your config.'
32+
warning :broken_scoping_deprecated, 'Config option :broken_scoping is deprecated. It will always be false beginning in Mongoid 9.0. Please use load_defaults for Mongoid 8.0 or later, then remove it from your config.'
33+
warning :broken_updates_deprecated, 'Config option :broken_updates is deprecated. It will always be false beginning in Mongoid 9.0. Please use load_defaults for Mongoid 8.0 or later, then remove it from your config.'
34+
warning :compare_time_by_ms_deprecated, 'Config option :compare_time_by_ms is deprecated. It will always be true beginning in Mongoid 9.0. Please use load_defaults for Mongoid 8.0 or later, then remove it from your config.'
35+
warning :legacy_attributes_deprecated, 'Config option :legacy_attributes is deprecated. It will always be false beginning in Mongoid 9.0. Please use load_defaults for Mongoid 8.0 or later, then remove it from your config.'
36+
warning :legacy_pluck_distinct_deprecated, 'Config option :legacy_pluck_distinct is deprecated. It will always be false beginning in Mongoid 9.0. Please use load_defaults for Mongoid 8.0 or later, then remove it from your config.'
37+
warning :legacy_triple_equals_deprecated, 'Config option :legacy_triple_equals is deprecated. It will always be false beginning in Mongoid 9.0. Please use load_defaults for Mongoid 8.0 or later, then remove it from your config.'
38+
warning :object_id_as_json_oid_deprecated, 'Config option :object_id_as_json_oid is deprecated. It will always be false beginning in Mongoid 9.0. Please use load_defaults for Mongoid 8.0 or later, then remove it from your config.'
39+
warning :overwrite_chained_operators_deprecated, 'Config option :overwrite_chained_operators is deprecated. It will always be false beginning in Mongoid 9.0. Please use load_defaults for Mongoid 8.0 or later, then remove it from your config.'
2940
warning :mutable_ids, 'In Mongoid 9.0 the _id field will be immutable. In earlier versions of 8.x, mutating the _id field was supported inconsistently. Prepare your code for 9.0 by setting Mongoid::Config.immutable_ids to true.'
3041
end
3142
end

spec/mongoid/config_spec.rb

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -937,29 +937,45 @@ def self.logger
937937
end
938938
end
939939

940-
describe '#use_activesupport_time_zone=' do
940+
describe 'deprecations' do
941+
{ use_activesupport_time_zone: true,
942+
broken_aggregables: false,
943+
broken_alias_handling: false,
944+
broken_and: false,
945+
broken_scoping: false,
946+
broken_updates: false,
947+
compare_time_by_ms: true,
948+
legacy_attributes: false,
949+
legacy_pluck_distinct: false,
950+
legacy_triple_equals: false,
951+
object_id_as_json_oid: false,
952+
overwrite_chained_operators: false }.each do |option, default|
953+
954+
context ":#{option} option" do
941955

942-
before do
943-
Mongoid::Warnings.class_eval do
944-
@use_activesupport_time_zone_deprecated = false
945-
end
946-
end
956+
before do
957+
Mongoid::Warnings.class_eval do
958+
instance_variable_set(:"@#{option}_deprecated", false)
959+
end
960+
end
947961

948-
let(:warning) do
949-
"Config option :use_activesupport_time_zone is deprecated and should be removed from your config. It will be always true beginning in Mongoid 9.0."
950-
end
962+
let(:matcher) do
963+
/Config option :#{option}.+\. It will always be #{default} beginning in Mongoid 9\.0\./
964+
end
951965

952-
context 'when set to true' do
953-
it 'does not give a deprecation warning' do
954-
expect(Mongoid.logger).to receive(:warn).with(warning)
955-
described_class.use_activesupport_time_zone = true
956-
end
957-
end
966+
context 'when set to true' do
967+
it 'gives a deprecation warning' do
968+
expect(Mongoid.logger).to receive(:warn).with(matcher)
969+
described_class.send(:"#{option}=", true)
970+
end
971+
end
958972

959-
context 'when set to false' do
960-
it 'gives a deprecation warning' do
961-
expect(Mongoid.logger).to receive(:warn).with(warning)
962-
described_class.use_activesupport_time_zone = false
973+
context 'when set to false' do
974+
it 'gives a deprecation warning' do
975+
expect(Mongoid.logger).to receive(:warn).with(matcher)
976+
described_class.send(:"#{option}=", false)
977+
end
978+
end
963979
end
964980
end
965981
end

0 commit comments

Comments
 (0)