From a4c0c18e3dd0ab17db521dd634e107b97d402326 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 11 Apr 2012 17:27:44 +0000 Subject: [PATCH] Merged r9384, r9385 from trunk. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.4-stable@9386 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issue_relations_controller.rb | 2 +- .../issue_relations_controller_test.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/controllers/issue_relations_controller.rb b/app/controllers/issue_relations_controller.rb index ec87db727..b032d1769 100644 --- a/app/controllers/issue_relations_controller.rb +++ b/app/controllers/issue_relations_controller.rb @@ -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 diff --git a/test/functional/issue_relations_controller_test.rb b/test/functional/issue_relations_controller_test.rb index 19f72b8b8..36ccf4a98 100644 --- a/test/functional/issue_relations_controller_test.rb +++ b/test/functional/issue_relations_controller_test.rb @@ -48,6 +48,10 @@ class IssueRelationsControllerTest < ActionController::TestCase post :create, :issue_id => 1, :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''} end + relation = IssueRelation.first(:order => 'id DESC') + assert_equal 1, relation.issue_from_id + assert_equal 2, relation.issue_to_id + assert_equal 'relates', relation.relation_type end def test_create_xhr @@ -61,6 +65,9 @@ class IssueRelationsControllerTest < ActionController::TestCase assert_select 'tr', 2 # relations end end + relation = IssueRelation.first(:order => 'id DESC') + assert_equal 3, relation.issue_from_id + assert_equal 1, relation.issue_to_id end def test_create_should_accept_id_with_hash @@ -69,6 +76,18 @@ class IssueRelationsControllerTest < ActionController::TestCase 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_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 -- 2.39.5