From c0965004486f2ea5a9656ba718a3377c9614f97d Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 26 Jan 2014 21:09:06 +0000 Subject: Add support for JSON time_precision to Time and DateTime --- activesupport/test/json/encoding_test.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'activesupport/test/json') diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 52d2708d1e..c4283ee79a 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -474,7 +474,25 @@ EXPECTED assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(time) end ensure - ActiveSupport::JSON::Encoding.time_precision = nil + 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)) + 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)) + end + ensure + ActiveSupport::JSON::Encoding.time_precision = 3 end def test_twz_to_json_when_wrapping_a_date_time -- cgit v1.2.3