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