Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sentiment/emotion_filter_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Sentiment
class EmotionFilterOrder
def self.register!(plugin)
Emotions::LIST.each do |emotion|
filter_order_emotion = ->(scope, order_direction) do
filter_order_emotion = ->(scope, order_direction, _guardian) do
scope_period =
scope
.arel
Expand Down
13 changes: 4 additions & 9 deletions spec/lib/modules/sentiment/emotion_filter_order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
let(:post_1) { Fabricate(:post) }
let(:post_2) { Fabricate(:post) }
let(:post_3) { Fabricate(:post) }
let(:guardian) { Guardian.new }
let(:classification_1) do
{
love: 0.9444406,
Expand Down Expand Up @@ -179,7 +180,7 @@
.find { _1.keys.include? "order:emotion_#{emotion}" }
.values
.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(
Expand All @@ -190,18 +191,12 @@

it "sorts emotion in ascending order" do
expect(
TopicsFilter
.new(guardian: Guardian.new)
.filter_from_query_string("order:emotion_love-asc")
.pluck(:id),
TopicsFilter.new(guardian:).filter_from_query_string("order:emotion_love-asc").pluck(:id),
).to contain_exactly(post_2.topic.id, post_1.topic.id)
end
it "sorts emotion in default descending order" do
expect(
TopicsFilter
.new(guardian: Guardian.new)
.filter_from_query_string("order:emotion_love")
.pluck(:id),
TopicsFilter.new(guardian:).filter_from_query_string("order:emotion_love").pluck(:id),
).to contain_exactly(post_1.topic.id, post_2.topic.id)
end
end
Loading