Skip to content

Commit 1a97bc7

Browse files
MONGOID-5490: Deprecate :use_activesupport_time_zone (#5488)
* Deprecate the use_activesupport_time_zone_deprecated config option. * Typo * Update config.rb * Update mongoid-8.1.txt --------- Co-authored-by: shields <[email protected]>
1 parent 102cb44 commit 1a97bc7

File tree

6 files changed

+58
-2
lines changed

6 files changed

+58
-2
lines changed

docs/reference/configuration.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ for details on driver options.
450450
# existing method. (default: false)
451451
scope_overwrite_exception: false
452452

453-
# Use ActiveSupport's time zone in time operations instead of
453+
# (Deprecated) Use ActiveSupport's time zone in time operations instead of
454454
# the Ruby default time zone. See the time zone section below for
455455
# further information. (default: true)
456456
use_activesupport_time_zone: true
@@ -463,6 +463,7 @@ for details on driver options.
463463
# (Deprecated) In MongoDB 4.0 and earlier, set whether to create
464464
# indexes in the background by default. (default: false)
465465
background_indexing: false
466+
466467
# Configure driver-specific options. (optional)
467468
driver_options:
468469
# When this flag is turned off, inline options will be correctly
@@ -768,7 +769,11 @@ Note that MongoDB stores all times in UTC without time zone information.
768769

769770
Mongoid offers the following time zone-related configuration options:
770771

771-
- ``use_activesupport_time_zone``: If true, prefer to work with times using
772+
- ``use_activesupport_time_zone``:
773+
This option is deprecated and will be removed in Mongoid 9.0,
774+
always behaving as true.
775+
776+
If true (default), prefer to work with times using
772777
``ActiveSupport::TimeWithZone``. Values in fields of type ``Time``
773778
will be returned as instances of ``ActiveSupport::TimeWithZone``.
774779
When parsing times without time zone information (such as when
@@ -787,6 +792,7 @@ Mongoid offers the following time zone-related configuration options:
787792
Also note that Mongoid may still utilize both ``Time`` and
788793
``ActiveSupport::TimeWithZone`` classes internally, as appropriate,
789794
regardless of the ``use_activesupport_time_zone`` setting.
795+
790796
- ``use_utc``:
791797
If true, times stored in MongoDB will be returned in UTC.
792798
If false, times stored in MongoDB will be returned in local time

docs/release-notes/mongoid-8.1.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ The complete list of releases is available `on GitHub
1717
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

20+
21+
Deprecated ``use_activesupport_time_zone`` config option
22+
--------------------------------------------------------
23+
24+
The config option ``use_activesupport_time_zone`` has been deprecated.
25+
Beginning in Mongoid 9.0, it will be ignored and always behave as true.
26+
Since ``use_activesupport_time_zone`` currently defaults to true, it is
27+
safe to remove from your config file at this time.
28+
29+
2030
Added ``load_async`` method on ``Criteria`` to asynchronously load documents
2131
----------------------------------------------------------------------------
2232

lib/mongoid/config.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ module Config
7272

7373
# Use ActiveSupport's time zone in time operations instead of the
7474
# Ruby default time zone.
75+
# @deprecated
7576
option :use_activesupport_time_zone, default: true
7677

7778
# Return stored times as UTC.
@@ -396,5 +397,14 @@ def global_client
396397
client
397398
end
398399
end
400+
401+
module DeprecateUseActivesupportTimeZone
402+
def use_activesupport_time_zone=(value)
403+
Mongoid::Warnings.warn_use_activesupport_time_zone_deprecated
404+
super
405+
end
406+
end
407+
408+
prepend DeprecateUseActivesupportTimeZone
399409
end
400410
end

lib/mongoid/extensions/time.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ module ClassMethods
3434
# ::Time.configured
3535
#
3636
# @return [ Time ] The configured time.
37+
#
38+
# @deprecated
3739
def configured
3840
Mongoid.use_activesupport_time_zone? ? (::Time.zone || ::Time) : ::Time
3941
end

lib/mongoid/warnings.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ 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.'
2829
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.'
2930
end
3031
end

spec/mongoid/config_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,4 +936,31 @@ def self.logger
936936
end
937937
end
938938
end
939+
940+
describe '#use_activesupport_time_zone=' do
941+
942+
before do
943+
Mongoid::Warnings.class_eval do
944+
@use_activesupport_time_zone_deprecated = false
945+
end
946+
end
947+
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
951+
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
958+
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
963+
end
964+
end
965+
end
939966
end

0 commit comments

Comments
 (0)