diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2013-11-05 21:01:38 -0800 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2013-11-06 17:16:11 -0800 |
commit | 798881ecd4510b9e1e5e10529fc2d81b9deb961e (patch) | |
tree | 5518edc1602caa1f36985f9ea8f9a725fa99fed2 /activesupport/test/json | |
parent | 6da5ff45c6d69912fb96870f31aaf0c0590fa212 (diff) | |
download | rails-798881ecd4510b9e1e5e10529fc2d81b9deb961e.tar.gz rails-798881ecd4510b9e1e5e10529fc2d81b9deb961e.tar.bz2 rails-798881ecd4510b9e1e5e10529fc2d81b9deb961e.zip |
Do not expose internal state in the public encoder API (i.e. as_json)
See [1] for why this is not a good idea.
As part of this refactor, circular reference protection in as_json has
been removed and the corresponding error class has been deprecated.
As discussed with @jeremy, circular reference error is considered
programmer errors and protecting against it is out of scope for
the encoder.
This is again based on the excellent work by @sergiocampama in #11728.
[1]: https://github.com/intridea/multi_json/pull/138#issuecomment-24468223
Diffstat (limited to 'activesupport/test/json')
-rw-r--r-- | activesupport/test/json/encoding_test.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 99120f1d2a..11a2ca9d90 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -146,19 +146,25 @@ class TestJSONEncoding < ActiveSupport::TestCase def test_exception_raised_when_encoding_circular_reference_in_array a = [1] a << a - assert_raise(ActiveSupport::JSON::Encoding::CircularReferenceError) { ActiveSupport::JSON.encode(a) } + assert_deprecated do + assert_raise(ActiveSupport::JSON::Encoding::CircularReferenceError) { ActiveSupport::JSON.encode(a) } + end end def test_exception_raised_when_encoding_circular_reference_in_hash a = { :name => 'foo' } a[:next] = a - assert_raise(ActiveSupport::JSON::Encoding::CircularReferenceError) { ActiveSupport::JSON.encode(a) } + assert_deprecated do + assert_raise(ActiveSupport::JSON::Encoding::CircularReferenceError) { ActiveSupport::JSON.encode(a) } + end end def test_exception_raised_when_encoding_circular_reference_in_hash_inside_array a = { :name => 'foo', :sub => [] } a[:sub] << a - assert_raise(ActiveSupport::JSON::Encoding::CircularReferenceError) { ActiveSupport::JSON.encode(a) } + assert_deprecated do + assert_raise(ActiveSupport::JSON::Encoding::CircularReferenceError) { ActiveSupport::JSON.encode(a) } + end end def test_hash_key_identifiers_are_always_quoted |