mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #15857 from zuhao/refactor_activesupport_encoding_test
Avoid hardcoded magic number in test teardown.
This commit is contained in:
commit
213e73dda3
1 changed files with 19 additions and 14 deletions
|
@ -494,31 +494,28 @@ EXPECTED
|
||||||
|
|
||||||
def test_twz_to_json_with_custom_time_precision
|
def test_twz_to_json_with_custom_time_precision
|
||||||
with_standard_json_time_format(true) do
|
with_standard_json_time_format(true) do
|
||||||
ActiveSupport::JSON::Encoding.time_precision = 0
|
with_time_precision(0) do
|
||||||
zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
|
zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
|
||||||
time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone)
|
time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone)
|
||||||
assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(time)
|
assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(time)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
ensure
|
|
||||||
ActiveSupport::JSON::Encoding.time_precision = 3
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_time_to_json_with_custom_time_precision
|
def test_time_to_json_with_custom_time_precision
|
||||||
with_standard_json_time_format(true) do
|
with_standard_json_time_format(true) do
|
||||||
ActiveSupport::JSON::Encoding.time_precision = 0
|
with_time_precision(0) do
|
||||||
assert_equal "\"2000-01-01T00:00:00Z\"", ActiveSupport::JSON.encode(Time.utc(2000))
|
assert_equal "\"2000-01-01T00:00:00Z\"", ActiveSupport::JSON.encode(Time.utc(2000))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
ensure
|
|
||||||
ActiveSupport::JSON::Encoding.time_precision = 3
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_datetime_to_json_with_custom_time_precision
|
def test_datetime_to_json_with_custom_time_precision
|
||||||
with_standard_json_time_format(true) do
|
with_standard_json_time_format(true) do
|
||||||
ActiveSupport::JSON::Encoding.time_precision = 0
|
with_time_precision(0) do
|
||||||
assert_equal "\"2000-01-01T00:00:00+00:00\"", ActiveSupport::JSON.encode(DateTime.new(2000))
|
assert_equal "\"2000-01-01T00:00:00+00:00\"", ActiveSupport::JSON.encode(DateTime.new(2000))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
ensure
|
|
||||||
ActiveSupport::JSON::Encoding.time_precision = 3
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_twz_to_json_when_wrapping_a_date_time
|
def test_twz_to_json_when_wrapping_a_date_time
|
||||||
|
@ -539,4 +536,12 @@ EXPECTED
|
||||||
ensure
|
ensure
|
||||||
ActiveSupport.use_standard_json_time_format = old
|
ActiveSupport.use_standard_json_time_format = old
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_time_precision(value)
|
||||||
|
old_value = ActiveSupport::JSON::Encoding.time_precision
|
||||||
|
ActiveSupport::JSON::Encoding.time_precision = value
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
ActiveSupport::JSON::Encoding.time_precision = old_value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue