aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZuhao Wan <wanzuhao@gmail.com>2014-06-22 18:36:07 +0800
committerZuhao Wan <wanzuhao@gmail.com>2014-06-22 18:36:07 +0800
commit42b33590f36f9d31486c1de506f417070fd96d7b (patch)
tree1f58a91112178d5e1acced8aec1096f5c129cdc5
parent0e9a7059664eb9dee8e3afae60d26ff858d0d84b (diff)
downloadrails-42b33590f36f9d31486c1de506f417070fd96d7b.tar.gz
rails-42b33590f36f9d31486c1de506f417070fd96d7b.tar.bz2
rails-42b33590f36f9d31486c1de506f417070fd96d7b.zip
Avoid hardcoded magic number in test teardown.
-rw-r--r--activesupport/test/json/encoding_test.rb33
1 files changed, 19 insertions, 14 deletions
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index b4cf37b177..ad358ad21d 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -494,31 +494,28 @@ EXPECTED
def test_twz_to_json_with_custom_time_precision
with_standard_json_time_format(true) do
- ActiveSupport::JSON::Encoding.time_precision = 0
- zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
- time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone)
- assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(time)
+ with_time_precision(0) do
+ zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
+ time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone)
+ assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(time)
+ end
end
- ensure
- ActiveSupport::JSON::Encoding.time_precision = 3
end
def test_time_to_json_with_custom_time_precision
with_standard_json_time_format(true) do
- ActiveSupport::JSON::Encoding.time_precision = 0
- assert_equal "\"2000-01-01T00:00:00Z\"", ActiveSupport::JSON.encode(Time.utc(2000))
+ with_time_precision(0) do
+ assert_equal "\"2000-01-01T00:00:00Z\"", ActiveSupport::JSON.encode(Time.utc(2000))
+ end
end
- ensure
- ActiveSupport::JSON::Encoding.time_precision = 3
end
def test_datetime_to_json_with_custom_time_precision
with_standard_json_time_format(true) do
- ActiveSupport::JSON::Encoding.time_precision = 0
- assert_equal "\"2000-01-01T00:00:00+00:00\"", ActiveSupport::JSON.encode(DateTime.new(2000))
+ with_time_precision(0) do
+ assert_equal "\"2000-01-01T00:00:00+00:00\"", ActiveSupport::JSON.encode(DateTime.new(2000))
+ end
end
- ensure
- ActiveSupport::JSON::Encoding.time_precision = 3
end
def test_twz_to_json_when_wrapping_a_date_time
@@ -539,4 +536,12 @@ EXPECTED
ensure
ActiveSupport.use_standard_json_time_format = old
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