Skip to content

Commit 3dd0af5

Browse files
authored
Merge pull request rails#41873 from rails/prevent-deprecation-warning-with-yaml-twz
Use YAML.load_tags/dump_tags to prevent deprecation warnings
2 parents 12c4b77 + db9ba18 commit 3dd0af5

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

activesupport/lib/active_support/time_with_zone.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require "yaml"
4+
35
require "active_support/duration"
46
require "active_support/values/time_zone"
57
require "active_support/core_ext/object/acts_like"
@@ -182,7 +184,6 @@ def init_with(coder) #:nodoc:
182184
end
183185

184186
def encode_with(coder) #:nodoc:
185-
coder.tag = "!ruby/object:ActiveSupport::TimeWithZone"
186187
coder.map = { "utc" => utc, "zone" => time_zone, "time" => time }
187188
end
188189

@@ -588,3 +589,8 @@ def wrap_with_time_zone(time)
588589
end
589590
end
590591
end
592+
593+
# These prevent Psych from calling `ActiveSupport::TimeWithZone.name`
594+
# and triggering the deprecation warning about the change in Rails 7.1.
595+
YAML.load_tags["!ruby/object:ActiveSupport::TimeWithZone"] = "ActiveSupport::TimeWithZone"
596+
YAML.dump_tags[ActiveSupport::TimeWithZone] = "!ruby/object:ActiveSupport::TimeWithZone"

activesupport/test/core_ext/hash_ext_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ def test_three_levels_with_array
585585
end
586586

587587
def test_timezoned_attributes
588+
# TODO: Remove assertion in Rails 7.1 and add ActiveSupport::TimeWithZone to XML type mapping
588589
assert_deprecated("ActiveSupport::TimeWithZone.name has been deprecated") do
589590
xml = {
590591
created_at: Time.utc(1999, 2, 2),

activesupport/test/core_ext/time_with_zone_test.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ def test_to_yaml
186186
time: 1999-12-31 19:00:00.000000000 Z
187187
EOF
188188

189-
assert_deprecated("ActiveSupport::TimeWithZone.name has been deprecated") do
189+
# TODO: Remove assertion in Rails 7.1
190+
assert_not_deprecated do
190191
assert_equal(yaml, @twz.to_yaml)
191192
end
192193
end
@@ -201,7 +202,8 @@ def test_ruby_to_yaml
201202
time: 1999-12-31 19:00:00.000000000 Z
202203
EOF
203204

204-
assert_deprecated("ActiveSupport::TimeWithZone.name has been deprecated") do
205+
# TODO: Remove assertion in Rails 7.1
206+
assert_not_deprecated do
205207
assert_equal(yaml, { "twz" => @twz }.to_yaml)
206208
end
207209
end
@@ -571,6 +573,7 @@ def test_is_a
571573
end
572574

573575
def test_class_name
576+
# TODO: Remove assertion in Rails 7.1 and change expected value
574577
assert_deprecated("ActiveSupport::TimeWithZone.name has been deprecated") do
575578
assert_equal "Time", ActiveSupport::TimeWithZone.name
576579
end

0 commit comments

Comments
 (0)