@@ -1,1753 +1,1753 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 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. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
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 'issues_controller' |
|
19 | require 'issues_controller' | |
20 |
|
20 | |||
21 | class IssuesControllerTest < ActionController::TestCase |
|
21 | class IssuesControllerTest < ActionController::TestCase | |
22 | fixtures :projects, |
|
22 | fixtures :projects, | |
23 | :users, |
|
23 | :users, | |
24 | :roles, |
|
24 | :roles, | |
25 | :members, |
|
25 | :members, | |
26 | :member_roles, |
|
26 | :member_roles, | |
27 | :issues, |
|
27 | :issues, | |
28 | :issue_statuses, |
|
28 | :issue_statuses, | |
29 | :versions, |
|
29 | :versions, | |
30 | :trackers, |
|
30 | :trackers, | |
31 | :projects_trackers, |
|
31 | :projects_trackers, | |
32 | :issue_categories, |
|
32 | :issue_categories, | |
33 | :enabled_modules, |
|
33 | :enabled_modules, | |
34 | :enumerations, |
|
34 | :enumerations, | |
35 | :attachments, |
|
35 | :attachments, | |
36 | :workflows, |
|
36 | :workflows, | |
37 | :custom_fields, |
|
37 | :custom_fields, | |
38 | :custom_values, |
|
38 | :custom_values, | |
39 | :custom_fields_projects, |
|
39 | :custom_fields_projects, | |
40 | :custom_fields_trackers, |
|
40 | :custom_fields_trackers, | |
41 | :time_entries, |
|
41 | :time_entries, | |
42 | :journals, |
|
42 | :journals, | |
43 | :journal_details, |
|
43 | :journal_details, | |
44 | :queries |
|
44 | :queries | |
45 |
|
45 | |||
46 | def setup |
|
46 | def setup | |
47 | @controller = IssuesController.new |
|
47 | @controller = IssuesController.new | |
48 | @request = ActionController::TestRequest.new |
|
48 | @request = ActionController::TestRequest.new | |
49 | @response = ActionController::TestResponse.new |
|
49 | @response = ActionController::TestResponse.new | |
50 | User.current = nil |
|
50 | User.current = nil | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def test_index |
|
53 | def test_index | |
54 | Setting.default_language = 'en' |
|
54 | Setting.default_language = 'en' | |
55 |
|
55 | |||
56 | get :index |
|
56 | get :index | |
57 | assert_response :success |
|
57 | assert_response :success | |
58 | assert_template 'index' |
|
58 | assert_template 'index' | |
59 | assert_not_nil assigns(:issues) |
|
59 | assert_not_nil assigns(:issues) | |
60 | assert_nil assigns(:project) |
|
60 | assert_nil assigns(:project) | |
61 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
61 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
62 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
62 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
63 | # private projects hidden |
|
63 | # private projects hidden | |
64 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
64 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ | |
65 | assert_no_tag :tag => 'a', :content => /Issue on project 2/ |
|
65 | assert_no_tag :tag => 'a', :content => /Issue on project 2/ | |
66 | # project column |
|
66 | # project column | |
67 | assert_tag :tag => 'th', :content => /Project/ |
|
67 | assert_tag :tag => 'th', :content => /Project/ | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
70 | def test_index_should_not_list_issues_when_module_disabled |
|
70 | def test_index_should_not_list_issues_when_module_disabled | |
71 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") |
|
71 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") | |
72 | get :index |
|
72 | get :index | |
73 | assert_response :success |
|
73 | assert_response :success | |
74 | assert_template 'index' |
|
74 | assert_template 'index' | |
75 | assert_not_nil assigns(:issues) |
|
75 | assert_not_nil assigns(:issues) | |
76 | assert_nil assigns(:project) |
|
76 | assert_nil assigns(:project) | |
77 | assert_no_tag :tag => 'a', :content => /Can't print recipes/ |
|
77 | assert_no_tag :tag => 'a', :content => /Can't print recipes/ | |
78 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
78 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | def test_index_should_list_visible_issues_only |
|
81 | def test_index_should_list_visible_issues_only | |
82 | get :index, :per_page => 100 |
|
82 | get :index, :per_page => 100 | |
83 | assert_response :success |
|
83 | assert_response :success | |
84 | assert_not_nil assigns(:issues) |
|
84 | assert_not_nil assigns(:issues) | |
85 | assert_nil assigns(:issues).detect {|issue| !issue.visible?} |
|
85 | assert_nil assigns(:issues).detect {|issue| !issue.visible?} | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | def test_index_with_project |
|
88 | def test_index_with_project | |
89 | Setting.display_subprojects_issues = 0 |
|
89 | Setting.display_subprojects_issues = 0 | |
90 | get :index, :project_id => 1 |
|
90 | get :index, :project_id => 1 | |
91 | assert_response :success |
|
91 | assert_response :success | |
92 | assert_template 'index' |
|
92 | assert_template 'index' | |
93 | assert_not_nil assigns(:issues) |
|
93 | assert_not_nil assigns(:issues) | |
94 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
94 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
95 | assert_no_tag :tag => 'a', :content => /Subproject issue/ |
|
95 | assert_no_tag :tag => 'a', :content => /Subproject issue/ | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | def test_index_with_project_and_subprojects |
|
98 | def test_index_with_project_and_subprojects | |
99 | Setting.display_subprojects_issues = 1 |
|
99 | Setting.display_subprojects_issues = 1 | |
100 | get :index, :project_id => 1 |
|
100 | get :index, :project_id => 1 | |
101 | assert_response :success |
|
101 | assert_response :success | |
102 | assert_template 'index' |
|
102 | assert_template 'index' | |
103 | assert_not_nil assigns(:issues) |
|
103 | assert_not_nil assigns(:issues) | |
104 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
104 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
105 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
105 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
106 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
106 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ | |
107 | end |
|
107 | end | |
108 |
|
108 | |||
109 | def test_index_with_project_and_subprojects_should_show_private_subprojects |
|
109 | def test_index_with_project_and_subprojects_should_show_private_subprojects | |
110 | @request.session[:user_id] = 2 |
|
110 | @request.session[:user_id] = 2 | |
111 | Setting.display_subprojects_issues = 1 |
|
111 | Setting.display_subprojects_issues = 1 | |
112 | get :index, :project_id => 1 |
|
112 | get :index, :project_id => 1 | |
113 | assert_response :success |
|
113 | assert_response :success | |
114 | assert_template 'index' |
|
114 | assert_template 'index' | |
115 | assert_not_nil assigns(:issues) |
|
115 | assert_not_nil assigns(:issues) | |
116 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
116 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
117 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
117 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
118 | assert_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
118 | assert_tag :tag => 'a', :content => /Issue of a private subproject/ | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | def test_index_with_project_and_default_filter |
|
121 | def test_index_with_project_and_default_filter | |
122 | get :index, :project_id => 1, :set_filter => 1 |
|
122 | get :index, :project_id => 1, :set_filter => 1 | |
123 | assert_response :success |
|
123 | assert_response :success | |
124 | assert_template 'index' |
|
124 | assert_template 'index' | |
125 | assert_not_nil assigns(:issues) |
|
125 | assert_not_nil assigns(:issues) | |
126 |
|
126 | |||
127 | query = assigns(:query) |
|
127 | query = assigns(:query) | |
128 | assert_not_nil query |
|
128 | assert_not_nil query | |
129 | # default filter |
|
129 | # default filter | |
130 | assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters) |
|
130 | assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters) | |
131 | end |
|
131 | end | |
132 |
|
132 | |||
133 | def test_index_with_project_and_filter |
|
133 | def test_index_with_project_and_filter | |
134 | get :index, :project_id => 1, :set_filter => 1, |
|
134 | get :index, :project_id => 1, :set_filter => 1, | |
135 | :f => ['tracker_id'], |
|
135 | :f => ['tracker_id'], | |
136 | :op => {'tracker_id' => '='}, |
|
136 | :op => {'tracker_id' => '='}, | |
137 | :v => {'tracker_id' => ['1']} |
|
137 | :v => {'tracker_id' => ['1']} | |
138 | assert_response :success |
|
138 | assert_response :success | |
139 | assert_template 'index' |
|
139 | assert_template 'index' | |
140 | assert_not_nil assigns(:issues) |
|
140 | assert_not_nil assigns(:issues) | |
141 |
|
141 | |||
142 | query = assigns(:query) |
|
142 | query = assigns(:query) | |
143 | assert_not_nil query |
|
143 | assert_not_nil query | |
144 | assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters) |
|
144 | assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters) | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
147 | def test_index_with_short_filters |
|
147 | def test_index_with_short_filters | |
148 |
|
148 | |||
149 | to_test = { |
|
149 | to_test = { | |
150 | 'status_id' => { |
|
150 | 'status_id' => { | |
151 | 'o' => { :op => 'o', :values => [''] }, |
|
151 | 'o' => { :op => 'o', :values => [''] }, | |
152 | 'c' => { :op => 'c', :values => [''] }, |
|
152 | 'c' => { :op => 'c', :values => [''] }, | |
153 | '7' => { :op => '=', :values => ['7'] }, |
|
153 | '7' => { :op => '=', :values => ['7'] }, | |
154 | '7|3|4' => { :op => '=', :values => ['7', '3', '4'] }, |
|
154 | '7|3|4' => { :op => '=', :values => ['7', '3', '4'] }, | |
155 | '=7' => { :op => '=', :values => ['7'] }, |
|
155 | '=7' => { :op => '=', :values => ['7'] }, | |
156 | '!3' => { :op => '!', :values => ['3'] }, |
|
156 | '!3' => { :op => '!', :values => ['3'] }, | |
157 | '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }}, |
|
157 | '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }}, | |
158 | 'subject' => { |
|
158 | 'subject' => { | |
159 | 'This is a subject' => { :op => '=', :values => ['This is a subject'] }, |
|
159 | 'This is a subject' => { :op => '=', :values => ['This is a subject'] }, | |
160 | 'o' => { :op => '=', :values => ['o'] }, |
|
160 | 'o' => { :op => '=', :values => ['o'] }, | |
161 | '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] }, |
|
161 | '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] }, | |
162 | '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }}, |
|
162 | '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }}, | |
163 | 'tracker_id' => { |
|
163 | 'tracker_id' => { | |
164 | '3' => { :op => '=', :values => ['3'] }, |
|
164 | '3' => { :op => '=', :values => ['3'] }, | |
165 | '=3' => { :op => '=', :values => ['3'] }}, |
|
165 | '=3' => { :op => '=', :values => ['3'] }}, | |
166 | 'start_date' => { |
|
166 | 'start_date' => { | |
167 | '2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, |
|
167 | '2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, | |
168 | '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, |
|
168 | '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, | |
169 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, |
|
169 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, | |
170 | '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] }, |
|
170 | '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] }, | |
171 | '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] }, |
|
171 | '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] }, | |
172 | '<t+2' => { :op => '<t+', :values => ['2'] }, |
|
172 | '<t+2' => { :op => '<t+', :values => ['2'] }, | |
173 | '>t+2' => { :op => '>t+', :values => ['2'] }, |
|
173 | '>t+2' => { :op => '>t+', :values => ['2'] }, | |
174 | 't+2' => { :op => 't+', :values => ['2'] }, |
|
174 | 't+2' => { :op => 't+', :values => ['2'] }, | |
175 | 't' => { :op => 't', :values => [''] }, |
|
175 | 't' => { :op => 't', :values => [''] }, | |
176 | 'w' => { :op => 'w', :values => [''] }, |
|
176 | 'w' => { :op => 'w', :values => [''] }, | |
177 | '>t-2' => { :op => '>t-', :values => ['2'] }, |
|
177 | '>t-2' => { :op => '>t-', :values => ['2'] }, | |
178 | '<t-2' => { :op => '<t-', :values => ['2'] }, |
|
178 | '<t-2' => { :op => '<t-', :values => ['2'] }, | |
179 | 't-2' => { :op => 't-', :values => ['2'] }}, |
|
179 | 't-2' => { :op => 't-', :values => ['2'] }}, | |
180 | 'created_on' => { |
|
180 | 'created_on' => { | |
181 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, |
|
181 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, | |
182 | '<t+2' => { :op => '=', :values => ['<t+2'] }, |
|
182 | '<t+2' => { :op => '=', :values => ['<t+2'] }, | |
183 | '>t+2' => { :op => '=', :values => ['>t+2'] }, |
|
183 | '>t+2' => { :op => '=', :values => ['>t+2'] }, | |
184 | 't+2' => { :op => 't', :values => ['+2'] }}, |
|
184 | 't+2' => { :op => 't', :values => ['+2'] }}, | |
185 | 'cf_1' => { |
|
185 | 'cf_1' => { | |
186 | 'c' => { :op => '=', :values => ['c'] }, |
|
186 | 'c' => { :op => '=', :values => ['c'] }, | |
187 | '!c' => { :op => '!', :values => ['c'] }, |
|
187 | '!c' => { :op => '!', :values => ['c'] }, | |
188 | '!*' => { :op => '!*', :values => [''] }, |
|
188 | '!*' => { :op => '!*', :values => [''] }, | |
189 | '*' => { :op => '*', :values => [''] }}, |
|
189 | '*' => { :op => '*', :values => [''] }}, | |
190 | 'estimated_hours' => { |
|
190 | 'estimated_hours' => { | |
191 | '=13.4' => { :op => '=', :values => ['13.4'] }, |
|
191 | '=13.4' => { :op => '=', :values => ['13.4'] }, | |
192 | '>=45' => { :op => '>=', :values => ['45'] }, |
|
192 | '>=45' => { :op => '>=', :values => ['45'] }, | |
193 | '<=125' => { :op => '<=', :values => ['125'] }, |
|
193 | '<=125' => { :op => '<=', :values => ['125'] }, | |
194 | '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] }, |
|
194 | '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] }, | |
195 | '!*' => { :op => '!*', :values => [''] }, |
|
195 | '!*' => { :op => '!*', :values => [''] }, | |
196 | '*' => { :op => '*', :values => [''] }} |
|
196 | '*' => { :op => '*', :values => [''] }} | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | default_filter = { 'status_id' => {:operator => 'o', :values => [''] }} |
|
199 | default_filter = { 'status_id' => {:operator => 'o', :values => [''] }} | |
200 |
|
200 | |||
201 | to_test.each do |field, expression_and_expected| |
|
201 | to_test.each do |field, expression_and_expected| | |
202 | expression_and_expected.each do |filter_expression, expected| |
|
202 | expression_and_expected.each do |filter_expression, expected| | |
203 |
|
203 | |||
204 | get :index, :set_filter => 1, field => filter_expression |
|
204 | get :index, :set_filter => 1, field => filter_expression | |
205 |
|
205 | |||
206 | assert_response :success |
|
206 | assert_response :success | |
207 | assert_template 'index' |
|
207 | assert_template 'index' | |
208 | assert_not_nil assigns(:issues) |
|
208 | assert_not_nil assigns(:issues) | |
209 |
|
209 | |||
210 | query = assigns(:query) |
|
210 | query = assigns(:query) | |
211 | assert_not_nil query |
|
211 | assert_not_nil query | |
212 | assert query.has_filter?(field) |
|
212 | assert query.has_filter?(field) | |
213 | assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters) |
|
213 | assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters) | |
214 | end |
|
214 | end | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | end |
|
217 | end | |
218 |
|
218 | |||
219 | def test_index_with_project_and_empty_filters |
|
219 | def test_index_with_project_and_empty_filters | |
220 | get :index, :project_id => 1, :set_filter => 1, :fields => [''] |
|
220 | get :index, :project_id => 1, :set_filter => 1, :fields => [''] | |
221 | assert_response :success |
|
221 | assert_response :success | |
222 | assert_template 'index' |
|
222 | assert_template 'index' | |
223 | assert_not_nil assigns(:issues) |
|
223 | assert_not_nil assigns(:issues) | |
224 |
|
224 | |||
225 | query = assigns(:query) |
|
225 | query = assigns(:query) | |
226 | assert_not_nil query |
|
226 | assert_not_nil query | |
227 | # no filter |
|
227 | # no filter | |
228 | assert_equal({}, query.filters) |
|
228 | assert_equal({}, query.filters) | |
229 | end |
|
229 | end | |
230 |
|
230 | |||
231 | def test_index_with_query |
|
231 | def test_index_with_query | |
232 | get :index, :project_id => 1, :query_id => 5 |
|
232 | get :index, :project_id => 1, :query_id => 5 | |
233 | assert_response :success |
|
233 | assert_response :success | |
234 | assert_template 'index' |
|
234 | assert_template 'index' | |
235 | assert_not_nil assigns(:issues) |
|
235 | assert_not_nil assigns(:issues) | |
236 | assert_nil assigns(:issue_count_by_group) |
|
236 | assert_nil assigns(:issue_count_by_group) | |
237 | end |
|
237 | end | |
238 |
|
238 | |||
239 | def test_index_with_query_grouped_by_tracker |
|
239 | def test_index_with_query_grouped_by_tracker | |
240 | get :index, :project_id => 1, :query_id => 6 |
|
240 | get :index, :project_id => 1, :query_id => 6 | |
241 | assert_response :success |
|
241 | assert_response :success | |
242 | assert_template 'index' |
|
242 | assert_template 'index' | |
243 | assert_not_nil assigns(:issues) |
|
243 | assert_not_nil assigns(:issues) | |
244 | assert_not_nil assigns(:issue_count_by_group) |
|
244 | assert_not_nil assigns(:issue_count_by_group) | |
245 | end |
|
245 | end | |
246 |
|
246 | |||
247 | def test_index_with_query_grouped_by_list_custom_field |
|
247 | def test_index_with_query_grouped_by_list_custom_field | |
248 | get :index, :project_id => 1, :query_id => 9 |
|
248 | get :index, :project_id => 1, :query_id => 9 | |
249 | assert_response :success |
|
249 | assert_response :success | |
250 | assert_template 'index' |
|
250 | assert_template 'index' | |
251 | assert_not_nil assigns(:issues) |
|
251 | assert_not_nil assigns(:issues) | |
252 | assert_not_nil assigns(:issue_count_by_group) |
|
252 | assert_not_nil assigns(:issue_count_by_group) | |
253 | end |
|
253 | end | |
254 |
|
254 | |||
255 | def test_private_query_should_not_be_available_to_other_users |
|
255 | def test_private_query_should_not_be_available_to_other_users | |
256 | q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil) |
|
256 | q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil) | |
257 | @request.session[:user_id] = 3 |
|
257 | @request.session[:user_id] = 3 | |
258 |
|
258 | |||
259 | get :index, :query_id => q.id |
|
259 | get :index, :query_id => q.id | |
260 | assert_response 403 |
|
260 | assert_response 403 | |
261 | end |
|
261 | end | |
262 |
|
262 | |||
263 | def test_private_query_should_be_available_to_its_user |
|
263 | def test_private_query_should_be_available_to_its_user | |
264 | q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil) |
|
264 | q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil) | |
265 | @request.session[:user_id] = 2 |
|
265 | @request.session[:user_id] = 2 | |
266 |
|
266 | |||
267 | get :index, :query_id => q.id |
|
267 | get :index, :query_id => q.id | |
268 | assert_response :success |
|
268 | assert_response :success | |
269 | end |
|
269 | end | |
270 |
|
270 | |||
271 | def test_public_query_should_be_available_to_other_users |
|
271 | def test_public_query_should_be_available_to_other_users | |
272 | q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil) |
|
272 | q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil) | |
273 | @request.session[:user_id] = 3 |
|
273 | @request.session[:user_id] = 3 | |
274 |
|
274 | |||
275 | get :index, :query_id => q.id |
|
275 | get :index, :query_id => q.id | |
276 | assert_response :success |
|
276 | assert_response :success | |
277 | end |
|
277 | end | |
278 |
|
278 | |||
279 | def test_index_sort_by_field_not_included_in_columns |
|
279 | def test_index_sort_by_field_not_included_in_columns | |
280 | Setting.issue_list_default_columns = %w(subject author) |
|
280 | Setting.issue_list_default_columns = %w(subject author) | |
281 | get :index, :sort => 'tracker' |
|
281 | get :index, :sort => 'tracker' | |
282 | end |
|
282 | end | |
283 |
|
283 | |||
284 | def test_index_csv_with_project |
|
284 | def test_index_csv_with_project | |
285 | Setting.default_language = 'en' |
|
285 | Setting.default_language = 'en' | |
286 |
|
286 | |||
287 | get :index, :format => 'csv' |
|
287 | get :index, :format => 'csv' | |
288 | assert_response :success |
|
288 | assert_response :success | |
289 | assert_not_nil assigns(:issues) |
|
289 | assert_not_nil assigns(:issues) | |
290 | assert_equal 'text/csv', @response.content_type |
|
290 | assert_equal 'text/csv', @response.content_type | |
291 | assert @response.body.starts_with?("#,") |
|
291 | assert @response.body.starts_with?("#,") | |
292 |
|
292 | |||
293 | get :index, :project_id => 1, :format => 'csv' |
|
293 | get :index, :project_id => 1, :format => 'csv' | |
294 | assert_response :success |
|
294 | assert_response :success | |
295 | assert_not_nil assigns(:issues) |
|
295 | assert_not_nil assigns(:issues) | |
296 | assert_equal 'text/csv', @response.content_type |
|
296 | assert_equal 'text/csv', @response.content_type | |
297 | end |
|
297 | end | |
298 |
|
298 | |||
299 | def test_index_pdf |
|
299 | def test_index_pdf | |
300 | get :index, :format => 'pdf' |
|
300 | get :index, :format => 'pdf' | |
301 | assert_response :success |
|
301 | assert_response :success | |
302 | assert_not_nil assigns(:issues) |
|
302 | assert_not_nil assigns(:issues) | |
303 | assert_equal 'application/pdf', @response.content_type |
|
303 | assert_equal 'application/pdf', @response.content_type | |
304 |
|
304 | |||
305 | get :index, :project_id => 1, :format => 'pdf' |
|
305 | get :index, :project_id => 1, :format => 'pdf' | |
306 | assert_response :success |
|
306 | assert_response :success | |
307 | assert_not_nil assigns(:issues) |
|
307 | assert_not_nil assigns(:issues) | |
308 | assert_equal 'application/pdf', @response.content_type |
|
308 | assert_equal 'application/pdf', @response.content_type | |
309 |
|
309 | |||
310 | get :index, :project_id => 1, :query_id => 6, :format => 'pdf' |
|
310 | get :index, :project_id => 1, :query_id => 6, :format => 'pdf' | |
311 | assert_response :success |
|
311 | assert_response :success | |
312 | assert_not_nil assigns(:issues) |
|
312 | assert_not_nil assigns(:issues) | |
313 | assert_equal 'application/pdf', @response.content_type |
|
313 | assert_equal 'application/pdf', @response.content_type | |
314 | end |
|
314 | end | |
315 |
|
315 | |||
316 | def test_index_pdf_with_query_grouped_by_list_custom_field |
|
316 | def test_index_pdf_with_query_grouped_by_list_custom_field | |
317 | get :index, :project_id => 1, :query_id => 9, :format => 'pdf' |
|
317 | get :index, :project_id => 1, :query_id => 9, :format => 'pdf' | |
318 | assert_response :success |
|
318 | assert_response :success | |
319 | assert_not_nil assigns(:issues) |
|
319 | assert_not_nil assigns(:issues) | |
320 | assert_not_nil assigns(:issue_count_by_group) |
|
320 | assert_not_nil assigns(:issue_count_by_group) | |
321 | assert_equal 'application/pdf', @response.content_type |
|
321 | assert_equal 'application/pdf', @response.content_type | |
322 | end |
|
322 | end | |
323 |
|
323 | |||
324 | def test_index_sort |
|
324 | def test_index_sort | |
325 | get :index, :sort => 'tracker,id:desc' |
|
325 | get :index, :sort => 'tracker,id:desc' | |
326 | assert_response :success |
|
326 | assert_response :success | |
327 |
|
327 | |||
328 | sort_params = @request.session['issues_index_sort'] |
|
328 | sort_params = @request.session['issues_index_sort'] | |
329 | assert sort_params.is_a?(String) |
|
329 | assert sort_params.is_a?(String) | |
330 | assert_equal 'tracker,id:desc', sort_params |
|
330 | assert_equal 'tracker,id:desc', sort_params | |
331 |
|
331 | |||
332 | issues = assigns(:issues) |
|
332 | issues = assigns(:issues) | |
333 | assert_not_nil issues |
|
333 | assert_not_nil issues | |
334 | assert !issues.empty? |
|
334 | assert !issues.empty? | |
335 | assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id) |
|
335 | assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id) | |
336 | end |
|
336 | end | |
337 |
|
337 | |||
338 | def test_index_with_columns |
|
338 | def test_index_with_columns | |
339 | columns = ['tracker', 'subject', 'assigned_to'] |
|
339 | columns = ['tracker', 'subject', 'assigned_to'] | |
340 | get :index, :set_filter => 1, :c => columns |
|
340 | get :index, :set_filter => 1, :c => columns | |
341 | assert_response :success |
|
341 | assert_response :success | |
342 |
|
342 | |||
343 | # query should use specified columns |
|
343 | # query should use specified columns | |
344 | query = assigns(:query) |
|
344 | query = assigns(:query) | |
345 | assert_kind_of Query, query |
|
345 | assert_kind_of Query, query | |
346 | assert_equal columns, query.column_names.map(&:to_s) |
|
346 | assert_equal columns, query.column_names.map(&:to_s) | |
347 |
|
347 | |||
348 | # columns should be stored in session |
|
348 | # columns should be stored in session | |
349 | assert_kind_of Hash, session[:query] |
|
349 | assert_kind_of Hash, session[:query] | |
350 | assert_kind_of Array, session[:query][:column_names] |
|
350 | assert_kind_of Array, session[:query][:column_names] | |
351 | assert_equal columns, session[:query][:column_names].map(&:to_s) |
|
351 | assert_equal columns, session[:query][:column_names].map(&:to_s) | |
352 |
|
352 | |||
353 | # ensure only these columns are kept in the selected columns list |
|
353 | # ensure only these columns are kept in the selected columns list | |
354 | assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' }, |
|
354 | assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' }, | |
355 | :children => { :count => 3 } |
|
355 | :children => { :count => 3 } | |
356 | assert_no_tag :tag => 'option', :attributes => { :value => 'project' }, |
|
356 | assert_no_tag :tag => 'option', :attributes => { :value => 'project' }, | |
357 | :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } } |
|
357 | :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } } | |
358 | end |
|
358 | end | |
359 |
|
359 | |||
360 | def test_index_without_project_should_implicitly_add_project_column_to_default_columns |
|
360 | def test_index_without_project_should_implicitly_add_project_column_to_default_columns | |
361 | Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] |
|
361 | Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] | |
362 | get :index, :set_filter => 1 |
|
362 | get :index, :set_filter => 1 | |
363 |
|
363 | |||
364 | # query should use specified columns |
|
364 | # query should use specified columns | |
365 | query = assigns(:query) |
|
365 | query = assigns(:query) | |
366 | assert_kind_of Query, query |
|
366 | assert_kind_of Query, query | |
367 | assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name) |
|
367 | assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name) | |
368 | end |
|
368 | end | |
369 |
|
369 | |||
370 | def test_index_without_project_and_explicit_default_columns_should_not_add_project_column |
|
370 | def test_index_without_project_and_explicit_default_columns_should_not_add_project_column | |
371 | Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] |
|
371 | Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] | |
372 | columns = ['tracker', 'subject', 'assigned_to'] |
|
372 | columns = ['tracker', 'subject', 'assigned_to'] | |
373 | get :index, :set_filter => 1, :c => columns |
|
373 | get :index, :set_filter => 1, :c => columns | |
374 |
|
374 | |||
375 | # query should use specified columns |
|
375 | # query should use specified columns | |
376 | query = assigns(:query) |
|
376 | query = assigns(:query) | |
377 | assert_kind_of Query, query |
|
377 | assert_kind_of Query, query | |
378 | assert_equal columns.map(&:to_sym), query.columns.map(&:name) |
|
378 | assert_equal columns.map(&:to_sym), query.columns.map(&:name) | |
379 | end |
|
379 | end | |
380 |
|
380 | |||
381 | def test_index_with_custom_field_column |
|
381 | def test_index_with_custom_field_column | |
382 | columns = %w(tracker subject cf_2) |
|
382 | columns = %w(tracker subject cf_2) | |
383 | get :index, :set_filter => 1, :c => columns |
|
383 | get :index, :set_filter => 1, :c => columns | |
384 | assert_response :success |
|
384 | assert_response :success | |
385 |
|
385 | |||
386 | # query should use specified columns |
|
386 | # query should use specified columns | |
387 | query = assigns(:query) |
|
387 | query = assigns(:query) | |
388 | assert_kind_of Query, query |
|
388 | assert_kind_of Query, query | |
389 | assert_equal columns, query.column_names.map(&:to_s) |
|
389 | assert_equal columns, query.column_names.map(&:to_s) | |
390 |
|
390 | |||
391 | assert_tag :td, |
|
391 | assert_tag :td, | |
392 | :attributes => {:class => 'cf_2 string'}, |
|
392 | :attributes => {:class => 'cf_2 string'}, | |
393 | :ancestor => {:tag => 'table', :attributes => {:class => /issues/}} |
|
393 | :ancestor => {:tag => 'table', :attributes => {:class => /issues/}} | |
394 | end |
|
394 | end | |
395 |
|
395 | |||
396 | def test_index_send_html_if_query_is_invalid |
|
396 | def test_index_send_html_if_query_is_invalid | |
397 | get :index, :f => ['start_date'], :op => {:start_date => '='} |
|
397 | get :index, :f => ['start_date'], :op => {:start_date => '='} | |
398 | assert_equal 'text/html', @response.content_type |
|
398 | assert_equal 'text/html', @response.content_type | |
399 | assert_template 'index' |
|
399 | assert_template 'index' | |
400 | end |
|
400 | end | |
401 |
|
401 | |||
402 | def test_index_send_nothing_if_query_is_invalid |
|
402 | def test_index_send_nothing_if_query_is_invalid | |
403 | get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv' |
|
403 | get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv' | |
404 | assert_equal 'text/csv', @response.content_type |
|
404 | assert_equal 'text/csv', @response.content_type | |
405 | assert @response.body.blank? |
|
405 | assert @response.body.blank? | |
406 | end |
|
406 | end | |
407 |
|
407 | |||
408 | def test_show_by_anonymous |
|
408 | def test_show_by_anonymous | |
409 | get :show, :id => 1 |
|
409 | get :show, :id => 1 | |
410 | assert_response :success |
|
410 | assert_response :success | |
411 | assert_template 'show' |
|
411 | assert_template 'show' | |
412 | assert_not_nil assigns(:issue) |
|
412 | assert_not_nil assigns(:issue) | |
413 | assert_equal Issue.find(1), assigns(:issue) |
|
413 | assert_equal Issue.find(1), assigns(:issue) | |
414 |
|
414 | |||
415 | # anonymous role is allowed to add a note |
|
415 | # anonymous role is allowed to add a note | |
416 | assert_tag :tag => 'form', |
|
416 | assert_tag :tag => 'form', | |
417 | :descendant => { :tag => 'fieldset', |
|
417 | :descendant => { :tag => 'fieldset', | |
418 | :child => { :tag => 'legend', |
|
418 | :child => { :tag => 'legend', | |
419 | :content => /Notes/ } } |
|
419 | :content => /Notes/ } } | |
420 | end |
|
420 | end | |
421 |
|
421 | |||
422 | def test_show_by_manager |
|
422 | def test_show_by_manager | |
423 | @request.session[:user_id] = 2 |
|
423 | @request.session[:user_id] = 2 | |
424 | get :show, :id => 1 |
|
424 | get :show, :id => 1 | |
425 | assert_response :success |
|
425 | assert_response :success | |
426 |
|
426 | |||
427 | assert_tag :tag => 'a', |
|
427 | assert_tag :tag => 'a', | |
428 | :content => /Quote/ |
|
428 | :content => /Quote/ | |
429 |
|
429 | |||
430 | assert_tag :tag => 'form', |
|
430 | assert_tag :tag => 'form', | |
431 | :descendant => { :tag => 'fieldset', |
|
431 | :descendant => { :tag => 'fieldset', | |
432 | :child => { :tag => 'legend', |
|
432 | :child => { :tag => 'legend', | |
433 | :content => /Change properties/ } }, |
|
433 | :content => /Change properties/ } }, | |
434 | :descendant => { :tag => 'fieldset', |
|
434 | :descendant => { :tag => 'fieldset', | |
435 | :child => { :tag => 'legend', |
|
435 | :child => { :tag => 'legend', | |
436 | :content => /Log time/ } }, |
|
436 | :content => /Log time/ } }, | |
437 | :descendant => { :tag => 'fieldset', |
|
437 | :descendant => { :tag => 'fieldset', | |
438 | :child => { :tag => 'legend', |
|
438 | :child => { :tag => 'legend', | |
439 | :content => /Notes/ } } |
|
439 | :content => /Notes/ } } | |
440 | end |
|
440 | end | |
441 |
|
441 | |||
442 | def test_update_form_should_not_display_inactive_enumerations |
|
442 | def test_update_form_should_not_display_inactive_enumerations | |
443 | @request.session[:user_id] = 2 |
|
443 | @request.session[:user_id] = 2 | |
444 | get :show, :id => 1 |
|
444 | get :show, :id => 1 | |
445 | assert_response :success |
|
445 | assert_response :success | |
446 |
|
446 | |||
447 | assert ! IssuePriority.find(15).active? |
|
447 | assert ! IssuePriority.find(15).active? | |
448 | assert_no_tag :option, :attributes => {:value => '15'}, |
|
448 | assert_no_tag :option, :attributes => {:value => '15'}, | |
449 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } |
|
449 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } | |
450 | end |
|
450 | end | |
451 |
|
451 | |||
452 | def test_update_form_should_allow_attachment_upload |
|
452 | def test_update_form_should_allow_attachment_upload | |
453 | @request.session[:user_id] = 2 |
|
453 | @request.session[:user_id] = 2 | |
454 | get :show, :id => 1 |
|
454 | get :show, :id => 1 | |
455 |
|
455 | |||
456 | assert_tag :tag => 'form', |
|
456 | assert_tag :tag => 'form', | |
457 | :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'}, |
|
457 | :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'}, | |
458 | :descendant => { |
|
458 | :descendant => { | |
459 | :tag => 'input', |
|
459 | :tag => 'input', | |
460 | :attributes => {:type => 'file', :name => 'attachments[1][file]'} |
|
460 | :attributes => {:type => 'file', :name => 'attachments[1][file]'} | |
461 | } |
|
461 | } | |
462 | end |
|
462 | end | |
463 |
|
463 | |||
464 | def test_show_should_deny_anonymous_access_without_permission |
|
464 | def test_show_should_deny_anonymous_access_without_permission | |
465 | Role.anonymous.remove_permission!(:view_issues) |
|
465 | Role.anonymous.remove_permission!(:view_issues) | |
466 | get :show, :id => 1 |
|
466 | get :show, :id => 1 | |
467 | assert_response :redirect |
|
467 | assert_response :redirect | |
468 | end |
|
468 | end | |
469 |
|
469 | |||
470 | def test_show_should_deny_anonymous_access_to_private_issue |
|
470 | def test_show_should_deny_anonymous_access_to_private_issue | |
471 | Issue.update_all(["is_private = ?", true], "id = 1") |
|
471 | Issue.update_all(["is_private = ?", true], "id = 1") | |
472 | get :show, :id => 1 |
|
472 | get :show, :id => 1 | |
473 | assert_response :redirect |
|
473 | assert_response :redirect | |
474 | end |
|
474 | end | |
475 |
|
475 | |||
476 | def test_show_should_deny_non_member_access_without_permission |
|
476 | def test_show_should_deny_non_member_access_without_permission | |
477 | Role.non_member.remove_permission!(:view_issues) |
|
477 | Role.non_member.remove_permission!(:view_issues) | |
478 | @request.session[:user_id] = 9 |
|
478 | @request.session[:user_id] = 9 | |
479 | get :show, :id => 1 |
|
479 | get :show, :id => 1 | |
480 | assert_response 403 |
|
480 | assert_response 403 | |
481 | end |
|
481 | end | |
482 |
|
482 | |||
483 | def test_show_should_deny_non_member_access_to_private_issue |
|
483 | def test_show_should_deny_non_member_access_to_private_issue | |
484 | Issue.update_all(["is_private = ?", true], "id = 1") |
|
484 | Issue.update_all(["is_private = ?", true], "id = 1") | |
485 | @request.session[:user_id] = 9 |
|
485 | @request.session[:user_id] = 9 | |
486 | get :show, :id => 1 |
|
486 | get :show, :id => 1 | |
487 | assert_response 403 |
|
487 | assert_response 403 | |
488 | end |
|
488 | end | |
489 |
|
489 | |||
490 | def test_show_should_deny_member_access_without_permission |
|
490 | def test_show_should_deny_member_access_without_permission | |
491 | Role.find(1).remove_permission!(:view_issues) |
|
491 | Role.find(1).remove_permission!(:view_issues) | |
492 | @request.session[:user_id] = 2 |
|
492 | @request.session[:user_id] = 2 | |
493 | get :show, :id => 1 |
|
493 | get :show, :id => 1 | |
494 | assert_response 403 |
|
494 | assert_response 403 | |
495 | end |
|
495 | end | |
496 |
|
496 | |||
497 | def test_show_should_deny_member_access_to_private_issue_without_permission |
|
497 | def test_show_should_deny_member_access_to_private_issue_without_permission | |
498 | Issue.update_all(["is_private = ?", true], "id = 1") |
|
498 | Issue.update_all(["is_private = ?", true], "id = 1") | |
499 | @request.session[:user_id] = 3 |
|
499 | @request.session[:user_id] = 3 | |
500 | get :show, :id => 1 |
|
500 | get :show, :id => 1 | |
501 | assert_response 403 |
|
501 | assert_response 403 | |
502 | end |
|
502 | end | |
503 |
|
503 | |||
504 | def test_show_should_allow_author_access_to_private_issue |
|
504 | def test_show_should_allow_author_access_to_private_issue | |
505 | Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1") |
|
505 | Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1") | |
506 | @request.session[:user_id] = 3 |
|
506 | @request.session[:user_id] = 3 | |
507 | get :show, :id => 1 |
|
507 | get :show, :id => 1 | |
508 | assert_response :success |
|
508 | assert_response :success | |
509 | end |
|
509 | end | |
510 |
|
510 | |||
511 | def test_show_should_allow_assignee_access_to_private_issue |
|
511 | def test_show_should_allow_assignee_access_to_private_issue | |
512 | Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1") |
|
512 | Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1") | |
513 | @request.session[:user_id] = 3 |
|
513 | @request.session[:user_id] = 3 | |
514 | get :show, :id => 1 |
|
514 | get :show, :id => 1 | |
515 | assert_response :success |
|
515 | assert_response :success | |
516 | end |
|
516 | end | |
517 |
|
517 | |||
518 | def test_show_should_allow_member_access_to_private_issue_with_permission |
|
518 | def test_show_should_allow_member_access_to_private_issue_with_permission | |
519 | Issue.update_all(["is_private = ?", true], "id = 1") |
|
519 | Issue.update_all(["is_private = ?", true], "id = 1") | |
520 | User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all' |
|
520 | User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all' | |
521 | @request.session[:user_id] = 3 |
|
521 | @request.session[:user_id] = 3 | |
522 | get :show, :id => 1 |
|
522 | get :show, :id => 1 | |
523 | assert_response :success |
|
523 | assert_response :success | |
524 | end |
|
524 | end | |
525 |
|
525 | |||
526 | def test_show_should_not_disclose_relations_to_invisible_issues |
|
526 | def test_show_should_not_disclose_relations_to_invisible_issues | |
527 | Setting.cross_project_issue_relations = '1' |
|
527 | Setting.cross_project_issue_relations = '1' | |
528 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates') |
|
528 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates') | |
529 | # Relation to a private project issue |
|
529 | # Relation to a private project issue | |
530 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates') |
|
530 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates') | |
531 |
|
531 | |||
532 | get :show, :id => 1 |
|
532 | get :show, :id => 1 | |
533 | assert_response :success |
|
533 | assert_response :success | |
534 |
|
534 | |||
535 | assert_tag :div, :attributes => { :id => 'relations' }, |
|
535 | assert_tag :div, :attributes => { :id => 'relations' }, | |
536 | :descendant => { :tag => 'a', :content => /#2$/ } |
|
536 | :descendant => { :tag => 'a', :content => /#2$/ } | |
537 | assert_no_tag :div, :attributes => { :id => 'relations' }, |
|
537 | assert_no_tag :div, :attributes => { :id => 'relations' }, | |
538 | :descendant => { :tag => 'a', :content => /#4$/ } |
|
538 | :descendant => { :tag => 'a', :content => /#4$/ } | |
539 | end |
|
539 | end | |
540 |
|
540 | |||
541 | def test_show_atom |
|
541 | def test_show_atom | |
542 | get :show, :id => 2, :format => 'atom' |
|
542 | get :show, :id => 2, :format => 'atom' | |
543 | assert_response :success |
|
543 | assert_response :success | |
544 | assert_template 'journals/index' |
|
544 | assert_template 'journals/index' | |
545 | # Inline image |
|
545 | # Inline image | |
546 | assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10')) |
|
546 | assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10')) | |
547 | end |
|
547 | end | |
548 |
|
548 | |||
549 | def test_show_export_to_pdf |
|
549 | def test_show_export_to_pdf | |
550 | get :show, :id => 3, :format => 'pdf' |
|
550 | get :show, :id => 3, :format => 'pdf' | |
551 | assert_response :success |
|
551 | assert_response :success | |
552 | assert_equal 'application/pdf', @response.content_type |
|
552 | assert_equal 'application/pdf', @response.content_type | |
553 | assert @response.body.starts_with?('%PDF') |
|
553 | assert @response.body.starts_with?('%PDF') | |
554 | assert_not_nil assigns(:issue) |
|
554 | assert_not_nil assigns(:issue) | |
555 | end |
|
555 | end | |
556 |
|
556 | |||
557 | def test_get_new |
|
557 | def test_get_new | |
558 | @request.session[:user_id] = 2 |
|
558 | @request.session[:user_id] = 2 | |
559 | get :new, :project_id => 1, :tracker_id => 1 |
|
559 | get :new, :project_id => 1, :tracker_id => 1 | |
560 | assert_response :success |
|
560 | assert_response :success | |
561 | assert_template 'new' |
|
561 | assert_template 'new' | |
562 |
|
562 | |||
563 | assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]', |
|
563 | assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]', | |
564 | :value => 'Default string' } |
|
564 | :value => 'Default string' } | |
565 |
|
565 | |||
566 | # Be sure we don't display inactive IssuePriorities |
|
566 | # Be sure we don't display inactive IssuePriorities | |
567 | assert ! IssuePriority.find(15).active? |
|
567 | assert ! IssuePriority.find(15).active? | |
568 | assert_no_tag :option, :attributes => {:value => '15'}, |
|
568 | assert_no_tag :option, :attributes => {:value => '15'}, | |
569 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } |
|
569 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } | |
570 | end |
|
570 | end | |
571 |
|
571 | |||
572 | def test_get_new_without_default_start_date_is_creation_date |
|
572 | def test_get_new_without_default_start_date_is_creation_date | |
573 | Setting.default_issue_start_date_to_creation_date = 0 |
|
573 | Setting.default_issue_start_date_to_creation_date = 0 | |
574 |
|
574 | |||
575 | @request.session[:user_id] = 2 |
|
575 | @request.session[:user_id] = 2 | |
576 | get :new, :project_id => 1, :tracker_id => 1 |
|
576 | get :new, :project_id => 1, :tracker_id => 1 | |
577 | assert_response :success |
|
577 | assert_response :success | |
578 | assert_template 'new' |
|
578 | assert_template 'new' | |
579 |
|
579 | |||
580 | assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]', |
|
580 | assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]', | |
581 | :value => nil } |
|
581 | :value => nil } | |
582 | end |
|
582 | end | |
583 |
|
583 | |||
584 | def test_get_new_with_default_start_date_is_creation_date |
|
584 | def test_get_new_with_default_start_date_is_creation_date | |
585 | Setting.default_issue_start_date_to_creation_date = 1 |
|
585 | Setting.default_issue_start_date_to_creation_date = 1 | |
586 |
|
586 | |||
587 | @request.session[:user_id] = 2 |
|
587 | @request.session[:user_id] = 2 | |
588 | get :new, :project_id => 1, :tracker_id => 1 |
|
588 | get :new, :project_id => 1, :tracker_id => 1 | |
589 | assert_response :success |
|
589 | assert_response :success | |
590 | assert_template 'new' |
|
590 | assert_template 'new' | |
591 |
|
591 | |||
592 | assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]', |
|
592 | assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]', | |
593 | :value => Date.today.to_s } |
|
593 | :value => Date.today.to_s } | |
594 | end |
|
594 | end | |
595 |
|
595 | |||
596 | def test_get_new_form_should_allow_attachment_upload |
|
596 | def test_get_new_form_should_allow_attachment_upload | |
597 | @request.session[:user_id] = 2 |
|
597 | @request.session[:user_id] = 2 | |
598 | get :new, :project_id => 1, :tracker_id => 1 |
|
598 | get :new, :project_id => 1, :tracker_id => 1 | |
599 |
|
599 | |||
600 | assert_tag :tag => 'form', |
|
600 | assert_tag :tag => 'form', | |
601 | :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'}, |
|
601 | :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'}, | |
602 | :descendant => { |
|
602 | :descendant => { | |
603 | :tag => 'input', |
|
603 | :tag => 'input', | |
604 | :attributes => {:type => 'file', :name => 'attachments[1][file]'} |
|
604 | :attributes => {:type => 'file', :name => 'attachments[1][file]'} | |
605 | } |
|
605 | } | |
606 | end |
|
606 | end | |
607 |
|
607 | |||
608 | def test_get_new_without_tracker_id |
|
608 | def test_get_new_without_tracker_id | |
609 | @request.session[:user_id] = 2 |
|
609 | @request.session[:user_id] = 2 | |
610 | get :new, :project_id => 1 |
|
610 | get :new, :project_id => 1 | |
611 | assert_response :success |
|
611 | assert_response :success | |
612 | assert_template 'new' |
|
612 | assert_template 'new' | |
613 |
|
613 | |||
614 | issue = assigns(:issue) |
|
614 | issue = assigns(:issue) | |
615 | assert_not_nil issue |
|
615 | assert_not_nil issue | |
616 | assert_equal Project.find(1).trackers.first, issue.tracker |
|
616 | assert_equal Project.find(1).trackers.first, issue.tracker | |
617 | end |
|
617 | end | |
618 |
|
618 | |||
619 | def test_get_new_with_no_default_status_should_display_an_error |
|
619 | def test_get_new_with_no_default_status_should_display_an_error | |
620 | @request.session[:user_id] = 2 |
|
620 | @request.session[:user_id] = 2 | |
621 | IssueStatus.delete_all |
|
621 | IssueStatus.delete_all | |
622 |
|
622 | |||
623 | get :new, :project_id => 1 |
|
623 | get :new, :project_id => 1 | |
624 | assert_response 500 |
|
624 | assert_response 500 | |
625 | assert_error_tag :content => /No default issue/ |
|
625 | assert_error_tag :content => /No default issue/ | |
626 | end |
|
626 | end | |
627 |
|
627 | |||
628 | def test_get_new_with_no_tracker_should_display_an_error |
|
628 | def test_get_new_with_no_tracker_should_display_an_error | |
629 | @request.session[:user_id] = 2 |
|
629 | @request.session[:user_id] = 2 | |
630 | Tracker.delete_all |
|
630 | Tracker.delete_all | |
631 |
|
631 | |||
632 | get :new, :project_id => 1 |
|
632 | get :new, :project_id => 1 | |
633 | assert_response 500 |
|
633 | assert_response 500 | |
634 | assert_error_tag :content => /No tracker/ |
|
634 | assert_error_tag :content => /No tracker/ | |
635 | end |
|
635 | end | |
636 |
|
636 | |||
637 | def test_update_new_form |
|
637 | def test_update_new_form | |
638 | @request.session[:user_id] = 2 |
|
638 | @request.session[:user_id] = 2 | |
639 | xhr :post, :new, :project_id => 1, |
|
639 | xhr :post, :new, :project_id => 1, | |
640 | :issue => {:tracker_id => 2, |
|
640 | :issue => {:tracker_id => 2, | |
641 | :subject => 'This is the test_new issue', |
|
641 | :subject => 'This is the test_new issue', | |
642 | :description => 'This is the description', |
|
642 | :description => 'This is the description', | |
643 | :priority_id => 5} |
|
643 | :priority_id => 5} | |
644 | assert_response :success |
|
644 | assert_response :success | |
645 | assert_template 'attributes' |
|
645 | assert_template 'attributes' | |
646 |
|
646 | |||
647 | issue = assigns(:issue) |
|
647 | issue = assigns(:issue) | |
648 | assert_kind_of Issue, issue |
|
648 | assert_kind_of Issue, issue | |
649 | assert_equal 1, issue.project_id |
|
649 | assert_equal 1, issue.project_id | |
650 | assert_equal 2, issue.tracker_id |
|
650 | assert_equal 2, issue.tracker_id | |
651 | assert_equal 'This is the test_new issue', issue.subject |
|
651 | assert_equal 'This is the test_new issue', issue.subject | |
652 | end |
|
652 | end | |
653 |
|
653 | |||
654 | def test_post_create |
|
654 | def test_post_create | |
655 | @request.session[:user_id] = 2 |
|
655 | @request.session[:user_id] = 2 | |
656 | assert_difference 'Issue.count' do |
|
656 | assert_difference 'Issue.count' do | |
657 | post :create, :project_id => 1, |
|
657 | post :create, :project_id => 1, | |
658 | :issue => {:tracker_id => 3, |
|
658 | :issue => {:tracker_id => 3, | |
659 | :status_id => 2, |
|
659 | :status_id => 2, | |
660 | :subject => 'This is the test_new issue', |
|
660 | :subject => 'This is the test_new issue', | |
661 | :description => 'This is the description', |
|
661 | :description => 'This is the description', | |
662 | :priority_id => 5, |
|
662 | :priority_id => 5, | |
663 | :start_date => '2010-11-07', |
|
663 | :start_date => '2010-11-07', | |
664 | :estimated_hours => '', |
|
664 | :estimated_hours => '', | |
665 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
665 | :custom_field_values => {'2' => 'Value for field 2'}} | |
666 | end |
|
666 | end | |
667 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
667 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
668 |
|
668 | |||
669 | issue = Issue.find_by_subject('This is the test_new issue') |
|
669 | issue = Issue.find_by_subject('This is the test_new issue') | |
670 | assert_not_nil issue |
|
670 | assert_not_nil issue | |
671 | assert_equal 2, issue.author_id |
|
671 | assert_equal 2, issue.author_id | |
672 | assert_equal 3, issue.tracker_id |
|
672 | assert_equal 3, issue.tracker_id | |
673 | assert_equal 2, issue.status_id |
|
673 | assert_equal 2, issue.status_id | |
674 | assert_equal Date.parse('2010-11-07'), issue.start_date |
|
674 | assert_equal Date.parse('2010-11-07'), issue.start_date | |
675 | assert_nil issue.estimated_hours |
|
675 | assert_nil issue.estimated_hours | |
676 | v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) |
|
676 | v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) | |
677 | assert_not_nil v |
|
677 | assert_not_nil v | |
678 | assert_equal 'Value for field 2', v.value |
|
678 | assert_equal 'Value for field 2', v.value | |
679 | end |
|
679 | end | |
680 |
|
680 | |||
681 | def test_post_new_with_group_assignment |
|
681 | def test_post_new_with_group_assignment | |
682 | group = Group.find(11) |
|
682 | group = Group.find(11) | |
683 | project = Project.find(1) |
|
683 | project = Project.find(1) | |
684 | project.members << Member.new(:principal => group, :roles => [Role.first]) |
|
684 | project.members << Member.new(:principal => group, :roles => [Role.first]) | |
685 |
|
685 | |||
686 | with_settings :issue_group_assignment => '1' do |
|
686 | with_settings :issue_group_assignment => '1' do | |
687 | @request.session[:user_id] = 2 |
|
687 | @request.session[:user_id] = 2 | |
688 | assert_difference 'Issue.count' do |
|
688 | assert_difference 'Issue.count' do | |
689 | post :create, :project_id => project.id, |
|
689 | post :create, :project_id => project.id, | |
690 | :issue => {:tracker_id => 3, |
|
690 | :issue => {:tracker_id => 3, | |
691 | :status_id => 1, |
|
691 | :status_id => 1, | |
692 | :subject => 'This is the test_new_with_group_assignment issue', |
|
692 | :subject => 'This is the test_new_with_group_assignment issue', | |
693 | :assigned_to_id => group.id} |
|
693 | :assigned_to_id => group.id} | |
694 | end |
|
694 | end | |
695 | end |
|
695 | end | |
696 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
696 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
697 |
|
697 | |||
698 | issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue') |
|
698 | issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue') | |
699 | assert_not_nil issue |
|
699 | assert_not_nil issue | |
700 | assert_equal group, issue.assigned_to |
|
700 | assert_equal group, issue.assigned_to | |
701 | end |
|
701 | end | |
702 |
|
702 | |||
703 | def test_post_create_without_start_date_and_default_start_date_is_not_creation_date |
|
703 | def test_post_create_without_start_date_and_default_start_date_is_not_creation_date | |
704 | Setting.default_issue_start_date_to_creation_date = 0 |
|
704 | Setting.default_issue_start_date_to_creation_date = 0 | |
705 |
|
705 | |||
706 | @request.session[:user_id] = 2 |
|
706 | @request.session[:user_id] = 2 | |
707 | assert_difference 'Issue.count' do |
|
707 | assert_difference 'Issue.count' do | |
708 | post :create, :project_id => 1, |
|
708 | post :create, :project_id => 1, | |
709 | :issue => {:tracker_id => 3, |
|
709 | :issue => {:tracker_id => 3, | |
710 | :status_id => 2, |
|
710 | :status_id => 2, | |
711 | :subject => 'This is the test_new issue', |
|
711 | :subject => 'This is the test_new issue', | |
712 | :description => 'This is the description', |
|
712 | :description => 'This is the description', | |
713 | :priority_id => 5, |
|
713 | :priority_id => 5, | |
714 | :estimated_hours => '', |
|
714 | :estimated_hours => '', | |
715 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
715 | :custom_field_values => {'2' => 'Value for field 2'}} | |
716 | end |
|
716 | end | |
717 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
717 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
718 |
|
718 | |||
719 | issue = Issue.find_by_subject('This is the test_new issue') |
|
719 | issue = Issue.find_by_subject('This is the test_new issue') | |
720 | assert_not_nil issue |
|
720 | assert_not_nil issue | |
721 | assert_nil issue.start_date |
|
721 | assert_nil issue.start_date | |
722 | end |
|
722 | end | |
723 |
|
723 | |||
724 | def test_post_create_without_start_date_and_default_start_date_is_creation_date |
|
724 | def test_post_create_without_start_date_and_default_start_date_is_creation_date | |
725 | Setting.default_issue_start_date_to_creation_date = 1 |
|
725 | Setting.default_issue_start_date_to_creation_date = 1 | |
726 |
|
726 | |||
727 | @request.session[:user_id] = 2 |
|
727 | @request.session[:user_id] = 2 | |
728 | assert_difference 'Issue.count' do |
|
728 | assert_difference 'Issue.count' do | |
729 | post :create, :project_id => 1, |
|
729 | post :create, :project_id => 1, | |
730 | :issue => {:tracker_id => 3, |
|
730 | :issue => {:tracker_id => 3, | |
731 | :status_id => 2, |
|
731 | :status_id => 2, | |
732 | :subject => 'This is the test_new issue', |
|
732 | :subject => 'This is the test_new issue', | |
733 | :description => 'This is the description', |
|
733 | :description => 'This is the description', | |
734 | :priority_id => 5, |
|
734 | :priority_id => 5, | |
735 | :estimated_hours => '', |
|
735 | :estimated_hours => '', | |
736 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
736 | :custom_field_values => {'2' => 'Value for field 2'}} | |
737 | end |
|
737 | end | |
738 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
738 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
739 |
|
739 | |||
740 | issue = Issue.find_by_subject('This is the test_new issue') |
|
740 | issue = Issue.find_by_subject('This is the test_new issue') | |
741 | assert_not_nil issue |
|
741 | assert_not_nil issue | |
742 | assert_equal Date.today, issue.start_date |
|
742 | assert_equal Date.today, issue.start_date | |
743 | end |
|
743 | end | |
744 |
|
744 | |||
745 | def test_post_create_and_continue |
|
745 | def test_post_create_and_continue | |
746 | @request.session[:user_id] = 2 |
|
746 | @request.session[:user_id] = 2 | |
747 | assert_difference 'Issue.count' do |
|
747 | assert_difference 'Issue.count' do | |
748 | post :create, :project_id => 1, |
|
748 | post :create, :project_id => 1, | |
749 | :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5}, |
|
749 | :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5}, | |
750 | :continue => '' |
|
750 | :continue => '' | |
751 | end |
|
751 | end | |
752 |
|
752 | |||
753 | issue = Issue.first(:order => 'id DESC') |
|
753 | issue = Issue.first(:order => 'id DESC') | |
754 | assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3} |
|
754 | assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3} | |
755 | assert_not_nil flash[:notice], "flash was not set" |
|
755 | assert_not_nil flash[:notice], "flash was not set" | |
756 | assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}" |
|
756 | assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}" | |
757 | end |
|
757 | end | |
758 |
|
758 | |||
759 | def test_post_create_without_custom_fields_param |
|
759 | def test_post_create_without_custom_fields_param | |
760 | @request.session[:user_id] = 2 |
|
760 | @request.session[:user_id] = 2 | |
761 | assert_difference 'Issue.count' do |
|
761 | assert_difference 'Issue.count' do | |
762 | post :create, :project_id => 1, |
|
762 | post :create, :project_id => 1, | |
763 | :issue => {:tracker_id => 1, |
|
763 | :issue => {:tracker_id => 1, | |
764 | :subject => 'This is the test_new issue', |
|
764 | :subject => 'This is the test_new issue', | |
765 | :description => 'This is the description', |
|
765 | :description => 'This is the description', | |
766 | :priority_id => 5} |
|
766 | :priority_id => 5} | |
767 | end |
|
767 | end | |
768 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
768 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
769 | end |
|
769 | end | |
770 |
|
770 | |||
771 | def test_post_create_with_required_custom_field_and_without_custom_fields_param |
|
771 | def test_post_create_with_required_custom_field_and_without_custom_fields_param | |
772 | field = IssueCustomField.find_by_name('Database') |
|
772 | field = IssueCustomField.find_by_name('Database') | |
773 | field.update_attribute(:is_required, true) |
|
773 | field.update_attribute(:is_required, true) | |
774 |
|
774 | |||
775 | @request.session[:user_id] = 2 |
|
775 | @request.session[:user_id] = 2 | |
776 | post :create, :project_id => 1, |
|
776 | post :create, :project_id => 1, | |
777 | :issue => {:tracker_id => 1, |
|
777 | :issue => {:tracker_id => 1, | |
778 | :subject => 'This is the test_new issue', |
|
778 | :subject => 'This is the test_new issue', | |
779 | :description => 'This is the description', |
|
779 | :description => 'This is the description', | |
780 | :priority_id => 5} |
|
780 | :priority_id => 5} | |
781 | assert_response :success |
|
781 | assert_response :success | |
782 | assert_template 'new' |
|
782 | assert_template 'new' | |
783 | issue = assigns(:issue) |
|
783 | issue = assigns(:issue) | |
784 | assert_not_nil issue |
|
784 | assert_not_nil issue | |
785 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) |
|
785 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) | |
786 | end |
|
786 | end | |
787 |
|
787 | |||
788 | def test_post_create_with_watchers |
|
788 | def test_post_create_with_watchers | |
789 | @request.session[:user_id] = 2 |
|
789 | @request.session[:user_id] = 2 | |
790 | ActionMailer::Base.deliveries.clear |
|
790 | ActionMailer::Base.deliveries.clear | |
791 |
|
791 | |||
792 | assert_difference 'Watcher.count', 2 do |
|
792 | assert_difference 'Watcher.count', 2 do | |
793 | post :create, :project_id => 1, |
|
793 | post :create, :project_id => 1, | |
794 | :issue => {:tracker_id => 1, |
|
794 | :issue => {:tracker_id => 1, | |
795 | :subject => 'This is a new issue with watchers', |
|
795 | :subject => 'This is a new issue with watchers', | |
796 | :description => 'This is the description', |
|
796 | :description => 'This is the description', | |
797 | :priority_id => 5, |
|
797 | :priority_id => 5, | |
798 | :watcher_user_ids => ['2', '3']} |
|
798 | :watcher_user_ids => ['2', '3']} | |
799 | end |
|
799 | end | |
800 | issue = Issue.find_by_subject('This is a new issue with watchers') |
|
800 | issue = Issue.find_by_subject('This is a new issue with watchers') | |
801 | assert_not_nil issue |
|
801 | assert_not_nil issue | |
802 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
802 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue | |
803 |
|
803 | |||
804 | # Watchers added |
|
804 | # Watchers added | |
805 | assert_equal [2, 3], issue.watcher_user_ids.sort |
|
805 | assert_equal [2, 3], issue.watcher_user_ids.sort | |
806 | assert issue.watched_by?(User.find(3)) |
|
806 | assert issue.watched_by?(User.find(3)) | |
807 | # Watchers notified |
|
807 | # Watchers notified | |
808 | mail = ActionMailer::Base.deliveries.last |
|
808 | mail = ActionMailer::Base.deliveries.last | |
809 | assert_kind_of TMail::Mail, mail |
|
809 | assert_kind_of TMail::Mail, mail | |
810 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) |
|
810 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) | |
811 | end |
|
811 | end | |
812 |
|
812 | |||
813 | def test_post_create_subissue |
|
813 | def test_post_create_subissue | |
814 | @request.session[:user_id] = 2 |
|
814 | @request.session[:user_id] = 2 | |
815 |
|
815 | |||
816 | assert_difference 'Issue.count' do |
|
816 | assert_difference 'Issue.count' do | |
817 | post :create, :project_id => 1, |
|
817 | post :create, :project_id => 1, | |
818 | :issue => {:tracker_id => 1, |
|
818 | :issue => {:tracker_id => 1, | |
819 | :subject => 'This is a child issue', |
|
819 | :subject => 'This is a child issue', | |
820 | :parent_issue_id => 2} |
|
820 | :parent_issue_id => 2} | |
821 | end |
|
821 | end | |
822 | issue = Issue.find_by_subject('This is a child issue') |
|
822 | issue = Issue.find_by_subject('This is a child issue') | |
823 | assert_not_nil issue |
|
823 | assert_not_nil issue | |
824 | assert_equal Issue.find(2), issue.parent |
|
824 | assert_equal Issue.find(2), issue.parent | |
825 | end |
|
825 | end | |
826 |
|
826 | |||
827 | def test_post_create_subissue_with_non_numeric_parent_id |
|
827 | def test_post_create_subissue_with_non_numeric_parent_id | |
828 | @request.session[:user_id] = 2 |
|
828 | @request.session[:user_id] = 2 | |
829 |
|
829 | |||
830 | assert_difference 'Issue.count' do |
|
830 | assert_difference 'Issue.count' do | |
831 | post :create, :project_id => 1, |
|
831 | post :create, :project_id => 1, | |
832 | :issue => {:tracker_id => 1, |
|
832 | :issue => {:tracker_id => 1, | |
833 | :subject => 'This is a child issue', |
|
833 | :subject => 'This is a child issue', | |
834 | :parent_issue_id => 'ABC'} |
|
834 | :parent_issue_id => 'ABC'} | |
835 | end |
|
835 | end | |
836 | issue = Issue.find_by_subject('This is a child issue') |
|
836 | issue = Issue.find_by_subject('This is a child issue') | |
837 | assert_not_nil issue |
|
837 | assert_not_nil issue | |
838 | assert_nil issue.parent |
|
838 | assert_nil issue.parent | |
839 | end |
|
839 | end | |
840 |
|
840 | |||
841 | def test_post_create_private |
|
841 | def test_post_create_private | |
842 | @request.session[:user_id] = 2 |
|
842 | @request.session[:user_id] = 2 | |
843 |
|
843 | |||
844 | assert_difference 'Issue.count' do |
|
844 | assert_difference 'Issue.count' do | |
845 | post :create, :project_id => 1, |
|
845 | post :create, :project_id => 1, | |
846 | :issue => {:tracker_id => 1, |
|
846 | :issue => {:tracker_id => 1, | |
847 | :subject => 'This is a private issue', |
|
847 | :subject => 'This is a private issue', | |
848 | :is_private => '1'} |
|
848 | :is_private => '1'} | |
849 | end |
|
849 | end | |
850 | issue = Issue.first(:order => 'id DESC') |
|
850 | issue = Issue.first(:order => 'id DESC') | |
851 | assert issue.is_private? |
|
851 | assert issue.is_private? | |
852 | end |
|
852 | end | |
853 |
|
853 | |||
854 | def test_post_create_private_with_set_own_issues_private_permission |
|
854 | def test_post_create_private_with_set_own_issues_private_permission | |
855 | role = Role.find(1) |
|
855 | role = Role.find(1) | |
856 | role.remove_permission! :set_issues_private |
|
856 | role.remove_permission! :set_issues_private | |
857 | role.add_permission! :set_own_issues_private |
|
857 | role.add_permission! :set_own_issues_private | |
858 |
|
858 | |||
859 | @request.session[:user_id] = 2 |
|
859 | @request.session[:user_id] = 2 | |
860 |
|
860 | |||
861 | assert_difference 'Issue.count' do |
|
861 | assert_difference 'Issue.count' do | |
862 | post :create, :project_id => 1, |
|
862 | post :create, :project_id => 1, | |
863 | :issue => {:tracker_id => 1, |
|
863 | :issue => {:tracker_id => 1, | |
864 | :subject => 'This is a private issue', |
|
864 | :subject => 'This is a private issue', | |
865 | :is_private => '1'} |
|
865 | :is_private => '1'} | |
866 | end |
|
866 | end | |
867 | issue = Issue.first(:order => 'id DESC') |
|
867 | issue = Issue.first(:order => 'id DESC') | |
868 | assert issue.is_private? |
|
868 | assert issue.is_private? | |
869 | end |
|
869 | end | |
870 |
|
870 | |||
871 | def test_post_create_should_send_a_notification |
|
871 | def test_post_create_should_send_a_notification | |
872 | ActionMailer::Base.deliveries.clear |
|
872 | ActionMailer::Base.deliveries.clear | |
873 | @request.session[:user_id] = 2 |
|
873 | @request.session[:user_id] = 2 | |
874 | assert_difference 'Issue.count' do |
|
874 | assert_difference 'Issue.count' do | |
875 | post :create, :project_id => 1, |
|
875 | post :create, :project_id => 1, | |
876 | :issue => {:tracker_id => 3, |
|
876 | :issue => {:tracker_id => 3, | |
877 | :subject => 'This is the test_new issue', |
|
877 | :subject => 'This is the test_new issue', | |
878 | :description => 'This is the description', |
|
878 | :description => 'This is the description', | |
879 | :priority_id => 5, |
|
879 | :priority_id => 5, | |
880 | :estimated_hours => '', |
|
880 | :estimated_hours => '', | |
881 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
881 | :custom_field_values => {'2' => 'Value for field 2'}} | |
882 | end |
|
882 | end | |
883 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
883 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
884 |
|
884 | |||
885 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
885 | assert_equal 1, ActionMailer::Base.deliveries.size | |
886 | end |
|
886 | end | |
887 |
|
887 | |||
888 | def test_post_create_should_preserve_fields_values_on_validation_failure |
|
888 | def test_post_create_should_preserve_fields_values_on_validation_failure | |
889 | @request.session[:user_id] = 2 |
|
889 | @request.session[:user_id] = 2 | |
890 | post :create, :project_id => 1, |
|
890 | post :create, :project_id => 1, | |
891 | :issue => {:tracker_id => 1, |
|
891 | :issue => {:tracker_id => 1, | |
892 | # empty subject |
|
892 | # empty subject | |
893 | :subject => '', |
|
893 | :subject => '', | |
894 | :description => 'This is a description', |
|
894 | :description => 'This is a description', | |
895 | :priority_id => 6, |
|
895 | :priority_id => 6, | |
896 | :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} |
|
896 | :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} | |
897 | assert_response :success |
|
897 | assert_response :success | |
898 | assert_template 'new' |
|
898 | assert_template 'new' | |
899 |
|
899 | |||
900 | assert_tag :textarea, :attributes => { :name => 'issue[description]' }, |
|
900 | assert_tag :textarea, :attributes => { :name => 'issue[description]' }, | |
901 | :content => 'This is a description' |
|
901 | :content => 'This is a description' | |
902 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
|
902 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, | |
903 | :child => { :tag => 'option', :attributes => { :selected => 'selected', |
|
903 | :child => { :tag => 'option', :attributes => { :selected => 'selected', | |
904 | :value => '6' }, |
|
904 | :value => '6' }, | |
905 | :content => 'High' } |
|
905 | :content => 'High' } | |
906 | # Custom fields |
|
906 | # Custom fields | |
907 | assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, |
|
907 | assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, | |
908 | :child => { :tag => 'option', :attributes => { :selected => 'selected', |
|
908 | :child => { :tag => 'option', :attributes => { :selected => 'selected', | |
909 | :value => 'Oracle' }, |
|
909 | :value => 'Oracle' }, | |
910 | :content => 'Oracle' } |
|
910 | :content => 'Oracle' } | |
911 | assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]', |
|
911 | assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]', | |
912 | :value => 'Value for field 2'} |
|
912 | :value => 'Value for field 2'} | |
913 | end |
|
913 | end | |
914 |
|
914 | |||
915 | def test_post_create_should_ignore_non_safe_attributes |
|
915 | def test_post_create_should_ignore_non_safe_attributes | |
916 | @request.session[:user_id] = 2 |
|
916 | @request.session[:user_id] = 2 | |
917 | assert_nothing_raised do |
|
917 | assert_nothing_raised do | |
918 | post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" } |
|
918 | post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" } | |
919 | end |
|
919 | end | |
920 | end |
|
920 | end | |
921 |
|
921 | |||
922 | def test_post_create_with_attachment |
|
922 | def test_post_create_with_attachment | |
923 | set_tmp_attachments_directory |
|
923 | set_tmp_attachments_directory | |
924 | @request.session[:user_id] = 2 |
|
924 | @request.session[:user_id] = 2 | |
925 |
|
925 | |||
926 | assert_difference 'Issue.count' do |
|
926 | assert_difference 'Issue.count' do | |
927 | assert_difference 'Attachment.count' do |
|
927 | assert_difference 'Attachment.count' do | |
928 | post :create, :project_id => 1, |
|
928 | post :create, :project_id => 1, | |
929 | :issue => { :tracker_id => '1', :subject => 'With attachment' }, |
|
929 | :issue => { :tracker_id => '1', :subject => 'With attachment' }, | |
930 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
930 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | |
931 | end |
|
931 | end | |
932 | end |
|
932 | end | |
933 |
|
933 | |||
934 | issue = Issue.first(:order => 'id DESC') |
|
934 | issue = Issue.first(:order => 'id DESC') | |
935 | attachment = Attachment.first(:order => 'id DESC') |
|
935 | attachment = Attachment.first(:order => 'id DESC') | |
936 |
|
936 | |||
937 | assert_equal issue, attachment.container |
|
937 | assert_equal issue, attachment.container | |
938 | assert_equal 2, attachment.author_id |
|
938 | assert_equal 2, attachment.author_id | |
939 | assert_equal 'testfile.txt', attachment.filename |
|
939 | assert_equal 'testfile.txt', attachment.filename | |
940 | assert_equal 'text/plain', attachment.content_type |
|
940 | assert_equal 'text/plain', attachment.content_type | |
941 | assert_equal 'test file', attachment.description |
|
941 | assert_equal 'test file', attachment.description | |
942 | assert_equal 59, attachment.filesize |
|
942 | assert_equal 59, attachment.filesize | |
943 | assert File.exists?(attachment.diskfile) |
|
943 | assert File.exists?(attachment.diskfile) | |
944 | assert_equal 59, File.size(attachment.diskfile) |
|
944 | assert_equal 59, File.size(attachment.diskfile) | |
945 | end |
|
945 | end | |
946 |
|
946 | |||
947 | context "without workflow privilege" do |
|
947 | context "without workflow privilege" do | |
948 | setup do |
|
948 | setup do | |
949 | Workflow.delete_all(["role_id = ?", Role.anonymous.id]) |
|
949 | Workflow.delete_all(["role_id = ?", Role.anonymous.id]) | |
950 | Role.anonymous.add_permission! :add_issues, :add_issue_notes |
|
950 | Role.anonymous.add_permission! :add_issues, :add_issue_notes | |
951 | end |
|
951 | end | |
952 |
|
952 | |||
953 | context "#new" do |
|
953 | context "#new" do | |
954 | should "propose default status only" do |
|
954 | should "propose default status only" do | |
955 | get :new, :project_id => 1 |
|
955 | get :new, :project_id => 1 | |
956 | assert_response :success |
|
956 | assert_response :success | |
957 | assert_template 'new' |
|
957 | assert_template 'new' | |
958 | assert_tag :tag => 'select', |
|
958 | assert_tag :tag => 'select', | |
959 | :attributes => {:name => 'issue[status_id]'}, |
|
959 | :attributes => {:name => 'issue[status_id]'}, | |
960 | :children => {:count => 1}, |
|
960 | :children => {:count => 1}, | |
961 | :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}} |
|
961 | :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}} | |
962 | end |
|
962 | end | |
963 |
|
963 | |||
964 | should "accept default status" do |
|
964 | should "accept default status" do | |
965 | assert_difference 'Issue.count' do |
|
965 | assert_difference 'Issue.count' do | |
966 | post :create, :project_id => 1, |
|
966 | post :create, :project_id => 1, | |
967 | :issue => {:tracker_id => 1, |
|
967 | :issue => {:tracker_id => 1, | |
968 | :subject => 'This is an issue', |
|
968 | :subject => 'This is an issue', | |
969 | :status_id => 1} |
|
969 | :status_id => 1} | |
970 | end |
|
970 | end | |
971 | issue = Issue.last(:order => 'id') |
|
971 | issue = Issue.last(:order => 'id') | |
972 | assert_equal IssueStatus.default, issue.status |
|
972 | assert_equal IssueStatus.default, issue.status | |
973 | end |
|
973 | end | |
974 |
|
974 | |||
975 | should "ignore unauthorized status" do |
|
975 | should "ignore unauthorized status" do | |
976 | assert_difference 'Issue.count' do |
|
976 | assert_difference 'Issue.count' do | |
977 | post :create, :project_id => 1, |
|
977 | post :create, :project_id => 1, | |
978 | :issue => {:tracker_id => 1, |
|
978 | :issue => {:tracker_id => 1, | |
979 | :subject => 'This is an issue', |
|
979 | :subject => 'This is an issue', | |
980 | :status_id => 3} |
|
980 | :status_id => 3} | |
981 | end |
|
981 | end | |
982 | issue = Issue.last(:order => 'id') |
|
982 | issue = Issue.last(:order => 'id') | |
983 | assert_equal IssueStatus.default, issue.status |
|
983 | assert_equal IssueStatus.default, issue.status | |
984 | end |
|
984 | end | |
985 | end |
|
985 | end | |
986 |
|
986 | |||
987 | context "#update" do |
|
987 | context "#update" do | |
988 | should "ignore status change" do |
|
988 | should "ignore status change" do | |
989 | assert_difference 'Journal.count' do |
|
989 | assert_difference 'Journal.count' do | |
990 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} |
|
990 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} | |
991 | end |
|
991 | end | |
992 | assert_equal 1, Issue.find(1).status_id |
|
992 | assert_equal 1, Issue.find(1).status_id | |
993 | end |
|
993 | end | |
994 |
|
994 | |||
995 | should "ignore attributes changes" do |
|
995 | should "ignore attributes changes" do | |
996 | assert_difference 'Journal.count' do |
|
996 | assert_difference 'Journal.count' do | |
997 | put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} |
|
997 | put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} | |
998 | end |
|
998 | end | |
999 | issue = Issue.find(1) |
|
999 | issue = Issue.find(1) | |
1000 | assert_equal "Can't print recipes", issue.subject |
|
1000 | assert_equal "Can't print recipes", issue.subject | |
1001 | assert_nil issue.assigned_to |
|
1001 | assert_nil issue.assigned_to | |
1002 | end |
|
1002 | end | |
1003 | end |
|
1003 | end | |
1004 | end |
|
1004 | end | |
1005 |
|
1005 | |||
1006 | context "with workflow privilege" do |
|
1006 | context "with workflow privilege" do | |
1007 | setup do |
|
1007 | setup do | |
1008 | Workflow.delete_all(["role_id = ?", Role.anonymous.id]) |
|
1008 | Workflow.delete_all(["role_id = ?", Role.anonymous.id]) | |
1009 | Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3) |
|
1009 | Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3) | |
1010 | Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4) |
|
1010 | Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4) | |
1011 | Role.anonymous.add_permission! :add_issues, :add_issue_notes |
|
1011 | Role.anonymous.add_permission! :add_issues, :add_issue_notes | |
1012 | end |
|
1012 | end | |
1013 |
|
1013 | |||
1014 | context "#update" do |
|
1014 | context "#update" do | |
1015 | should "accept authorized status" do |
|
1015 | should "accept authorized status" do | |
1016 | assert_difference 'Journal.count' do |
|
1016 | assert_difference 'Journal.count' do | |
1017 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} |
|
1017 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} | |
1018 | end |
|
1018 | end | |
1019 | assert_equal 3, Issue.find(1).status_id |
|
1019 | assert_equal 3, Issue.find(1).status_id | |
1020 | end |
|
1020 | end | |
1021 |
|
1021 | |||
1022 | should "ignore unauthorized status" do |
|
1022 | should "ignore unauthorized status" do | |
1023 | assert_difference 'Journal.count' do |
|
1023 | assert_difference 'Journal.count' do | |
1024 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} |
|
1024 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} | |
1025 | end |
|
1025 | end | |
1026 | assert_equal 1, Issue.find(1).status_id |
|
1026 | assert_equal 1, Issue.find(1).status_id | |
1027 | end |
|
1027 | end | |
1028 |
|
1028 | |||
1029 | should "accept authorized attributes changes" do |
|
1029 | should "accept authorized attributes changes" do | |
1030 | assert_difference 'Journal.count' do |
|
1030 | assert_difference 'Journal.count' do | |
1031 | put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2} |
|
1031 | put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2} | |
1032 | end |
|
1032 | end | |
1033 | issue = Issue.find(1) |
|
1033 | issue = Issue.find(1) | |
1034 | assert_equal 2, issue.assigned_to_id |
|
1034 | assert_equal 2, issue.assigned_to_id | |
1035 | end |
|
1035 | end | |
1036 |
|
1036 | |||
1037 | should "ignore unauthorized attributes changes" do |
|
1037 | should "ignore unauthorized attributes changes" do | |
1038 | assert_difference 'Journal.count' do |
|
1038 | assert_difference 'Journal.count' do | |
1039 | put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'} |
|
1039 | put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'} | |
1040 | end |
|
1040 | end | |
1041 | issue = Issue.find(1) |
|
1041 | issue = Issue.find(1) | |
1042 | assert_equal "Can't print recipes", issue.subject |
|
1042 | assert_equal "Can't print recipes", issue.subject | |
1043 | end |
|
1043 | end | |
1044 | end |
|
1044 | end | |
1045 |
|
1045 | |||
1046 | context "and :edit_issues permission" do |
|
1046 | context "and :edit_issues permission" do | |
1047 | setup do |
|
1047 | setup do | |
1048 | Role.anonymous.add_permission! :add_issues, :edit_issues |
|
1048 | Role.anonymous.add_permission! :add_issues, :edit_issues | |
1049 | end |
|
1049 | end | |
1050 |
|
1050 | |||
1051 | should "accept authorized status" do |
|
1051 | should "accept authorized status" do | |
1052 | assert_difference 'Journal.count' do |
|
1052 | assert_difference 'Journal.count' do | |
1053 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} |
|
1053 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} | |
1054 | end |
|
1054 | end | |
1055 | assert_equal 3, Issue.find(1).status_id |
|
1055 | assert_equal 3, Issue.find(1).status_id | |
1056 | end |
|
1056 | end | |
1057 |
|
1057 | |||
1058 | should "ignore unauthorized status" do |
|
1058 | should "ignore unauthorized status" do | |
1059 | assert_difference 'Journal.count' do |
|
1059 | assert_difference 'Journal.count' do | |
1060 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} |
|
1060 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} | |
1061 | end |
|
1061 | end | |
1062 | assert_equal 1, Issue.find(1).status_id |
|
1062 | assert_equal 1, Issue.find(1).status_id | |
1063 | end |
|
1063 | end | |
1064 |
|
1064 | |||
1065 | should "accept authorized attributes changes" do |
|
1065 | should "accept authorized attributes changes" do | |
1066 | assert_difference 'Journal.count' do |
|
1066 | assert_difference 'Journal.count' do | |
1067 | put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} |
|
1067 | put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} | |
1068 | end |
|
1068 | end | |
1069 | issue = Issue.find(1) |
|
1069 | issue = Issue.find(1) | |
1070 | assert_equal "changed", issue.subject |
|
1070 | assert_equal "changed", issue.subject | |
1071 | assert_equal 2, issue.assigned_to_id |
|
1071 | assert_equal 2, issue.assigned_to_id | |
1072 | end |
|
1072 | end | |
1073 | end |
|
1073 | end | |
1074 | end |
|
1074 | end | |
1075 |
|
1075 | |||
1076 | def test_copy_issue |
|
1076 | def test_copy_issue | |
1077 | @request.session[:user_id] = 2 |
|
1077 | @request.session[:user_id] = 2 | |
1078 | get :new, :project_id => 1, :copy_from => 1 |
|
1078 | get :new, :project_id => 1, :copy_from => 1 | |
1079 | assert_template 'new' |
|
1079 | assert_template 'new' | |
1080 | assert_not_nil assigns(:issue) |
|
1080 | assert_not_nil assigns(:issue) | |
1081 | orig = Issue.find(1) |
|
1081 | orig = Issue.find(1) | |
1082 | assert_equal orig.subject, assigns(:issue).subject |
|
1082 | assert_equal orig.subject, assigns(:issue).subject | |
1083 | end |
|
1083 | end | |
1084 |
|
1084 | |||
1085 | def test_get_edit |
|
1085 | def test_get_edit | |
1086 | @request.session[:user_id] = 2 |
|
1086 | @request.session[:user_id] = 2 | |
1087 | get :edit, :id => 1 |
|
1087 | get :edit, :id => 1 | |
1088 | assert_response :success |
|
1088 | assert_response :success | |
1089 | assert_template 'edit' |
|
1089 | assert_template 'edit' | |
1090 | assert_not_nil assigns(:issue) |
|
1090 | assert_not_nil assigns(:issue) | |
1091 | assert_equal Issue.find(1), assigns(:issue) |
|
1091 | assert_equal Issue.find(1), assigns(:issue) | |
1092 |
|
1092 | |||
1093 | # Be sure we don't display inactive IssuePriorities |
|
1093 | # Be sure we don't display inactive IssuePriorities | |
1094 | assert ! IssuePriority.find(15).active? |
|
1094 | assert ! IssuePriority.find(15).active? | |
1095 | assert_no_tag :option, :attributes => {:value => '15'}, |
|
1095 | assert_no_tag :option, :attributes => {:value => '15'}, | |
1096 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } |
|
1096 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } | |
1097 | end |
|
1097 | end | |
1098 |
|
1098 | |||
1099 | def test_get_edit_with_params |
|
1099 | def test_get_edit_with_params | |
1100 | @request.session[:user_id] = 2 |
|
1100 | @request.session[:user_id] = 2 | |
1101 | get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }, |
|
1101 | get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }, | |
1102 | :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id } |
|
1102 | :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id } | |
1103 | assert_response :success |
|
1103 | assert_response :success | |
1104 | assert_template 'edit' |
|
1104 | assert_template 'edit' | |
1105 |
|
1105 | |||
1106 | issue = assigns(:issue) |
|
1106 | issue = assigns(:issue) | |
1107 | assert_not_nil issue |
|
1107 | assert_not_nil issue | |
1108 |
|
1108 | |||
1109 | assert_equal 5, issue.status_id |
|
1109 | assert_equal 5, issue.status_id | |
1110 | assert_tag :select, :attributes => { :name => 'issue[status_id]' }, |
|
1110 | assert_tag :select, :attributes => { :name => 'issue[status_id]' }, | |
1111 | :child => { :tag => 'option', |
|
1111 | :child => { :tag => 'option', | |
1112 | :content => 'Closed', |
|
1112 | :content => 'Closed', | |
1113 | :attributes => { :selected => 'selected' } } |
|
1113 | :attributes => { :selected => 'selected' } } | |
1114 |
|
1114 | |||
1115 | assert_equal 7, issue.priority_id |
|
1115 | assert_equal 7, issue.priority_id | |
1116 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
|
1116 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, | |
1117 | :child => { :tag => 'option', |
|
1117 | :child => { :tag => 'option', | |
1118 | :content => 'Urgent', |
|
1118 | :content => 'Urgent', | |
1119 | :attributes => { :selected => 'selected' } } |
|
1119 | :attributes => { :selected => 'selected' } } | |
1120 |
|
1120 | |||
1121 | assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' } |
|
1121 | assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' } | |
1122 | assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' }, |
|
1122 | assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' }, | |
1123 | :child => { :tag => 'option', |
|
1123 | :child => { :tag => 'option', | |
1124 | :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } } |
|
1124 | :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } } | |
1125 | assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' } |
|
1125 | assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' } | |
1126 | end |
|
1126 | end | |
1127 |
|
1127 | |||
1128 | def test_update_edit_form |
|
1128 | def test_update_edit_form | |
1129 | @request.session[:user_id] = 2 |
|
1129 | @request.session[:user_id] = 2 | |
1130 | xhr :post, :new, :project_id => 1, |
|
1130 | xhr :post, :new, :project_id => 1, | |
1131 | :id => 1, |
|
1131 | :id => 1, | |
1132 | :issue => {:tracker_id => 2, |
|
1132 | :issue => {:tracker_id => 2, | |
1133 | :subject => 'This is the test_new issue', |
|
1133 | :subject => 'This is the test_new issue', | |
1134 | :description => 'This is the description', |
|
1134 | :description => 'This is the description', | |
1135 | :priority_id => 5} |
|
1135 | :priority_id => 5} | |
1136 | assert_response :success |
|
1136 | assert_response :success | |
1137 | assert_template 'attributes' |
|
1137 | assert_template 'attributes' | |
1138 |
|
1138 | |||
1139 | issue = assigns(:issue) |
|
1139 | issue = assigns(:issue) | |
1140 | assert_kind_of Issue, issue |
|
1140 | assert_kind_of Issue, issue | |
1141 | assert_equal 1, issue.id |
|
1141 | assert_equal 1, issue.id | |
1142 | assert_equal 1, issue.project_id |
|
1142 | assert_equal 1, issue.project_id | |
1143 | assert_equal 2, issue.tracker_id |
|
1143 | assert_equal 2, issue.tracker_id | |
1144 | assert_equal 'This is the test_new issue', issue.subject |
|
1144 | assert_equal 'This is the test_new issue', issue.subject | |
1145 | end |
|
1145 | end | |
1146 |
|
1146 | |||
1147 | def test_update_using_invalid_http_verbs |
|
1147 | def test_update_using_invalid_http_verbs | |
1148 | @request.session[:user_id] = 2 |
|
1148 | @request.session[:user_id] = 2 | |
1149 | subject = 'Updated by an invalid http verb' |
|
1149 | subject = 'Updated by an invalid http verb' | |
1150 |
|
1150 | |||
1151 | get :update, :id => 1, :issue => {:subject => subject} |
|
1151 | get :update, :id => 1, :issue => {:subject => subject} | |
1152 | assert_not_equal subject, Issue.find(1).subject |
|
1152 | assert_not_equal subject, Issue.find(1).subject | |
1153 |
|
1153 | |||
1154 | post :update, :id => 1, :issue => {:subject => subject} |
|
1154 | post :update, :id => 1, :issue => {:subject => subject} | |
1155 | assert_not_equal subject, Issue.find(1).subject |
|
1155 | assert_not_equal subject, Issue.find(1).subject | |
1156 |
|
1156 | |||
1157 | delete :update, :id => 1, :issue => {:subject => subject} |
|
1157 | delete :update, :id => 1, :issue => {:subject => subject} | |
1158 | assert_not_equal subject, Issue.find(1).subject |
|
1158 | assert_not_equal subject, Issue.find(1).subject | |
1159 | end |
|
1159 | end | |
1160 |
|
1160 | |||
1161 | def test_put_update_without_custom_fields_param |
|
1161 | def test_put_update_without_custom_fields_param | |
1162 | @request.session[:user_id] = 2 |
|
1162 | @request.session[:user_id] = 2 | |
1163 | ActionMailer::Base.deliveries.clear |
|
1163 | ActionMailer::Base.deliveries.clear | |
1164 |
|
1164 | |||
1165 | issue = Issue.find(1) |
|
1165 | issue = Issue.find(1) | |
1166 | assert_equal '125', issue.custom_value_for(2).value |
|
1166 | assert_equal '125', issue.custom_value_for(2).value | |
1167 | old_subject = issue.subject |
|
1167 | old_subject = issue.subject | |
1168 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
|
1168 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' | |
1169 |
|
1169 | |||
1170 | assert_difference('Journal.count') do |
|
1170 | assert_difference('Journal.count') do | |
1171 | assert_difference('JournalDetail.count', 2) do |
|
1171 | assert_difference('JournalDetail.count', 2) do | |
1172 | put :update, :id => 1, :issue => {:subject => new_subject, |
|
1172 | put :update, :id => 1, :issue => {:subject => new_subject, | |
1173 | :priority_id => '6', |
|
1173 | :priority_id => '6', | |
1174 | :category_id => '1' # no change |
|
1174 | :category_id => '1' # no change | |
1175 | } |
|
1175 | } | |
1176 | end |
|
1176 | end | |
1177 | end |
|
1177 | end | |
1178 | assert_redirected_to :action => 'show', :id => '1' |
|
1178 | assert_redirected_to :action => 'show', :id => '1' | |
1179 | issue.reload |
|
1179 | issue.reload | |
1180 | assert_equal new_subject, issue.subject |
|
1180 | assert_equal new_subject, issue.subject | |
1181 | # Make sure custom fields were not cleared |
|
1181 | # Make sure custom fields were not cleared | |
1182 | assert_equal '125', issue.custom_value_for(2).value |
|
1182 | assert_equal '125', issue.custom_value_for(2).value | |
1183 |
|
1183 | |||
1184 | mail = ActionMailer::Base.deliveries.last |
|
1184 | mail = ActionMailer::Base.deliveries.last | |
1185 | assert_kind_of TMail::Mail, mail |
|
1185 | assert_kind_of TMail::Mail, mail | |
1186 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") |
|
1186 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") | |
1187 | assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}") |
|
1187 | assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}") | |
1188 | end |
|
1188 | end | |
1189 |
|
1189 | |||
1190 | def test_put_update_with_custom_field_change |
|
1190 | def test_put_update_with_custom_field_change | |
1191 | @request.session[:user_id] = 2 |
|
1191 | @request.session[:user_id] = 2 | |
1192 | issue = Issue.find(1) |
|
1192 | issue = Issue.find(1) | |
1193 | assert_equal '125', issue.custom_value_for(2).value |
|
1193 | assert_equal '125', issue.custom_value_for(2).value | |
1194 |
|
1194 | |||
1195 | assert_difference('Journal.count') do |
|
1195 | assert_difference('Journal.count') do | |
1196 | assert_difference('JournalDetail.count', 3) do |
|
1196 | assert_difference('JournalDetail.count', 3) do | |
1197 | put :update, :id => 1, :issue => {:subject => 'Custom field change', |
|
1197 | put :update, :id => 1, :issue => {:subject => 'Custom field change', | |
1198 | :priority_id => '6', |
|
1198 | :priority_id => '6', | |
1199 | :category_id => '1', # no change |
|
1199 | :category_id => '1', # no change | |
1200 | :custom_field_values => { '2' => 'New custom value' } |
|
1200 | :custom_field_values => { '2' => 'New custom value' } | |
1201 | } |
|
1201 | } | |
1202 | end |
|
1202 | end | |
1203 | end |
|
1203 | end | |
1204 | assert_redirected_to :action => 'show', :id => '1' |
|
1204 | assert_redirected_to :action => 'show', :id => '1' | |
1205 | issue.reload |
|
1205 | issue.reload | |
1206 | assert_equal 'New custom value', issue.custom_value_for(2).value |
|
1206 | assert_equal 'New custom value', issue.custom_value_for(2).value | |
1207 |
|
1207 | |||
1208 | mail = ActionMailer::Base.deliveries.last |
|
1208 | mail = ActionMailer::Base.deliveries.last | |
1209 | assert_kind_of TMail::Mail, mail |
|
1209 | assert_kind_of TMail::Mail, mail | |
1210 | assert mail.body.include?("Searchable field changed from 125 to New custom value") |
|
1210 | assert mail.body.include?("Searchable field changed from 125 to New custom value") | |
1211 | end |
|
1211 | end | |
1212 |
|
1212 | |||
1213 | def test_put_update_with_status_and_assignee_change |
|
1213 | def test_put_update_with_status_and_assignee_change | |
1214 | issue = Issue.find(1) |
|
1214 | issue = Issue.find(1) | |
1215 | assert_equal 1, issue.status_id |
|
1215 | assert_equal 1, issue.status_id | |
1216 | @request.session[:user_id] = 2 |
|
1216 | @request.session[:user_id] = 2 | |
1217 | assert_difference('TimeEntry.count', 0) do |
|
1217 | assert_difference('TimeEntry.count', 0) do | |
1218 | put :update, |
|
1218 | put :update, | |
1219 | :id => 1, |
|
1219 | :id => 1, | |
1220 | :issue => { :status_id => 2, :assigned_to_id => 3 }, |
|
1220 | :issue => { :status_id => 2, :assigned_to_id => 3 }, | |
1221 | :notes => 'Assigned to dlopper', |
|
1221 | :notes => 'Assigned to dlopper', | |
1222 | :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } |
|
1222 | :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } | |
1223 | end |
|
1223 | end | |
1224 | assert_redirected_to :action => 'show', :id => '1' |
|
1224 | assert_redirected_to :action => 'show', :id => '1' | |
1225 | issue.reload |
|
1225 | issue.reload | |
1226 | assert_equal 2, issue.status_id |
|
1226 | assert_equal 2, issue.status_id | |
1227 | j = Journal.find(:first, :order => 'id DESC') |
|
1227 | j = Journal.find(:first, :order => 'id DESC') | |
1228 | assert_equal 'Assigned to dlopper', j.notes |
|
1228 | assert_equal 'Assigned to dlopper', j.notes | |
1229 | assert_equal 2, j.details.size |
|
1229 | assert_equal 2, j.details.size | |
1230 |
|
1230 | |||
1231 | mail = ActionMailer::Base.deliveries.last |
|
1231 | mail = ActionMailer::Base.deliveries.last | |
1232 | assert mail.body.include?("Status changed from New to Assigned") |
|
1232 | assert mail.body.include?("Status changed from New to Assigned") | |
1233 | # subject should contain the new status |
|
1233 | # subject should contain the new status | |
1234 | assert mail.subject.include?("(#{ IssueStatus.find(2).name })") |
|
1234 | assert mail.subject.include?("(#{ IssueStatus.find(2).name })") | |
1235 | end |
|
1235 | end | |
1236 |
|
1236 | |||
1237 | def test_put_update_with_note_only |
|
1237 | def test_put_update_with_note_only | |
1238 | notes = 'Note added by IssuesControllerTest#test_update_with_note_only' |
|
1238 | notes = 'Note added by IssuesControllerTest#test_update_with_note_only' | |
1239 | # anonymous user |
|
1239 | # anonymous user | |
1240 | put :update, |
|
1240 | put :update, | |
1241 | :id => 1, |
|
1241 | :id => 1, | |
1242 | :notes => notes |
|
1242 | :notes => notes | |
1243 | assert_redirected_to :action => 'show', :id => '1' |
|
1243 | assert_redirected_to :action => 'show', :id => '1' | |
1244 | j = Journal.find(:first, :order => 'id DESC') |
|
1244 | j = Journal.find(:first, :order => 'id DESC') | |
1245 | assert_equal notes, j.notes |
|
1245 | assert_equal notes, j.notes | |
1246 | assert_equal 0, j.details.size |
|
1246 | assert_equal 0, j.details.size | |
1247 | assert_equal User.anonymous, j.user |
|
1247 | assert_equal User.anonymous, j.user | |
1248 |
|
1248 | |||
1249 | mail = ActionMailer::Base.deliveries.last |
|
1249 | mail = ActionMailer::Base.deliveries.last | |
1250 | assert mail.body.include?(notes) |
|
1250 | assert mail.body.include?(notes) | |
1251 | end |
|
1251 | end | |
1252 |
|
1252 | |||
1253 | def test_put_update_with_note_and_spent_time |
|
1253 | def test_put_update_with_note_and_spent_time | |
1254 | @request.session[:user_id] = 2 |
|
1254 | @request.session[:user_id] = 2 | |
1255 | spent_hours_before = Issue.find(1).spent_hours |
|
1255 | spent_hours_before = Issue.find(1).spent_hours | |
1256 | assert_difference('TimeEntry.count') do |
|
1256 | assert_difference('TimeEntry.count') do | |
1257 | put :update, |
|
1257 | put :update, | |
1258 | :id => 1, |
|
1258 | :id => 1, | |
1259 | :notes => '2.5 hours added', |
|
1259 | :notes => '2.5 hours added', | |
1260 | :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id } |
|
1260 | :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id } | |
1261 | end |
|
1261 | end | |
1262 | assert_redirected_to :action => 'show', :id => '1' |
|
1262 | assert_redirected_to :action => 'show', :id => '1' | |
1263 |
|
1263 | |||
1264 | issue = Issue.find(1) |
|
1264 | issue = Issue.find(1) | |
1265 |
|
1265 | |||
1266 | j = Journal.find(:first, :order => 'id DESC') |
|
1266 | j = Journal.find(:first, :order => 'id DESC') | |
1267 | assert_equal '2.5 hours added', j.notes |
|
1267 | assert_equal '2.5 hours added', j.notes | |
1268 | assert_equal 0, j.details.size |
|
1268 | assert_equal 0, j.details.size | |
1269 |
|
1269 | |||
1270 | t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time') |
|
1270 | t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time') | |
1271 | assert_not_nil t |
|
1271 | assert_not_nil t | |
1272 | assert_equal 2.5, t.hours |
|
1272 | assert_equal 2.5, t.hours | |
1273 | assert_equal spent_hours_before + 2.5, issue.spent_hours |
|
1273 | assert_equal spent_hours_before + 2.5, issue.spent_hours | |
1274 | end |
|
1274 | end | |
1275 |
|
1275 | |||
1276 | def test_put_update_with_attachment_only |
|
1276 | def test_put_update_with_attachment_only | |
1277 | set_tmp_attachments_directory |
|
1277 | set_tmp_attachments_directory | |
1278 |
|
1278 | |||
1279 | # Delete all fixtured journals, a race condition can occur causing the wrong |
|
1279 | # Delete all fixtured journals, a race condition can occur causing the wrong | |
1280 | # journal to get fetched in the next find. |
|
1280 | # journal to get fetched in the next find. | |
1281 | Journal.delete_all |
|
1281 | Journal.delete_all | |
1282 |
|
1282 | |||
1283 | # anonymous user |
|
1283 | # anonymous user | |
1284 | assert_difference 'Attachment.count' do |
|
1284 | assert_difference 'Attachment.count' do | |
1285 | put :update, :id => 1, |
|
1285 | put :update, :id => 1, | |
1286 | :notes => '', |
|
1286 | :notes => '', | |
1287 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
1287 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | |
1288 | end |
|
1288 | end | |
1289 |
|
1289 | |||
1290 | assert_redirected_to :action => 'show', :id => '1' |
|
1290 | assert_redirected_to :action => 'show', :id => '1' | |
1291 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') |
|
1291 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') | |
1292 | assert j.notes.blank? |
|
1292 | assert j.notes.blank? | |
1293 | assert_equal 1, j.details.size |
|
1293 | assert_equal 1, j.details.size | |
1294 | assert_equal 'testfile.txt', j.details.first.value |
|
1294 | assert_equal 'testfile.txt', j.details.first.value | |
1295 | assert_equal User.anonymous, j.user |
|
1295 | assert_equal User.anonymous, j.user | |
1296 |
|
1296 | |||
1297 | attachment = Attachment.first(:order => 'id DESC') |
|
1297 | attachment = Attachment.first(:order => 'id DESC') | |
1298 | assert_equal Issue.find(1), attachment.container |
|
1298 | assert_equal Issue.find(1), attachment.container | |
1299 | assert_equal User.anonymous, attachment.author |
|
1299 | assert_equal User.anonymous, attachment.author | |
1300 | assert_equal 'testfile.txt', attachment.filename |
|
1300 | assert_equal 'testfile.txt', attachment.filename | |
1301 | assert_equal 'text/plain', attachment.content_type |
|
1301 | assert_equal 'text/plain', attachment.content_type | |
1302 | assert_equal 'test file', attachment.description |
|
1302 | assert_equal 'test file', attachment.description | |
1303 | assert_equal 59, attachment.filesize |
|
1303 | assert_equal 59, attachment.filesize | |
1304 | assert File.exists?(attachment.diskfile) |
|
1304 | assert File.exists?(attachment.diskfile) | |
1305 | assert_equal 59, File.size(attachment.diskfile) |
|
1305 | assert_equal 59, File.size(attachment.diskfile) | |
1306 |
|
1306 | |||
1307 | mail = ActionMailer::Base.deliveries.last |
|
1307 | mail = ActionMailer::Base.deliveries.last | |
1308 | assert mail.body.include?('testfile.txt') |
|
1308 | assert mail.body.include?('testfile.txt') | |
1309 | end |
|
1309 | end | |
1310 |
|
1310 | |||
1311 | def test_put_update_with_attachment_that_fails_to_save |
|
1311 | def test_put_update_with_attachment_that_fails_to_save | |
1312 | set_tmp_attachments_directory |
|
1312 | set_tmp_attachments_directory | |
1313 |
|
1313 | |||
1314 | # Delete all fixtured journals, a race condition can occur causing the wrong |
|
1314 | # Delete all fixtured journals, a race condition can occur causing the wrong | |
1315 | # journal to get fetched in the next find. |
|
1315 | # journal to get fetched in the next find. | |
1316 | Journal.delete_all |
|
1316 | Journal.delete_all | |
1317 |
|
1317 | |||
1318 | # Mock out the unsaved attachment |
|
1318 | # Mock out the unsaved attachment | |
1319 | Attachment.any_instance.stubs(:create).returns(Attachment.new) |
|
1319 | Attachment.any_instance.stubs(:create).returns(Attachment.new) | |
1320 |
|
1320 | |||
1321 | # anonymous user |
|
1321 | # anonymous user | |
1322 | put :update, |
|
1322 | put :update, | |
1323 | :id => 1, |
|
1323 | :id => 1, | |
1324 | :notes => '', |
|
1324 | :notes => '', | |
1325 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
1325 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
1326 | assert_redirected_to :action => 'show', :id => '1' |
|
1326 | assert_redirected_to :action => 'show', :id => '1' | |
1327 | assert_equal '1 file(s) could not be saved.', flash[:warning] |
|
1327 | assert_equal '1 file(s) could not be saved.', flash[:warning] | |
1328 |
|
1328 | |||
1329 | end if Object.const_defined?(:Mocha) |
|
1329 | end if Object.const_defined?(:Mocha) | |
1330 |
|
1330 | |||
1331 | def test_put_update_with_no_change |
|
1331 | def test_put_update_with_no_change | |
1332 | issue = Issue.find(1) |
|
1332 | issue = Issue.find(1) | |
1333 | issue.journals.clear |
|
1333 | issue.journals.clear | |
1334 | ActionMailer::Base.deliveries.clear |
|
1334 | ActionMailer::Base.deliveries.clear | |
1335 |
|
1335 | |||
1336 | put :update, |
|
1336 | put :update, | |
1337 | :id => 1, |
|
1337 | :id => 1, | |
1338 | :notes => '' |
|
1338 | :notes => '' | |
1339 | assert_redirected_to :action => 'show', :id => '1' |
|
1339 | assert_redirected_to :action => 'show', :id => '1' | |
1340 |
|
1340 | |||
1341 | issue.reload |
|
1341 | issue.reload | |
1342 | assert issue.journals.empty? |
|
1342 | assert issue.journals.empty? | |
1343 | # No email should be sent |
|
1343 | # No email should be sent | |
1344 | assert ActionMailer::Base.deliveries.empty? |
|
1344 | assert ActionMailer::Base.deliveries.empty? | |
1345 | end |
|
1345 | end | |
1346 |
|
1346 | |||
1347 | def test_put_update_should_send_a_notification |
|
1347 | def test_put_update_should_send_a_notification | |
1348 | @request.session[:user_id] = 2 |
|
1348 | @request.session[:user_id] = 2 | |
1349 | ActionMailer::Base.deliveries.clear |
|
1349 | ActionMailer::Base.deliveries.clear | |
1350 | issue = Issue.find(1) |
|
1350 | issue = Issue.find(1) | |
1351 | old_subject = issue.subject |
|
1351 | old_subject = issue.subject | |
1352 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
|
1352 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' | |
1353 |
|
1353 | |||
1354 | put :update, :id => 1, :issue => {:subject => new_subject, |
|
1354 | put :update, :id => 1, :issue => {:subject => new_subject, | |
1355 | :priority_id => '6', |
|
1355 | :priority_id => '6', | |
1356 | :category_id => '1' # no change |
|
1356 | :category_id => '1' # no change | |
1357 | } |
|
1357 | } | |
1358 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
1358 | assert_equal 1, ActionMailer::Base.deliveries.size | |
1359 | end |
|
1359 | end | |
1360 |
|
1360 | |||
1361 | def test_put_update_with_invalid_spent_time_hours_only |
|
1361 | def test_put_update_with_invalid_spent_time_hours_only | |
1362 | @request.session[:user_id] = 2 |
|
1362 | @request.session[:user_id] = 2 | |
1363 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' |
|
1363 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' | |
1364 |
|
1364 | |||
1365 | assert_no_difference('Journal.count') do |
|
1365 | assert_no_difference('Journal.count') do | |
1366 | put :update, |
|
1366 | put :update, | |
1367 | :id => 1, |
|
1367 | :id => 1, | |
1368 | :notes => notes, |
|
1368 | :notes => notes, | |
1369 | :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} |
|
1369 | :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} | |
1370 | end |
|
1370 | end | |
1371 | assert_response :success |
|
1371 | assert_response :success | |
1372 | assert_template 'edit' |
|
1372 | assert_template 'edit' | |
1373 |
|
1373 | |||
1374 | assert_error_tag :descendant => {:content => /Activity can't be blank/} |
|
1374 | assert_error_tag :descendant => {:content => /Activity can't be blank/} | |
1375 | assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes |
|
1375 | assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes | |
1376 | assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" } |
|
1376 | assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" } | |
1377 | end |
|
1377 | end | |
1378 |
|
1378 | |||
1379 | def test_put_update_with_invalid_spent_time_comments_only |
|
1379 | def test_put_update_with_invalid_spent_time_comments_only | |
1380 | @request.session[:user_id] = 2 |
|
1380 | @request.session[:user_id] = 2 | |
1381 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' |
|
1381 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' | |
1382 |
|
1382 | |||
1383 | assert_no_difference('Journal.count') do |
|
1383 | assert_no_difference('Journal.count') do | |
1384 | put :update, |
|
1384 | put :update, | |
1385 | :id => 1, |
|
1385 | :id => 1, | |
1386 | :notes => notes, |
|
1386 | :notes => notes, | |
1387 | :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""} |
|
1387 | :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""} | |
1388 | end |
|
1388 | end | |
1389 | assert_response :success |
|
1389 | assert_response :success | |
1390 | assert_template 'edit' |
|
1390 | assert_template 'edit' | |
1391 |
|
1391 | |||
1392 | assert_error_tag :descendant => {:content => /Activity can't be blank/} |
|
1392 | assert_error_tag :descendant => {:content => /Activity can't be blank/} | |
1393 | assert_error_tag :descendant => {:content => /Hours can't be blank/} |
|
1393 | assert_error_tag :descendant => {:content => /Hours can't be blank/} | |
1394 | assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes |
|
1394 | assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes | |
1395 | assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" } |
|
1395 | assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" } | |
1396 | end |
|
1396 | end | |
1397 |
|
1397 | |||
1398 | def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject |
|
1398 | def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject | |
1399 | issue = Issue.find(2) |
|
1399 | issue = Issue.find(2) | |
1400 | @request.session[:user_id] = 2 |
|
1400 | @request.session[:user_id] = 2 | |
1401 |
|
1401 | |||
1402 | put :update, |
|
1402 | put :update, | |
1403 | :id => issue.id, |
|
1403 | :id => issue.id, | |
1404 | :issue => { |
|
1404 | :issue => { | |
1405 | :fixed_version_id => 4 |
|
1405 | :fixed_version_id => 4 | |
1406 | } |
|
1406 | } | |
1407 |
|
1407 | |||
1408 | assert_response :redirect |
|
1408 | assert_response :redirect | |
1409 | issue.reload |
|
1409 | issue.reload | |
1410 | assert_equal 4, issue.fixed_version_id |
|
1410 | assert_equal 4, issue.fixed_version_id | |
1411 | assert_not_equal issue.project_id, issue.fixed_version.project_id |
|
1411 | assert_not_equal issue.project_id, issue.fixed_version.project_id | |
1412 | end |
|
1412 | end | |
1413 |
|
1413 | |||
1414 | def test_put_update_should_redirect_back_using_the_back_url_parameter |
|
1414 | def test_put_update_should_redirect_back_using_the_back_url_parameter | |
1415 | issue = Issue.find(2) |
|
1415 | issue = Issue.find(2) | |
1416 | @request.session[:user_id] = 2 |
|
1416 | @request.session[:user_id] = 2 | |
1417 |
|
1417 | |||
1418 | put :update, |
|
1418 | put :update, | |
1419 | :id => issue.id, |
|
1419 | :id => issue.id, | |
1420 | :issue => { |
|
1420 | :issue => { | |
1421 | :fixed_version_id => 4 |
|
1421 | :fixed_version_id => 4 | |
1422 | }, |
|
1422 | }, | |
1423 | :back_url => '/issues' |
|
1423 | :back_url => '/issues' | |
1424 |
|
1424 | |||
1425 | assert_response :redirect |
|
1425 | assert_response :redirect | |
1426 | assert_redirected_to '/issues' |
|
1426 | assert_redirected_to '/issues' | |
1427 | end |
|
1427 | end | |
1428 |
|
1428 | |||
1429 | def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
1429 | def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host | |
1430 | issue = Issue.find(2) |
|
1430 | issue = Issue.find(2) | |
1431 | @request.session[:user_id] = 2 |
|
1431 | @request.session[:user_id] = 2 | |
1432 |
|
1432 | |||
1433 | put :update, |
|
1433 | put :update, | |
1434 | :id => issue.id, |
|
1434 | :id => issue.id, | |
1435 | :issue => { |
|
1435 | :issue => { | |
1436 | :fixed_version_id => 4 |
|
1436 | :fixed_version_id => 4 | |
1437 | }, |
|
1437 | }, | |
1438 | :back_url => 'http://google.com' |
|
1438 | :back_url => 'http://google.com' | |
1439 |
|
1439 | |||
1440 | assert_response :redirect |
|
1440 | assert_response :redirect | |
1441 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id |
|
1441 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id | |
1442 | end |
|
1442 | end | |
1443 |
|
1443 | |||
1444 | def test_get_bulk_edit |
|
1444 | def test_get_bulk_edit | |
1445 | @request.session[:user_id] = 2 |
|
1445 | @request.session[:user_id] = 2 | |
1446 | get :bulk_edit, :ids => [1, 2] |
|
1446 | get :bulk_edit, :ids => [1, 2] | |
1447 | assert_response :success |
|
1447 | assert_response :success | |
1448 | assert_template 'bulk_edit' |
|
1448 | assert_template 'bulk_edit' | |
1449 |
|
1449 | |||
1450 | assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} |
|
1450 | assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} | |
1451 |
|
1451 | |||
1452 | # Project specific custom field, date type |
|
1452 | # Project specific custom field, date type | |
1453 | field = CustomField.find(9) |
|
1453 | field = CustomField.find(9) | |
1454 | assert !field.is_for_all? |
|
1454 | assert !field.is_for_all? | |
1455 | assert_equal 'date', field.field_format |
|
1455 | assert_equal 'date', field.field_format | |
1456 | assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} |
|
1456 | assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} | |
1457 |
|
1457 | |||
1458 | # System wide custom field |
|
1458 | # System wide custom field | |
1459 | assert CustomField.find(1).is_for_all? |
|
1459 | assert CustomField.find(1).is_for_all? | |
1460 | assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} |
|
1460 | assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} | |
1461 |
|
1461 | |||
1462 | # Be sure we don't display inactive IssuePriorities |
|
1462 | # Be sure we don't display inactive IssuePriorities | |
1463 | assert ! IssuePriority.find(15).active? |
|
1463 | assert ! IssuePriority.find(15).active? | |
1464 | assert_no_tag :option, :attributes => {:value => '15'}, |
|
1464 | assert_no_tag :option, :attributes => {:value => '15'}, | |
1465 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } |
|
1465 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } | |
1466 | end |
|
1466 | end | |
1467 |
|
1467 | |||
1468 | def test_get_bulk_edit_on_different_projects |
|
1468 | def test_get_bulk_edit_on_different_projects | |
1469 | @request.session[:user_id] = 2 |
|
1469 | @request.session[:user_id] = 2 | |
1470 | get :bulk_edit, :ids => [1, 2, 6] |
|
1470 | get :bulk_edit, :ids => [1, 2, 6] | |
1471 | assert_response :success |
|
1471 | assert_response :success | |
1472 | assert_template 'bulk_edit' |
|
1472 | assert_template 'bulk_edit' | |
1473 |
|
1473 | |||
1474 | # Can not set issues from different projects as children of an issue |
|
1474 | # Can not set issues from different projects as children of an issue | |
1475 | assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} |
|
1475 | assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} | |
1476 |
|
1476 | |||
1477 | # Project specific custom field, date type |
|
1477 | # Project specific custom field, date type | |
1478 | field = CustomField.find(9) |
|
1478 | field = CustomField.find(9) | |
1479 | assert !field.is_for_all? |
|
1479 | assert !field.is_for_all? | |
1480 | assert !field.project_ids.include?(Issue.find(6).project_id) |
|
1480 | assert !field.project_ids.include?(Issue.find(6).project_id) | |
1481 | assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} |
|
1481 | assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} | |
1482 | end |
|
1482 | end | |
1483 |
|
1483 | |||
1484 | def test_get_bulk_edit_with_user_custom_field |
|
1484 | def test_get_bulk_edit_with_user_custom_field | |
1485 | field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true) |
|
1485 | field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true) | |
1486 |
|
1486 | |||
1487 | @request.session[:user_id] = 2 |
|
1487 | @request.session[:user_id] = 2 | |
1488 | get :bulk_edit, :ids => [1, 2] |
|
1488 | get :bulk_edit, :ids => [1, 2] | |
1489 | assert_response :success |
|
1489 | assert_response :success | |
1490 | assert_template 'bulk_edit' |
|
1490 | assert_template 'bulk_edit' | |
1491 |
|
1491 | |||
1492 | assert_tag :select, |
|
1492 | assert_tag :select, | |
1493 | :attributes => {:name => "issue[custom_field_values][#{field.id}]"}, |
|
1493 | :attributes => {:name => "issue[custom_field_values][#{field.id}]"}, | |
1494 | :children => { |
|
1494 | :children => { | |
1495 | :only => {:tag => 'option'}, |
|
1495 | :only => {:tag => 'option'}, | |
1496 | :count => Project.find(1).users.count + 1 |
|
1496 | :count => Project.find(1).users.count + 1 | |
1497 | } |
|
1497 | } | |
1498 | end |
|
1498 | end | |
1499 |
|
1499 | |||
1500 | def test_get_bulk_edit_with_version_custom_field |
|
1500 | def test_get_bulk_edit_with_version_custom_field | |
1501 | field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true) |
|
1501 | field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true) | |
1502 |
|
1502 | |||
1503 | @request.session[:user_id] = 2 |
|
1503 | @request.session[:user_id] = 2 | |
1504 | get :bulk_edit, :ids => [1, 2] |
|
1504 | get :bulk_edit, :ids => [1, 2] | |
1505 | assert_response :success |
|
1505 | assert_response :success | |
1506 | assert_template 'bulk_edit' |
|
1506 | assert_template 'bulk_edit' | |
1507 |
|
1507 | |||
1508 | assert_tag :select, |
|
1508 | assert_tag :select, | |
1509 | :attributes => {:name => "issue[custom_field_values][#{field.id}]"}, |
|
1509 | :attributes => {:name => "issue[custom_field_values][#{field.id}]"}, | |
1510 | :children => { |
|
1510 | :children => { | |
1511 | :only => {:tag => 'option'}, |
|
1511 | :only => {:tag => 'option'}, | |
1512 | :count => Project.find(1).versions.count + 1 |
|
1512 | :count => Project.find(1).shared_versions.count + 1 | |
1513 | } |
|
1513 | } | |
1514 | end |
|
1514 | end | |
1515 |
|
1515 | |||
1516 | def test_bulk_update |
|
1516 | def test_bulk_update | |
1517 | @request.session[:user_id] = 2 |
|
1517 | @request.session[:user_id] = 2 | |
1518 | # update issues priority |
|
1518 | # update issues priority | |
1519 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', |
|
1519 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', | |
1520 | :issue => {:priority_id => 7, |
|
1520 | :issue => {:priority_id => 7, | |
1521 | :assigned_to_id => '', |
|
1521 | :assigned_to_id => '', | |
1522 | :custom_field_values => {'2' => ''}} |
|
1522 | :custom_field_values => {'2' => ''}} | |
1523 |
|
1523 | |||
1524 | assert_response 302 |
|
1524 | assert_response 302 | |
1525 | # check that the issues were updated |
|
1525 | # check that the issues were updated | |
1526 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} |
|
1526 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} | |
1527 |
|
1527 | |||
1528 | issue = Issue.find(1) |
|
1528 | issue = Issue.find(1) | |
1529 | journal = issue.journals.find(:first, :order => 'created_on DESC') |
|
1529 | journal = issue.journals.find(:first, :order => 'created_on DESC') | |
1530 | assert_equal '125', issue.custom_value_for(2).value |
|
1530 | assert_equal '125', issue.custom_value_for(2).value | |
1531 | assert_equal 'Bulk editing', journal.notes |
|
1531 | assert_equal 'Bulk editing', journal.notes | |
1532 | assert_equal 1, journal.details.size |
|
1532 | assert_equal 1, journal.details.size | |
1533 | end |
|
1533 | end | |
1534 |
|
1534 | |||
1535 | def test_bulk_update_with_group_assignee |
|
1535 | def test_bulk_update_with_group_assignee | |
1536 | group = Group.find(11) |
|
1536 | group = Group.find(11) | |
1537 | project = Project.find(1) |
|
1537 | project = Project.find(1) | |
1538 | project.members << Member.new(:principal => group, :roles => [Role.first]) |
|
1538 | project.members << Member.new(:principal => group, :roles => [Role.first]) | |
1539 |
|
1539 | |||
1540 | @request.session[:user_id] = 2 |
|
1540 | @request.session[:user_id] = 2 | |
1541 | # update issues assignee |
|
1541 | # update issues assignee | |
1542 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', |
|
1542 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', | |
1543 | :issue => {:priority_id => '', |
|
1543 | :issue => {:priority_id => '', | |
1544 | :assigned_to_id => group.id, |
|
1544 | :assigned_to_id => group.id, | |
1545 | :custom_field_values => {'2' => ''}} |
|
1545 | :custom_field_values => {'2' => ''}} | |
1546 |
|
1546 | |||
1547 | assert_response 302 |
|
1547 | assert_response 302 | |
1548 | assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to} |
|
1548 | assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to} | |
1549 | end |
|
1549 | end | |
1550 |
|
1550 | |||
1551 | def test_bulk_update_on_different_projects |
|
1551 | def test_bulk_update_on_different_projects | |
1552 | @request.session[:user_id] = 2 |
|
1552 | @request.session[:user_id] = 2 | |
1553 | # update issues priority |
|
1553 | # update issues priority | |
1554 | post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing', |
|
1554 | post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing', | |
1555 | :issue => {:priority_id => 7, |
|
1555 | :issue => {:priority_id => 7, | |
1556 | :assigned_to_id => '', |
|
1556 | :assigned_to_id => '', | |
1557 | :custom_field_values => {'2' => ''}} |
|
1557 | :custom_field_values => {'2' => ''}} | |
1558 |
|
1558 | |||
1559 | assert_response 302 |
|
1559 | assert_response 302 | |
1560 | # check that the issues were updated |
|
1560 | # check that the issues were updated | |
1561 | assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id) |
|
1561 | assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id) | |
1562 |
|
1562 | |||
1563 | issue = Issue.find(1) |
|
1563 | issue = Issue.find(1) | |
1564 | journal = issue.journals.find(:first, :order => 'created_on DESC') |
|
1564 | journal = issue.journals.find(:first, :order => 'created_on DESC') | |
1565 | assert_equal '125', issue.custom_value_for(2).value |
|
1565 | assert_equal '125', issue.custom_value_for(2).value | |
1566 | assert_equal 'Bulk editing', journal.notes |
|
1566 | assert_equal 'Bulk editing', journal.notes | |
1567 | assert_equal 1, journal.details.size |
|
1567 | assert_equal 1, journal.details.size | |
1568 | end |
|
1568 | end | |
1569 |
|
1569 | |||
1570 | def test_bulk_update_on_different_projects_without_rights |
|
1570 | def test_bulk_update_on_different_projects_without_rights | |
1571 | @request.session[:user_id] = 3 |
|
1571 | @request.session[:user_id] = 3 | |
1572 | user = User.find(3) |
|
1572 | user = User.find(3) | |
1573 | action = { :controller => "issues", :action => "bulk_update" } |
|
1573 | action = { :controller => "issues", :action => "bulk_update" } | |
1574 | assert user.allowed_to?(action, Issue.find(1).project) |
|
1574 | assert user.allowed_to?(action, Issue.find(1).project) | |
1575 | assert ! user.allowed_to?(action, Issue.find(6).project) |
|
1575 | assert ! user.allowed_to?(action, Issue.find(6).project) | |
1576 | post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail', |
|
1576 | post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail', | |
1577 | :issue => {:priority_id => 7, |
|
1577 | :issue => {:priority_id => 7, | |
1578 | :assigned_to_id => '', |
|
1578 | :assigned_to_id => '', | |
1579 | :custom_field_values => {'2' => ''}} |
|
1579 | :custom_field_values => {'2' => ''}} | |
1580 | assert_response 403 |
|
1580 | assert_response 403 | |
1581 | assert_not_equal "Bulk should fail", Journal.last.notes |
|
1581 | assert_not_equal "Bulk should fail", Journal.last.notes | |
1582 | end |
|
1582 | end | |
1583 |
|
1583 | |||
1584 | def test_bullk_update_should_send_a_notification |
|
1584 | def test_bullk_update_should_send_a_notification | |
1585 | @request.session[:user_id] = 2 |
|
1585 | @request.session[:user_id] = 2 | |
1586 | ActionMailer::Base.deliveries.clear |
|
1586 | ActionMailer::Base.deliveries.clear | |
1587 | post(:bulk_update, |
|
1587 | post(:bulk_update, | |
1588 | { |
|
1588 | { | |
1589 | :ids => [1, 2], |
|
1589 | :ids => [1, 2], | |
1590 | :notes => 'Bulk editing', |
|
1590 | :notes => 'Bulk editing', | |
1591 | :issue => { |
|
1591 | :issue => { | |
1592 | :priority_id => 7, |
|
1592 | :priority_id => 7, | |
1593 | :assigned_to_id => '', |
|
1593 | :assigned_to_id => '', | |
1594 | :custom_field_values => {'2' => ''} |
|
1594 | :custom_field_values => {'2' => ''} | |
1595 | } |
|
1595 | } | |
1596 | }) |
|
1596 | }) | |
1597 |
|
1597 | |||
1598 | assert_response 302 |
|
1598 | assert_response 302 | |
1599 | assert_equal 2, ActionMailer::Base.deliveries.size |
|
1599 | assert_equal 2, ActionMailer::Base.deliveries.size | |
1600 | end |
|
1600 | end | |
1601 |
|
1601 | |||
1602 | def test_bulk_update_status |
|
1602 | def test_bulk_update_status | |
1603 | @request.session[:user_id] = 2 |
|
1603 | @request.session[:user_id] = 2 | |
1604 | # update issues priority |
|
1604 | # update issues priority | |
1605 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status', |
|
1605 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status', | |
1606 | :issue => {:priority_id => '', |
|
1606 | :issue => {:priority_id => '', | |
1607 | :assigned_to_id => '', |
|
1607 | :assigned_to_id => '', | |
1608 | :status_id => '5'} |
|
1608 | :status_id => '5'} | |
1609 |
|
1609 | |||
1610 | assert_response 302 |
|
1610 | assert_response 302 | |
1611 | issue = Issue.find(1) |
|
1611 | issue = Issue.find(1) | |
1612 | assert issue.closed? |
|
1612 | assert issue.closed? | |
1613 | end |
|
1613 | end | |
1614 |
|
1614 | |||
1615 | def test_bulk_update_parent_id |
|
1615 | def test_bulk_update_parent_id | |
1616 | @request.session[:user_id] = 2 |
|
1616 | @request.session[:user_id] = 2 | |
1617 | post :bulk_update, :ids => [1, 3], |
|
1617 | post :bulk_update, :ids => [1, 3], | |
1618 | :notes => 'Bulk editing parent', |
|
1618 | :notes => 'Bulk editing parent', | |
1619 | :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'} |
|
1619 | :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'} | |
1620 |
|
1620 | |||
1621 | assert_response 302 |
|
1621 | assert_response 302 | |
1622 | parent = Issue.find(2) |
|
1622 | parent = Issue.find(2) | |
1623 | assert_equal parent.id, Issue.find(1).parent_id |
|
1623 | assert_equal parent.id, Issue.find(1).parent_id | |
1624 | assert_equal parent.id, Issue.find(3).parent_id |
|
1624 | assert_equal parent.id, Issue.find(3).parent_id | |
1625 | assert_equal [1, 3], parent.children.collect(&:id).sort |
|
1625 | assert_equal [1, 3], parent.children.collect(&:id).sort | |
1626 | end |
|
1626 | end | |
1627 |
|
1627 | |||
1628 | def test_bulk_update_custom_field |
|
1628 | def test_bulk_update_custom_field | |
1629 | @request.session[:user_id] = 2 |
|
1629 | @request.session[:user_id] = 2 | |
1630 | # update issues priority |
|
1630 | # update issues priority | |
1631 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field', |
|
1631 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field', | |
1632 | :issue => {:priority_id => '', |
|
1632 | :issue => {:priority_id => '', | |
1633 | :assigned_to_id => '', |
|
1633 | :assigned_to_id => '', | |
1634 | :custom_field_values => {'2' => '777'}} |
|
1634 | :custom_field_values => {'2' => '777'}} | |
1635 |
|
1635 | |||
1636 | assert_response 302 |
|
1636 | assert_response 302 | |
1637 |
|
1637 | |||
1638 | issue = Issue.find(1) |
|
1638 | issue = Issue.find(1) | |
1639 | journal = issue.journals.find(:first, :order => 'created_on DESC') |
|
1639 | journal = issue.journals.find(:first, :order => 'created_on DESC') | |
1640 | assert_equal '777', issue.custom_value_for(2).value |
|
1640 | assert_equal '777', issue.custom_value_for(2).value | |
1641 | assert_equal 1, journal.details.size |
|
1641 | assert_equal 1, journal.details.size | |
1642 | assert_equal '125', journal.details.first.old_value |
|
1642 | assert_equal '125', journal.details.first.old_value | |
1643 | assert_equal '777', journal.details.first.value |
|
1643 | assert_equal '777', journal.details.first.value | |
1644 | end |
|
1644 | end | |
1645 |
|
1645 | |||
1646 | def test_bulk_update_unassign |
|
1646 | def test_bulk_update_unassign | |
1647 | assert_not_nil Issue.find(2).assigned_to |
|
1647 | assert_not_nil Issue.find(2).assigned_to | |
1648 | @request.session[:user_id] = 2 |
|
1648 | @request.session[:user_id] = 2 | |
1649 | # unassign issues |
|
1649 | # unassign issues | |
1650 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'} |
|
1650 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'} | |
1651 | assert_response 302 |
|
1651 | assert_response 302 | |
1652 | # check that the issues were updated |
|
1652 | # check that the issues were updated | |
1653 | assert_nil Issue.find(2).assigned_to |
|
1653 | assert_nil Issue.find(2).assigned_to | |
1654 | end |
|
1654 | end | |
1655 |
|
1655 | |||
1656 | def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject |
|
1656 | def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject | |
1657 | @request.session[:user_id] = 2 |
|
1657 | @request.session[:user_id] = 2 | |
1658 |
|
1658 | |||
1659 | post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4} |
|
1659 | post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4} | |
1660 |
|
1660 | |||
1661 | assert_response :redirect |
|
1661 | assert_response :redirect | |
1662 | issues = Issue.find([1,2]) |
|
1662 | issues = Issue.find([1,2]) | |
1663 | issues.each do |issue| |
|
1663 | issues.each do |issue| | |
1664 | assert_equal 4, issue.fixed_version_id |
|
1664 | assert_equal 4, issue.fixed_version_id | |
1665 | assert_not_equal issue.project_id, issue.fixed_version.project_id |
|
1665 | assert_not_equal issue.project_id, issue.fixed_version.project_id | |
1666 | end |
|
1666 | end | |
1667 | end |
|
1667 | end | |
1668 |
|
1668 | |||
1669 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter |
|
1669 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter | |
1670 | @request.session[:user_id] = 2 |
|
1670 | @request.session[:user_id] = 2 | |
1671 | post :bulk_update, :ids => [1,2], :back_url => '/issues' |
|
1671 | post :bulk_update, :ids => [1,2], :back_url => '/issues' | |
1672 |
|
1672 | |||
1673 | assert_response :redirect |
|
1673 | assert_response :redirect | |
1674 | assert_redirected_to '/issues' |
|
1674 | assert_redirected_to '/issues' | |
1675 | end |
|
1675 | end | |
1676 |
|
1676 | |||
1677 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
1677 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host | |
1678 | @request.session[:user_id] = 2 |
|
1678 | @request.session[:user_id] = 2 | |
1679 | post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' |
|
1679 | post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' | |
1680 |
|
1680 | |||
1681 | assert_response :redirect |
|
1681 | assert_response :redirect | |
1682 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier |
|
1682 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier | |
1683 | end |
|
1683 | end | |
1684 |
|
1684 | |||
1685 | def test_destroy_issue_with_no_time_entries |
|
1685 | def test_destroy_issue_with_no_time_entries | |
1686 | assert_nil TimeEntry.find_by_issue_id(2) |
|
1686 | assert_nil TimeEntry.find_by_issue_id(2) | |
1687 | @request.session[:user_id] = 2 |
|
1687 | @request.session[:user_id] = 2 | |
1688 | post :destroy, :id => 2 |
|
1688 | post :destroy, :id => 2 | |
1689 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1689 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1690 | assert_nil Issue.find_by_id(2) |
|
1690 | assert_nil Issue.find_by_id(2) | |
1691 | end |
|
1691 | end | |
1692 |
|
1692 | |||
1693 | def test_destroy_issues_with_time_entries |
|
1693 | def test_destroy_issues_with_time_entries | |
1694 | @request.session[:user_id] = 2 |
|
1694 | @request.session[:user_id] = 2 | |
1695 | post :destroy, :ids => [1, 3] |
|
1695 | post :destroy, :ids => [1, 3] | |
1696 | assert_response :success |
|
1696 | assert_response :success | |
1697 | assert_template 'destroy' |
|
1697 | assert_template 'destroy' | |
1698 | assert_not_nil assigns(:hours) |
|
1698 | assert_not_nil assigns(:hours) | |
1699 | assert Issue.find_by_id(1) && Issue.find_by_id(3) |
|
1699 | assert Issue.find_by_id(1) && Issue.find_by_id(3) | |
1700 | end |
|
1700 | end | |
1701 |
|
1701 | |||
1702 | def test_destroy_issues_and_destroy_time_entries |
|
1702 | def test_destroy_issues_and_destroy_time_entries | |
1703 | @request.session[:user_id] = 2 |
|
1703 | @request.session[:user_id] = 2 | |
1704 | post :destroy, :ids => [1, 3], :todo => 'destroy' |
|
1704 | post :destroy, :ids => [1, 3], :todo => 'destroy' | |
1705 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1705 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1706 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
1706 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
1707 | assert_nil TimeEntry.find_by_id([1, 2]) |
|
1707 | assert_nil TimeEntry.find_by_id([1, 2]) | |
1708 | end |
|
1708 | end | |
1709 |
|
1709 | |||
1710 | def test_destroy_issues_and_assign_time_entries_to_project |
|
1710 | def test_destroy_issues_and_assign_time_entries_to_project | |
1711 | @request.session[:user_id] = 2 |
|
1711 | @request.session[:user_id] = 2 | |
1712 | post :destroy, :ids => [1, 3], :todo => 'nullify' |
|
1712 | post :destroy, :ids => [1, 3], :todo => 'nullify' | |
1713 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1713 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1714 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
1714 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
1715 | assert_nil TimeEntry.find(1).issue_id |
|
1715 | assert_nil TimeEntry.find(1).issue_id | |
1716 | assert_nil TimeEntry.find(2).issue_id |
|
1716 | assert_nil TimeEntry.find(2).issue_id | |
1717 | end |
|
1717 | end | |
1718 |
|
1718 | |||
1719 | def test_destroy_issues_and_reassign_time_entries_to_another_issue |
|
1719 | def test_destroy_issues_and_reassign_time_entries_to_another_issue | |
1720 | @request.session[:user_id] = 2 |
|
1720 | @request.session[:user_id] = 2 | |
1721 | post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 |
|
1721 | post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 | |
1722 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1722 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1723 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
1723 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
1724 | assert_equal 2, TimeEntry.find(1).issue_id |
|
1724 | assert_equal 2, TimeEntry.find(1).issue_id | |
1725 | assert_equal 2, TimeEntry.find(2).issue_id |
|
1725 | assert_equal 2, TimeEntry.find(2).issue_id | |
1726 | end |
|
1726 | end | |
1727 |
|
1727 | |||
1728 | def test_destroy_issues_from_different_projects |
|
1728 | def test_destroy_issues_from_different_projects | |
1729 | @request.session[:user_id] = 2 |
|
1729 | @request.session[:user_id] = 2 | |
1730 | post :destroy, :ids => [1, 2, 6], :todo => 'destroy' |
|
1730 | post :destroy, :ids => [1, 2, 6], :todo => 'destroy' | |
1731 | assert_redirected_to :controller => 'issues', :action => 'index' |
|
1731 | assert_redirected_to :controller => 'issues', :action => 'index' | |
1732 | assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6)) |
|
1732 | assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6)) | |
1733 | end |
|
1733 | end | |
1734 |
|
1734 | |||
1735 | def test_destroy_parent_and_child_issues |
|
1735 | def test_destroy_parent_and_child_issues | |
1736 | parent = Issue.generate!(:project_id => 1, :tracker_id => 1) |
|
1736 | parent = Issue.generate!(:project_id => 1, :tracker_id => 1) | |
1737 | child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id) |
|
1737 | child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id) | |
1738 | assert child.is_descendant_of?(parent.reload) |
|
1738 | assert child.is_descendant_of?(parent.reload) | |
1739 |
|
1739 | |||
1740 | @request.session[:user_id] = 2 |
|
1740 | @request.session[:user_id] = 2 | |
1741 | assert_difference 'Issue.count', -2 do |
|
1741 | assert_difference 'Issue.count', -2 do | |
1742 | post :destroy, :ids => [parent.id, child.id], :todo => 'destroy' |
|
1742 | post :destroy, :ids => [parent.id, child.id], :todo => 'destroy' | |
1743 | end |
|
1743 | end | |
1744 | assert_response 302 |
|
1744 | assert_response 302 | |
1745 | end |
|
1745 | end | |
1746 |
|
1746 | |||
1747 | def test_default_search_scope |
|
1747 | def test_default_search_scope | |
1748 | get :index |
|
1748 | get :index | |
1749 | assert_tag :div, :attributes => {:id => 'quick-search'}, |
|
1749 | assert_tag :div, :attributes => {:id => 'quick-search'}, | |
1750 | :child => {:tag => 'form', |
|
1750 | :child => {:tag => 'form', | |
1751 | :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} |
|
1751 | :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} | |
1752 | end |
|
1752 | end | |
1753 | end |
|
1753 | end |
General Comments 0
You need to be logged in to leave comments.
Login now