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

This commit is contained in:
Guo Xiang Tan 2018-07-24 14:47:55 +08:00
parent 663d78414b
commit 7a2bf8e368
2 changed files with 8 additions and 1 deletions

View File

@ -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

View File

@ -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