From 6ec2e8ac220024c6e8159c81dbe76ef8e812ed6f Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sun, 5 Mar 2017 23:19:00 +0900 Subject: Fix `deserialize` with JSON array Fixes #28285. --- activerecord/test/cases/adapters/postgresql/json_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/adapters/postgresql/json_test.rb b/activerecord/test/cases/adapters/postgresql/json_test.rb index 93558ac4d2..d4e627001c 100644 --- a/activerecord/test/cases/adapters/postgresql/json_test.rb +++ b/activerecord/test/cases/adapters/postgresql/json_test.rb @@ -16,6 +16,7 @@ module PostgresqlJSONSharedTestCases @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 @@ module PostgresqlJSONSharedTestCases 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") -- cgit v1.2.3