aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/json/decoding_test.rb
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2013-09-13 00:03:12 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2013-10-30 10:56:00 -0700
commit1fb79691548cd370e83625045a0a445c97fa0dea (patch)
tree2df3256b8da7efc52f4da3e13300562cdd9abfcc /activesupport/test/json/decoding_test.rb
parentdae66a0c9733a7fd2ba4357e24b03b386be3e38f (diff)
downloadrails-1fb79691548cd370e83625045a0a445c97fa0dea.tar.gz
rails-1fb79691548cd370e83625045a0a445c97fa0dea.tar.bz2
rails-1fb79691548cd370e83625045a0a445c97fa0dea.zip
Raise an error when AS::JSON.decode is called with options
Rails 4.1 has switched away from MultiJson, and does not currently support any options on `ActiveSupport::JSON.decode`. Passing in unsupported options (i.e. any non-empty options hash) will now raise an ArgumentError. Rationale: 1. We cannot guarantee the underlying JSON parser won't change in the future, hence we cannot guarantee a consistent set of options the method could take 2. The `json` gem, which happens to be the current JSON parser, takes many dangerous options that is irrelevant to the purpose of AS's JSON decoding API 3. To reserve the options hash for future use, e.g. overriding default global options like ActiveSupport.parse_json_times This change *DOES NOT* introduce any changes in the public API. The signature of the method is still decode(json_text, options). The difference is this method previously accepted undocumented options which does different things when the underlying adapter changes. It now correctly raises an ArgumentError when it encounters options that it does not recognize (and currently it does not support any options).
Diffstat (limited to 'activesupport/test/json/decoding_test.rb')
-rw-r--r--activesupport/test/json/decoding_test.rb6
1 files changed, 2 insertions, 4 deletions
diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb
index e9780b36e4..07d7e530ca 100644
--- a/activesupport/test/json/decoding_test.rb
+++ b/activesupport/test/json/decoding_test.rb
@@ -98,10 +98,8 @@ class TestJSONDecoding < ActiveSupport::TestCase
assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%()) }
end
- def test_cannot_force_json_unmarshalling
- encodeded = %q({"json_class":"TestJSONDecoding::Foo"})
- decodeded = {"json_class"=>"TestJSONDecoding::Foo"}
- assert_equal decodeded, ActiveSupport::JSON.decode(encodeded, create_additions: true)
+ def test_cannot_pass_unsupported_options
+ assert_raise(ArgumentError) { ActiveSupport::JSON.decode("", create_additions: true) }
end
end