From 172e7022a12f8598081eef71640a3fe871216345 Mon Sep 17 00:00:00 2001 From: ishikawa999 Date: Sat, 24 Oct 2020 07:00:01 +0000 Subject: [PATCH 1/2] Add WikiRedirectsController --- app/controllers/wiki_redirects_controller.rb | 35 +++++++++++++++ config/routes.rb | 1 + .../wiki_redirects_controller_test.rb | 43 +++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 app/controllers/wiki_redirects_controller.rb create mode 100644 test/functional/wiki_redirects_controller_test.rb diff --git a/app/controllers/wiki_redirects_controller.rb b/app/controllers/wiki_redirects_controller.rb new file mode 100644 index 0000000000..e23916df25 --- /dev/null +++ b/app/controllers/wiki_redirects_controller.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006-2020 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +class WikiRedirectsController < ApplicationController + before_action :find_wiki_redirect + + def destroy + @wiki_redirect.destroy + end + + private + def find_wiki_redirect + @project = Project.find(params[:project_id]) + @wiki_redirect= WikiRedirect.find(params[:id]) + render_404 unless @wiki_redirect + rescue ActiveRecord::RecordNotFound + render_404 + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index acc3ca4651..aa55abd00e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -195,6 +195,7 @@ get 'export' get 'date_index' post 'new' + resources :redirects, controller: 'wiki_redirects', only: :destroy end end match 'wiki', :controller => 'wiki', :action => 'show', :via => :get diff --git a/test/functional/wiki_redirects_controller_test.rb b/test/functional/wiki_redirects_controller_test.rb new file mode 100644 index 0000000000..5755384e63 --- /dev/null +++ b/test/functional/wiki_redirects_controller_test.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006-2020 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../test_helper', __FILE__) + +class WikiRedirectsControllerTest < Redmine::ControllerTest + fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, + :enabled_modules, :wikis, :wiki_pages, :wiki_contents, + :wiki_content_versions, :attachments, + :issues, :issue_statuses, :trackers + + def setup + #User.current = User.find(1) + @request.session[:user_id] = 1 + end + + def test_destroy + wiki_page = WikiPage.find(2) + + wiki_redirect = WikiRedirect.create!(wiki_id: 1, title: 'Test', redirects_to: wiki_page.title, redirects_to_wiki_id: 1) + + delete :destroy, params: { id: wiki_redirect.id, project_id: wiki_page.wiki.project_id } + + # WikiRedirectが消えていること + assert_not WikiRedirect.where(id: wiki_redirect.id).exists? + end +end \ No newline at end of file From b2cbf4b1394ca23702fb442f25cfbf93d9d7f496 Mon Sep 17 00:00:00 2001 From: ishikawa999 Date: Sat, 24 Oct 2020 07:34:02 +0000 Subject: [PATCH 2/2] Clean up --- app/controllers/wiki_redirects_controller.rb | 1 + test/functional/wiki_redirects_controller_test.rb | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/wiki_redirects_controller.rb b/app/controllers/wiki_redirects_controller.rb index e23916df25..29b5d208c8 100644 --- a/app/controllers/wiki_redirects_controller.rb +++ b/app/controllers/wiki_redirects_controller.rb @@ -25,6 +25,7 @@ def destroy end private + def find_wiki_redirect @project = Project.find(params[:project_id]) @wiki_redirect= WikiRedirect.find(params[:id]) diff --git a/test/functional/wiki_redirects_controller_test.rb b/test/functional/wiki_redirects_controller_test.rb index 5755384e63..ac65645882 100644 --- a/test/functional/wiki_redirects_controller_test.rb +++ b/test/functional/wiki_redirects_controller_test.rb @@ -26,8 +26,7 @@ class WikiRedirectsControllerTest < Redmine::ControllerTest :issues, :issue_statuses, :trackers def setup - #User.current = User.find(1) - @request.session[:user_id] = 1 + User.current = User.find(1) end def test_destroy