Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 2dd7068

Browse files
authored
DEV: add guardian argument to TopicsFilter callback (#1206)
To match the updates in discourse/discourse#31908
1 parent 7e4f937 commit 2dd7068

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

lib/sentiment/emotion_filter_order.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Sentiment
55
class EmotionFilterOrder
66
def self.register!(plugin)
77
Emotions::LIST.each do |emotion|
8-
filter_order_emotion = ->(scope, order_direction) do
8+
filter_order_emotion = ->(scope, order_direction, _guardian) do
99
scope_period =
1010
scope
1111
.arel

spec/lib/modules/sentiment/emotion_filter_order_spec.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
let(:post_1) { Fabricate(:post) }
99
let(:post_2) { Fabricate(:post) }
1010
let(:post_3) { Fabricate(:post) }
11+
let(:guardian) { Guardian.new }
1112
let(:classification_1) do
1213
{
1314
love: 0.9444406,
@@ -179,7 +180,7 @@
179180
.find { _1.keys.include? "order:emotion_#{emotion}" }
180181
.values
181182
.first
182-
result = filter.call(scope, order_direction)
183+
result = filter.call(scope, order_direction, guardian)
183184

184185
expect(result.to_sql).to include("classification_results")
185186
expect(result.to_sql).to include(
@@ -190,18 +191,12 @@
190191

191192
it "sorts emotion in ascending order" do
192193
expect(
193-
TopicsFilter
194-
.new(guardian: Guardian.new)
195-
.filter_from_query_string("order:emotion_love-asc")
196-
.pluck(:id),
194+
TopicsFilter.new(guardian:).filter_from_query_string("order:emotion_love-asc").pluck(:id),
197195
).to contain_exactly(post_2.topic.id, post_1.topic.id)
198196
end
199197
it "sorts emotion in default descending order" do
200198
expect(
201-
TopicsFilter
202-
.new(guardian: Guardian.new)
203-
.filter_from_query_string("order:emotion_love")
204-
.pluck(:id),
199+
TopicsFilter.new(guardian:).filter_from_query_string("order:emotion_love").pluck(:id),
205200
).to contain_exactly(post_1.topic.id, post_2.topic.id)
206201
end
207202
end

0 commit comments

Comments
 (0)