aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorEugene Kenny <elkenny@gmail.com>2017-01-15 01:06:46 +0000
committerEugene Kenny <elkenny@gmail.com>2017-01-15 01:06:46 +0000
commitafa2da6456c0e33c1c31dbbcee66f72fd8f32005 (patch)
tree5918203a6d02b9fca8bf62af44186d0816252914 /activerecord/test
parentaaece61a53dc943ac0e4b696c39ba61f46b7c7a3 (diff)
downloadrails-afa2da6456c0e33c1c31dbbcee66f72fd8f32005.tar.gz
rails-afa2da6456c0e33c1c31dbbcee66f72fd8f32005.tar.bz2
rails-afa2da6456c0e33c1c31dbbcee66f72fd8f32005.zip
Add test for update_counters with empty touch
This is a regression test for a fix included in https://github.com/rails/rails/commit/bad9bfbea6d6af9dc28583e08a49492668087393. Without that change, this test would fail with: ActiveRecord::StatementInvalid: SQLite3::SQLException: near "WHERE": syntax error: UPDATE "topics" SET "replies_count" = COALESCE("replies_count", 0) - 1, WHERE "topics"."id" = ?
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/counter_cache_test.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/test/cases/counter_cache_test.rb b/activerecord/test/cases/counter_cache_test.rb
index c7d0ba32b4..46d7526cc0 100644
--- a/activerecord/test/cases/counter_cache_test.rb
+++ b/activerecord/test/cases/counter_cache_test.rb
@@ -221,6 +221,15 @@ class CounterCacheTest < ActiveRecord::TestCase
assert_equal previously_updated_at, @topic.updated_at
end
+ test "update counters doesn't touch timestamps with touch: []" do
+ @topic.update_column :updated_at, 5.minutes.ago
+ previously_updated_at = @topic.updated_at
+
+ Topic.update_counters(@topic.id, replies_count: -1, touch: [])
+
+ assert_equal previously_updated_at, @topic.updated_at
+ end
+
test "update counters with touch: true" do
assert_touching @topic, :updated_at do
Topic.update_counters(@topic.id, replies_count: -1, touch: true)