Skip to content

Commit 725f8f4

Browse files
authored
Merge pull request rails#41835 from rails/deprecate-astwz-name-override
Deprecate ActiveSupport::TimeWithZone.name
2 parents b80a2bd + 3f4b41a commit 725f8f4

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

activesupport/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Deprecate `ActiveSupport::TimeWithZone.name` so that from Rails 7.1 it will use the default implementation.
2+
3+
*Andrew White*
4+
15
* Tests parallelization is now disabled when running individual files to prevent the setup overhead.
26

37
It can still be enforced if the environment variable `PARALLEL_WORKERS` is present and set to a value greater than 1.

activesupport/lib/active_support/time_with_zone.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ module ActiveSupport
4040
class TimeWithZone
4141
# Report class name as 'Time' to thwart type checking.
4242
def self.name
43+
ActiveSupport::Deprecation.warn(<<~EOM)
44+
ActiveSupport::TimeWithZone.name has been deprecated and
45+
from Rails 7.1 will use the default Ruby implementation.
46+
EOM
47+
4348
"Time"
4449
end
4550

activesupport/test/core_ext/hash_ext_test.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -585,12 +585,15 @@ def test_three_levels_with_array
585585
end
586586

587587
def test_timezoned_attributes
588-
xml = {
589-
created_at: Time.utc(1999, 2, 2),
590-
local_created_at: Time.utc(1999, 2, 2).in_time_zone("Eastern Time (US & Canada)")
591-
}.to_xml(@xml_options)
592-
assert_match %r{<created-at type="dateTime">1999-02-02T00:00:00Z</created-at>}, xml
593-
assert_match %r{<local-created-at type="dateTime">1999-02-01T19:00:00-05:00</local-created-at>}, xml
588+
assert_deprecated("ActiveSupport::TimeWithZone.name has been deprecated") do
589+
xml = {
590+
created_at: Time.utc(1999, 2, 2),
591+
local_created_at: Time.utc(1999, 2, 2).in_time_zone("Eastern Time (US & Canada)")
592+
}.to_xml(@xml_options)
593+
594+
assert_match %r{<created-at type="dateTime">1999-02-02T00:00:00Z</created-at>}, xml
595+
assert_match %r{<local-created-at type="dateTime">1999-02-01T19:00:00-05:00</local-created-at>}, xml
596+
end
594597
end
595598

596599
def test_multiple_records_from_xml_with_attributes_other_than_type_ignores_them_without_exploding

activesupport/test/core_ext/time_with_zone_test.rb

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

189-
assert_equal(yaml, @twz.to_yaml)
189+
assert_deprecated("ActiveSupport::TimeWithZone.name has been deprecated") do
190+
assert_equal(yaml, @twz.to_yaml)
191+
end
190192
end
191193

192194
def test_ruby_to_yaml
@@ -199,7 +201,9 @@ def test_ruby_to_yaml
199201
time: 1999-12-31 19:00:00.000000000 Z
200202
EOF
201203

202-
assert_equal(yaml, { "twz" => @twz }.to_yaml)
204+
assert_deprecated("ActiveSupport::TimeWithZone.name has been deprecated") do
205+
assert_equal(yaml, { "twz" => @twz }.to_yaml)
206+
end
203207
end
204208

205209
def test_yaml_load
@@ -567,7 +571,9 @@ def test_is_a
567571
end
568572

569573
def test_class_name
570-
assert_equal "Time", ActiveSupport::TimeWithZone.name
574+
assert_deprecated("ActiveSupport::TimeWithZone.name has been deprecated") do
575+
assert_equal "Time", ActiveSupport::TimeWithZone.name
576+
end
571577
end
572578

573579
def test_method_missing_with_time_return_value

0 commit comments

Comments
 (0)