mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
DEV: Allow additional TopicList preloaded associations (#18891)
This provides a means to allow additional associations to be preloaded when generating a TopicList.
This commit is contained in:
@ -919,6 +919,22 @@ RSpec.describe TopicQuery do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when preloading associations' do
|
||||
it "preloads associations" do
|
||||
DiscoursePluginRegistry.register_topic_preloader_association(:first_post, Plugin::Instance.new)
|
||||
|
||||
topic = Fabricate(:topic)
|
||||
Fabricate(:post, topic: topic)
|
||||
|
||||
new_topic = topic_query.list_new.topics.first
|
||||
expect(new_topic.association(:image_upload).loaded?).to eq(true) # Preloaded by default
|
||||
expect(new_topic.association(:first_post).loaded?).to eq(true) # Testing a user-defined preloaded association
|
||||
expect(new_topic.association(:user).loaded?).to eq(false) # Testing the negative
|
||||
|
||||
DiscoursePluginRegistry.reset_register!(:topic_preloader_associations)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a new topic' do
|
||||
let!(:new_topic) { Fabricate(:topic, user: creator, bumped_at: 10.minutes.ago) }
|
||||
let(:topics) { topic_query.list_new.topics }
|
||||
|
Reference in New Issue
Block a user