diff options
author | akihiro17 <coolwizard11@gmail.com> | 2017-01-13 01:55:29 +0900 |
---|---|---|
committer | akihiro17 <coolwizard11@gmail.com> | 2017-01-14 01:00:33 +0900 |
commit | bad9bfbea6d6af9dc28583e08a49492668087393 (patch) | |
tree | c7004fc8d7149ff0cda205e3d67a9f831a992ea7 /activerecord/test | |
parent | aa0a3d26e338dd293a632e99e815e5ca6fad0d58 (diff) | |
download | rails-bad9bfbea6d6af9dc28583e08a49492668087393.tar.gz rails-bad9bfbea6d6af9dc28583e08a49492668087393.tar.bz2 rails-bad9bfbea6d6af9dc28583e08a49492668087393.zip |
Add the touch option to ActiveRecord#increment! and decrement!
Supports the `touch` option from update_counters.
The default behavior is not to update timestamp columns.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/persistence_test.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index 3f1da82cb4..5b7e2fd008 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -139,6 +139,14 @@ class PersistenceTest < ActiveRecord::TestCase assert_equal initial_credit + 2, a1.reload.credit_limit end + def test_increment_updates_timestamps + topic = topics(:first) + topic.update_columns(updated_at: 5.minutes.ago) + previous_updated_at = topic.updated_at + topic.increment!(:replies_count, touch: true) + assert_operator previous_updated_at, :<, topic.reload.updated_at + end + def test_destroy_all conditions = "author_name = 'Mary'" topics_by_mary = Topic.all.merge!(where: conditions, order: "id").to_a @@ -230,6 +238,14 @@ class PersistenceTest < ActiveRecord::TestCase assert_equal 41, accounts(:signals37, :reload).credit_limit end + def test_decrement_updates_timestamps + topic = topics(:first) + topic.update_columns(updated_at: 5.minutes.ago) + previous_updated_at = topic.updated_at + topic.decrement!(:replies_count, touch: true) + assert_operator previous_updated_at, :<, topic.reload.updated_at + end + def test_create topic = Topic.new topic.title = "New Topic" |