FIX: Use tag-intersection route when building more_topics_url from tag-intersection
This commit is contained in:
parent
12a18d4d55
commit
6a68ba147b
@ -102,8 +102,13 @@ class TagsController < ::ApplicationController
|
||||
Discourse.filters.each do |filter|
|
||||
define_method("show_#{filter}") do
|
||||
@tag_id = params[:tag_id].force_encoding("UTF-8")
|
||||
@additional_tags =
|
||||
params[:additional_tag_ids].to_s.split("/").map { |t| t.force_encoding("UTF-8") }
|
||||
if params[:additional_tag_ids]
|
||||
@additional_tags = params[:additional_tag_ids].to_s.split("/")
|
||||
elsif params[:tags]
|
||||
# Set additional tags to all passed tags excluding the primary tag (tag_id)
|
||||
@additional_tags = params[:tags].reject { |t| t == params[:tag_id] }
|
||||
end
|
||||
@additional_tags = @additional_tags&.map { |t| t.force_encoding("UTF-8") }
|
||||
|
||||
list_opts = build_topic_list_options
|
||||
@list = nil
|
||||
@ -483,6 +488,9 @@ class TagsController < ::ApplicationController
|
||||
def url_method(opts = {})
|
||||
if opts[:category_slug_path_with_id]
|
||||
"tag_category_#{action_name}_path"
|
||||
# expect tag intersection if multiple tags are present
|
||||
elsif opts[:tags] && opts[:tags].length > 1
|
||||
"tag_intersection_path"
|
||||
else
|
||||
"tag_#{action_name}_path"
|
||||
end
|
||||
|
||||
@ -392,6 +392,24 @@ RSpec.describe TagsController do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with a tag intersection" do
|
||||
it "should generate a tag intersection `load_more_topic` url" do
|
||||
tag = Fabricate(:tag)
|
||||
tag_2 = Fabricate(:tag)
|
||||
|
||||
# Create topics with both tags included
|
||||
3.times { Fabricate(:topic, tags: [tag, tag_2]) }
|
||||
|
||||
sign_in(admin)
|
||||
get "/tags/intersection/#{tag.name}/#{tag_2.name}.json?per_page=2"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["topic_list"]["more_topics_url"]).to eq(
|
||||
"/tags/intersection/#{tag.name}/#{tag_2.name}?match_all_tags=true&page=1&per_page=2&tags%5B%5D=#{tag.name}&tags%5B%5D=#{tag_2.name}",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#show" do
|
||||
|
||||
Reference in New Issue
Block a user