comparison test/functional/issue_relations_controller_test.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children 622f24f53b42 261b3d9a4903
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.expand_path('../../test_helper', __FILE__) 18 require File.expand_path('../../test_helper', __FILE__)
19 require 'issue_relations_controller'
20
21 # Re-raise errors caught by the controller.
22 class IssueRelationsController; def rescue_action(e) raise e end; end
23
24 19
25 class IssueRelationsControllerTest < ActionController::TestCase 20 class IssueRelationsControllerTest < ActionController::TestCase
26 fixtures :projects, 21 fixtures :projects,
27 :users, 22 :users,
28 :roles, 23 :roles,
34 :enabled_modules, 29 :enabled_modules,
35 :enumerations, 30 :enumerations,
36 :trackers 31 :trackers
37 32
38 def setup 33 def setup
39 @controller = IssueRelationsController.new
40 @request = ActionController::TestRequest.new
41 @response = ActionController::TestResponse.new
42 User.current = nil 34 User.current = nil
35 @request.session[:user_id] = 3
43 end 36 end
44 37
45 def test_create 38 def test_create
46 assert_difference 'IssueRelation.count' do 39 assert_difference 'IssueRelation.count' do
47 @request.session[:user_id] = 3
48 post :create, :issue_id => 1, 40 post :create, :issue_id => 1,
49 :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''} 41 :relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''}
50 end 42 end
43 relation = IssueRelation.first(:order => 'id DESC')
44 assert_equal 1, relation.issue_from_id
45 assert_equal 2, relation.issue_to_id
46 assert_equal 'relates', relation.relation_type
51 end 47 end
52 48
53 def test_create_xhr 49 def test_create_xhr
54 assert_difference 'IssueRelation.count' do 50 assert_difference 'IssueRelation.count' do
55 @request.session[:user_id] = 3 51 xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''}
56 xhr :post, :create, 52 assert_response :success
57 :issue_id => 3, 53 assert_template 'create'
58 :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''} 54 assert_equal 'text/javascript', response.content_type
59 assert_select_rjs 'relations' do
60 assert_select 'table', 1
61 assert_select 'tr', 2 # relations
62 end
63 end 55 end
56 relation = IssueRelation.first(:order => 'id DESC')
57 assert_equal 3, relation.issue_from_id
58 assert_equal 1, relation.issue_to_id
59
60 assert_match /Bug #1/, response.body
64 end 61 end
65 62
66 def test_create_should_accept_id_with_hash 63 def test_create_should_accept_id_with_hash
67 assert_difference 'IssueRelation.count' do 64 assert_difference 'IssueRelation.count' do
68 @request.session[:user_id] = 3
69 post :create, :issue_id => 1, 65 post :create, :issue_id => 1,
70 :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''} 66 :relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''}
71 end 67 end
68 relation = IssueRelation.first(:order => 'id DESC')
69 assert_equal 2, relation.issue_to_id
70 end
71
72 def test_create_should_strip_id
73 assert_difference 'IssueRelation.count' do
74 post :create, :issue_id => 1,
75 :relation => {:issue_to_id => ' 2 ', :relation_type => 'relates', :delay => ''}
76 end
77 relation = IssueRelation.first(:order => 'id DESC')
78 assert_equal 2, relation.issue_to_id
72 end 79 end
73 80
74 def test_create_should_not_break_with_non_numerical_id 81 def test_create_should_not_break_with_non_numerical_id
75 assert_no_difference 'IssueRelation.count' do 82 assert_no_difference 'IssueRelation.count' do
76 assert_nothing_raised do 83 assert_nothing_raised do
77 @request.session[:user_id] = 3
78 post :create, :issue_id => 1, 84 post :create, :issue_id => 1,
79 :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''} 85 :relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''}
80 end 86 end
81 end 87 end
82 end 88 end
84 def test_should_create_relations_with_visible_issues_only 90 def test_should_create_relations_with_visible_issues_only
85 Setting.cross_project_issue_relations = '1' 91 Setting.cross_project_issue_relations = '1'
86 assert_nil Issue.visible(User.find(3)).find_by_id(4) 92 assert_nil Issue.visible(User.find(3)).find_by_id(4)
87 93
88 assert_no_difference 'IssueRelation.count' do 94 assert_no_difference 'IssueRelation.count' do
89 @request.session[:user_id] = 3
90 post :create, :issue_id => 1, 95 post :create, :issue_id => 1,
91 :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''} 96 :relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''}
92 end 97 end
93 end 98 end
94 99
95 should "prevent relation creation when there's a circular dependency" 100 should "prevent relation creation when there's a circular dependency"
96 101
102 def test_create_xhr_with_failure
103 assert_no_difference 'IssueRelation.count' do
104 xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '999', :relation_type => 'relates', :delay => ''}
105
106 assert_response :success
107 assert_template 'create'
108 assert_equal 'text/javascript', response.content_type
109 end
110
111 assert_match /errorExplanation/, response.body
112 end
113
97 def test_destroy 114 def test_destroy
98 assert_difference 'IssueRelation.count', -1 do 115 assert_difference 'IssueRelation.count', -1 do
99 @request.session[:user_id] = 3
100 delete :destroy, :id => '2' 116 delete :destroy, :id => '2'
101 end 117 end
102 end 118 end
103 119
104 def test_destroy_xhr 120 def test_destroy_xhr
106 r.issue_from_id = 3 122 r.issue_from_id = 3
107 r.issue_to_id = 1 123 r.issue_to_id = 1
108 end 124 end
109 125
110 assert_difference 'IssueRelation.count', -1 do 126 assert_difference 'IssueRelation.count', -1 do
111 @request.session[:user_id] = 3
112 xhr :delete, :destroy, :id => '2' 127 xhr :delete, :destroy, :id => '2'
113 assert_select_rjs :remove, 'relation-2' 128
129 assert_response :success
130 assert_template 'destroy'
131 assert_equal 'text/javascript', response.content_type
132 assert_match /relation-2/, response.body
114 end 133 end
115 end 134 end
116 end 135 end