aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/json/encoding_test.rb
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2013-11-22 11:01:40 -0800
committerGodfrey Chan <godfreykfc@gmail.com>2013-11-22 11:01:40 -0800
commit663c059d4a043e0baabb69e60436bb849eb620fb (patch)
tree9b91d30c4880500da68a613a6ff4ed8474928897 /activesupport/test/json/encoding_test.rb
parent34c08d2ead9360e1d9577dbc491d221ab66a2151 (diff)
downloadrails-663c059d4a043e0baabb69e60436bb849eb620fb.tar.gz
rails-663c059d4a043e0baabb69e60436bb849eb620fb.tar.bz2
rails-663c059d4a043e0baabb69e60436bb849eb620fb.zip
When Array#as_json and Hash#as_json are called without options, they
should also call #as_json on the children without options (instead of nil)
Diffstat (limited to 'activesupport/test/json/encoding_test.rb')
-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 39da760bf2..00f43be6d4 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -32,6 +32,12 @@ class TestJSONEncoding < ActiveSupport::TestCase
end
end
+ class OptionsTest
+ def as_json(options = :default)
+ options
+ end
+ end
+
class HashWithAsJson < Hash
attr_accessor :as_json_called
@@ -332,6 +338,16 @@ class TestJSONEncoding < ActiveSupport::TestCase
"other_hash" => {"foo"=>"other_foo","test"=>"other_test"}}, ActiveSupport::JSON.decode(hash.to_json))
end
+ def test_hash_as_json_without_options
+ json = { foo: OptionsTest.new }.as_json
+ assert_equal({"foo" => :default}, json)
+ end
+
+ def test_array_as_json_without_options
+ json = [ OptionsTest.new ].as_json
+ assert_equal([:default], json)
+ end
+
def test_struct_encoding
Struct.new('UserNameAndEmail', :name, :email)
Struct.new('UserNameAndDate', :name, :date)