annotate .svn/pristine/92/920c665fe00c7af87265d22d1b8ec934bc035540.svn-base @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1295 19
Chris@1295 20 class IssueRelationsControllerTest < ActionController::TestCase
Chris@1295 21 fixtures :projects,
Chris@1295 22 :users,
Chris@1295 23 :roles,
Chris@1295 24 :members,
Chris@1295 25 :member_roles,
Chris@1295 26 :issues,
Chris@1295 27 :issue_statuses,
Chris@1295 28 :issue_relations,
Chris@1295 29 :enabled_modules,
Chris@1295 30 :enumerations,
Chris@1295 31 :trackers
Chris@1295 32
Chris@1295 33 def setup
Chris@1295 34 User.current = nil
Chris@1295 35 @request.session[:user_id] = 3
Chris@1295 36 end
Chris@1295 37
Chris@1295 38 def test_create
Chris@1295 39 assert_difference 'IssueRelation.count' do
Chris@1295 40 post :create, :issue_id => 1,
Chris@1295 41 :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''}
Chris@1295 42 end
Chris@1295 43 relation = IssueRelation.first(:order => 'id DESC')
Chris@1295 44 assert_equal 1, relation.issue_from_id
Chris@1295 45 assert_equal 2, relation.issue_to_id
Chris@1295 46 assert_equal 'relates', relation.relation_type
Chris@1295 47 end
Chris@1295 48
Chris@1295 49 def test_create_xhr
Chris@1295 50 assert_difference 'IssueRelation.count' do
Chris@1295 51 xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''}
Chris@1295 52 assert_response :success
Chris@1295 53 assert_template 'create'
Chris@1295 54 assert_equal 'text/javascript', response.content_type
Chris@1295 55 end
Chris@1295 56 relation = IssueRelation.first(:order => 'id DESC')
Chris@1295 57 assert_equal 3, relation.issue_from_id
Chris@1295 58 assert_equal 1, relation.issue_to_id
Chris@1295 59
Chris@1295 60 assert_match /Bug #1/, response.body
Chris@1295 61 end
Chris@1295 62
Chris@1295 63 def test_create_should_accept_id_with_hash
Chris@1295 64 assert_difference 'IssueRelation.count' do
Chris@1295 65 post :create, :issue_id => 1,
Chris@1295 66 :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''}
Chris@1295 67 end
Chris@1295 68 relation = IssueRelation.first(:order => 'id DESC')
Chris@1295 69 assert_equal 2, relation.issue_to_id
Chris@1295 70 end
Chris@1295 71
Chris@1295 72 def test_create_should_strip_id
Chris@1295 73 assert_difference 'IssueRelation.count' do
Chris@1295 74 post :create, :issue_id => 1,
Chris@1295 75 :relation => {:issue_to_id => ' 2 ', :relation_type => 'relates', :delay => ''}
Chris@1295 76 end
Chris@1295 77 relation = IssueRelation.first(:order => 'id DESC')
Chris@1295 78 assert_equal 2, relation.issue_to_id
Chris@1295 79 end
Chris@1295 80
Chris@1295 81 def test_create_should_not_break_with_non_numerical_id
Chris@1295 82 assert_no_difference 'IssueRelation.count' do
Chris@1295 83 assert_nothing_raised do
Chris@1295 84 post :create, :issue_id => 1,
Chris@1295 85 :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''}
Chris@1295 86 end
Chris@1295 87 end
Chris@1295 88 end
Chris@1295 89
Chris@1295 90 def test_should_create_relations_with_visible_issues_only
Chris@1295 91 Setting.cross_project_issue_relations = '1'
Chris@1295 92 assert_nil Issue.visible(User.find(3)).find_by_id(4)
Chris@1295 93
Chris@1295 94 assert_no_difference 'IssueRelation.count' do
Chris@1295 95 post :create, :issue_id => 1,
Chris@1295 96 :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''}
Chris@1295 97 end
Chris@1295 98 end
Chris@1295 99
Chris@1295 100 should "prevent relation creation when there's a circular dependency"
Chris@1295 101
Chris@1295 102 def test_create_xhr_with_failure
Chris@1295 103 assert_no_difference 'IssueRelation.count' do
Chris@1295 104 xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '999', :relation_type => 'relates', :delay => ''}
Chris@1295 105
Chris@1295 106 assert_response :success
Chris@1295 107 assert_template 'create'
Chris@1295 108 assert_equal 'text/javascript', response.content_type
Chris@1295 109 end
Chris@1295 110
Chris@1295 111 assert_match /errorExplanation/, response.body
Chris@1295 112 end
Chris@1295 113
Chris@1295 114 def test_destroy
Chris@1295 115 assert_difference 'IssueRelation.count', -1 do
Chris@1295 116 delete :destroy, :id => '2'
Chris@1295 117 end
Chris@1295 118 end
Chris@1295 119
Chris@1295 120 def test_destroy_xhr
Chris@1295 121 IssueRelation.create!(:relation_type => IssueRelation::TYPE_RELATES) do |r|
Chris@1295 122 r.issue_from_id = 3
Chris@1295 123 r.issue_to_id = 1
Chris@1295 124 end
Chris@1295 125
Chris@1295 126 assert_difference 'IssueRelation.count', -1 do
Chris@1295 127 xhr :delete, :destroy, :id => '2'
Chris@1295 128
Chris@1295 129 assert_response :success
Chris@1295 130 assert_template 'destroy'
Chris@1295 131 assert_equal 'text/javascript', response.content_type
Chris@1295 132 assert_match /relation-2/, response.body
Chris@1295 133 end
Chris@1295 134 end
Chris@1295 135 end