]> source.dussan.org Git - redmine.git/commitdiff
Fixed that submitting the form without selecting a value may raise raises an error...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 17 May 2013 18:18:06 +0000 (18:18 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 17 May 2013 18:18:06 +0000 (18:18 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11854 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/enumerations_controller.rb
app/views/enumerations/destroy.html.erb
test/functional/enumerations_controller_test.rb

index 125e87cff86422f7e7bb4ca6f1ec8d6ef67b00c0..2ca68f4f64dc693164d5b5bcfd721837449dafad 100644 (file)
@@ -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
index 3b47b40b2612d1cc1101e2bd10c694d6088593cb..b469d4f9b393a1078b5816919c9520eec5ebc2f9 100644 (file)
@@ -4,7 +4,7 @@
 <div class="box">
 <p><strong><%= l(:text_enumeration_destroy_question, @enumeration.objects_count) %></strong></p>
 <p><label for='reassign_to_id'><%= l(:text_enumeration_category_reassign_to) %></label>
-<%= select_tag 'reassign_to_id', (content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---") + options_from_collection_for_select(@enumerations, 'id', 'name')) %></p>
+<%= select_tag 'reassign_to_id', (content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---", :value => '') + options_from_collection_for_select(@enumerations, 'id', 'name')) %></p>
 </div>
 
 <%= submit_tag l(:button_apply) %>
index 1986f47318a94e67a9a745deb8a3c4d1dc595f30..8e18ea194ad5c29423ec4d3a2b4e7af2db64ab71 100644 (file)
@@ -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