diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-17 17:05:34 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-17 17:47:57 -0600 |
commit | ba29c28a47c8a8016f32cad8b7fcc6dbd0e06162 (patch) | |
tree | 97d739d6a0ae02ca88d18586c7ba8fdf2f6e0b95 /activerecord/test/cases | |
parent | 7f7e2f12ab835526c6914843b983619ed12c9b68 (diff) | |
download | rails-ba29c28a47c8a8016f32cad8b7fcc6dbd0e06162.tar.gz rails-ba29c28a47c8a8016f32cad8b7fcc6dbd0e06162.tar.bz2 rails-ba29c28a47c8a8016f32cad8b7fcc6dbd0e06162.zip |
Detect mutations of arrays and array members
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/array_test.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/array_test.rb b/activerecord/test/cases/adapters/postgresql/array_test.rb index 15901b389e..266592e2c7 100644 --- a/activerecord/test/cases/adapters/postgresql/array_test.rb +++ b/activerecord/test/cases/adapters/postgresql/array_test.rb @@ -16,6 +16,7 @@ class PostgresqlArrayTest < ActiveRecord::TestCase t.string 'tags', array: true t.integer 'ratings', array: true t.datetime :datetimes, array: true + t.hstore :hstores, array: true end end @column = PgArray.columns_hash['tags'] @@ -221,6 +222,28 @@ class PostgresqlArrayTest < ActiveRecord::TestCase assert_equal %({hello,;"world;"}), semicolon_delim.type_cast_for_database(strings) end + def test_mutate_array + x = PgArray.create!(tags: %w(one two)) + + x.tags << "three" + x.save! + x.reload + + assert_equal %w(one two three), x.tags + assert_not x.changed? + end + + def test_mutate_value_in_array + x = PgArray.create!(hstores: [{ a: 'a' }, { b: 'b' }]) + + x.hstores.first['a'] = 'c' + x.save! + x.reload + + assert_equal [{ 'a' => 'c' }, { 'b' => 'b' }], x.hstores + assert_not x.changed? + end + def test_datetime_with_timezone_awareness tz = "Pacific Time (US & Canada)" |