A platform for community discussion. Free, open, simple.
DEV: Minor refactoring and improvements to `TopicsFilter` (#21068)
Alan Guo Xiang Tan3b045a20161c
diff --git a/spec/lib/topics_filter_spec.rb b/spec/lib/topics_filter_spec.rbindex 9872cc4f1a0..950db2f9a38 100644--- a/spec/lib/topics_filter_spec.rb+++ b/spec/lib/topics_filter_spec.rb@@ -91,6 +91,29 @@ RSpec.describe TopicsFilter doendend+ describe "when query string is `in:bookmarked in:pinnned`" do+ it "should return topics that are bookmarked and pinned" do+ expect(+ TopicsFilter+ .new(guardian: Guardian.new(user))+ .filter_from_query_string("in:bookmarked in:pinned")+ .pluck(:id),+ ).to eq([])++ BookmarkManager.new(user).create_for(+ bookmarkable_id: pinned_topic.id,+ bookmarkable_type: "Topic",+ )++ expect(+ TopicsFilter+ .new(guardian: Guardian.new(user))+ .filter_from_query_string("in:bookmarked in:pinned")+ .pluck(:id),+ ).to contain_exactly(pinned_topic.id)+ end+ end+TopicUser.notification_levels.keys.each do |notification_level|describe "when query string is `in:#{notification_level}`" dofab!("user_#{notification_level}_topic".to_sym) do@@ -584,6 +607,19 @@ RSpec.describe TopicsFilter do.pluck(:id),).not_to include(topic_in_private_category.id)end++ describe "when query string is `status:closed status:unlisted`" do+ fab!(:closed_and_unlisted_topic) { Fabricate(:topic, closed: true, visible: false) }++ it "should only return topics that have been closed and are not visible" do+ expect(+ TopicsFilter+ .new(guardian: Guardian.new)+ .filter_from_query_string("status:closed status:unlisted")+ .pluck(:id),+ ).to contain_exactly(closed_and_unlisted_topic.id)+ end+ endenddescribe "when filtering by tags" do