From a272453bd0a1696efe2fba3eaa9a2d3932c7c4f3 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 31 Mar 2020 18:11:15 -0500 Subject: [PATCH] wikis: redirect legacy title param to show page. Redirect /wiki_pages?title=touhou to /wiki_pages/touhou. --- app/controllers/wiki_pages_controller.rb | 16 ++++++---------- test/functional/wiki_pages_controller_test.rb | 5 +++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/controllers/wiki_pages_controller.rb b/app/controllers/wiki_pages_controller.rb index 09212fab6..19b5a5cd1 100644 --- a/app/controllers/wiki_pages_controller.rb +++ b/app/controllers/wiki_pages_controller.rb @@ -1,6 +1,5 @@ class WikiPagesController < ApplicationController respond_to :html, :xml, :json, :js - before_action :normalize_search_params, :only => [:index] layout "sidebar" def new @@ -15,8 +14,12 @@ class WikiPagesController < ApplicationController end def index - @wiki_pages = authorize WikiPage.paginated_search(params) - respond_with(@wiki_pages) + if params[:title].present? + redirect_to wiki_pages_path(search: { title_normalize: params[:title] }, redirect: true) + else + @wiki_pages = authorize WikiPage.paginated_search(params) + respond_with(@wiki_pages) + end end def search @@ -90,11 +93,4 @@ class WikiPagesController < ApplicationController true end end - - def normalize_search_params - if params[:title] - params[:search] ||= {} - params[:search][:title] = params.delete(:title) - end - end end diff --git a/test/functional/wiki_pages_controller_test.rb b/test/functional/wiki_pages_controller_test.rb index c98dd8458..de2a1ea04 100644 --- a/test/functional/wiki_pages_controller_test.rb +++ b/test/functional/wiki_pages_controller_test.rb @@ -31,6 +31,11 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_select "tr td:first-child", text: "abc" end + + should "redirect the legacy title param to the show page" do + get wiki_pages_path(title: "abc") + assert_redirected_to wiki_pages_path(search: { title_normalize: "abc" }, redirect: true) + end end context "search action" do