aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAndrew White <pixeltrix@users.noreply.github.com>2017-03-06 11:00:46 +0000
committerGitHub <noreply@github.com>2017-03-06 11:00:46 +0000
commit0b5c7e354291bdf674fa8777b6443b224924bad4 (patch)
tree7167b977441ff5eb0f713ddda50f7739eeb2c7be /activerecord
parent99e4ed78b90c9df76b5444edf61575e2bfab1f85 (diff)
parent6ec2e8ac220024c6e8159c81dbe76ef8e812ed6f (diff)
downloadrails-0b5c7e354291bdf674fa8777b6443b224924bad4.tar.gz
rails-0b5c7e354291bdf674fa8777b6443b224924bad4.tar.bz2
rails-0b5c7e354291bdf674fa8777b6443b224924bad4.zip
Merge pull request #28295 from kamipo/fix_deserialize_with_json_array
Fix `deserialize` with JSON array
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md6
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb2
-rw-r--r--activerecord/test/cases/adapters/postgresql/json_test.rb10
3 files changed, 17 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index abc415ea14..b2c57e792f 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,9 @@
+* Fix `deserialize` with JSON array.
+
+ Fixes #28285.
+
+ *Ryuta Kamizono*
+
* Fix `rake db:schema:load` with subdirectories.
*Ryuta Kamizono*
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb
index e1a75f8e5e..a73a8c1726 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb
@@ -23,7 +23,7 @@ module ActiveRecord
when ::String
type_cast_array(@pg_decoder.decode(value), :deserialize)
when Data
- deserialize(value.values)
+ type_cast_array(value.values, :deserialize)
else
super
end
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")