mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:44:49 +08:00
DEV: Introduced topic_query_create_list_topics modifier (#21016)
Introduced a modifier on topic_query to change list while they're created Co-authored-by: Jarek Radosz <jradosz@gmail.com>
This commit is contained in:
parent
18470c9195
commit
f8fb7ee9f3
|
@ -460,6 +460,8 @@ class TopicQuery
|
|||
options[:filter] ||= filter
|
||||
topics ||= default_results(options)
|
||||
topics = yield(topics) if block_given?
|
||||
topics =
|
||||
DiscoursePluginRegistry.apply_modifier(:topic_query_create_list_topics, topics, options, self)
|
||||
|
||||
options = options.merge(@options)
|
||||
if %w[activity default].include?(options[:order] || "activity") && !options[:unordered] &&
|
||||
|
|
|
@ -1940,4 +1940,29 @@ RSpec.describe TopicQuery do
|
|||
).to contain_exactly(category.topic_id, subcategory.topic_id, subcategory_regular_topic.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "with topic_query_create_list_topics modifier" do
|
||||
fab!(:topic1) { Fabricate(:topic, created_at: 3.days.ago, bumped_at: 1.hour.ago) }
|
||||
fab!(:topic2) { Fabricate(:topic, created_at: 2.days.ago, bumped_at: 3.hour.ago) }
|
||||
|
||||
after { DiscoursePluginRegistry.clear_modifiers! }
|
||||
|
||||
it "allows changing" do
|
||||
original_topic_query = TopicQuery.new(user)
|
||||
|
||||
Plugin::Instance
|
||||
.new
|
||||
.register_modifier(:topic_query_create_list_topics) do |topics, options, topic_query|
|
||||
expect(topic_query).to eq(topic_query)
|
||||
topic_query.options[:order] = "created"
|
||||
topics
|
||||
end
|
||||
|
||||
expect(original_topic_query.list_latest.topics.map(&:id)).to eq([topic1, topic2].map(&:id))
|
||||
|
||||
DiscoursePluginRegistry.clear_modifiers!
|
||||
|
||||
expect(original_topic_query.list_latest.topics.map(&:id)).to eq([topic2, topic1].map(&:id))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user