aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/json
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2014-01-26 21:09:06 +0000
committerAndrew White <andyw@pixeltrix.co.uk>2014-01-26 21:25:54 +0000
commitc0965004486f2ea5a9656ba718a3377c9614f97d (patch)
treeea749309291e3b1478ebdd6968ed7d1b8a70eec7 /activesupport/test/json
parent9484f4b821d90136b106cb7e0e3ebaad31493ee2 (diff)
downloadrails-c0965004486f2ea5a9656ba718a3377c9614f97d.tar.gz
rails-c0965004486f2ea5a9656ba718a3377c9614f97d.tar.bz2
rails-c0965004486f2ea5a9656ba718a3377c9614f97d.zip
Add support for JSON time_precision to Time and DateTime
Diffstat (limited to 'activesupport/test/json')
-rw-r--r--activesupport/test/json/encoding_test.rb20
1 files changed, 19 insertions, 1 deletions
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