From: Jean-Philippe Lang Date: Fri, 17 May 2013 18:18:06 +0000 (+0000) Subject: Fixed that submitting the form without selecting a value may raise raises an error... X-Git-Tag: 2.4.0~349 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c90bf645f51383ffb7bf2e3427b3e4c4672580f3;p=redmine.git Fixed that submitting the form without selecting a value may raise raises an error with SQLServer (#13783). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11854 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/enumerations_controller.rb b/app/controllers/enumerations_controller.rb index 125e87cff..2ca68f4f6 100644 --- a/app/controllers/enumerations_controller.rb +++ b/app/controllers/enumerations_controller.rb @@ -70,12 +70,10 @@ class EnumerationsController < ApplicationController @enumeration.destroy redirect_to enumerations_path return - elsif params[:reassign_to_id] - if reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id]) - @enumeration.destroy(reassign_to) - redirect_to enumerations_path - return - end + elsif params[:reassign_to_id].present? && (reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id].to_i)) + @enumeration.destroy(reassign_to) + redirect_to enumerations_path + return end @enumerations = @enumeration.class.system.all - [@enumeration] end diff --git a/app/views/enumerations/destroy.html.erb b/app/views/enumerations/destroy.html.erb index 3b47b40b2..b469d4f9b 100644 --- a/app/views/enumerations/destroy.html.erb +++ b/app/views/enumerations/destroy.html.erb @@ -4,7 +4,7 @@

<%= l(:text_enumeration_destroy_question, @enumeration.objects_count) %>

-<%= select_tag 'reassign_to_id', (content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---") + options_from_collection_for_select(@enumerations, 'id', 'name')) %>

+<%= select_tag 'reassign_to_id', (content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---", :value => '') + options_from_collection_for_select(@enumerations, 'id', 'name')) %>

<%= submit_tag l(:button_apply) %> diff --git a/test/functional/enumerations_controller_test.rb b/test/functional/enumerations_controller_test.rb index 1986f4731..8e18ea194 100644 --- a/test/functional/enumerations_controller_test.rb +++ b/test/functional/enumerations_controller_test.rb @@ -126,4 +126,11 @@ class EnumerationsControllerTest < ActionController::TestCase # check that the issue was reassign assert_equal 6, issue.reload.priority_id end + + def test_destroy_enumeration_in_use_with_blank_reassignment + assert_no_difference 'IssuePriority.count' do + delete :destroy, :id => 4, :reassign_to_id => '' + end + assert_response :success + end end