diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2013-11-15 10:29:38 -0800 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2013-11-26 09:50:59 -0800 |
commit | ca12db0efbf07c1a3182556e99af4ebbfcd59dee (patch) | |
tree | 5b0e43b7bc2e7d41b7b7184d09455dcdb8e0c5f9 | |
parent | cfaa2aa99fbd2149872af1c43673cff97673f138 (diff) | |
download | rails-ca12db0efbf07c1a3182556e99af4ebbfcd59dee.tar.gz rails-ca12db0efbf07c1a3182556e99af4ebbfcd59dee.tar.bz2 rails-ca12db0efbf07c1a3182556e99af4ebbfcd59dee.zip |
Expanded coverage on JSON encoding
-rw-r--r-- | activesupport/test/json/encoding_test.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index c28a8a6c24..1e32830ced 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -22,7 +22,7 @@ class TestJSONEncoding < ActiveSupport::TestCase @serialized = serialized end - def as_json(options) + def as_json(options = nil) @serialized end end @@ -338,7 +338,7 @@ class TestJSONEncoding < ActiveSupport::TestCase assert_equal(%([{"address":{"city":"London"}},{"address":{"city":"Paris"}}]), json) end - def test_to_json_should_not_keep_options_around + def test_hash_to_json_should_not_keep_options_around f = CustomWithOptions.new f.foo = "hello" f.bar = "world" @@ -348,6 +348,16 @@ class TestJSONEncoding < ActiveSupport::TestCase "other_hash" => {"foo"=>"other_foo","test"=>"other_test"}}, ActiveSupport::JSON.decode(hash.to_json)) end + def test_array_to_json_should_not_keep_options_around + f = CustomWithOptions.new + f.foo = "hello" + f.bar = "world" + + array = [f, {"foo" => "other_foo", "test" => "other_test"}] + assert_equal([{"foo"=>"hello","bar"=>"world"}, + {"foo"=>"other_foo","test"=>"other_test"}], ActiveSupport::JSON.decode(array.to_json)) + end + def test_hash_as_json_without_options json = { foo: OptionsTest.new }.as_json assert_equal({"foo" => :default}, json) |