From 7d23826cee5a3acc43bd9155bc417d6e14575c56 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 20 May 2015 10:16:17 -0400 Subject: [PATCH] FIX: Keep around the page when redirecting --- app/controllers/topics_controller.rb | 3 +++ spec/controllers/topics_controller_spec.rb | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 683768dfc..30e9c483b 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -439,6 +439,9 @@ class TopicsController < ApplicationController url << "/#{post_number}" if post_number.to_i > 0 url << ".json" if request.format.json? + page = params[:page].to_i + url << "?page=#{page}" if page != 0 + redirect_to url, status: 301 end diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index a655ba0e6..8e5b83b19 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -532,6 +532,11 @@ describe TopicsController do expect(response).to redirect_to(topic.relative_url + "/42") end + it 'keeps the page around when redirecting' do + xhr :get, :show, id: topic.slug, post_number: 42, page: 123 + expect(response).to redirect_to(topic.relative_url + "/42?page=123") + end + it 'returns 404 when an invalid slug is given and no id' do xhr :get, :show, id: 'nope-nope' expect(response.status).to eq(404)