Expanded coverage on JSON encoding

This commit is contained in:
Godfrey Chan 2013-11-15 10:29:38 -08:00
parent cfaa2aa99f
commit ca12db0efb

@ -22,7 +22,7 @@ def initialize(serialized)
@serialized = serialized
end
def as_json(options)
def as_json(options = nil)
@serialized
end
end
@ -338,7 +338,7 @@ def test_enumerable_should_pass_encoding_options_to_children_in_to_json
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 @@ def test_to_json_should_not_keep_options_around
"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)