aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/json
diff options
context:
space:
mode:
authorgbuesing <gbuesing@gmail.com>2008-05-18 10:48:11 -0500
committergbuesing <gbuesing@gmail.com>2008-05-18 10:48:11 -0500
commitbe85868987675a158fd4111393b9161296431728 (patch)
tree96550f51df56389008dde65bbfee092c2c5a279a /activesupport/test/json
parent0f333449bd47737a7260d7b9770a2bc50a373abb (diff)
downloadrails-be85868987675a158fd4111393b9161296431728.tar.gz
rails-be85868987675a158fd4111393b9161296431728.tar.bz2
rails-be85868987675a158fd4111393b9161296431728.zip
Time#to_json: don't convert to utc before encoding. References #175
Diffstat (limited to 'activesupport/test/json')
-rw-r--r--activesupport/test/json/encoding_test.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index 7bc8eaf06c..38bb8f3e79 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -90,6 +90,15 @@ class TestJSONEncoding < Test::Unit::TestCase
def test_hash_should_allow_key_filtering_with_except
assert_equal %({"b": 2}), { 'foo' => 'bar', :b => 2, :c => 3 }.to_json(:except => ['foo', :c])
end
+
+ def test_time_to_json_includes_local_offset
+ ActiveSupport.use_standard_json_time_format = true
+ with_env_tz 'US/Eastern' do
+ assert_equal %("2005-02-01T15:15:10-05:00"), Time.local(2005,2,1,15,15,10).to_json
+ end
+ ensure
+ ActiveSupport.use_standard_json_time_format = false
+ end
protected
def with_kcode(code)
@@ -108,6 +117,13 @@ class TestJSONEncoding < Test::Unit::TestCase
def object_keys(json_object)
json_object[1..-2].scan(/([^{}:,\s]+):/).flatten.sort
end
+
+ def with_env_tz(new_tz = 'US/Eastern')
+ old_tz, ENV['TZ'] = ENV['TZ'], new_tz
+ yield
+ ensure
+ old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ')
+ end
end
uses_mocha 'JsonOptionsTests' do