diff options
author | Tadas Tamosauskas <tadas@pdfcv.com> | 2013-09-28 16:10:59 +0100 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-12-23 16:27:54 -0200 |
commit | 73bba4c1e1f7fa23aa1a126971338d94ae42398f (patch) | |
tree | 27ac306d20b5f6216e838314025f7218633dfdea /activerecord/test | |
parent | 56510091fb8d178ec7c2391bed9fbdb9e3a54287 (diff) | |
download | rails-73bba4c1e1f7fa23aa1a126971338d94ae42398f.tar.gz rails-73bba4c1e1f7fa23aa1a126971338d94ae42398f.tar.bz2 rails-73bba4c1e1f7fa23aa1a126971338d94ae42398f.zip |
Serialize postgres' hstore, json and array types correctly in AR update methods.
Fixes #12261. Closes #12395.
Conflicts:
activerecord/CHANGELOG.md
activerecord/test/cases/adapters/postgresql/array_test.rb
activerecord/test/cases/adapters/postgresql/json_test.rb
Diffstat (limited to 'activerecord/test')
3 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/array_test.rb b/activerecord/test/cases/adapters/postgresql/array_test.rb index b0870e2256..cf059d20e2 100644 --- a/activerecord/test/cases/adapters/postgresql/array_test.rb +++ b/activerecord/test/cases/adapters/postgresql/array_test.rb @@ -128,6 +128,12 @@ class PostgresqlArrayTest < ActiveRecord::TestCase assert_equal("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...]", record.attribute_for_inspect(:ratings)) end + def test_update_all + PgArray.create! tags: ["one", "two", "three"] + PgArray.update_all tags: ["four", "five"] + assert_equal ["four", "five"], PgArray.first.tags + end + private def assert_cycle field, array # test creation diff --git a/activerecord/test/cases/adapters/postgresql/hstore_test.rb b/activerecord/test/cases/adapters/postgresql/hstore_test.rb index 2845413575..730020b5c8 100644 --- a/activerecord/test/cases/adapters/postgresql/hstore_test.rb +++ b/activerecord/test/cases/adapters/postgresql/hstore_test.rb @@ -206,6 +206,12 @@ class PostgresqlHstoreTest < ActiveRecord::TestCase def test_multiline assert_cycle("a\nb" => "c\nd") end + + def test_update_all + Hstore.create! tags: { "one" => "two" } + Hstore.update_all tags: { "three" => "four" } + assert_equal({ "three" => "four" }, Hstore.first.tags) + end end private diff --git a/activerecord/test/cases/adapters/postgresql/json_test.rb b/activerecord/test/cases/adapters/postgresql/json_test.rb index c33c7ef968..10efa8b802 100644 --- a/activerecord/test/cases/adapters/postgresql/json_test.rb +++ b/activerecord/test/cases/adapters/postgresql/json_test.rb @@ -121,4 +121,10 @@ class PostgresqlJSONTest < ActiveRecord::TestCase x = JsonDataType.first assert_equal "640×1136", x.resolution end + + def test_update_all + JsonDataType.create! payload: { "one" => "two" } + JsonDataType.update_all payload: { "three" => "four" } + assert_equal({ "three" => "four" }, JsonDataType.first.payload) + end end |