FIX: Allow match_all_tags to be passed as a URL param (#17972)

`TopicQueryParams` allows for `match_all_tags` to be passed as a query parameter. `TagsController` forces the value to be true.

This change allows a value to be passed, and only sets it to true if no value has been set. It then uses `ActiveModel::Type::Boolean.new.cast` to compare the value.
This commit is contained in:
jbrw
2022-08-19 15:41:56 -04:00
committed by GitHub
parent 42385d020d
commit 73b2522261
3 changed files with 6 additions and 2 deletions

View File

@ -427,6 +427,10 @@ RSpec.describe TopicQuery do
expect(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" do
expect(TopicQuery.new(moderator, tags: [tag.name, 'notatag'], match_all_tags: true).list_latest.topics).to be_empty
end