Expanded coverage on JSON encoding
This commit is contained in:
parent
cfaa2aa99f
commit
ca12db0efb
@ -22,7 +22,7 @@ def initialize(serialized)
|
|||||||
@serialized = serialized
|
@serialized = serialized
|
||||||
end
|
end
|
||||||
|
|
||||||
def as_json(options)
|
def as_json(options = nil)
|
||||||
@serialized
|
@serialized
|
||||||
end
|
end
|
||||||
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)
|
assert_equal(%([{"address":{"city":"London"}},{"address":{"city":"Paris"}}]), json)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_to_json_should_not_keep_options_around
|
def test_hash_to_json_should_not_keep_options_around
|
||||||
f = CustomWithOptions.new
|
f = CustomWithOptions.new
|
||||||
f.foo = "hello"
|
f.foo = "hello"
|
||||||
f.bar = "world"
|
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))
|
"other_hash" => {"foo"=>"other_foo","test"=>"other_test"}}, ActiveSupport::JSON.decode(hash.to_json))
|
||||||
end
|
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
|
def test_hash_as_json_without_options
|
||||||
json = { foo: OptionsTest.new }.as_json
|
json = { foo: OptionsTest.new }.as_json
|
||||||
assert_equal({"foo" => :default}, json)
|
assert_equal({"foo" => :default}, json)
|
||||||
|
Loading…
Reference in New Issue
Block a user