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