Permalink
Browse files

Fix `deserialize` with JSON array

Fixes #28285.
  • Loading branch information...
kamipo committed Mar 5, 2017
1 parent d731d63 commit 6ec2e8ac220024c6e8159c81dbe76ef8e812ed6f
@@ -1,3 +1,9 @@
* Fix `deserialize` with JSON array.
Fixes #28285.
*Ryuta Kamizono*
* Fix `rake db:schema:load` with subdirectories.
*Ryuta Kamizono*
@@ -23,7 +23,7 @@ def deserialize(value)
when ::String
type_cast_array(@pg_decoder.decode(value), :deserialize)
when Data
deserialize(value.values)
type_cast_array(value.values, :deserialize)
else
super
end
@@ -16,6 +16,7 @@ def setup
@connection.create_table("json_data_type") do |t|
t.public_send column_type, "payload", default: {} # t.json 'payload', default: {}
t.public_send column_type, "settings" # t.json 'settings'
t.public_send column_type, "objects", array: true # t.json 'objects', array: true
end
rescue ActiveRecord::StatementInvalid
skip "do not test on PostgreSQL without #{column_type} type."
@@ -75,6 +76,15 @@ def test_cast_value_on_write
assert_equal({ "string" => "foo", "symbol" => "bar" }, x.reload.payload)
end
def test_deserialize_with_array
x = JsonDataType.new(objects: ["foo" => "bar"])
assert_equal ["foo" => "bar"], x.objects
x.save!
assert_equal ["foo" => "bar"], x.objects
x.reload
assert_equal ["foo" => "bar"], x.objects
end
def test_type_cast_json
type = JsonDataType.type_for_attribute("payload")

0 comments on commit 6ec2e8a

Please sign in to comment.