FIX: Generate correct prev and next topics page URL (#11431)

It did not work well for category + tags pages.
This commit is contained in:
Bianca Nenciu 2020-12-08 17:34:28 +02:00 committed by GitHub
parent f62ea77666
commit 9df2bce538
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -409,8 +409,6 @@ class TagsController < ::ApplicationController
end
def construct_url_with(action, opts)
method = url_method(opts)
page_params =
case action
when :prev
@ -421,13 +419,13 @@ class TagsController < ::ApplicationController
raise "unreachable"
end
if page_params.include?(:category_slug_path_with_id)
opts = opts.dup
opts.delete(:category)
end
opts = opts.merge(page_params)
opts.delete(:category) if opts.include?(:category_slug_path_with_id)
method = url_method(opts)
begin
url = public_send(method, opts.merge(page_params))
url = public_send(method, opts)
rescue ActionController::UrlGenerationError
raise Discourse::NotFound
end
@ -451,6 +449,7 @@ class TagsController < ::ApplicationController
q: params[:q]
)
options[:no_subcategories] = true if params[:no_subcategories] == 'true'
options[:per_page] = params[:per_page].to_i.clamp(1, 30) if params[:per_page].present?
if params[:tag_id] == 'none'
options.delete(:tags)

View File

@ -204,6 +204,13 @@ describe TagsController do
expect(topic_ids).to_not include(topic_out_of_category.id)
expect(topic_ids).to_not include(topic_in_category_without_tag.id)
end
it "should produce the right next topic URL" do
get "/tags/c/#{category.slug_path.join("/")}/#{category.id}/#{tag.name}.json?per_page=1"
expect(response.parsed_body['topic_list']['more_topics_url'])
.to start_with("/tags/c/#{category.slug_path.join('/')}/#{category.id}/#{tag.name}")
end
end
context "with a subcategory in the path" do