Skip to content

A platform for community discussion. Free, open, simple.

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

Bianca Nenciu9df2bce53842
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index ea4909f38fc..3fe3019e974 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -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)
diff --git a/spec/requests/tags_controller_spec.rb b/spec/requests/tags_controller_spec.rb
index ffcbe86a3a3..8a9ace93cb7 100644
--- a/spec/requests/tags_controller_spec.rb
+++ b/spec/requests/tags_controller_spec.rb
@@ -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