mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 01:31:35 +08:00
FIX: ensures tags/categories are present (#28230)
Prior to this fix the query in stalled_topic_finder would assume that tags/categories would be nil or an array of ids. However it can be an empty array, in this case the query will not return results.
This commit is contained in:
@ -7,7 +7,7 @@ class DiscourseAutomation::StalledTopicFinder
|
|||||||
FROM topics t
|
FROM topics t
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
sql += <<~SQL if tags
|
sql += <<~SQL if tags.present?
|
||||||
JOIN topic_tags ON topic_tags.topic_id = t.id
|
JOIN topic_tags ON topic_tags.topic_id = t.id
|
||||||
JOIN tags
|
JOIN tags
|
||||||
ON tags.name IN (:tags)
|
ON tags.name IN (:tags)
|
||||||
@ -31,7 +31,7 @@ class DiscourseAutomation::StalledTopicFinder
|
|||||||
)
|
)
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
sql += <<~SQL if categories
|
sql += <<~SQL if categories.present?
|
||||||
AND t.category_id IN (:categories)
|
AND t.category_id IN (:categories)
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
|
@ -56,6 +56,14 @@ describe DiscourseAutomation::StalledTopicFinder do
|
|||||||
described_class.call(2.hours.from_now, tags: [tag_1.name]).map(&:id),
|
described_class.call(2.hours.from_now, tags: [tag_1.name]).map(&:id),
|
||||||
).to contain_exactly(topic_1.id)
|
).to contain_exactly(topic_1.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "still finds topics if tags is empty" do
|
||||||
|
create_post(topic: topic_4, user: user)
|
||||||
|
|
||||||
|
expect(described_class.call(2.hours.from_now, tags: []).map(&:id)).to contain_exactly(
|
||||||
|
topic_4.id,
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "filter by categories" do
|
describe "filter by categories" do
|
||||||
@ -80,6 +88,14 @@ describe DiscourseAutomation::StalledTopicFinder do
|
|||||||
described_class.call(2.hours.from_now, categories: [category_1.id]).map(&:id),
|
described_class.call(2.hours.from_now, categories: [category_1.id]).map(&:id),
|
||||||
).to contain_exactly(topic_1.id)
|
).to contain_exactly(topic_1.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "still finds topics if categories is empty" do
|
||||||
|
create_post(topic: topic_1, user: user)
|
||||||
|
|
||||||
|
expect(described_class.call(2.hours.from_now, categories: []).map(&:id)).to contain_exactly(
|
||||||
|
topic_1.id,
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "filter recent topic owner replies" do
|
describe "filter recent topic owner replies" do
|
||||||
|
Reference in New Issue
Block a user