mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: ability to register custom filters for posts (#12938)
Allow plugins to extend TopicView to filter posts
This commit is contained in:
committed by
GitHub
parent
f337d59ed9
commit
a4bd1806d9
@@ -55,6 +55,29 @@ describe TopicView do
|
||||
end
|
||||
end
|
||||
|
||||
context 'custom filters' do
|
||||
fab!(:p0) { Fabricate(:post, topic: topic) }
|
||||
fab!(:p1) { Fabricate(:post, topic: topic, wiki: true) }
|
||||
|
||||
it 'allows to register custom filters' do
|
||||
tv = TopicView.new(topic.id, evil_trout, { filter: 'wiki' })
|
||||
expect(tv.filter_posts({ filter: "wiki" })).to eq([p0, p1])
|
||||
|
||||
TopicView.add_custom_filter("wiki") do |posts, topic_view|
|
||||
posts.where(wiki: true)
|
||||
end
|
||||
|
||||
tv = TopicView.new(topic.id, evil_trout, { filter: 'wiki' })
|
||||
expect(tv.filter_posts).to eq([p1])
|
||||
|
||||
tv = TopicView.new(topic.id, evil_trout, { filter: 'whatever' })
|
||||
expect(tv.filter_posts).to eq([p0, p1])
|
||||
|
||||
ensure
|
||||
TopicView.instance_variable_set(:@custom_filters, [])
|
||||
end
|
||||
end
|
||||
|
||||
context "setup_filtered_posts" do
|
||||
describe "filters posts with ignored users" do
|
||||
fab!(:ignored_user) { Fabricate(:ignored_user, user: evil_trout, ignored_user: user) }
|
||||
|
||||
Reference in New Issue
Block a user