OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Fix double render and missing translation on `types_controller#move`
Aaron Contreras7ddcaf331244
diff --git a/app/controllers/types_controller.rb b/app/controllers/types_controller.rbindex 99be7bfa094..d2a62840334 100644--- a/app/controllers/types_controller.rb+++ b/app/controllers/types_controller.rb@@ -99,11 +99,11 @@ class TypesController < ApplicationControllerif @type.update(permitted_params.type_move)flash[:notice] = I18n.t(:notice_successful_update)+ redirect_to types_pathelse- flash.now[:error] = t('type_could_not_be_saved')+ flash.now[:error] = I18n.t(:error_type_could_not_be_saved)render action: 'edit'end- redirect_to types_pathenddef destroydiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 5077258d746..e97489de01e 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1374,6 +1374,7 @@ en:error_password_change_failed: 'An error occurred when trying to change the password.'error_scm_command_failed: "An error occurred when trying to access the repository: %{value}"error_scm_not_found: "The entry or revision was not found in the repository."+ error_type_could_not_be_saved: "Type could not be saved"error_unable_delete_status: "The work package status cannot be deleted since it is used by at least one work package."error_unable_delete_default_status: "Unable to delete the default work package status. Please select another default work package status before deleting the current one."error_unable_to_connect: "Unable to connect (%{value})"diff --git a/spec/controllers/types_controller_spec.rb b/spec/controllers/types_controller_spec.rbindex 3c928def1da..4962c67b921 100644--- a/spec/controllers/types_controller_spec.rb+++ b/spec/controllers/types_controller_spec.rb@@ -300,19 +300,45 @@ RSpec.describe TypesController doenddescribe 'POST move' do- let!(:type) { create(:type, name: 'My type', position: '1') }- let!(:type2) { create(:type, name: 'My type 2', position: '2') }- let(:params) { { 'id' => type.id, 'type' => { move_to: 'lower' } } }+ context 'with a successful update' do+ let!(:type) { create(:type, name: 'My type', position: '1') }+ let!(:type2) { create(:type, name: 'My type 2', position: '2') }+ let(:params) { { 'id' => type.id, 'type' => { move_to: 'lower' } } }- before do- post :move, params:+ before do+ post :move, params:+ end++ it { expect(response).to be_redirect }+ it { expect(response).to redirect_to(types_path) }++ it 'has the position updated' do+ expect(Type.find_by(name: 'My type').position).to eq(2)+ endend- it { expect(response).to be_redirect }- it { expect(response).to redirect_to(types_path) }+ context 'with a failed update' do+ let!(:type) { create(:type, name: 'My type', position: '1') }+ let!(:type2) { create(:type, name: 'My type 2', position: '2') }+ let(:params) { { 'id' => type.id, 'type' => { move_to: 'lower' } } }- it 'has the position updated' do- expect(Type.find_by(name: 'My type').position).to eq(2)+ before do+ allow(Type).to receive(:find).and_return(type)+ allow(type).to receive(:update).and_return false++ post :move, params:+ end++ it { expect(response).not_to be_redirect }+ it { expect(response).to render_template('edit') }++ it 'has an unsuccessful move flash' do+ expect(flash[:error]).to eq(I18n.t(:error_type_could_not_be_saved))+ end++ it "doesn't update the position" do+ expect(Type.find_by(name: 'My type').position).to eq(1)+ endendend