diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-12 15:13:28 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-13 14:07:41 -0600 |
commit | 4bf8ffc6516312e68fb0d2b4ac97505f8d0cf192 (patch) | |
tree | 239a8205dc68ac3bada7a2712f52f2defa159f00 /activerecord/test/cases/adapters | |
parent | 8a3046133aba188d81f31b034d6594899b23c70c (diff) | |
download | rails-4bf8ffc6516312e68fb0d2b4ac97505f8d0cf192.tar.gz rails-4bf8ffc6516312e68fb0d2b4ac97505f8d0cf192.tar.bz2 rails-4bf8ffc6516312e68fb0d2b4ac97505f8d0cf192.zip |
Detect in-place changes on mutable AR attributes
We have several mutable types on Active Record now. (Serialized, JSON,
HStore). We need to be able to detect if these have been modified in
place.
Diffstat (limited to 'activerecord/test/cases/adapters')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/hstore_test.rb | 9 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/json_test.rb | 20 |
2 files changed, 29 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/hstore_test.rb b/activerecord/test/cases/adapters/postgresql/hstore_test.rb index a25c9cb5e4..83b495d600 100644 --- a/activerecord/test/cases/adapters/postgresql/hstore_test.rb +++ b/activerecord/test/cases/adapters/postgresql/hstore_test.rb @@ -163,6 +163,15 @@ class PostgresqlHstoreTest < ActiveRecord::TestCase assert_equal "GMT", y.timezone end + def test_changes_in_place + hstore = Hstore.create!(settings: { 'one' => 'two' }) + hstore.settings['three'] = 'four' + hstore.save! + hstore.reload + + assert_equal 'four', hstore.settings['three'] + end + def test_gen1 assert_equal(%q(" "=>""), @column.class.hstore_to_string({' '=>''})) end diff --git a/activerecord/test/cases/adapters/postgresql/json_test.rb b/activerecord/test/cases/adapters/postgresql/json_test.rb index 3ee8839823..a3400a5a19 100644 --- a/activerecord/test/cases/adapters/postgresql/json_test.rb +++ b/activerecord/test/cases/adapters/postgresql/json_test.rb @@ -165,4 +165,24 @@ class PostgresqlJSONTest < ActiveRecord::TestCase JsonDataType.update_all payload: { } assert_equal({ }, json.reload.payload) end + + def test_changes_in_place + json = JsonDataType.new + assert_not json.changed? + + json.payload = { 'one' => 'two' } + assert json.changed? + assert json.payload_changed? + + json.save! + assert_not json.changed? + + json.payload['three'] = 'four' + assert json.payload_changed? + + json.save! + json.reload + + assert json.payload['three'] = 'four' + end end |