From 7a2bf8e36815803abfb23b712fdeb4d268dd4abc Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 24 Jul 2018 14:47:55 +0800 Subject: [PATCH] Fix invalid query syntax when `CategoryCustomField#value` is blank. --- app/models/category.rb | 4 +++- spec/models/category_spec.rb | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/category.rb b/app/models/category.rb index ce12d3115f5..25535782d37 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -388,9 +388,10 @@ class Category < ActiveRecord::Base def self.auto_bump_topic! bumped = false + auto_bumps = CategoryCustomField .where(name: Category::NUM_AUTO_BUMP_DAILY) - .where('value::int > 0') + .where('NULLIF(value, \'\')::int > 0') .pluck(:category_id) if (auto_bumps.length > 0) @@ -399,6 +400,7 @@ class Category < ActiveRecord::Base break if bumped end end + bumped end diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index d116df07a63..89a66214a21 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -734,6 +734,11 @@ describe Category do category.auto_bump_limiter.clear! expect(Category.auto_bump_topic!).to eq(true) expect(Topic.where(bumped_at: time).count).to eq(1) + + category.num_auto_bump_daily = "" + category.save! + + expect(Category.auto_bump_topic!).to eq(false) end end