From afa2da6456c0e33c1c31dbbcee66f72fd8f32005 Mon Sep 17 00:00:00 2001 From: Eugene Kenny Date: Sun, 15 Jan 2017 01:06:46 +0000 Subject: 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" = ? --- activerecord/test/cases/counter_cache_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activerecord') 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) -- cgit v1.2.3