mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 14:13:38 +08:00
DEV: Support both tag:
as an alias for tags:
filter for /filter
(#21353)
We already support `category:` as an alias for `categories` so it makes sense to support `tag:` as an alias for `tags:`.
This commit is contained in:
parent
f47a4e61ad
commit
b4cf990a51
|
@ -9,7 +9,7 @@ class TopicsFilter
|
|||
@topic_notification_levels = Set.new
|
||||
end
|
||||
|
||||
FILTER_ALIASES = { "categories" => "category" }
|
||||
FILTER_ALIASES = { "categories" => "category", "tags" => "tag" }
|
||||
private_constant :FILTER_ALIASES
|
||||
|
||||
def filter_from_query_string(query_string)
|
||||
|
@ -74,7 +74,7 @@ class TopicsFilter
|
|||
filter_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)
|
||||
|
|
|
@ -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`" do
|
||||
expect(
|
||||
TopicsFilter
|
||||
|
|
Loading…
Reference in New Issue
Block a user