A platform for community discussion. Free, open, simple.
FIX: Allow `match_all_tags` to be passed as a URL param (#17972)
jbrw73b25222614d
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rbindex 096c4d8c382..662d8da5029 100644--- a/app/controllers/tags_controller.rb+++ b/app/controllers/tags_controller.rb@@ -479,7 +479,7 @@ class TagsController < ::ApplicationControlleroptions[:no_tags] = trueelseoptions[:tags] = tag_params- options[:match_all_tags] = true+ options[:match_all_tags] ||= trueendoptionsdiff --git a/lib/topic_query.rb b/lib/topic_query.rbindex f525bb195d8..3f7a5aecb44 100644--- a/lib/topic_query.rb+++ b/lib/topic_query.rb@@ -680,7 +680,7 @@ class TopicQuerytags_query = tags_arg[0].is_a?(String) ? Tag.where_name(tags_arg) : Tag.where(id: tags_arg)tags = tags_query.select(:id, :target_tag_id).map { |t| t.target_tag_id || t.id }.uniq- if @options[:match_all_tags]+ if ActiveModel::Type::Boolean.new.cast(@options[:match_all_tags])# ALL of the given tags:if tags_arg.length == tags.lengthtags.each_with_index do |tag, index|diff --git a/spec/lib/topic_query_spec.rb b/spec/lib/topic_query_spec.rbindex 47a5c8a92df..b2183f2c980 100644--- a/spec/lib/topic_query_spec.rb+++ b/spec/lib/topic_query_spec.rb@@ -427,6 +427,10 @@ RSpec.describe TopicQuery doexpect(TopicQuery.new(moderator, tags: [tag.name, other_tag.name], match_all_tags: true).list_latest.topics.map(&:id)).to eq([tagged_topic3.id])end+ it "can return topics with tag intersections using truthy/falsey values" do+ expect(TopicQuery.new(moderator, tags: [tag.name, other_tag.name], match_all_tags: "false").list_latest.topics.map(&:id).sort).to eq([tagged_topic1.id, tagged_topic2.id, tagged_topic3.id].sort)+ end+it "returns an empty relation when an invalid tag is passed" doexpect(TopicQuery.new(moderator, tags: [tag.name, 'notatag'], match_all_tags: true).list_latest.topics).to be_emptyend