mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-06-29 11:02:17 +00:00
DEV: add guardian
argument to TopicsFilter
callback (#1206)
To match the updates in discourse/discourse#31908
This commit is contained in:
parent
7e4f93724d
commit
2dd7068b46
@ -5,7 +5,7 @@ module DiscourseAi
|
|||||||
class EmotionFilterOrder
|
class EmotionFilterOrder
|
||||||
def self.register!(plugin)
|
def self.register!(plugin)
|
||||||
Emotions::LIST.each do |emotion|
|
Emotions::LIST.each do |emotion|
|
||||||
filter_order_emotion = ->(scope, order_direction) do
|
filter_order_emotion = ->(scope, order_direction, _guardian) do
|
||||||
scope_period =
|
scope_period =
|
||||||
scope
|
scope
|
||||||
.arel
|
.arel
|
||||||
|
@ -8,6 +8,7 @@ RSpec.describe DiscourseAi::Sentiment::EmotionFilterOrder do
|
|||||||
let(:post_1) { Fabricate(:post) }
|
let(:post_1) { Fabricate(:post) }
|
||||||
let(:post_2) { Fabricate(:post) }
|
let(:post_2) { Fabricate(:post) }
|
||||||
let(:post_3) { Fabricate(:post) }
|
let(:post_3) { Fabricate(:post) }
|
||||||
|
let(:guardian) { Guardian.new }
|
||||||
let(:classification_1) do
|
let(:classification_1) do
|
||||||
{
|
{
|
||||||
love: 0.9444406,
|
love: 0.9444406,
|
||||||
@ -179,7 +180,7 @@ RSpec.describe DiscourseAi::Sentiment::EmotionFilterOrder do
|
|||||||
.find { _1.keys.include? "order:emotion_#{emotion}" }
|
.find { _1.keys.include? "order:emotion_#{emotion}" }
|
||||||
.values
|
.values
|
||||||
.first
|
.first
|
||||||
result = filter.call(scope, order_direction)
|
result = filter.call(scope, order_direction, guardian)
|
||||||
|
|
||||||
expect(result.to_sql).to include("classification_results")
|
expect(result.to_sql).to include("classification_results")
|
||||||
expect(result.to_sql).to include(
|
expect(result.to_sql).to include(
|
||||||
@ -190,18 +191,12 @@ RSpec.describe DiscourseAi::Sentiment::EmotionFilterOrder do
|
|||||||
|
|
||||||
it "sorts emotion in ascending order" do
|
it "sorts emotion in ascending order" do
|
||||||
expect(
|
expect(
|
||||||
TopicsFilter
|
TopicsFilter.new(guardian:).filter_from_query_string("order:emotion_love-asc").pluck(:id),
|
||||||
.new(guardian: Guardian.new)
|
|
||||||
.filter_from_query_string("order:emotion_love-asc")
|
|
||||||
.pluck(:id),
|
|
||||||
).to contain_exactly(post_2.topic.id, post_1.topic.id)
|
).to contain_exactly(post_2.topic.id, post_1.topic.id)
|
||||||
end
|
end
|
||||||
it "sorts emotion in default descending order" do
|
it "sorts emotion in default descending order" do
|
||||||
expect(
|
expect(
|
||||||
TopicsFilter
|
TopicsFilter.new(guardian:).filter_from_query_string("order:emotion_love").pluck(:id),
|
||||||
.new(guardian: Guardian.new)
|
|
||||||
.filter_from_query_string("order:emotion_love")
|
|
||||||
.pluck(:id),
|
|
||||||
).to contain_exactly(post_1.topic.id, post_2.topic.id)
|
).to contain_exactly(post_1.topic.id, post_2.topic.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user