Skip to content

A platform for community discussion. Free, open, simple.

Fix invalid query syntax when `CategoryCustomField#value` is blank.

Guo Xiang Tan7a2bf8e36815
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