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

Commit dc7977a

Browse files
committed
DEV: Update solved report due to changes in solved plugin
1 parent 7e4f937 commit dc7977a

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

lib/automation/report_context_generator.rb

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,11 @@ def initialize(
6565
@posts = @posts.where(topic_id: topic_ids_with_tags)
6666
end
6767

68-
@solutions = {}
69-
if defined?(::DiscourseSolved)
70-
TopicCustomField
71-
.where(name: ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD)
68+
@solutions =
69+
DiscourseSolved::SolvedTopic
7270
.where(topic_id: @posts.select(:topic_id))
73-
.pluck(:topic_id, :value)
74-
.each do |topic_id, post_id|
75-
@solutions[topic_id] ||= Set.new
76-
@solutions[topic_id] << post_id.to_i
77-
end
78-
end
71+
.pluck(:topic_id, :answer_post_id)
72+
.to_h
7973
end
8074

8175
def format_topic(topic)
@@ -97,9 +91,7 @@ def format_post(post)
9791
buffer = []
9892
buffer << ""
9993
buffer << "post_number: #{post.post_number}"
100-
if @solutions.key?(post.topic_id) && @solutions[post.topic_id].include?(post.id)
101-
buffer << "solution: true"
102-
end
94+
buffer << "solution: true" if @solutions[post.topic_id] == post.id
10395
buffer << post.created_at.strftime("%Y-%m-%d %H:%M")
10496
buffer << "user: #{post.user&.username}"
10597
buffer << "likes: #{post.like_count}"

spec/lib/modules/automation/report_context_generator_spec.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ module Automation
4545

4646
if defined?(::DiscourseSolved)
4747
it "will correctly denote solved topics" do
48-
topic_with_likes.custom_fields[
49-
::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD
50-
] = post_with_likes2.id
51-
topic_with_likes.save_custom_fields
48+
Fabricate(:solved_topic, topic: topic_with_likes, answer_post: post_with_likes2)
5249

5350
context = ReportContextGenerator.generate(start_date: 1.day.ago, duration: 2.day)
5451

0 commit comments

Comments
 (0)