Skip to content

Commit

Permalink
DEV: lint & add tests for assigns_reminder_assigned_topics_query
Browse files Browse the repository at this point in the history
Linted and added tests for `assigns_reminder_assigned_topics_query` modifier.
  • Loading branch information
Grubba27 committed Apr 25, 2024
1 parent e102d82 commit 3e0a596
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
13 changes: 6 additions & 7 deletions app/lib/plugin_initializer.rb
Expand Up @@ -14,16 +14,15 @@ def apply_plugin_api
end
end

class AssignsRemainderForTopicsQuery < PluginInitializer
class AssignsReminderForTopicsQuery < PluginInitializer
def apply_plugin_api
plugin.register_modifier(:assigns_reminder_assigned_topics_query) do |query|
next query if !SiteSetting.ignore_solved_topics_in_assigned_reminder
query.where(
"topics.id NOT IN (
SELECT topic_id
FROM topic_custom_fields
WHERE name = 'accepted_answer_post_id'
)",
query.where.not(
id:
TopicCustomField.where(
name: ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD,
).pluck(:topic_id),
)
end
end
Expand Down
2 changes: 2 additions & 0 deletions plugin.rb
Expand Up @@ -47,6 +47,8 @@ class Engine < ::Rails::Engine
require_relative "app/lib/web_hook_extension"
require_relative "app/serializers/concerns/topic_answer_mixin"

require_relative "app/lib/plugin_initializer"
DiscourseSolved::AssignsReminderForTopicsQuery.new(self).apply_plugin_api
module ::DiscourseSolved
def self.accept_answer!(post, acting_user, topic: nil)
topic ||= post.topic
Expand Down
26 changes: 26 additions & 0 deletions spec/integration/solved_spec.rb
Expand Up @@ -397,4 +397,30 @@
expect(p1.topic.assignment.reload.status).to eq("Done")
end
end

context "with using assigns_reminder_assigned_topics_query modifier" do
class DummyClass
def test
DiscoursePluginRegistry.apply_modifier(:assigns_reminder_assigned_topics_query, Topic.all)
end
end

before { SiteSetting.ignore_solved_topics_in_assigned_reminder = true }

it "should not include solved topics in the query" do
topic = Fabricate(:topic)
topic2 = Fabricate(:topic)
topic3 = Fabricate(:topic)
post = Fabricate(:post, topic: topic)

DiscourseSolved.accept_answer!(post, Discourse.system_user)

topics = DummyClass.new.test.to_a

expect(topics).not_to include(topic)

expect(topics).to include(topic2)
expect(topics).to include(topic3)
end
end
end

0 comments on commit 3e0a596

Please sign in to comment.