]> source.dussan.org Git - redmine.git/commitdiff
Strip issue id when adding a relation.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 11 Apr 2012 17:25:05 +0000 (17:25 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 11 Apr 2012 17:25:05 +0000 (17:25 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9384 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issue_relations_controller.rb
test/functional/issue_relations_controller_test.rb

index ec87db727cf9514094ccc1c52eaf0db70421cc0e..b032d1769a6edca9f0e9d63f9982a6a1de0ee81d 100644 (file)
@@ -42,7 +42,7 @@ class IssueRelationsController < ApplicationController
   def create
     @relation = IssueRelation.new(params[:relation])
     @relation.issue_from = @issue
-    if params[:relation] && m = params[:relation][:issue_to_id].to_s.match(/^#?(\d+)$/)
+    if params[:relation] && m = params[:relation][:issue_to_id].to_s.strip.match(/^#?(\d+)$/)
       @relation.issue_to = Issue.visible.find_by_id(m[1].to_i)
     end
     saved = @relation.save
index 19f72b8b8d0d27ec261ed87e80860d03da48e22c..66c482700896304f3cca5092a11df464befd7c3c 100644 (file)
@@ -71,6 +71,16 @@ class IssueRelationsControllerTest < ActionController::TestCase
     end
   end
 
+  def test_create_should_strip_id
+    assert_difference 'IssueRelation.count' do
+      @request.session[:user_id] = 3
+      post :create, :issue_id => 1,
+                 :relation => {:issue_to_id => ' 2  ', :relation_type => 'relates', :delay => ''}
+    end
+    relation = IssueRelation.first(:order => 'id DESC')
+    assert_equal 2, relation.issue_to_id
+  end
+
   def test_create_should_not_break_with_non_numerical_id
     assert_no_difference 'IssueRelation.count' do
       assert_nothing_raised do