From a2bcc9c40eb99b901f2f92b2f4fa1f840583c6b8 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 1 Oct 2016 12:46:29 +0000 Subject: [PATCH] Rename AttachmentsController#edit and #update to #edit_all and #update_all (#22356). git-svn-id: http://svn.redmine.org/redmine/trunk@15860 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/attachments_controller.rb | 12 ++++++---- .../{edit.html.erb => edit_all.html.erb} | 0 config/routes.rb | 4 ++-- .../functional/attachments_controller_test.rb | 24 +++++++++---------- 4 files changed, 21 insertions(+), 19 deletions(-) rename app/views/attachments/{edit.html.erb => edit_all.html.erb} (100%) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 19a51b9cc..f002c907c 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -17,7 +17,7 @@ class AttachmentsController < ApplicationController before_action :find_attachment, :only => [:show, :download, :thumbnail, :destroy] - before_action :find_editable_attachments, :only => [:edit, :update] + before_action :find_editable_attachments, :only => [:edit_all, :update_all] before_action :file_readable, :read_authorize, :only => [:show, :download, :thumbnail] before_action :delete_authorize, :only => :destroy before_action :authorize_global, :only => :upload @@ -26,7 +26,7 @@ class AttachmentsController < ApplicationController # MIME type text/javascript. skip_after_filter :verify_same_origin_request, :only => :download - accept_api_auth :show, :download, :thumbnail, :upload, :destroy + accept_api_auth :show, :download, :thumbnail, :upload, :update, :destroy def show respond_to do |format| @@ -107,17 +107,19 @@ class AttachmentsController < ApplicationController end end - def edit + # Edit all the attachments of a container + def edit_all end - def update + # Update all the attachments of a container + def update_all if params[:attachments].is_a?(Hash) if Attachment.update_attachments(@attachments, params[:attachments]) redirect_back_or_default home_path return end end - render :action => 'edit' + render :action => 'edit_all' end def destroy diff --git a/app/views/attachments/edit.html.erb b/app/views/attachments/edit_all.html.erb similarity index 100% rename from app/views/attachments/edit.html.erb rename to app/views/attachments/edit_all.html.erb diff --git a/config/routes.rb b/config/routes.rb index b8e465a63..7fe0ae95c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -294,8 +294,8 @@ Rails.application.routes.draw do get 'attachments/download/:id', :to => 'attachments#download', :id => /\d+/ get 'attachments/thumbnail/:id(/:size)', :to => 'attachments#thumbnail', :id => /\d+/, :size => /\d+/, :as => 'thumbnail' resources :attachments, :only => [:show, :destroy] - get 'attachments/:object_type/:object_id/edit', :to => 'attachments#edit', :as => :object_attachments_edit - patch 'attachments/:object_type/:object_id', :to => 'attachments#update', :as => :object_attachments + get 'attachments/:object_type/:object_id/edit', :to => 'attachments#edit_all', :as => :object_attachments_edit + patch 'attachments/:object_type/:object_id', :to => 'attachments#update_all', :as => :object_attachments resources :groups do resources :memberships, :controller => 'principal_memberships' diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index 6a44ca40c..665eb1d9d 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -354,9 +354,9 @@ class AttachmentsControllerTest < Redmine::ControllerTest puts '(ImageMagick convert not available)' end - def test_edit + def test_edit_all @request.session[:user_id] = 2 - get :edit, :object_type => 'issues', :object_id => '2' + get :edit_all, :object_type => 'issues', :object_id => '2' assert_response :success assert_select 'form[action=?]', '/attachments/issues/2' do @@ -371,24 +371,24 @@ class AttachmentsControllerTest < Redmine::ControllerTest end end - def test_edit_invalid_container_class_should_return_404 - get :edit, :object_type => 'nuggets', :object_id => '3' + def test_edit_all_with_invalid_container_class_should_return_404 + get :edit_all, :object_type => 'nuggets', :object_id => '3' assert_response 404 end - def test_edit_invalid_object_should_return_404 - get :edit, :object_type => 'issues', :object_id => '999' + def test_edit_all_with_invalid_object_should_return_404 + get :edit_all, :object_type => 'issues', :object_id => '999' assert_response 404 end - def test_edit_for_object_that_is_not_visible_should_return_403 - get :edit, :object_type => 'issues', :object_id => '4' + def test_edit_all_for_object_that_is_not_visible_should_return_403 + get :edit_all, :object_type => 'issues', :object_id => '4' assert_response 403 end - def test_update + def test_update_all @request.session[:user_id] = 2 - patch :update, :object_type => 'issues', :object_id => '2', :attachments => { + patch :update_all, :object_type => 'issues', :object_id => '2', :attachments => { '1' => {:filename => 'newname.text', :description => ''}, '4' => {:filename => 'newname.rb', :description => 'Renamed'}, } @@ -399,9 +399,9 @@ class AttachmentsControllerTest < Redmine::ControllerTest assert_equal 'Renamed', attachment.description end - def test_update_with_failure + def test_update_all_with_failure @request.session[:user_id] = 2 - patch :update, :object_type => 'issues', :object_id => '3', :attachments => { + patch :update_all, :object_type => 'issues', :object_id => '3', :attachments => { '1' => {:filename => '', :description => ''}, '4' => {:filename => 'newname.rb', :description => 'Renamed'}, } -- 2.39.5