diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-06-22 13:47:25 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-06-22 13:47:25 +0200 |
commit | e32dade8666d8a79463becf651956d57ce6f6710 (patch) | |
tree | cca0ef10f99ba6b51f8277335e12d44d52112471 /activesupport | |
parent | 213e73dda3580d553c022a1e01565ac1e026d162 (diff) | |
parent | 17ad556a3f3918612fcebafbfec21e32d44b83f5 (diff) | |
download | rails-e32dade8666d8a79463becf651956d57ce6f6710.tar.gz rails-e32dade8666d8a79463becf651956d57ce6f6710.tar.bz2 rails-e32dade8666d8a79463becf651956d57ce6f6710.zip |
Merge pull request #15856 from zuhao/refactor_activesupport_decoding_test
Use with_parse_json_times helper in tests.
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/test/json/decoding_test.rb | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 07d7e530ca..80bf255080 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -73,22 +73,20 @@ class TestJSONDecoding < ActiveSupport::TestCase TESTS.each_with_index do |(json, expected), index| test "json decodes #{index}" do - prev = ActiveSupport.parse_json_times - ActiveSupport.parse_json_times = true - silence_warnings do - assert_equal expected, ActiveSupport::JSON.decode(json), "JSON decoding \ - failed for #{json}" + with_parse_json_times(true) do + silence_warnings do + assert_equal expected, ActiveSupport::JSON.decode(json), "JSON decoding \ + failed for #{json}" + end end - ActiveSupport.parse_json_times = prev end end test "json decodes time json with time parsing disabled" do - prev = ActiveSupport.parse_json_times - ActiveSupport.parse_json_times = false - expected = {"a" => "2007-01-01 01:12:34 Z"} - assert_equal expected, ActiveSupport::JSON.decode(%({"a": "2007-01-01 01:12:34 Z"})) - ActiveSupport.parse_json_times = prev + with_parse_json_times(false) do + expected = {"a" => "2007-01-01 01:12:34 Z"} + assert_equal expected, ActiveSupport::JSON.decode(%({"a": "2007-01-01 01:12:34 Z"})) + end end def test_failed_json_decoding @@ -101,5 +99,15 @@ class TestJSONDecoding < ActiveSupport::TestCase def test_cannot_pass_unsupported_options assert_raise(ArgumentError) { ActiveSupport::JSON.decode("", create_additions: true) } end + + private + + def with_parse_json_times(value) + old_value = ActiveSupport.parse_json_times + ActiveSupport.parse_json_times = value + yield + ensure + ActiveSupport.parse_json_times = old_value + end end |