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