A platform for community discussion. Free, open, simple.
DEV: Change `created-by` topics query filter to `created-by:@<username>` (#21317)
Alan Guo Xiang Tan93f7c242406e
diff --git a/lib/topics_filter.rb b/lib/topics_filter.rbindex e8b82bd6100..a11587c1120 100644--- a/lib/topics_filter.rb+++ b/lib/topics_filter.rb@@ -132,6 +132,8 @@ class TopicsFilter"posters-min", "posters-max", "views-min", "views-max"value = values.lastvalue if value =~ /\A\d+\z/+ when "created-by"+ values.flat_map { |value| value.split(",").map { |username| username.delete_prefix("@") } }elsevaluesenddiff --git a/spec/lib/topics_filter_spec.rb b/spec/lib/topics_filter_spec.rbindex 4306caca60c..f1e38d4e519 100644--- a/spec/lib/topics_filter_spec.rb+++ b/spec/lib/topics_filter_spec.rb@@ -780,67 +780,69 @@ RSpec.describe TopicsFilter dofab!(:topic2_by_user) { Fabricate(:topic, user: user) }fab!(:topic_by_user2) { Fabricate(:topic, user: user2) }- describe "when query string is `created-by:username`" do+ describe "when query string is `created-by:@username`" doit "should return the topics created by the specified user" doexpect(TopicsFilter.new(guardian: Guardian.new)- .filter_from_query_string("created-by:#{user.username}")+ .filter_from_query_string("created-by:@#{user.username}").pluck(:id),).to contain_exactly(topic_by_user.id, topic2_by_user.id)endend- describe "when query string is `created-by:username2`" do+ describe "when query string is `created-by:@username2`" doit "should return the topics created by the specified user" doexpect(TopicsFilter.new(guardian: Guardian.new)- .filter_from_query_string("created-by:#{user2.username}")+ .filter_from_query_string("created-by:@#{user2.username}").pluck(:id),).to contain_exactly(topic_by_user2.id)endend- describe "when query string is `created-by:username created-by:username2`" do+ describe "when query string is `created-by:@username created-by:@username2`" doit "should return the topics created by either of the specified users" doexpect(TopicsFilter.new(guardian: Guardian.new)- .filter_from_query_string("created-by:#{user.username} created-by:#{user2.username}")+ .filter_from_query_string(+ "created-by:@#{user.username} created-by:@#{user2.username}",+ ).pluck(:id),).to contain_exactly(topic_by_user.id, topic2_by_user.id, topic_by_user2.id)endend- describe "when query string is `created-by:username,invalid`" do+ describe "when query string is `created-by:@username,invalid`" doit "should only return the topics created by the user with the valid username" doexpect(TopicsFilter.new(guardian: Guardian.new)- .filter_from_query_string("created-by:#{user.username},invalid")+ .filter_from_query_string("created-by:@#{user.username},invalid").pluck(:id),).to contain_exactly(topic_by_user.id, topic2_by_user.id)endend- describe "when query string is `created-by:username,username2`" do+ describe "when query string is `created-by:@username,@username2`" doit "should return the topics created by either of the specified users" doexpect(TopicsFilter.new(guardian: Guardian.new)- .filter_from_query_string("created-by:#{user.username},#{user2.username}")+ .filter_from_query_string("created-by:@#{user.username},@#{user2.username}").pluck(:id),).to contain_exactly(topic_by_user.id, topic2_by_user.id, topic_by_user2.id)endend- describe "when query string is `created-by:invalid`" do+ describe "when query string is `created-by:@invalid`" doit "should not return any topics" doexpect(TopicsFilter.new(guardian: Guardian.new)- .filter_from_query_string("created-by:invalid")+ .filter_from_query_string("created-by:@invalid").pluck(:id),).to eq([])end