A platform for community discussion. Free, open, simple.
DEV: Support both `tag:` as an alias for `tags:` filter for `/filter` (#21353)
Alan Guo Xiang Tanb4cf990a51a3
diff --git a/lib/topics_filter.rb b/lib/topics_filter.rbindex f859af5d0b9..9cad48ea254 100644--- a/lib/topics_filter.rb+++ b/lib/topics_filter.rb@@ -9,7 +9,7 @@ class TopicsFilter@topic_notification_levels = Set.newend- FILTER_ALIASES = { "categories" => "category" }+ FILTER_ALIASES = { "categories" => "category", "tags" => "tag" }private_constant :FILTER_ALIASESdef filter_from_query_string(query_string)@@ -74,7 +74,7 @@ class TopicsFilterfilter_by_number_of_posters(max: filter_values)when "status"filter_values.each { |status| @scope = filter_status(status: status) }- when "tags"+ when "tag"filter_tags(values: key_prefixes.zip(filter_values))when "views-min"filter_by_number_of_views(min: filter_values)diff --git a/spec/lib/topics_filter_spec.rb b/spec/lib/topics_filter_spec.rbindex 24d56c63695..9d16c7df132 100644--- a/spec/lib/topics_filter_spec.rb+++ b/spec/lib/topics_filter_spec.rb@@ -663,6 +663,17 @@ RSpec.describe TopicsFilter do)end+ describe "when query string is `tag:tag1+tag2`" do+ it "should only return topics that are tagged with all of the specified tags" do+ expect(+ TopicsFilter+ .new(guardian: Guardian.new)+ .filter_from_query_string("tag:#{tag.name}+#{tag2.name}")+ .pluck(:id),+ ).to contain_exactly(topic_with_tag_and_tag2.id)+ end+ end+it "should only return topics that are tagged with all of the specified tags when query string is `tags:tag1+tag2`" doexpect(TopicsFilter