@@ -1,3992 +1,4008 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2014 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2014 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 |
|
19 | |||
20 | class IssuesControllerTest < ActionController::TestCase |
|
20 | class IssuesControllerTest < ActionController::TestCase | |
21 | fixtures :projects, |
|
21 | fixtures :projects, | |
22 | :users, |
|
22 | :users, | |
23 | :roles, |
|
23 | :roles, | |
24 | :members, |
|
24 | :members, | |
25 | :member_roles, |
|
25 | :member_roles, | |
26 | :issues, |
|
26 | :issues, | |
27 | :issue_statuses, |
|
27 | :issue_statuses, | |
28 | :issue_relations, |
|
28 | :issue_relations, | |
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 | :repositories, |
|
45 | :repositories, | |
46 | :changesets |
|
46 | :changesets | |
47 |
|
47 | |||
48 | include Redmine::I18n |
|
48 | include Redmine::I18n | |
49 |
|
49 | |||
50 | def setup |
|
50 | def setup | |
51 | User.current = nil |
|
51 | User.current = nil | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | def test_index |
|
54 | def test_index | |
55 | with_settings :default_language => "en" do |
|
55 | with_settings :default_language => "en" do | |
56 | get :index |
|
56 | get :index | |
57 | assert_response :success |
|
57 | assert_response :success | |
58 | assert_template 'index' |
|
58 | assert_template 'index' | |
59 | assert_not_nil assigns(:issues) |
|
59 | assert_not_nil assigns(:issues) | |
60 | assert_nil assigns(:project) |
|
60 | assert_nil assigns(:project) | |
61 |
|
61 | |||
62 | # links to visible issues |
|
62 | # links to visible issues | |
63 | assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/ |
|
63 | assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/ | |
64 | assert_select 'a[href=/issues/5]', :text => /Subproject issue/ |
|
64 | assert_select 'a[href=/issues/5]', :text => /Subproject issue/ | |
65 | # private projects hidden |
|
65 | # private projects hidden | |
66 | assert_select 'a[href=/issues/6]', 0 |
|
66 | assert_select 'a[href=/issues/6]', 0 | |
67 | assert_select 'a[href=/issues/4]', 0 |
|
67 | assert_select 'a[href=/issues/4]', 0 | |
68 | # project column |
|
68 | # project column | |
69 | assert_select 'th', :text => /Project/ |
|
69 | assert_select 'th', :text => /Project/ | |
70 | end |
|
70 | end | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
73 | def test_index_should_not_list_issues_when_module_disabled |
|
73 | def test_index_should_not_list_issues_when_module_disabled | |
74 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") |
|
74 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") | |
75 | get :index |
|
75 | get :index | |
76 | assert_response :success |
|
76 | assert_response :success | |
77 | assert_template 'index' |
|
77 | assert_template 'index' | |
78 | assert_not_nil assigns(:issues) |
|
78 | assert_not_nil assigns(:issues) | |
79 | assert_nil assigns(:project) |
|
79 | assert_nil assigns(:project) | |
80 |
|
80 | |||
81 | assert_select 'a[href=/issues/1]', 0 |
|
81 | assert_select 'a[href=/issues/1]', 0 | |
82 | assert_select 'a[href=/issues/5]', :text => /Subproject issue/ |
|
82 | assert_select 'a[href=/issues/5]', :text => /Subproject issue/ | |
83 | end |
|
83 | end | |
84 |
|
84 | |||
85 | def test_index_should_list_visible_issues_only |
|
85 | def test_index_should_list_visible_issues_only | |
86 | get :index, :per_page => 100 |
|
86 | get :index, :per_page => 100 | |
87 | assert_response :success |
|
87 | assert_response :success | |
88 | assert_not_nil assigns(:issues) |
|
88 | assert_not_nil assigns(:issues) | |
89 | assert_nil assigns(:issues).detect {|issue| !issue.visible?} |
|
89 | assert_nil assigns(:issues).detect {|issue| !issue.visible?} | |
90 | end |
|
90 | end | |
91 |
|
91 | |||
92 | def test_index_with_project |
|
92 | def test_index_with_project | |
93 | Setting.display_subprojects_issues = 0 |
|
93 | Setting.display_subprojects_issues = 0 | |
94 | get :index, :project_id => 1 |
|
94 | get :index, :project_id => 1 | |
95 | assert_response :success |
|
95 | assert_response :success | |
96 | assert_template 'index' |
|
96 | assert_template 'index' | |
97 | assert_not_nil assigns(:issues) |
|
97 | assert_not_nil assigns(:issues) | |
98 |
|
98 | |||
99 | assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/ |
|
99 | assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/ | |
100 | assert_select 'a[href=/issues/5]', 0 |
|
100 | assert_select 'a[href=/issues/5]', 0 | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | def test_index_with_project_and_subprojects |
|
103 | def test_index_with_project_and_subprojects | |
104 | Setting.display_subprojects_issues = 1 |
|
104 | Setting.display_subprojects_issues = 1 | |
105 | get :index, :project_id => 1 |
|
105 | get :index, :project_id => 1 | |
106 | assert_response :success |
|
106 | assert_response :success | |
107 | assert_template 'index' |
|
107 | assert_template 'index' | |
108 | assert_not_nil assigns(:issues) |
|
108 | assert_not_nil assigns(:issues) | |
109 |
|
109 | |||
110 | assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/ |
|
110 | assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/ | |
111 | assert_select 'a[href=/issues/5]', :text => /Subproject issue/ |
|
111 | assert_select 'a[href=/issues/5]', :text => /Subproject issue/ | |
112 | assert_select 'a[href=/issues/6]', 0 |
|
112 | assert_select 'a[href=/issues/6]', 0 | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission |
|
115 | def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission | |
116 | @request.session[:user_id] = 2 |
|
116 | @request.session[:user_id] = 2 | |
117 | Setting.display_subprojects_issues = 1 |
|
117 | Setting.display_subprojects_issues = 1 | |
118 | get :index, :project_id => 1 |
|
118 | get :index, :project_id => 1 | |
119 | assert_response :success |
|
119 | assert_response :success | |
120 | assert_template 'index' |
|
120 | assert_template 'index' | |
121 | assert_not_nil assigns(:issues) |
|
121 | assert_not_nil assigns(:issues) | |
122 |
|
122 | |||
123 | assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/ |
|
123 | assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/ | |
124 | assert_select 'a[href=/issues/5]', :text => /Subproject issue/ |
|
124 | assert_select 'a[href=/issues/5]', :text => /Subproject issue/ | |
125 | assert_select 'a[href=/issues/6]', :text => /Issue of a private subproject/ |
|
125 | assert_select 'a[href=/issues/6]', :text => /Issue of a private subproject/ | |
126 | end |
|
126 | end | |
127 |
|
127 | |||
128 | def test_index_with_project_and_default_filter |
|
128 | def test_index_with_project_and_default_filter | |
129 | get :index, :project_id => 1, :set_filter => 1 |
|
129 | get :index, :project_id => 1, :set_filter => 1 | |
130 | assert_response :success |
|
130 | assert_response :success | |
131 | assert_template 'index' |
|
131 | assert_template 'index' | |
132 | assert_not_nil assigns(:issues) |
|
132 | assert_not_nil assigns(:issues) | |
133 |
|
133 | |||
134 | query = assigns(:query) |
|
134 | query = assigns(:query) | |
135 | assert_not_nil query |
|
135 | assert_not_nil query | |
136 | # default filter |
|
136 | # default filter | |
137 | assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters) |
|
137 | assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters) | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | def test_index_with_project_and_filter |
|
140 | def test_index_with_project_and_filter | |
141 | get :index, :project_id => 1, :set_filter => 1, |
|
141 | get :index, :project_id => 1, :set_filter => 1, | |
142 | :f => ['tracker_id'], |
|
142 | :f => ['tracker_id'], | |
143 | :op => {'tracker_id' => '='}, |
|
143 | :op => {'tracker_id' => '='}, | |
144 | :v => {'tracker_id' => ['1']} |
|
144 | :v => {'tracker_id' => ['1']} | |
145 | assert_response :success |
|
145 | assert_response :success | |
146 | assert_template 'index' |
|
146 | assert_template 'index' | |
147 | assert_not_nil assigns(:issues) |
|
147 | assert_not_nil assigns(:issues) | |
148 |
|
148 | |||
149 | query = assigns(:query) |
|
149 | query = assigns(:query) | |
150 | assert_not_nil query |
|
150 | assert_not_nil query | |
151 | assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters) |
|
151 | assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters) | |
152 | end |
|
152 | end | |
153 |
|
153 | |||
154 | def test_index_with_short_filters |
|
154 | def test_index_with_short_filters | |
155 | to_test = { |
|
155 | to_test = { | |
156 | 'status_id' => { |
|
156 | 'status_id' => { | |
157 | 'o' => { :op => 'o', :values => [''] }, |
|
157 | 'o' => { :op => 'o', :values => [''] }, | |
158 | 'c' => { :op => 'c', :values => [''] }, |
|
158 | 'c' => { :op => 'c', :values => [''] }, | |
159 | '7' => { :op => '=', :values => ['7'] }, |
|
159 | '7' => { :op => '=', :values => ['7'] }, | |
160 | '7|3|4' => { :op => '=', :values => ['7', '3', '4'] }, |
|
160 | '7|3|4' => { :op => '=', :values => ['7', '3', '4'] }, | |
161 | '=7' => { :op => '=', :values => ['7'] }, |
|
161 | '=7' => { :op => '=', :values => ['7'] }, | |
162 | '!3' => { :op => '!', :values => ['3'] }, |
|
162 | '!3' => { :op => '!', :values => ['3'] }, | |
163 | '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }}, |
|
163 | '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }}, | |
164 | 'subject' => { |
|
164 | 'subject' => { | |
165 | 'This is a subject' => { :op => '=', :values => ['This is a subject'] }, |
|
165 | 'This is a subject' => { :op => '=', :values => ['This is a subject'] }, | |
166 | 'o' => { :op => '=', :values => ['o'] }, |
|
166 | 'o' => { :op => '=', :values => ['o'] }, | |
167 | '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] }, |
|
167 | '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] }, | |
168 | '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }}, |
|
168 | '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }}, | |
169 | 'tracker_id' => { |
|
169 | 'tracker_id' => { | |
170 | '3' => { :op => '=', :values => ['3'] }, |
|
170 | '3' => { :op => '=', :values => ['3'] }, | |
171 | '=3' => { :op => '=', :values => ['3'] }}, |
|
171 | '=3' => { :op => '=', :values => ['3'] }}, | |
172 | 'start_date' => { |
|
172 | 'start_date' => { | |
173 | '2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, |
|
173 | '2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, | |
174 | '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, |
|
174 | '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, | |
175 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, |
|
175 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, | |
176 | '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] }, |
|
176 | '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] }, | |
177 | '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] }, |
|
177 | '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] }, | |
178 | '<t+2' => { :op => '<t+', :values => ['2'] }, |
|
178 | '<t+2' => { :op => '<t+', :values => ['2'] }, | |
179 | '>t+2' => { :op => '>t+', :values => ['2'] }, |
|
179 | '>t+2' => { :op => '>t+', :values => ['2'] }, | |
180 | 't+2' => { :op => 't+', :values => ['2'] }, |
|
180 | 't+2' => { :op => 't+', :values => ['2'] }, | |
181 | 't' => { :op => 't', :values => [''] }, |
|
181 | 't' => { :op => 't', :values => [''] }, | |
182 | 'w' => { :op => 'w', :values => [''] }, |
|
182 | 'w' => { :op => 'w', :values => [''] }, | |
183 | '>t-2' => { :op => '>t-', :values => ['2'] }, |
|
183 | '>t-2' => { :op => '>t-', :values => ['2'] }, | |
184 | '<t-2' => { :op => '<t-', :values => ['2'] }, |
|
184 | '<t-2' => { :op => '<t-', :values => ['2'] }, | |
185 | 't-2' => { :op => 't-', :values => ['2'] }}, |
|
185 | 't-2' => { :op => 't-', :values => ['2'] }}, | |
186 | 'created_on' => { |
|
186 | 'created_on' => { | |
187 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, |
|
187 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, | |
188 | '<t-2' => { :op => '<t-', :values => ['2'] }, |
|
188 | '<t-2' => { :op => '<t-', :values => ['2'] }, | |
189 | '>t-2' => { :op => '>t-', :values => ['2'] }, |
|
189 | '>t-2' => { :op => '>t-', :values => ['2'] }, | |
190 | 't-2' => { :op => 't-', :values => ['2'] }}, |
|
190 | 't-2' => { :op => 't-', :values => ['2'] }}, | |
191 | 'cf_1' => { |
|
191 | 'cf_1' => { | |
192 | 'c' => { :op => '=', :values => ['c'] }, |
|
192 | 'c' => { :op => '=', :values => ['c'] }, | |
193 | '!c' => { :op => '!', :values => ['c'] }, |
|
193 | '!c' => { :op => '!', :values => ['c'] }, | |
194 | '!*' => { :op => '!*', :values => [''] }, |
|
194 | '!*' => { :op => '!*', :values => [''] }, | |
195 | '*' => { :op => '*', :values => [''] }}, |
|
195 | '*' => { :op => '*', :values => [''] }}, | |
196 | 'estimated_hours' => { |
|
196 | 'estimated_hours' => { | |
197 | '=13.4' => { :op => '=', :values => ['13.4'] }, |
|
197 | '=13.4' => { :op => '=', :values => ['13.4'] }, | |
198 | '>=45' => { :op => '>=', :values => ['45'] }, |
|
198 | '>=45' => { :op => '>=', :values => ['45'] }, | |
199 | '<=125' => { :op => '<=', :values => ['125'] }, |
|
199 | '<=125' => { :op => '<=', :values => ['125'] }, | |
200 | '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] }, |
|
200 | '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] }, | |
201 | '!*' => { :op => '!*', :values => [''] }, |
|
201 | '!*' => { :op => '!*', :values => [''] }, | |
202 | '*' => { :op => '*', :values => [''] }} |
|
202 | '*' => { :op => '*', :values => [''] }} | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | default_filter = { 'status_id' => {:operator => 'o', :values => [''] }} |
|
205 | default_filter = { 'status_id' => {:operator => 'o', :values => [''] }} | |
206 |
|
206 | |||
207 | to_test.each do |field, expression_and_expected| |
|
207 | to_test.each do |field, expression_and_expected| | |
208 | expression_and_expected.each do |filter_expression, expected| |
|
208 | expression_and_expected.each do |filter_expression, expected| | |
209 |
|
209 | |||
210 | get :index, :set_filter => 1, field => filter_expression |
|
210 | get :index, :set_filter => 1, field => filter_expression | |
211 |
|
211 | |||
212 | assert_response :success |
|
212 | assert_response :success | |
213 | assert_template 'index' |
|
213 | assert_template 'index' | |
214 | assert_not_nil assigns(:issues) |
|
214 | assert_not_nil assigns(:issues) | |
215 |
|
215 | |||
216 | query = assigns(:query) |
|
216 | query = assigns(:query) | |
217 | assert_not_nil query |
|
217 | assert_not_nil query | |
218 | assert query.has_filter?(field) |
|
218 | assert query.has_filter?(field) | |
219 | assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters) |
|
219 | assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters) | |
220 | end |
|
220 | end | |
221 | end |
|
221 | end | |
222 | end |
|
222 | end | |
223 |
|
223 | |||
224 | def test_index_with_project_and_empty_filters |
|
224 | def test_index_with_project_and_empty_filters | |
225 | get :index, :project_id => 1, :set_filter => 1, :fields => [''] |
|
225 | get :index, :project_id => 1, :set_filter => 1, :fields => [''] | |
226 | assert_response :success |
|
226 | assert_response :success | |
227 | assert_template 'index' |
|
227 | assert_template 'index' | |
228 | assert_not_nil assigns(:issues) |
|
228 | assert_not_nil assigns(:issues) | |
229 |
|
229 | |||
230 | query = assigns(:query) |
|
230 | query = assigns(:query) | |
231 | assert_not_nil query |
|
231 | assert_not_nil query | |
232 | # no filter |
|
232 | # no filter | |
233 | assert_equal({}, query.filters) |
|
233 | assert_equal({}, query.filters) | |
234 | end |
|
234 | end | |
235 |
|
235 | |||
236 | def test_index_with_project_custom_field_filter |
|
236 | def test_index_with_project_custom_field_filter | |
237 | field = ProjectCustomField.create!(:name => 'Client', :is_filter => true, :field_format => 'string') |
|
237 | field = ProjectCustomField.create!(:name => 'Client', :is_filter => true, :field_format => 'string') | |
238 | CustomValue.create!(:custom_field => field, :customized => Project.find(3), :value => 'Foo') |
|
238 | CustomValue.create!(:custom_field => field, :customized => Project.find(3), :value => 'Foo') | |
239 | CustomValue.create!(:custom_field => field, :customized => Project.find(5), :value => 'Foo') |
|
239 | CustomValue.create!(:custom_field => field, :customized => Project.find(5), :value => 'Foo') | |
240 | filter_name = "project.cf_#{field.id}" |
|
240 | filter_name = "project.cf_#{field.id}" | |
241 | @request.session[:user_id] = 1 |
|
241 | @request.session[:user_id] = 1 | |
242 |
|
242 | |||
243 | get :index, :set_filter => 1, |
|
243 | get :index, :set_filter => 1, | |
244 | :f => [filter_name], |
|
244 | :f => [filter_name], | |
245 | :op => {filter_name => '='}, |
|
245 | :op => {filter_name => '='}, | |
246 | :v => {filter_name => ['Foo']} |
|
246 | :v => {filter_name => ['Foo']} | |
247 | assert_response :success |
|
247 | assert_response :success | |
248 | assert_template 'index' |
|
248 | assert_template 'index' | |
249 | assert_equal [3, 5], assigns(:issues).map(&:project_id).uniq.sort |
|
249 | assert_equal [3, 5], assigns(:issues).map(&:project_id).uniq.sort | |
250 | end |
|
250 | end | |
251 |
|
251 | |||
252 | def test_index_with_query |
|
252 | def test_index_with_query | |
253 | get :index, :project_id => 1, :query_id => 5 |
|
253 | get :index, :project_id => 1, :query_id => 5 | |
254 | assert_response :success |
|
254 | assert_response :success | |
255 | assert_template 'index' |
|
255 | assert_template 'index' | |
256 | assert_not_nil assigns(:issues) |
|
256 | assert_not_nil assigns(:issues) | |
257 | assert_nil assigns(:issue_count_by_group) |
|
257 | assert_nil assigns(:issue_count_by_group) | |
258 | end |
|
258 | end | |
259 |
|
259 | |||
260 | def test_index_with_query_grouped_by_tracker |
|
260 | def test_index_with_query_grouped_by_tracker | |
261 | get :index, :project_id => 1, :query_id => 6 |
|
261 | get :index, :project_id => 1, :query_id => 6 | |
262 | assert_response :success |
|
262 | assert_response :success | |
263 | assert_template 'index' |
|
263 | assert_template 'index' | |
264 | assert_not_nil assigns(:issues) |
|
264 | assert_not_nil assigns(:issues) | |
265 | assert_not_nil assigns(:issue_count_by_group) |
|
265 | assert_not_nil assigns(:issue_count_by_group) | |
266 | end |
|
266 | end | |
267 |
|
267 | |||
268 | def test_index_with_query_grouped_by_list_custom_field |
|
268 | def test_index_with_query_grouped_by_list_custom_field | |
269 | get :index, :project_id => 1, :query_id => 9 |
|
269 | get :index, :project_id => 1, :query_id => 9 | |
270 | assert_response :success |
|
270 | assert_response :success | |
271 | assert_template 'index' |
|
271 | assert_template 'index' | |
272 | assert_not_nil assigns(:issues) |
|
272 | assert_not_nil assigns(:issues) | |
273 | assert_not_nil assigns(:issue_count_by_group) |
|
273 | assert_not_nil assigns(:issue_count_by_group) | |
274 | end |
|
274 | end | |
275 |
|
275 | |||
276 | def test_index_with_query_grouped_by_user_custom_field |
|
276 | def test_index_with_query_grouped_by_user_custom_field | |
277 | cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user') |
|
277 | cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user') | |
278 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2') |
|
278 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2') | |
279 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3') |
|
279 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3') | |
280 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3') |
|
280 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3') | |
281 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '') |
|
281 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '') | |
282 |
|
282 | |||
283 | get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}" |
|
283 | get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}" | |
284 | assert_response :success |
|
284 | assert_response :success | |
285 |
|
285 | |||
286 | assert_select 'tr.group', 3 |
|
286 | assert_select 'tr.group', 3 | |
287 | assert_select 'tr.group' do |
|
287 | assert_select 'tr.group' do | |
288 | assert_select 'a', :text => 'John Smith' |
|
288 | assert_select 'a', :text => 'John Smith' | |
289 | assert_select 'span.count', :text => '1' |
|
289 | assert_select 'span.count', :text => '1' | |
290 | end |
|
290 | end | |
291 | assert_select 'tr.group' do |
|
291 | assert_select 'tr.group' do | |
292 | assert_select 'a', :text => 'Dave Lopper' |
|
292 | assert_select 'a', :text => 'Dave Lopper' | |
293 | assert_select 'span.count', :text => '2' |
|
293 | assert_select 'span.count', :text => '2' | |
294 | end |
|
294 | end | |
295 | end |
|
295 | end | |
296 |
|
296 | |||
297 | def test_index_with_query_grouped_by_tracker_in_normal_order |
|
297 | def test_index_with_query_grouped_by_tracker_in_normal_order | |
298 | 3.times {|i| Issue.generate!(:tracker_id => (i + 1))} |
|
298 | 3.times {|i| Issue.generate!(:tracker_id => (i + 1))} | |
299 |
|
299 | |||
300 | get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc' |
|
300 | get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc' | |
301 | assert_response :success |
|
301 | assert_response :success | |
302 |
|
302 | |||
303 | trackers = assigns(:issues).map(&:tracker).uniq |
|
303 | trackers = assigns(:issues).map(&:tracker).uniq | |
304 | assert_equal [1, 2, 3], trackers.map(&:id) |
|
304 | assert_equal [1, 2, 3], trackers.map(&:id) | |
305 | end |
|
305 | end | |
306 |
|
306 | |||
307 | def test_index_with_query_grouped_by_tracker_in_reverse_order |
|
307 | def test_index_with_query_grouped_by_tracker_in_reverse_order | |
308 | 3.times {|i| Issue.generate!(:tracker_id => (i + 1))} |
|
308 | 3.times {|i| Issue.generate!(:tracker_id => (i + 1))} | |
309 |
|
309 | |||
310 | get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc,tracker:desc' |
|
310 | get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc,tracker:desc' | |
311 | assert_response :success |
|
311 | assert_response :success | |
312 |
|
312 | |||
313 | trackers = assigns(:issues).map(&:tracker).uniq |
|
313 | trackers = assigns(:issues).map(&:tracker).uniq | |
314 | assert_equal [3, 2, 1], trackers.map(&:id) |
|
314 | assert_equal [3, 2, 1], trackers.map(&:id) | |
315 | end |
|
315 | end | |
316 |
|
316 | |||
317 | def test_index_with_query_id_and_project_id_should_set_session_query |
|
317 | def test_index_with_query_id_and_project_id_should_set_session_query | |
318 | get :index, :project_id => 1, :query_id => 4 |
|
318 | get :index, :project_id => 1, :query_id => 4 | |
319 | assert_response :success |
|
319 | assert_response :success | |
320 | assert_kind_of Hash, session[:query] |
|
320 | assert_kind_of Hash, session[:query] | |
321 | assert_equal 4, session[:query][:id] |
|
321 | assert_equal 4, session[:query][:id] | |
322 | assert_equal 1, session[:query][:project_id] |
|
322 | assert_equal 1, session[:query][:project_id] | |
323 | end |
|
323 | end | |
324 |
|
324 | |||
325 | def test_index_with_invalid_query_id_should_respond_404 |
|
325 | def test_index_with_invalid_query_id_should_respond_404 | |
326 | get :index, :project_id => 1, :query_id => 999 |
|
326 | get :index, :project_id => 1, :query_id => 999 | |
327 | assert_response 404 |
|
327 | assert_response 404 | |
328 | end |
|
328 | end | |
329 |
|
329 | |||
330 | def test_index_with_cross_project_query_in_session_should_show_project_issues |
|
330 | def test_index_with_cross_project_query_in_session_should_show_project_issues | |
331 | q = IssueQuery.create!(:name => "test", :user_id => 2, :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil) |
|
331 | q = IssueQuery.create!(:name => "test", :user_id => 2, :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil) | |
332 | @request.session[:query] = {:id => q.id, :project_id => 1} |
|
332 | @request.session[:query] = {:id => q.id, :project_id => 1} | |
333 |
|
333 | |||
334 | with_settings :display_subprojects_issues => '0' do |
|
334 | with_settings :display_subprojects_issues => '0' do | |
335 | get :index, :project_id => 1 |
|
335 | get :index, :project_id => 1 | |
336 | end |
|
336 | end | |
337 | assert_response :success |
|
337 | assert_response :success | |
338 | assert_not_nil assigns(:query) |
|
338 | assert_not_nil assigns(:query) | |
339 | assert_equal q.id, assigns(:query).id |
|
339 | assert_equal q.id, assigns(:query).id | |
340 | assert_equal 1, assigns(:query).project_id |
|
340 | assert_equal 1, assigns(:query).project_id | |
341 | assert_equal [1], assigns(:issues).map(&:project_id).uniq |
|
341 | assert_equal [1], assigns(:issues).map(&:project_id).uniq | |
342 | end |
|
342 | end | |
343 |
|
343 | |||
344 | def test_private_query_should_not_be_available_to_other_users |
|
344 | def test_private_query_should_not_be_available_to_other_users | |
345 | q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil) |
|
345 | q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil) | |
346 | @request.session[:user_id] = 3 |
|
346 | @request.session[:user_id] = 3 | |
347 |
|
347 | |||
348 | get :index, :query_id => q.id |
|
348 | get :index, :query_id => q.id | |
349 | assert_response 403 |
|
349 | assert_response 403 | |
350 | end |
|
350 | end | |
351 |
|
351 | |||
352 | def test_private_query_should_be_available_to_its_user |
|
352 | def test_private_query_should_be_available_to_its_user | |
353 | q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil) |
|
353 | q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil) | |
354 | @request.session[:user_id] = 2 |
|
354 | @request.session[:user_id] = 2 | |
355 |
|
355 | |||
356 | get :index, :query_id => q.id |
|
356 | get :index, :query_id => q.id | |
357 | assert_response :success |
|
357 | assert_response :success | |
358 | end |
|
358 | end | |
359 |
|
359 | |||
360 | def test_public_query_should_be_available_to_other_users |
|
360 | def test_public_query_should_be_available_to_other_users | |
361 | q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => nil) |
|
361 | q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => nil) | |
362 | @request.session[:user_id] = 3 |
|
362 | @request.session[:user_id] = 3 | |
363 |
|
363 | |||
364 | get :index, :query_id => q.id |
|
364 | get :index, :query_id => q.id | |
365 | assert_response :success |
|
365 | assert_response :success | |
366 | end |
|
366 | end | |
367 |
|
367 | |||
368 | def test_index_should_omit_page_param_in_export_links |
|
368 | def test_index_should_omit_page_param_in_export_links | |
369 | get :index, :page => 2 |
|
369 | get :index, :page => 2 | |
370 | assert_response :success |
|
370 | assert_response :success | |
371 | assert_select 'a.atom[href=/issues.atom]' |
|
371 | assert_select 'a.atom[href=/issues.atom]' | |
372 | assert_select 'a.csv[href=/issues.csv]' |
|
372 | assert_select 'a.csv[href=/issues.csv]' | |
373 | assert_select 'a.pdf[href=/issues.pdf]' |
|
373 | assert_select 'a.pdf[href=/issues.pdf]' | |
374 | assert_select 'form#csv-export-form[action=/issues.csv]' |
|
374 | assert_select 'form#csv-export-form[action=/issues.csv]' | |
375 | end |
|
375 | end | |
376 |
|
376 | |||
377 | def test_index_should_not_warn_when_not_exceeding_export_limit |
|
377 | def test_index_should_not_warn_when_not_exceeding_export_limit | |
378 | with_settings :issues_export_limit => 200 do |
|
378 | with_settings :issues_export_limit => 200 do | |
379 | get :index |
|
379 | get :index | |
380 | assert_select '#csv-export-options p.icon-warning', 0 |
|
380 | assert_select '#csv-export-options p.icon-warning', 0 | |
381 | end |
|
381 | end | |
382 | end |
|
382 | end | |
383 |
|
383 | |||
384 | def test_index_should_warn_when_exceeding_export_limit |
|
384 | def test_index_should_warn_when_exceeding_export_limit | |
385 | with_settings :issues_export_limit => 2 do |
|
385 | with_settings :issues_export_limit => 2 do | |
386 | get :index |
|
386 | get :index | |
387 | assert_select '#csv-export-options p.icon-warning', :text => %r{limit: 2} |
|
387 | assert_select '#csv-export-options p.icon-warning', :text => %r{limit: 2} | |
388 | end |
|
388 | end | |
389 | end |
|
389 | end | |
390 |
|
390 | |||
391 | def test_index_csv |
|
391 | def test_index_csv | |
392 | get :index, :format => 'csv' |
|
392 | get :index, :format => 'csv' | |
393 | assert_response :success |
|
393 | assert_response :success | |
394 | assert_not_nil assigns(:issues) |
|
394 | assert_not_nil assigns(:issues) | |
395 | assert_equal 'text/csv; header=present', @response.content_type |
|
395 | assert_equal 'text/csv; header=present', @response.content_type | |
396 | assert @response.body.starts_with?("#,") |
|
396 | assert @response.body.starts_with?("#,") | |
397 | lines = @response.body.chomp.split("\n") |
|
397 | lines = @response.body.chomp.split("\n") | |
398 | assert_equal assigns(:query).columns.size, lines[0].split(',').size |
|
398 | assert_equal assigns(:query).columns.size, lines[0].split(',').size | |
399 | end |
|
399 | end | |
400 |
|
400 | |||
401 | def test_index_csv_with_project |
|
401 | def test_index_csv_with_project | |
402 | get :index, :project_id => 1, :format => 'csv' |
|
402 | get :index, :project_id => 1, :format => 'csv' | |
403 | assert_response :success |
|
403 | assert_response :success | |
404 | assert_not_nil assigns(:issues) |
|
404 | assert_not_nil assigns(:issues) | |
405 | assert_equal 'text/csv; header=present', @response.content_type |
|
405 | assert_equal 'text/csv; header=present', @response.content_type | |
406 | end |
|
406 | end | |
407 |
|
407 | |||
408 | def test_index_csv_with_description |
|
408 | def test_index_csv_with_description | |
409 | Issue.generate!(:description => 'test_index_csv_with_description') |
|
409 | Issue.generate!(:description => 'test_index_csv_with_description') | |
410 |
|
410 | |||
411 | with_settings :default_language => 'en' do |
|
411 | with_settings :default_language => 'en' do | |
412 | get :index, :format => 'csv', :description => '1' |
|
412 | get :index, :format => 'csv', :description => '1' | |
413 | assert_response :success |
|
413 | assert_response :success | |
414 | assert_not_nil assigns(:issues) |
|
414 | assert_not_nil assigns(:issues) | |
415 | end |
|
415 | end | |
416 |
|
416 | |||
417 | assert_equal 'text/csv; header=present', response.content_type |
|
417 | assert_equal 'text/csv; header=present', response.content_type | |
418 | headers = response.body.chomp.split("\n").first.split(',') |
|
418 | headers = response.body.chomp.split("\n").first.split(',') | |
419 | assert_include 'Description', headers |
|
419 | assert_include 'Description', headers | |
420 | assert_include 'test_index_csv_with_description', response.body |
|
420 | assert_include 'test_index_csv_with_description', response.body | |
421 | end |
|
421 | end | |
422 |
|
422 | |||
423 | def test_index_csv_with_spent_time_column |
|
423 | def test_index_csv_with_spent_time_column | |
424 | issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2) |
|
424 | issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2) | |
425 | TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today) |
|
425 | TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today) | |
426 |
|
426 | |||
427 | get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours) |
|
427 | get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours) | |
428 | assert_response :success |
|
428 | assert_response :success | |
429 | assert_equal 'text/csv; header=present', @response.content_type |
|
429 | assert_equal 'text/csv; header=present', @response.content_type | |
430 | lines = @response.body.chomp.split("\n") |
|
430 | lines = @response.body.chomp.split("\n") | |
431 | assert_include "#{issue.id},#{issue.subject},7.33", lines |
|
431 | assert_include "#{issue.id},#{issue.subject},7.33", lines | |
432 | end |
|
432 | end | |
433 |
|
433 | |||
434 | def test_index_csv_with_all_columns |
|
434 | def test_index_csv_with_all_columns | |
435 | get :index, :format => 'csv', :columns => 'all' |
|
435 | get :index, :format => 'csv', :columns => 'all' | |
436 | assert_response :success |
|
436 | assert_response :success | |
437 | assert_not_nil assigns(:issues) |
|
437 | assert_not_nil assigns(:issues) | |
438 | assert_equal 'text/csv; header=present', @response.content_type |
|
438 | assert_equal 'text/csv; header=present', @response.content_type | |
439 | assert_match /\A#,/, response.body |
|
439 | assert_match /\A#,/, response.body | |
440 | lines = response.body.chomp.split("\n") |
|
440 | lines = response.body.chomp.split("\n") | |
441 | assert_equal assigns(:query).available_inline_columns.size, lines[0].split(',').size |
|
441 | assert_equal assigns(:query).available_inline_columns.size, lines[0].split(',').size | |
442 | end |
|
442 | end | |
443 |
|
443 | |||
444 | def test_index_csv_with_multi_column_field |
|
444 | def test_index_csv_with_multi_column_field | |
445 | CustomField.find(1).update_attribute :multiple, true |
|
445 | CustomField.find(1).update_attribute :multiple, true | |
446 | issue = Issue.find(1) |
|
446 | issue = Issue.find(1) | |
447 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
447 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} | |
448 | issue.save! |
|
448 | issue.save! | |
449 |
|
449 | |||
450 | get :index, :format => 'csv', :columns => 'all' |
|
450 | get :index, :format => 'csv', :columns => 'all' | |
451 | assert_response :success |
|
451 | assert_response :success | |
452 | lines = @response.body.chomp.split("\n") |
|
452 | lines = @response.body.chomp.split("\n") | |
453 | assert lines.detect {|line| line.include?('"MySQL, Oracle"')} |
|
453 | assert lines.detect {|line| line.include?('"MySQL, Oracle"')} | |
454 | end |
|
454 | end | |
455 |
|
455 | |||
456 | def test_index_csv_should_format_float_custom_fields_with_csv_decimal_separator |
|
456 | def test_index_csv_should_format_float_custom_fields_with_csv_decimal_separator | |
457 | field = IssueCustomField.create!(:name => 'Float', :is_for_all => true, :tracker_ids => [1], :field_format => 'float') |
|
457 | field = IssueCustomField.create!(:name => 'Float', :is_for_all => true, :tracker_ids => [1], :field_format => 'float') | |
458 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id => '185.6'}) |
|
458 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id => '185.6'}) | |
459 |
|
459 | |||
460 | with_settings :default_language => 'fr' do |
|
460 | with_settings :default_language => 'fr' do | |
461 | get :index, :format => 'csv', :columns => 'all' |
|
461 | get :index, :format => 'csv', :columns => 'all' | |
462 | assert_response :success |
|
462 | assert_response :success | |
463 | issue_line = response.body.chomp.split("\n").map {|line| line.split(';')}.detect {|line| line[0]==issue.id.to_s} |
|
463 | issue_line = response.body.chomp.split("\n").map {|line| line.split(';')}.detect {|line| line[0]==issue.id.to_s} | |
464 | assert_include '185,60', issue_line |
|
464 | assert_include '185,60', issue_line | |
465 | end |
|
465 | end | |
466 |
|
466 | |||
467 | with_settings :default_language => 'en' do |
|
467 | with_settings :default_language => 'en' do | |
468 | get :index, :format => 'csv', :columns => 'all' |
|
468 | get :index, :format => 'csv', :columns => 'all' | |
469 | assert_response :success |
|
469 | assert_response :success | |
470 | issue_line = response.body.chomp.split("\n").map {|line| line.split(',')}.detect {|line| line[0]==issue.id.to_s} |
|
470 | issue_line = response.body.chomp.split("\n").map {|line| line.split(',')}.detect {|line| line[0]==issue.id.to_s} | |
471 | assert_include '185.60', issue_line |
|
471 | assert_include '185.60', issue_line | |
472 | end |
|
472 | end | |
473 | end |
|
473 | end | |
474 |
|
474 | |||
475 | def test_index_csv_big_5 |
|
475 | def test_index_csv_big_5 | |
476 | with_settings :default_language => "zh-TW" do |
|
476 | with_settings :default_language => "zh-TW" do | |
477 | str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" |
|
477 | str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" | |
478 | str_big5 = "\xa4@\xa4\xeb" |
|
478 | str_big5 = "\xa4@\xa4\xeb" | |
479 | if str_utf8.respond_to?(:force_encoding) |
|
479 | if str_utf8.respond_to?(:force_encoding) | |
480 | str_utf8.force_encoding('UTF-8') |
|
480 | str_utf8.force_encoding('UTF-8') | |
481 | str_big5.force_encoding('Big5') |
|
481 | str_big5.force_encoding('Big5') | |
482 | end |
|
482 | end | |
483 | issue = Issue.generate!(:subject => str_utf8) |
|
483 | issue = Issue.generate!(:subject => str_utf8) | |
484 |
|
484 | |||
485 | get :index, :project_id => 1, |
|
485 | get :index, :project_id => 1, | |
486 | :f => ['subject'], |
|
486 | :f => ['subject'], | |
487 | :op => '=', :values => [str_utf8], |
|
487 | :op => '=', :values => [str_utf8], | |
488 | :format => 'csv' |
|
488 | :format => 'csv' | |
489 | assert_equal 'text/csv; header=present', @response.content_type |
|
489 | assert_equal 'text/csv; header=present', @response.content_type | |
490 | lines = @response.body.chomp.split("\n") |
|
490 | lines = @response.body.chomp.split("\n") | |
491 | s1 = "\xaa\xac\xbaA" |
|
491 | s1 = "\xaa\xac\xbaA" | |
492 | if str_utf8.respond_to?(:force_encoding) |
|
492 | if str_utf8.respond_to?(:force_encoding) | |
493 | s1.force_encoding('Big5') |
|
493 | s1.force_encoding('Big5') | |
494 | end |
|
494 | end | |
495 | assert_include s1, lines[0] |
|
495 | assert_include s1, lines[0] | |
496 | assert_include str_big5, lines[1] |
|
496 | assert_include str_big5, lines[1] | |
497 | end |
|
497 | end | |
498 | end |
|
498 | end | |
499 |
|
499 | |||
500 | def test_index_csv_cannot_convert_should_be_replaced_big_5 |
|
500 | def test_index_csv_cannot_convert_should_be_replaced_big_5 | |
501 | with_settings :default_language => "zh-TW" do |
|
501 | with_settings :default_language => "zh-TW" do | |
502 | str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85" |
|
502 | str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85" | |
503 | if str_utf8.respond_to?(:force_encoding) |
|
503 | if str_utf8.respond_to?(:force_encoding) | |
504 | str_utf8.force_encoding('UTF-8') |
|
504 | str_utf8.force_encoding('UTF-8') | |
505 | end |
|
505 | end | |
506 | issue = Issue.generate!(:subject => str_utf8) |
|
506 | issue = Issue.generate!(:subject => str_utf8) | |
507 |
|
507 | |||
508 | get :index, :project_id => 1, |
|
508 | get :index, :project_id => 1, | |
509 | :f => ['subject'], |
|
509 | :f => ['subject'], | |
510 | :op => '=', :values => [str_utf8], |
|
510 | :op => '=', :values => [str_utf8], | |
511 | :c => ['status', 'subject'], |
|
511 | :c => ['status', 'subject'], | |
512 | :format => 'csv', |
|
512 | :format => 'csv', | |
513 | :set_filter => 1 |
|
513 | :set_filter => 1 | |
514 | assert_equal 'text/csv; header=present', @response.content_type |
|
514 | assert_equal 'text/csv; header=present', @response.content_type | |
515 | lines = @response.body.chomp.split("\n") |
|
515 | lines = @response.body.chomp.split("\n") | |
516 | s1 = "\xaa\xac\xbaA" # status |
|
516 | s1 = "\xaa\xac\xbaA" # status | |
517 | if str_utf8.respond_to?(:force_encoding) |
|
517 | if str_utf8.respond_to?(:force_encoding) | |
518 | s1.force_encoding('Big5') |
|
518 | s1.force_encoding('Big5') | |
519 | end |
|
519 | end | |
520 | assert lines[0].include?(s1) |
|
520 | assert lines[0].include?(s1) | |
521 | s2 = lines[1].split(",")[2] |
|
521 | s2 = lines[1].split(",")[2] | |
522 | if s1.respond_to?(:force_encoding) |
|
522 | if s1.respond_to?(:force_encoding) | |
523 | s3 = "\xa5H?" # subject |
|
523 | s3 = "\xa5H?" # subject | |
524 | s3.force_encoding('Big5') |
|
524 | s3.force_encoding('Big5') | |
525 | assert_equal s3, s2 |
|
525 | assert_equal s3, s2 | |
526 | elsif RUBY_PLATFORM == 'java' |
|
526 | elsif RUBY_PLATFORM == 'java' | |
527 | assert_equal "??", s2 |
|
527 | assert_equal "??", s2 | |
528 | else |
|
528 | else | |
529 | assert_equal "\xa5H???", s2 |
|
529 | assert_equal "\xa5H???", s2 | |
530 | end |
|
530 | end | |
531 | end |
|
531 | end | |
532 | end |
|
532 | end | |
533 |
|
533 | |||
534 | def test_index_csv_tw |
|
534 | def test_index_csv_tw | |
535 | with_settings :default_language => "zh-TW" do |
|
535 | with_settings :default_language => "zh-TW" do | |
536 | str1 = "test_index_csv_tw" |
|
536 | str1 = "test_index_csv_tw" | |
537 | issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5') |
|
537 | issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5') | |
538 |
|
538 | |||
539 | get :index, :project_id => 1, |
|
539 | get :index, :project_id => 1, | |
540 | :f => ['subject'], |
|
540 | :f => ['subject'], | |
541 | :op => '=', :values => [str1], |
|
541 | :op => '=', :values => [str1], | |
542 | :c => ['estimated_hours', 'subject'], |
|
542 | :c => ['estimated_hours', 'subject'], | |
543 | :format => 'csv', |
|
543 | :format => 'csv', | |
544 | :set_filter => 1 |
|
544 | :set_filter => 1 | |
545 | assert_equal 'text/csv; header=present', @response.content_type |
|
545 | assert_equal 'text/csv; header=present', @response.content_type | |
546 | lines = @response.body.chomp.split("\n") |
|
546 | lines = @response.body.chomp.split("\n") | |
547 | assert_equal "#{issue.id},1234.50,#{str1}", lines[1] |
|
547 | assert_equal "#{issue.id},1234.50,#{str1}", lines[1] | |
548 | end |
|
548 | end | |
549 | end |
|
549 | end | |
550 |
|
550 | |||
551 | def test_index_csv_fr |
|
551 | def test_index_csv_fr | |
552 | with_settings :default_language => "fr" do |
|
552 | with_settings :default_language => "fr" do | |
553 | str1 = "test_index_csv_fr" |
|
553 | str1 = "test_index_csv_fr" | |
554 | issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5') |
|
554 | issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5') | |
555 |
|
555 | |||
556 | get :index, :project_id => 1, |
|
556 | get :index, :project_id => 1, | |
557 | :f => ['subject'], |
|
557 | :f => ['subject'], | |
558 | :op => '=', :values => [str1], |
|
558 | :op => '=', :values => [str1], | |
559 | :c => ['estimated_hours', 'subject'], |
|
559 | :c => ['estimated_hours', 'subject'], | |
560 | :format => 'csv', |
|
560 | :format => 'csv', | |
561 | :set_filter => 1 |
|
561 | :set_filter => 1 | |
562 | assert_equal 'text/csv; header=present', @response.content_type |
|
562 | assert_equal 'text/csv; header=present', @response.content_type | |
563 | lines = @response.body.chomp.split("\n") |
|
563 | lines = @response.body.chomp.split("\n") | |
564 | assert_equal "#{issue.id};1234,50;#{str1}", lines[1] |
|
564 | assert_equal "#{issue.id};1234,50;#{str1}", lines[1] | |
565 | end |
|
565 | end | |
566 | end |
|
566 | end | |
567 |
|
567 | |||
568 | def test_index_pdf |
|
568 | def test_index_pdf | |
569 | ["en", "zh", "zh-TW", "ja", "ko"].each do |lang| |
|
569 | ["en", "zh", "zh-TW", "ja", "ko"].each do |lang| | |
570 | with_settings :default_language => lang do |
|
570 | with_settings :default_language => lang do | |
571 |
|
571 | |||
572 | get :index |
|
572 | get :index | |
573 | assert_response :success |
|
573 | assert_response :success | |
574 | assert_template 'index' |
|
574 | assert_template 'index' | |
575 |
|
575 | |||
576 | get :index, :format => 'pdf' |
|
576 | get :index, :format => 'pdf' | |
577 | assert_response :success |
|
577 | assert_response :success | |
578 | assert_not_nil assigns(:issues) |
|
578 | assert_not_nil assigns(:issues) | |
579 | assert_equal 'application/pdf', @response.content_type |
|
579 | assert_equal 'application/pdf', @response.content_type | |
580 |
|
580 | |||
581 | get :index, :project_id => 1, :format => 'pdf' |
|
581 | get :index, :project_id => 1, :format => 'pdf' | |
582 | assert_response :success |
|
582 | assert_response :success | |
583 | assert_not_nil assigns(:issues) |
|
583 | assert_not_nil assigns(:issues) | |
584 | assert_equal 'application/pdf', @response.content_type |
|
584 | assert_equal 'application/pdf', @response.content_type | |
585 |
|
585 | |||
586 | get :index, :project_id => 1, :query_id => 6, :format => 'pdf' |
|
586 | get :index, :project_id => 1, :query_id => 6, :format => 'pdf' | |
587 | assert_response :success |
|
587 | assert_response :success | |
588 | assert_not_nil assigns(:issues) |
|
588 | assert_not_nil assigns(:issues) | |
589 | assert_equal 'application/pdf', @response.content_type |
|
589 | assert_equal 'application/pdf', @response.content_type | |
590 | end |
|
590 | end | |
591 | end |
|
591 | end | |
592 | end |
|
592 | end | |
593 |
|
593 | |||
594 | def test_index_pdf_with_query_grouped_by_list_custom_field |
|
594 | def test_index_pdf_with_query_grouped_by_list_custom_field | |
595 | get :index, :project_id => 1, :query_id => 9, :format => 'pdf' |
|
595 | get :index, :project_id => 1, :query_id => 9, :format => 'pdf' | |
596 | assert_response :success |
|
596 | assert_response :success | |
597 | assert_not_nil assigns(:issues) |
|
597 | assert_not_nil assigns(:issues) | |
598 | assert_not_nil assigns(:issue_count_by_group) |
|
598 | assert_not_nil assigns(:issue_count_by_group) | |
599 | assert_equal 'application/pdf', @response.content_type |
|
599 | assert_equal 'application/pdf', @response.content_type | |
600 | end |
|
600 | end | |
601 |
|
601 | |||
602 | def test_index_atom |
|
602 | def test_index_atom | |
603 | get :index, :project_id => 'ecookbook', :format => 'atom' |
|
603 | get :index, :project_id => 'ecookbook', :format => 'atom' | |
604 | assert_response :success |
|
604 | assert_response :success | |
605 | assert_template 'common/feed' |
|
605 | assert_template 'common/feed' | |
606 | assert_equal 'application/atom+xml', response.content_type |
|
606 | assert_equal 'application/atom+xml', response.content_type | |
607 |
|
607 | |||
608 | assert_select 'feed' do |
|
608 | assert_select 'feed' do | |
609 | assert_select 'link[rel=self][href=?]', 'http://test.host/projects/ecookbook/issues.atom' |
|
609 | assert_select 'link[rel=self][href=?]', 'http://test.host/projects/ecookbook/issues.atom' | |
610 | assert_select 'link[rel=alternate][href=?]', 'http://test.host/projects/ecookbook/issues' |
|
610 | assert_select 'link[rel=alternate][href=?]', 'http://test.host/projects/ecookbook/issues' | |
611 | assert_select 'entry link[href=?]', 'http://test.host/issues/1' |
|
611 | assert_select 'entry link[href=?]', 'http://test.host/issues/1' | |
612 | end |
|
612 | end | |
613 | end |
|
613 | end | |
614 |
|
614 | |||
615 | def test_index_sort |
|
615 | def test_index_sort | |
616 | get :index, :sort => 'tracker,id:desc' |
|
616 | get :index, :sort => 'tracker,id:desc' | |
617 | assert_response :success |
|
617 | assert_response :success | |
618 |
|
618 | |||
619 | sort_params = @request.session['issues_index_sort'] |
|
619 | sort_params = @request.session['issues_index_sort'] | |
620 | assert sort_params.is_a?(String) |
|
620 | assert sort_params.is_a?(String) | |
621 | assert_equal 'tracker,id:desc', sort_params |
|
621 | assert_equal 'tracker,id:desc', sort_params | |
622 |
|
622 | |||
623 | issues = assigns(:issues) |
|
623 | issues = assigns(:issues) | |
624 | assert_not_nil issues |
|
624 | assert_not_nil issues | |
625 | assert !issues.empty? |
|
625 | assert !issues.empty? | |
626 | assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id) |
|
626 | assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id) | |
627 | end |
|
627 | end | |
628 |
|
628 | |||
629 | def test_index_sort_by_field_not_included_in_columns |
|
629 | def test_index_sort_by_field_not_included_in_columns | |
630 | Setting.issue_list_default_columns = %w(subject author) |
|
630 | Setting.issue_list_default_columns = %w(subject author) | |
631 | get :index, :sort => 'tracker' |
|
631 | get :index, :sort => 'tracker' | |
632 | end |
|
632 | end | |
633 |
|
633 | |||
634 | def test_index_sort_by_assigned_to |
|
634 | def test_index_sort_by_assigned_to | |
635 | get :index, :sort => 'assigned_to' |
|
635 | get :index, :sort => 'assigned_to' | |
636 | assert_response :success |
|
636 | assert_response :success | |
637 | assignees = assigns(:issues).collect(&:assigned_to).compact |
|
637 | assignees = assigns(:issues).collect(&:assigned_to).compact | |
638 | assert_equal assignees.sort, assignees |
|
638 | assert_equal assignees.sort, assignees | |
639 | end |
|
639 | end | |
640 |
|
640 | |||
641 | def test_index_sort_by_assigned_to_desc |
|
641 | def test_index_sort_by_assigned_to_desc | |
642 | get :index, :sort => 'assigned_to:desc' |
|
642 | get :index, :sort => 'assigned_to:desc' | |
643 | assert_response :success |
|
643 | assert_response :success | |
644 | assignees = assigns(:issues).collect(&:assigned_to).compact |
|
644 | assignees = assigns(:issues).collect(&:assigned_to).compact | |
645 | assert_equal assignees.sort.reverse, assignees |
|
645 | assert_equal assignees.sort.reverse, assignees | |
646 | end |
|
646 | end | |
647 |
|
647 | |||
648 | def test_index_group_by_assigned_to |
|
648 | def test_index_group_by_assigned_to | |
649 | get :index, :group_by => 'assigned_to', :sort => 'priority' |
|
649 | get :index, :group_by => 'assigned_to', :sort => 'priority' | |
650 | assert_response :success |
|
650 | assert_response :success | |
651 | end |
|
651 | end | |
652 |
|
652 | |||
653 | def test_index_sort_by_author |
|
653 | def test_index_sort_by_author | |
654 | get :index, :sort => 'author' |
|
654 | get :index, :sort => 'author' | |
655 | assert_response :success |
|
655 | assert_response :success | |
656 | authors = assigns(:issues).collect(&:author) |
|
656 | authors = assigns(:issues).collect(&:author) | |
657 | assert_equal authors.sort, authors |
|
657 | assert_equal authors.sort, authors | |
658 | end |
|
658 | end | |
659 |
|
659 | |||
660 | def test_index_sort_by_author_desc |
|
660 | def test_index_sort_by_author_desc | |
661 | get :index, :sort => 'author:desc' |
|
661 | get :index, :sort => 'author:desc' | |
662 | assert_response :success |
|
662 | assert_response :success | |
663 | authors = assigns(:issues).collect(&:author) |
|
663 | authors = assigns(:issues).collect(&:author) | |
664 | assert_equal authors.sort.reverse, authors |
|
664 | assert_equal authors.sort.reverse, authors | |
665 | end |
|
665 | end | |
666 |
|
666 | |||
667 | def test_index_group_by_author |
|
667 | def test_index_group_by_author | |
668 | get :index, :group_by => 'author', :sort => 'priority' |
|
668 | get :index, :group_by => 'author', :sort => 'priority' | |
669 | assert_response :success |
|
669 | assert_response :success | |
670 | end |
|
670 | end | |
671 |
|
671 | |||
672 | def test_index_sort_by_spent_hours |
|
672 | def test_index_sort_by_spent_hours | |
673 | get :index, :sort => 'spent_hours:desc' |
|
673 | get :index, :sort => 'spent_hours:desc' | |
674 | assert_response :success |
|
674 | assert_response :success | |
675 | hours = assigns(:issues).collect(&:spent_hours) |
|
675 | hours = assigns(:issues).collect(&:spent_hours) | |
676 | assert_equal hours.sort.reverse, hours |
|
676 | assert_equal hours.sort.reverse, hours | |
677 | end |
|
677 | end | |
678 |
|
678 | |||
679 | def test_index_sort_by_user_custom_field |
|
679 | def test_index_sort_by_user_custom_field | |
680 | cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user') |
|
680 | cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user') | |
681 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2') |
|
681 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2') | |
682 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3') |
|
682 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3') | |
683 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3') |
|
683 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3') | |
684 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '') |
|
684 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '') | |
685 |
|
685 | |||
686 | get :index, :project_id => 1, :set_filter => 1, :sort => "cf_#{cf.id},id" |
|
686 | get :index, :project_id => 1, :set_filter => 1, :sort => "cf_#{cf.id},id" | |
687 | assert_response :success |
|
687 | assert_response :success | |
688 |
|
688 | |||
689 | assert_equal [2, 3, 1], assigns(:issues).select {|issue| issue.custom_field_value(cf).present?}.map(&:id) |
|
689 | assert_equal [2, 3, 1], assigns(:issues).select {|issue| issue.custom_field_value(cf).present?}.map(&:id) | |
690 | end |
|
690 | end | |
691 |
|
691 | |||
692 | def test_index_with_columns |
|
692 | def test_index_with_columns | |
693 | columns = ['tracker', 'subject', 'assigned_to'] |
|
693 | columns = ['tracker', 'subject', 'assigned_to'] | |
694 | get :index, :set_filter => 1, :c => columns |
|
694 | get :index, :set_filter => 1, :c => columns | |
695 | assert_response :success |
|
695 | assert_response :success | |
696 |
|
696 | |||
697 | # query should use specified columns |
|
697 | # query should use specified columns | |
698 | query = assigns(:query) |
|
698 | query = assigns(:query) | |
699 | assert_kind_of IssueQuery, query |
|
699 | assert_kind_of IssueQuery, query | |
700 | assert_equal columns, query.column_names.map(&:to_s) |
|
700 | assert_equal columns, query.column_names.map(&:to_s) | |
701 |
|
701 | |||
702 | # columns should be stored in session |
|
702 | # columns should be stored in session | |
703 | assert_kind_of Hash, session[:query] |
|
703 | assert_kind_of Hash, session[:query] | |
704 | assert_kind_of Array, session[:query][:column_names] |
|
704 | assert_kind_of Array, session[:query][:column_names] | |
705 | assert_equal columns, session[:query][:column_names].map(&:to_s) |
|
705 | assert_equal columns, session[:query][:column_names].map(&:to_s) | |
706 |
|
706 | |||
707 | # ensure only these columns are kept in the selected columns list |
|
707 | # ensure only these columns are kept in the selected columns list | |
708 | assert_select 'select#selected_columns option' do |
|
708 | assert_select 'select#selected_columns option' do | |
709 | assert_select 'option', 3 |
|
709 | assert_select 'option', 3 | |
710 | assert_select 'option[value=tracker]' |
|
710 | assert_select 'option[value=tracker]' | |
711 | assert_select 'option[value=project]', 0 |
|
711 | assert_select 'option[value=project]', 0 | |
712 | end |
|
712 | end | |
713 | end |
|
713 | end | |
714 |
|
714 | |||
715 | def test_index_without_project_should_implicitly_add_project_column_to_default_columns |
|
715 | def test_index_without_project_should_implicitly_add_project_column_to_default_columns | |
716 | Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] |
|
716 | Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] | |
717 | get :index, :set_filter => 1 |
|
717 | get :index, :set_filter => 1 | |
718 |
|
718 | |||
719 | # query should use specified columns |
|
719 | # query should use specified columns | |
720 | query = assigns(:query) |
|
720 | query = assigns(:query) | |
721 | assert_kind_of IssueQuery, query |
|
721 | assert_kind_of IssueQuery, query | |
722 | assert_equal [:id, :project, :tracker, :subject, :assigned_to], query.columns.map(&:name) |
|
722 | assert_equal [:id, :project, :tracker, :subject, :assigned_to], query.columns.map(&:name) | |
723 | end |
|
723 | end | |
724 |
|
724 | |||
725 | def test_index_without_project_and_explicit_default_columns_should_not_add_project_column |
|
725 | def test_index_without_project_and_explicit_default_columns_should_not_add_project_column | |
726 | Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] |
|
726 | Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] | |
727 | columns = ['id', 'tracker', 'subject', 'assigned_to'] |
|
727 | columns = ['id', 'tracker', 'subject', 'assigned_to'] | |
728 | get :index, :set_filter => 1, :c => columns |
|
728 | get :index, :set_filter => 1, :c => columns | |
729 |
|
729 | |||
730 | # query should use specified columns |
|
730 | # query should use specified columns | |
731 | query = assigns(:query) |
|
731 | query = assigns(:query) | |
732 | assert_kind_of IssueQuery, query |
|
732 | assert_kind_of IssueQuery, query | |
733 | assert_equal columns.map(&:to_sym), query.columns.map(&:name) |
|
733 | assert_equal columns.map(&:to_sym), query.columns.map(&:name) | |
734 | end |
|
734 | end | |
735 |
|
735 | |||
736 | def test_index_with_custom_field_column |
|
736 | def test_index_with_custom_field_column | |
737 | columns = %w(tracker subject cf_2) |
|
737 | columns = %w(tracker subject cf_2) | |
738 | get :index, :set_filter => 1, :c => columns |
|
738 | get :index, :set_filter => 1, :c => columns | |
739 | assert_response :success |
|
739 | assert_response :success | |
740 |
|
740 | |||
741 | # query should use specified columns |
|
741 | # query should use specified columns | |
742 | query = assigns(:query) |
|
742 | query = assigns(:query) | |
743 | assert_kind_of IssueQuery, query |
|
743 | assert_kind_of IssueQuery, query | |
744 | assert_equal columns, query.column_names.map(&:to_s) |
|
744 | assert_equal columns, query.column_names.map(&:to_s) | |
745 |
|
745 | |||
746 | assert_select 'table.issues td.cf_2.string' |
|
746 | assert_select 'table.issues td.cf_2.string' | |
747 | end |
|
747 | end | |
748 |
|
748 | |||
749 | def test_index_with_multi_custom_field_column |
|
749 | def test_index_with_multi_custom_field_column | |
750 | field = CustomField.find(1) |
|
750 | field = CustomField.find(1) | |
751 | field.update_attribute :multiple, true |
|
751 | field.update_attribute :multiple, true | |
752 | issue = Issue.find(1) |
|
752 | issue = Issue.find(1) | |
753 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
753 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} | |
754 | issue.save! |
|
754 | issue.save! | |
755 |
|
755 | |||
756 | get :index, :set_filter => 1, :c => %w(tracker subject cf_1) |
|
756 | get :index, :set_filter => 1, :c => %w(tracker subject cf_1) | |
757 | assert_response :success |
|
757 | assert_response :success | |
758 |
|
758 | |||
759 | assert_select 'table.issues td.cf_1', :text => 'MySQL, Oracle' |
|
759 | assert_select 'table.issues td.cf_1', :text => 'MySQL, Oracle' | |
760 | end |
|
760 | end | |
761 |
|
761 | |||
762 | def test_index_with_multi_user_custom_field_column |
|
762 | def test_index_with_multi_user_custom_field_column | |
763 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, |
|
763 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, | |
764 | :tracker_ids => [1], :is_for_all => true) |
|
764 | :tracker_ids => [1], :is_for_all => true) | |
765 | issue = Issue.find(1) |
|
765 | issue = Issue.find(1) | |
766 | issue.custom_field_values = {field.id => ['2', '3']} |
|
766 | issue.custom_field_values = {field.id => ['2', '3']} | |
767 | issue.save! |
|
767 | issue.save! | |
768 |
|
768 | |||
769 | get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"] |
|
769 | get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"] | |
770 | assert_response :success |
|
770 | assert_response :success | |
771 |
|
771 | |||
772 | assert_select "table.issues td.cf_#{field.id}" do |
|
772 | assert_select "table.issues td.cf_#{field.id}" do | |
773 | assert_select 'a', 2 |
|
773 | assert_select 'a', 2 | |
774 | assert_select 'a[href=?]', '/users/2', :text => 'John Smith' |
|
774 | assert_select 'a[href=?]', '/users/2', :text => 'John Smith' | |
775 | assert_select 'a[href=?]', '/users/3', :text => 'Dave Lopper' |
|
775 | assert_select 'a[href=?]', '/users/3', :text => 'Dave Lopper' | |
776 | end |
|
776 | end | |
777 | end |
|
777 | end | |
778 |
|
778 | |||
779 | def test_index_with_date_column |
|
779 | def test_index_with_date_column | |
780 | with_settings :date_format => '%d/%m/%Y' do |
|
780 | with_settings :date_format => '%d/%m/%Y' do | |
781 | Issue.find(1).update_attribute :start_date, '1987-08-24' |
|
781 | Issue.find(1).update_attribute :start_date, '1987-08-24' | |
782 | get :index, :set_filter => 1, :c => %w(start_date) |
|
782 | get :index, :set_filter => 1, :c => %w(start_date) | |
783 | assert_select "table.issues td.start_date", :text => '24/08/1987' |
|
783 | assert_select "table.issues td.start_date", :text => '24/08/1987' | |
784 | end |
|
784 | end | |
785 | end |
|
785 | end | |
786 |
|
786 | |||
787 | def test_index_with_done_ratio_column |
|
787 | def test_index_with_done_ratio_column | |
788 | Issue.find(1).update_attribute :done_ratio, 40 |
|
788 | Issue.find(1).update_attribute :done_ratio, 40 | |
789 | get :index, :set_filter => 1, :c => %w(done_ratio) |
|
789 | get :index, :set_filter => 1, :c => %w(done_ratio) | |
790 | assert_select 'table.issues td.done_ratio' do |
|
790 | assert_select 'table.issues td.done_ratio' do | |
791 | assert_select 'table.progress' do |
|
791 | assert_select 'table.progress' do | |
792 | assert_select 'td.closed[style=?]', 'width: 40%;' |
|
792 | assert_select 'td.closed[style=?]', 'width: 40%;' | |
793 | end |
|
793 | end | |
794 | end |
|
794 | end | |
795 | end |
|
795 | end | |
796 |
|
796 | |||
797 | def test_index_with_spent_hours_column |
|
797 | def test_index_with_spent_hours_column | |
798 | get :index, :set_filter => 1, :c => %w(subject spent_hours) |
|
798 | get :index, :set_filter => 1, :c => %w(subject spent_hours) | |
799 | assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00' |
|
799 | assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00' | |
800 | end |
|
800 | end | |
801 |
|
801 | |||
802 | def test_index_should_not_show_spent_hours_column_without_permission |
|
802 | def test_index_should_not_show_spent_hours_column_without_permission | |
803 | Role.anonymous.remove_permission! :view_time_entries |
|
803 | Role.anonymous.remove_permission! :view_time_entries | |
804 | get :index, :set_filter => 1, :c => %w(subject spent_hours) |
|
804 | get :index, :set_filter => 1, :c => %w(subject spent_hours) | |
805 | assert_select 'td.spent_hours', 0 |
|
805 | assert_select 'td.spent_hours', 0 | |
806 | end |
|
806 | end | |
807 |
|
807 | |||
808 | def test_index_with_fixed_version_column |
|
808 | def test_index_with_fixed_version_column | |
809 | get :index, :set_filter => 1, :c => %w(fixed_version) |
|
809 | get :index, :set_filter => 1, :c => %w(fixed_version) | |
810 | assert_select 'table.issues td.fixed_version' do |
|
810 | assert_select 'table.issues td.fixed_version' do | |
811 | assert_select 'a[href=?]', '/versions/2', :text => '1.0' |
|
811 | assert_select 'a[href=?]', '/versions/2', :text => '1.0' | |
812 | end |
|
812 | end | |
813 | end |
|
813 | end | |
814 |
|
814 | |||
815 | def test_index_with_relations_column |
|
815 | def test_index_with_relations_column | |
816 | IssueRelation.delete_all |
|
816 | IssueRelation.delete_all | |
817 | IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(1), :issue_to => Issue.find(7)) |
|
817 | IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(1), :issue_to => Issue.find(7)) | |
818 | IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(8), :issue_to => Issue.find(1)) |
|
818 | IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(8), :issue_to => Issue.find(1)) | |
819 | IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(1), :issue_to => Issue.find(11)) |
|
819 | IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(1), :issue_to => Issue.find(11)) | |
820 | IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(12), :issue_to => Issue.find(2)) |
|
820 | IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(12), :issue_to => Issue.find(2)) | |
821 |
|
821 | |||
822 | get :index, :set_filter => 1, :c => %w(subject relations) |
|
822 | get :index, :set_filter => 1, :c => %w(subject relations) | |
823 | assert_response :success |
|
823 | assert_response :success | |
824 | assert_select "tr#issue-1 td.relations" do |
|
824 | assert_select "tr#issue-1 td.relations" do | |
825 | assert_select "span", 3 |
|
825 | assert_select "span", 3 | |
826 | assert_select "span", :text => "Related to #7" |
|
826 | assert_select "span", :text => "Related to #7" | |
827 | assert_select "span", :text => "Related to #8" |
|
827 | assert_select "span", :text => "Related to #8" | |
828 | assert_select "span", :text => "Blocks #11" |
|
828 | assert_select "span", :text => "Blocks #11" | |
829 | end |
|
829 | end | |
830 | assert_select "tr#issue-2 td.relations" do |
|
830 | assert_select "tr#issue-2 td.relations" do | |
831 | assert_select "span", 1 |
|
831 | assert_select "span", 1 | |
832 | assert_select "span", :text => "Blocked by #12" |
|
832 | assert_select "span", :text => "Blocked by #12" | |
833 | end |
|
833 | end | |
834 | assert_select "tr#issue-3 td.relations" do |
|
834 | assert_select "tr#issue-3 td.relations" do | |
835 | assert_select "span", 0 |
|
835 | assert_select "span", 0 | |
836 | end |
|
836 | end | |
837 |
|
837 | |||
838 | get :index, :set_filter => 1, :c => %w(relations), :format => 'csv' |
|
838 | get :index, :set_filter => 1, :c => %w(relations), :format => 'csv' | |
839 | assert_response :success |
|
839 | assert_response :success | |
840 | assert_equal 'text/csv; header=present', response.content_type |
|
840 | assert_equal 'text/csv; header=present', response.content_type | |
841 | lines = response.body.chomp.split("\n") |
|
841 | lines = response.body.chomp.split("\n") | |
842 | assert_include '1,"Related to #7, Related to #8, Blocks #11"', lines |
|
842 | assert_include '1,"Related to #7, Related to #8, Blocks #11"', lines | |
843 | assert_include '2,Blocked by #12', lines |
|
843 | assert_include '2,Blocked by #12', lines | |
844 | assert_include '3,""', lines |
|
844 | assert_include '3,""', lines | |
845 |
|
845 | |||
846 | get :index, :set_filter => 1, :c => %w(subject relations), :format => 'pdf' |
|
846 | get :index, :set_filter => 1, :c => %w(subject relations), :format => 'pdf' | |
847 | assert_response :success |
|
847 | assert_response :success | |
848 | assert_equal 'application/pdf', response.content_type |
|
848 | assert_equal 'application/pdf', response.content_type | |
849 | end |
|
849 | end | |
850 |
|
850 | |||
851 | def test_index_with_description_column |
|
851 | def test_index_with_description_column | |
852 | get :index, :set_filter => 1, :c => %w(subject description) |
|
852 | get :index, :set_filter => 1, :c => %w(subject description) | |
853 |
|
853 | |||
854 | assert_select 'table.issues thead th', 3 # columns: chekbox + id + subject |
|
854 | assert_select 'table.issues thead th', 3 # columns: chekbox + id + subject | |
855 | assert_select 'td.description[colspan=3]', :text => 'Unable to print recipes' |
|
855 | assert_select 'td.description[colspan=3]', :text => 'Unable to print recipes' | |
856 |
|
856 | |||
857 | get :index, :set_filter => 1, :c => %w(subject description), :format => 'pdf' |
|
857 | get :index, :set_filter => 1, :c => %w(subject description), :format => 'pdf' | |
858 | assert_response :success |
|
858 | assert_response :success | |
859 | assert_equal 'application/pdf', response.content_type |
|
859 | assert_equal 'application/pdf', response.content_type | |
860 | end |
|
860 | end | |
861 |
|
861 | |||
862 | def test_index_send_html_if_query_is_invalid |
|
862 | def test_index_send_html_if_query_is_invalid | |
863 | get :index, :f => ['start_date'], :op => {:start_date => '='} |
|
863 | get :index, :f => ['start_date'], :op => {:start_date => '='} | |
864 | assert_equal 'text/html', @response.content_type |
|
864 | assert_equal 'text/html', @response.content_type | |
865 | assert_template 'index' |
|
865 | assert_template 'index' | |
866 | end |
|
866 | end | |
867 |
|
867 | |||
868 | def test_index_send_nothing_if_query_is_invalid |
|
868 | def test_index_send_nothing_if_query_is_invalid | |
869 | get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv' |
|
869 | get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv' | |
870 | assert_equal 'text/csv', @response.content_type |
|
870 | assert_equal 'text/csv', @response.content_type | |
871 | assert @response.body.blank? |
|
871 | assert @response.body.blank? | |
872 | end |
|
872 | end | |
873 |
|
873 | |||
874 | def test_show_by_anonymous |
|
874 | def test_show_by_anonymous | |
875 | get :show, :id => 1 |
|
875 | get :show, :id => 1 | |
876 | assert_response :success |
|
876 | assert_response :success | |
877 | assert_template 'show' |
|
877 | assert_template 'show' | |
878 | assert_equal Issue.find(1), assigns(:issue) |
|
878 | assert_equal Issue.find(1), assigns(:issue) | |
879 | assert_select 'div.issue div.description', :text => /Unable to print recipes/ |
|
879 | assert_select 'div.issue div.description', :text => /Unable to print recipes/ | |
880 | # anonymous role is allowed to add a note |
|
880 | # anonymous role is allowed to add a note | |
881 | assert_select 'form#issue-form' do |
|
881 | assert_select 'form#issue-form' do | |
882 | assert_select 'fieldset' do |
|
882 | assert_select 'fieldset' do | |
883 | assert_select 'legend', :text => 'Notes' |
|
883 | assert_select 'legend', :text => 'Notes' | |
884 | assert_select 'textarea[name=?]', 'issue[notes]' |
|
884 | assert_select 'textarea[name=?]', 'issue[notes]' | |
885 | end |
|
885 | end | |
886 | end |
|
886 | end | |
887 | assert_select 'title', :text => "Bug #1: #{ESCAPED_UCANT} print recipes - eCookbook - Redmine" |
|
887 | assert_select 'title', :text => "Bug #1: #{ESCAPED_UCANT} print recipes - eCookbook - Redmine" | |
888 | end |
|
888 | end | |
889 |
|
889 | |||
890 | def test_show_by_manager |
|
890 | def test_show_by_manager | |
891 | @request.session[:user_id] = 2 |
|
891 | @request.session[:user_id] = 2 | |
892 | get :show, :id => 1 |
|
892 | get :show, :id => 1 | |
893 | assert_response :success |
|
893 | assert_response :success | |
894 | assert_select 'a', :text => /Quote/ |
|
894 | assert_select 'a', :text => /Quote/ | |
895 | assert_select 'form#issue-form' do |
|
895 | assert_select 'form#issue-form' do | |
896 | assert_select 'fieldset' do |
|
896 | assert_select 'fieldset' do | |
897 | assert_select 'legend', :text => 'Change properties' |
|
897 | assert_select 'legend', :text => 'Change properties' | |
898 | assert_select 'input[name=?]', 'issue[subject]' |
|
898 | assert_select 'input[name=?]', 'issue[subject]' | |
899 | end |
|
899 | end | |
900 | assert_select 'fieldset' do |
|
900 | assert_select 'fieldset' do | |
901 | assert_select 'legend', :text => 'Log time' |
|
901 | assert_select 'legend', :text => 'Log time' | |
902 | assert_select 'input[name=?]', 'time_entry[hours]' |
|
902 | assert_select 'input[name=?]', 'time_entry[hours]' | |
903 | end |
|
903 | end | |
904 | assert_select 'fieldset' do |
|
904 | assert_select 'fieldset' do | |
905 | assert_select 'legend', :text => 'Notes' |
|
905 | assert_select 'legend', :text => 'Notes' | |
906 | assert_select 'textarea[name=?]', 'issue[notes]' |
|
906 | assert_select 'textarea[name=?]', 'issue[notes]' | |
907 | end |
|
907 | end | |
908 | end |
|
908 | end | |
909 | end |
|
909 | end | |
910 |
|
910 | |||
911 | def test_show_should_display_update_form |
|
911 | def test_show_should_display_update_form | |
912 | @request.session[:user_id] = 2 |
|
912 | @request.session[:user_id] = 2 | |
913 | get :show, :id => 1 |
|
913 | get :show, :id => 1 | |
914 | assert_response :success |
|
914 | assert_response :success | |
915 |
|
915 | |||
916 | assert_select 'form#issue-form' do |
|
916 | assert_select 'form#issue-form' do | |
917 | assert_select 'input[name=?]', 'issue[is_private]' |
|
917 | assert_select 'input[name=?]', 'issue[is_private]' | |
918 | assert_select 'select[name=?]', 'issue[project_id]' |
|
918 | assert_select 'select[name=?]', 'issue[project_id]' | |
919 | assert_select 'select[name=?]', 'issue[tracker_id]' |
|
919 | assert_select 'select[name=?]', 'issue[tracker_id]' | |
920 | assert_select 'input[name=?]', 'issue[subject]' |
|
920 | assert_select 'input[name=?]', 'issue[subject]' | |
921 | assert_select 'textarea[name=?]', 'issue[description]' |
|
921 | assert_select 'textarea[name=?]', 'issue[description]' | |
922 | assert_select 'select[name=?]', 'issue[status_id]' |
|
922 | assert_select 'select[name=?]', 'issue[status_id]' | |
923 | assert_select 'select[name=?]', 'issue[priority_id]' |
|
923 | assert_select 'select[name=?]', 'issue[priority_id]' | |
924 | assert_select 'select[name=?]', 'issue[assigned_to_id]' |
|
924 | assert_select 'select[name=?]', 'issue[assigned_to_id]' | |
925 | assert_select 'select[name=?]', 'issue[category_id]' |
|
925 | assert_select 'select[name=?]', 'issue[category_id]' | |
926 | assert_select 'select[name=?]', 'issue[fixed_version_id]' |
|
926 | assert_select 'select[name=?]', 'issue[fixed_version_id]' | |
927 | assert_select 'input[name=?]', 'issue[parent_issue_id]' |
|
927 | assert_select 'input[name=?]', 'issue[parent_issue_id]' | |
928 | assert_select 'input[name=?]', 'issue[start_date]' |
|
928 | assert_select 'input[name=?]', 'issue[start_date]' | |
929 | assert_select 'input[name=?]', 'issue[due_date]' |
|
929 | assert_select 'input[name=?]', 'issue[due_date]' | |
930 | assert_select 'select[name=?]', 'issue[done_ratio]' |
|
930 | assert_select 'select[name=?]', 'issue[done_ratio]' | |
931 | assert_select 'input[name=?]', 'issue[custom_field_values][2]' |
|
931 | assert_select 'input[name=?]', 'issue[custom_field_values][2]' | |
932 | assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0 |
|
932 | assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0 | |
933 | assert_select 'textarea[name=?]', 'issue[notes]' |
|
933 | assert_select 'textarea[name=?]', 'issue[notes]' | |
934 | end |
|
934 | end | |
935 | end |
|
935 | end | |
936 |
|
936 | |||
937 | def test_show_should_display_update_form_with_minimal_permissions |
|
937 | def test_show_should_display_update_form_with_minimal_permissions | |
938 | Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] |
|
938 | Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] | |
939 | WorkflowTransition.delete_all :role_id => 1 |
|
939 | WorkflowTransition.delete_all :role_id => 1 | |
940 |
|
940 | |||
941 | @request.session[:user_id] = 2 |
|
941 | @request.session[:user_id] = 2 | |
942 | get :show, :id => 1 |
|
942 | get :show, :id => 1 | |
943 | assert_response :success |
|
943 | assert_response :success | |
944 |
|
944 | |||
945 | assert_select 'form#issue-form' do |
|
945 | assert_select 'form#issue-form' do | |
946 | assert_select 'input[name=?]', 'issue[is_private]', 0 |
|
946 | assert_select 'input[name=?]', 'issue[is_private]', 0 | |
947 | assert_select 'select[name=?]', 'issue[project_id]', 0 |
|
947 | assert_select 'select[name=?]', 'issue[project_id]', 0 | |
948 | assert_select 'select[name=?]', 'issue[tracker_id]', 0 |
|
948 | assert_select 'select[name=?]', 'issue[tracker_id]', 0 | |
949 | assert_select 'input[name=?]', 'issue[subject]', 0 |
|
949 | assert_select 'input[name=?]', 'issue[subject]', 0 | |
950 | assert_select 'textarea[name=?]', 'issue[description]', 0 |
|
950 | assert_select 'textarea[name=?]', 'issue[description]', 0 | |
951 | assert_select 'select[name=?]', 'issue[status_id]', 0 |
|
951 | assert_select 'select[name=?]', 'issue[status_id]', 0 | |
952 | assert_select 'select[name=?]', 'issue[priority_id]', 0 |
|
952 | assert_select 'select[name=?]', 'issue[priority_id]', 0 | |
953 | assert_select 'select[name=?]', 'issue[assigned_to_id]', 0 |
|
953 | assert_select 'select[name=?]', 'issue[assigned_to_id]', 0 | |
954 | assert_select 'select[name=?]', 'issue[category_id]', 0 |
|
954 | assert_select 'select[name=?]', 'issue[category_id]', 0 | |
955 | assert_select 'select[name=?]', 'issue[fixed_version_id]', 0 |
|
955 | assert_select 'select[name=?]', 'issue[fixed_version_id]', 0 | |
956 | assert_select 'input[name=?]', 'issue[parent_issue_id]', 0 |
|
956 | assert_select 'input[name=?]', 'issue[parent_issue_id]', 0 | |
957 | assert_select 'input[name=?]', 'issue[start_date]', 0 |
|
957 | assert_select 'input[name=?]', 'issue[start_date]', 0 | |
958 | assert_select 'input[name=?]', 'issue[due_date]', 0 |
|
958 | assert_select 'input[name=?]', 'issue[due_date]', 0 | |
959 | assert_select 'select[name=?]', 'issue[done_ratio]', 0 |
|
959 | assert_select 'select[name=?]', 'issue[done_ratio]', 0 | |
960 | assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0 |
|
960 | assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0 | |
961 | assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0 |
|
961 | assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0 | |
962 | assert_select 'textarea[name=?]', 'issue[notes]' |
|
962 | assert_select 'textarea[name=?]', 'issue[notes]' | |
963 | end |
|
963 | end | |
964 | end |
|
964 | end | |
965 |
|
965 | |||
966 | def test_show_should_display_update_form_with_workflow_permissions |
|
966 | def test_show_should_display_update_form_with_workflow_permissions | |
967 | Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] |
|
967 | Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] | |
968 |
|
968 | |||
969 | @request.session[:user_id] = 2 |
|
969 | @request.session[:user_id] = 2 | |
970 | get :show, :id => 1 |
|
970 | get :show, :id => 1 | |
971 | assert_response :success |
|
971 | assert_response :success | |
972 |
|
972 | |||
973 | assert_select 'form#issue-form' do |
|
973 | assert_select 'form#issue-form' do | |
974 | assert_select 'input[name=?]', 'issue[is_private]', 0 |
|
974 | assert_select 'input[name=?]', 'issue[is_private]', 0 | |
975 | assert_select 'select[name=?]', 'issue[project_id]', 0 |
|
975 | assert_select 'select[name=?]', 'issue[project_id]', 0 | |
976 | assert_select 'select[name=?]', 'issue[tracker_id]', 0 |
|
976 | assert_select 'select[name=?]', 'issue[tracker_id]', 0 | |
977 | assert_select 'input[name=?]', 'issue[subject]', 0 |
|
977 | assert_select 'input[name=?]', 'issue[subject]', 0 | |
978 | assert_select 'textarea[name=?]', 'issue[description]', 0 |
|
978 | assert_select 'textarea[name=?]', 'issue[description]', 0 | |
979 | assert_select 'select[name=?]', 'issue[status_id]' |
|
979 | assert_select 'select[name=?]', 'issue[status_id]' | |
980 | assert_select 'select[name=?]', 'issue[priority_id]', 0 |
|
980 | assert_select 'select[name=?]', 'issue[priority_id]', 0 | |
981 | assert_select 'select[name=?]', 'issue[assigned_to_id]' |
|
981 | assert_select 'select[name=?]', 'issue[assigned_to_id]' | |
982 | assert_select 'select[name=?]', 'issue[category_id]', 0 |
|
982 | assert_select 'select[name=?]', 'issue[category_id]', 0 | |
983 | assert_select 'select[name=?]', 'issue[fixed_version_id]' |
|
983 | assert_select 'select[name=?]', 'issue[fixed_version_id]' | |
984 | assert_select 'input[name=?]', 'issue[parent_issue_id]', 0 |
|
984 | assert_select 'input[name=?]', 'issue[parent_issue_id]', 0 | |
985 | assert_select 'input[name=?]', 'issue[start_date]', 0 |
|
985 | assert_select 'input[name=?]', 'issue[start_date]', 0 | |
986 | assert_select 'input[name=?]', 'issue[due_date]', 0 |
|
986 | assert_select 'input[name=?]', 'issue[due_date]', 0 | |
987 | assert_select 'select[name=?]', 'issue[done_ratio]' |
|
987 | assert_select 'select[name=?]', 'issue[done_ratio]' | |
988 | assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0 |
|
988 | assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0 | |
989 | assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0 |
|
989 | assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0 | |
990 | assert_select 'textarea[name=?]', 'issue[notes]' |
|
990 | assert_select 'textarea[name=?]', 'issue[notes]' | |
991 | end |
|
991 | end | |
992 | end |
|
992 | end | |
993 |
|
993 | |||
994 | def test_show_should_not_display_update_form_without_permissions |
|
994 | def test_show_should_not_display_update_form_without_permissions | |
995 | Role.find(1).update_attribute :permissions, [:view_issues] |
|
995 | Role.find(1).update_attribute :permissions, [:view_issues] | |
996 |
|
996 | |||
997 | @request.session[:user_id] = 2 |
|
997 | @request.session[:user_id] = 2 | |
998 | get :show, :id => 1 |
|
998 | get :show, :id => 1 | |
999 | assert_response :success |
|
999 | assert_response :success | |
1000 |
|
1000 | |||
1001 | assert_select 'form#issue-form', 0 |
|
1001 | assert_select 'form#issue-form', 0 | |
1002 | end |
|
1002 | end | |
1003 |
|
1003 | |||
1004 | def test_update_form_should_not_display_inactive_enumerations |
|
1004 | def test_update_form_should_not_display_inactive_enumerations | |
1005 | assert !IssuePriority.find(15).active? |
|
1005 | assert !IssuePriority.find(15).active? | |
1006 |
|
1006 | |||
1007 | @request.session[:user_id] = 2 |
|
1007 | @request.session[:user_id] = 2 | |
1008 | get :show, :id => 1 |
|
1008 | get :show, :id => 1 | |
1009 | assert_response :success |
|
1009 | assert_response :success | |
1010 |
|
1010 | |||
1011 | assert_select 'form#issue-form' do |
|
1011 | assert_select 'form#issue-form' do | |
1012 | assert_select 'select[name=?]', 'issue[priority_id]' do |
|
1012 | assert_select 'select[name=?]', 'issue[priority_id]' do | |
1013 | assert_select 'option[value=4]' |
|
1013 | assert_select 'option[value=4]' | |
1014 | assert_select 'option[value=15]', 0 |
|
1014 | assert_select 'option[value=15]', 0 | |
1015 | end |
|
1015 | end | |
1016 | end |
|
1016 | end | |
1017 | end |
|
1017 | end | |
1018 |
|
1018 | |||
1019 | def test_update_form_should_allow_attachment_upload |
|
1019 | def test_update_form_should_allow_attachment_upload | |
1020 | @request.session[:user_id] = 2 |
|
1020 | @request.session[:user_id] = 2 | |
1021 | get :show, :id => 1 |
|
1021 | get :show, :id => 1 | |
1022 |
|
1022 | |||
1023 | assert_select 'form#issue-form[method=post][enctype=multipart/form-data]' do |
|
1023 | assert_select 'form#issue-form[method=post][enctype=multipart/form-data]' do | |
1024 | assert_select 'input[type=file][name=?]', 'attachments[dummy][file]' |
|
1024 | assert_select 'input[type=file][name=?]', 'attachments[dummy][file]' | |
1025 | end |
|
1025 | end | |
1026 | end |
|
1026 | end | |
1027 |
|
1027 | |||
1028 | def test_show_should_deny_anonymous_access_without_permission |
|
1028 | def test_show_should_deny_anonymous_access_without_permission | |
1029 | Role.anonymous.remove_permission!(:view_issues) |
|
1029 | Role.anonymous.remove_permission!(:view_issues) | |
1030 | get :show, :id => 1 |
|
1030 | get :show, :id => 1 | |
1031 | assert_response :redirect |
|
1031 | assert_response :redirect | |
1032 | end |
|
1032 | end | |
1033 |
|
1033 | |||
1034 | def test_show_should_deny_anonymous_access_to_private_issue |
|
1034 | def test_show_should_deny_anonymous_access_to_private_issue | |
1035 | Issue.where(:id => 1).update_all(["is_private = ?", true]) |
|
1035 | Issue.where(:id => 1).update_all(["is_private = ?", true]) | |
1036 | get :show, :id => 1 |
|
1036 | get :show, :id => 1 | |
1037 | assert_response :redirect |
|
1037 | assert_response :redirect | |
1038 | end |
|
1038 | end | |
1039 |
|
1039 | |||
1040 | def test_show_should_deny_non_member_access_without_permission |
|
1040 | def test_show_should_deny_non_member_access_without_permission | |
1041 | Role.non_member.remove_permission!(:view_issues) |
|
1041 | Role.non_member.remove_permission!(:view_issues) | |
1042 | @request.session[:user_id] = 9 |
|
1042 | @request.session[:user_id] = 9 | |
1043 | get :show, :id => 1 |
|
1043 | get :show, :id => 1 | |
1044 | assert_response 403 |
|
1044 | assert_response 403 | |
1045 | end |
|
1045 | end | |
1046 |
|
1046 | |||
1047 | def test_show_should_deny_non_member_access_to_private_issue |
|
1047 | def test_show_should_deny_non_member_access_to_private_issue | |
1048 | Issue.where(:id => 1).update_all(["is_private = ?", true]) |
|
1048 | Issue.where(:id => 1).update_all(["is_private = ?", true]) | |
1049 | @request.session[:user_id] = 9 |
|
1049 | @request.session[:user_id] = 9 | |
1050 | get :show, :id => 1 |
|
1050 | get :show, :id => 1 | |
1051 | assert_response 403 |
|
1051 | assert_response 403 | |
1052 | end |
|
1052 | end | |
1053 |
|
1053 | |||
1054 | def test_show_should_deny_member_access_without_permission |
|
1054 | def test_show_should_deny_member_access_without_permission | |
1055 | Role.find(1).remove_permission!(:view_issues) |
|
1055 | Role.find(1).remove_permission!(:view_issues) | |
1056 | @request.session[:user_id] = 2 |
|
1056 | @request.session[:user_id] = 2 | |
1057 | get :show, :id => 1 |
|
1057 | get :show, :id => 1 | |
1058 | assert_response 403 |
|
1058 | assert_response 403 | |
1059 | end |
|
1059 | end | |
1060 |
|
1060 | |||
1061 | def test_show_should_deny_member_access_to_private_issue_without_permission |
|
1061 | def test_show_should_deny_member_access_to_private_issue_without_permission | |
1062 | Issue.where(:id => 1).update_all(["is_private = ?", true]) |
|
1062 | Issue.where(:id => 1).update_all(["is_private = ?", true]) | |
1063 | @request.session[:user_id] = 3 |
|
1063 | @request.session[:user_id] = 3 | |
1064 | get :show, :id => 1 |
|
1064 | get :show, :id => 1 | |
1065 | assert_response 403 |
|
1065 | assert_response 403 | |
1066 | end |
|
1066 | end | |
1067 |
|
1067 | |||
1068 | def test_show_should_allow_author_access_to_private_issue |
|
1068 | def test_show_should_allow_author_access_to_private_issue | |
1069 | Issue.where(:id => 1).update_all(["is_private = ?, author_id = 3", true]) |
|
1069 | Issue.where(:id => 1).update_all(["is_private = ?, author_id = 3", true]) | |
1070 | @request.session[:user_id] = 3 |
|
1070 | @request.session[:user_id] = 3 | |
1071 | get :show, :id => 1 |
|
1071 | get :show, :id => 1 | |
1072 | assert_response :success |
|
1072 | assert_response :success | |
1073 | end |
|
1073 | end | |
1074 |
|
1074 | |||
1075 | def test_show_should_allow_assignee_access_to_private_issue |
|
1075 | def test_show_should_allow_assignee_access_to_private_issue | |
1076 | Issue.where(:id => 1).update_all(["is_private = ?, assigned_to_id = 3", true]) |
|
1076 | Issue.where(:id => 1).update_all(["is_private = ?, assigned_to_id = 3", true]) | |
1077 | @request.session[:user_id] = 3 |
|
1077 | @request.session[:user_id] = 3 | |
1078 | get :show, :id => 1 |
|
1078 | get :show, :id => 1 | |
1079 | assert_response :success |
|
1079 | assert_response :success | |
1080 | end |
|
1080 | end | |
1081 |
|
1081 | |||
1082 | def test_show_should_allow_member_access_to_private_issue_with_permission |
|
1082 | def test_show_should_allow_member_access_to_private_issue_with_permission | |
1083 | Issue.where(:id => 1).update_all(["is_private = ?", true]) |
|
1083 | Issue.where(:id => 1).update_all(["is_private = ?", true]) | |
1084 | User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all' |
|
1084 | User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all' | |
1085 | @request.session[:user_id] = 3 |
|
1085 | @request.session[:user_id] = 3 | |
1086 | get :show, :id => 1 |
|
1086 | get :show, :id => 1 | |
1087 | assert_response :success |
|
1087 | assert_response :success | |
1088 | end |
|
1088 | end | |
1089 |
|
1089 | |||
1090 | def test_show_should_not_disclose_relations_to_invisible_issues |
|
1090 | def test_show_should_not_disclose_relations_to_invisible_issues | |
1091 | Setting.cross_project_issue_relations = '1' |
|
1091 | Setting.cross_project_issue_relations = '1' | |
1092 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates') |
|
1092 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates') | |
1093 | # Relation to a private project issue |
|
1093 | # Relation to a private project issue | |
1094 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates') |
|
1094 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates') | |
1095 |
|
1095 | |||
1096 | get :show, :id => 1 |
|
1096 | get :show, :id => 1 | |
1097 | assert_response :success |
|
1097 | assert_response :success | |
1098 |
|
1098 | |||
1099 | assert_select 'div#relations' do |
|
1099 | assert_select 'div#relations' do | |
1100 | assert_select 'a', :text => /#2$/ |
|
1100 | assert_select 'a', :text => /#2$/ | |
1101 | assert_select 'a', :text => /#4$/, :count => 0 |
|
1101 | assert_select 'a', :text => /#4$/, :count => 0 | |
1102 | end |
|
1102 | end | |
1103 | end |
|
1103 | end | |
1104 |
|
1104 | |||
1105 | def test_show_should_list_subtasks |
|
1105 | def test_show_should_list_subtasks | |
1106 | Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue') |
|
1106 | Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue') | |
1107 |
|
1107 | |||
1108 | get :show, :id => 1 |
|
1108 | get :show, :id => 1 | |
1109 | assert_response :success |
|
1109 | assert_response :success | |
1110 |
|
1110 | |||
1111 | assert_select 'div#issue_tree' do |
|
1111 | assert_select 'div#issue_tree' do | |
1112 | assert_select 'td.subject', :text => /Child Issue/ |
|
1112 | assert_select 'td.subject', :text => /Child Issue/ | |
1113 | end |
|
1113 | end | |
1114 | end |
|
1114 | end | |
1115 |
|
1115 | |||
1116 | def test_show_should_list_parents |
|
1116 | def test_show_should_list_parents | |
1117 | issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue') |
|
1117 | issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue') | |
1118 |
|
1118 | |||
1119 | get :show, :id => issue.id |
|
1119 | get :show, :id => issue.id | |
1120 | assert_response :success |
|
1120 | assert_response :success | |
1121 |
|
1121 | |||
1122 | assert_select 'div.subject' do |
|
1122 | assert_select 'div.subject' do | |
1123 | assert_select 'h3', 'Child Issue' |
|
1123 | assert_select 'h3', 'Child Issue' | |
1124 | assert_select 'a[href=/issues/1]' |
|
1124 | assert_select 'a[href=/issues/1]' | |
1125 | end |
|
1125 | end | |
1126 | end |
|
1126 | end | |
1127 |
|
1127 | |||
1128 | def test_show_should_not_display_prev_next_links_without_query_in_session |
|
1128 | def test_show_should_not_display_prev_next_links_without_query_in_session | |
1129 | get :show, :id => 1 |
|
1129 | get :show, :id => 1 | |
1130 | assert_response :success |
|
1130 | assert_response :success | |
1131 | assert_nil assigns(:prev_issue_id) |
|
1131 | assert_nil assigns(:prev_issue_id) | |
1132 | assert_nil assigns(:next_issue_id) |
|
1132 | assert_nil assigns(:next_issue_id) | |
1133 |
|
1133 | |||
1134 | assert_select 'div.next-prev-links', 0 |
|
1134 | assert_select 'div.next-prev-links', 0 | |
1135 | end |
|
1135 | end | |
1136 |
|
1136 | |||
1137 | def test_show_should_display_prev_next_links_with_query_in_session |
|
1137 | def test_show_should_display_prev_next_links_with_query_in_session | |
1138 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil} |
|
1138 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil} | |
1139 | @request.session['issues_index_sort'] = 'id' |
|
1139 | @request.session['issues_index_sort'] = 'id' | |
1140 |
|
1140 | |||
1141 | with_settings :display_subprojects_issues => '0' do |
|
1141 | with_settings :display_subprojects_issues => '0' do | |
1142 | get :show, :id => 3 |
|
1142 | get :show, :id => 3 | |
1143 | end |
|
1143 | end | |
1144 |
|
1144 | |||
1145 | assert_response :success |
|
1145 | assert_response :success | |
1146 | # Previous and next issues for all projects |
|
1146 | # Previous and next issues for all projects | |
1147 | assert_equal 2, assigns(:prev_issue_id) |
|
1147 | assert_equal 2, assigns(:prev_issue_id) | |
1148 | assert_equal 5, assigns(:next_issue_id) |
|
1148 | assert_equal 5, assigns(:next_issue_id) | |
1149 |
|
1149 | |||
1150 | count = Issue.open.visible.count |
|
1150 | count = Issue.open.visible.count | |
1151 |
|
1151 | |||
1152 | assert_select 'div.next-prev-links' do |
|
1152 | assert_select 'div.next-prev-links' do | |
1153 | assert_select 'a[href=/issues/2]', :text => /Previous/ |
|
1153 | assert_select 'a[href=/issues/2]', :text => /Previous/ | |
1154 | assert_select 'a[href=/issues/5]', :text => /Next/ |
|
1154 | assert_select 'a[href=/issues/5]', :text => /Next/ | |
1155 | assert_select 'span.position', :text => "3 of #{count}" |
|
1155 | assert_select 'span.position', :text => "3 of #{count}" | |
1156 | end |
|
1156 | end | |
1157 | end |
|
1157 | end | |
1158 |
|
1158 | |||
1159 | def test_show_should_display_prev_next_links_with_saved_query_in_session |
|
1159 | def test_show_should_display_prev_next_links_with_saved_query_in_session | |
1160 | query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1, |
|
1160 | query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1, | |
1161 | :filters => {'status_id' => {:values => ['5'], :operator => '='}}, |
|
1161 | :filters => {'status_id' => {:values => ['5'], :operator => '='}}, | |
1162 | :sort_criteria => [['id', 'asc']]) |
|
1162 | :sort_criteria => [['id', 'asc']]) | |
1163 | @request.session[:query] = {:id => query.id, :project_id => nil} |
|
1163 | @request.session[:query] = {:id => query.id, :project_id => nil} | |
1164 |
|
1164 | |||
1165 | get :show, :id => 11 |
|
1165 | get :show, :id => 11 | |
1166 |
|
1166 | |||
1167 | assert_response :success |
|
1167 | assert_response :success | |
1168 | assert_equal query, assigns(:query) |
|
1168 | assert_equal query, assigns(:query) | |
1169 | # Previous and next issues for all projects |
|
1169 | # Previous and next issues for all projects | |
1170 | assert_equal 8, assigns(:prev_issue_id) |
|
1170 | assert_equal 8, assigns(:prev_issue_id) | |
1171 | assert_equal 12, assigns(:next_issue_id) |
|
1171 | assert_equal 12, assigns(:next_issue_id) | |
1172 |
|
1172 | |||
1173 | assert_select 'div.next-prev-links' do |
|
1173 | assert_select 'div.next-prev-links' do | |
1174 | assert_select 'a[href=/issues/8]', :text => /Previous/ |
|
1174 | assert_select 'a[href=/issues/8]', :text => /Previous/ | |
1175 | assert_select 'a[href=/issues/12]', :text => /Next/ |
|
1175 | assert_select 'a[href=/issues/12]', :text => /Next/ | |
1176 | end |
|
1176 | end | |
1177 | end |
|
1177 | end | |
1178 |
|
1178 | |||
1179 | def test_show_should_display_prev_next_links_with_query_and_sort_on_association |
|
1179 | def test_show_should_display_prev_next_links_with_query_and_sort_on_association | |
1180 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil} |
|
1180 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil} | |
1181 |
|
1181 | |||
1182 | %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort| |
|
1182 | %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort| | |
1183 | @request.session['issues_index_sort'] = assoc_sort |
|
1183 | @request.session['issues_index_sort'] = assoc_sort | |
1184 |
|
1184 | |||
1185 | get :show, :id => 3 |
|
1185 | get :show, :id => 3 | |
1186 | assert_response :success, "Wrong response status for #{assoc_sort} sort" |
|
1186 | assert_response :success, "Wrong response status for #{assoc_sort} sort" | |
1187 |
|
1187 | |||
1188 | assert_select 'div.next-prev-links' do |
|
1188 | assert_select 'div.next-prev-links' do | |
1189 | assert_select 'a', :text => /(Previous|Next)/ |
|
1189 | assert_select 'a', :text => /(Previous|Next)/ | |
1190 | end |
|
1190 | end | |
1191 | end |
|
1191 | end | |
1192 | end |
|
1192 | end | |
1193 |
|
1193 | |||
1194 | def test_show_should_display_prev_next_links_with_project_query_in_session |
|
1194 | def test_show_should_display_prev_next_links_with_project_query_in_session | |
1195 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1} |
|
1195 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1} | |
1196 | @request.session['issues_index_sort'] = 'id' |
|
1196 | @request.session['issues_index_sort'] = 'id' | |
1197 |
|
1197 | |||
1198 | with_settings :display_subprojects_issues => '0' do |
|
1198 | with_settings :display_subprojects_issues => '0' do | |
1199 | get :show, :id => 3 |
|
1199 | get :show, :id => 3 | |
1200 | end |
|
1200 | end | |
1201 |
|
1201 | |||
1202 | assert_response :success |
|
1202 | assert_response :success | |
1203 | # Previous and next issues inside project |
|
1203 | # Previous and next issues inside project | |
1204 | assert_equal 2, assigns(:prev_issue_id) |
|
1204 | assert_equal 2, assigns(:prev_issue_id) | |
1205 | assert_equal 7, assigns(:next_issue_id) |
|
1205 | assert_equal 7, assigns(:next_issue_id) | |
1206 |
|
1206 | |||
1207 | assert_select 'div.next-prev-links' do |
|
1207 | assert_select 'div.next-prev-links' do | |
1208 | assert_select 'a[href=/issues/2]', :text => /Previous/ |
|
1208 | assert_select 'a[href=/issues/2]', :text => /Previous/ | |
1209 | assert_select 'a[href=/issues/7]', :text => /Next/ |
|
1209 | assert_select 'a[href=/issues/7]', :text => /Next/ | |
1210 | end |
|
1210 | end | |
1211 | end |
|
1211 | end | |
1212 |
|
1212 | |||
1213 | def test_show_should_not_display_prev_link_for_first_issue |
|
1213 | def test_show_should_not_display_prev_link_for_first_issue | |
1214 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1} |
|
1214 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1} | |
1215 | @request.session['issues_index_sort'] = 'id' |
|
1215 | @request.session['issues_index_sort'] = 'id' | |
1216 |
|
1216 | |||
1217 | with_settings :display_subprojects_issues => '0' do |
|
1217 | with_settings :display_subprojects_issues => '0' do | |
1218 | get :show, :id => 1 |
|
1218 | get :show, :id => 1 | |
1219 | end |
|
1219 | end | |
1220 |
|
1220 | |||
1221 | assert_response :success |
|
1221 | assert_response :success | |
1222 | assert_nil assigns(:prev_issue_id) |
|
1222 | assert_nil assigns(:prev_issue_id) | |
1223 | assert_equal 2, assigns(:next_issue_id) |
|
1223 | assert_equal 2, assigns(:next_issue_id) | |
1224 |
|
1224 | |||
1225 | assert_select 'div.next-prev-links' do |
|
1225 | assert_select 'div.next-prev-links' do | |
1226 | assert_select 'a', :text => /Previous/, :count => 0 |
|
1226 | assert_select 'a', :text => /Previous/, :count => 0 | |
1227 | assert_select 'a[href=/issues/2]', :text => /Next/ |
|
1227 | assert_select 'a[href=/issues/2]', :text => /Next/ | |
1228 | end |
|
1228 | end | |
1229 | end |
|
1229 | end | |
1230 |
|
1230 | |||
1231 | def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results |
|
1231 | def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results | |
1232 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1} |
|
1232 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1} | |
1233 | @request.session['issues_index_sort'] = 'id' |
|
1233 | @request.session['issues_index_sort'] = 'id' | |
1234 |
|
1234 | |||
1235 | get :show, :id => 1 |
|
1235 | get :show, :id => 1 | |
1236 |
|
1236 | |||
1237 | assert_response :success |
|
1237 | assert_response :success | |
1238 | assert_nil assigns(:prev_issue_id) |
|
1238 | assert_nil assigns(:prev_issue_id) | |
1239 | assert_nil assigns(:next_issue_id) |
|
1239 | assert_nil assigns(:next_issue_id) | |
1240 |
|
1240 | |||
1241 | assert_select 'a', :text => /Previous/, :count => 0 |
|
1241 | assert_select 'a', :text => /Previous/, :count => 0 | |
1242 | assert_select 'a', :text => /Next/, :count => 0 |
|
1242 | assert_select 'a', :text => /Next/, :count => 0 | |
1243 | end |
|
1243 | end | |
1244 |
|
1244 | |||
1245 | def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field |
|
1245 | def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field | |
1246 | cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user') |
|
1246 | cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user') | |
1247 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2') |
|
1247 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2') | |
1248 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3') |
|
1248 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3') | |
1249 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3') |
|
1249 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3') | |
1250 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '') |
|
1250 | CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '') | |
1251 |
|
1251 | |||
1252 | query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1, :filters => {}, |
|
1252 | query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1, :filters => {}, | |
1253 | :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']]) |
|
1253 | :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']]) | |
1254 | @request.session[:query] = {:id => query.id, :project_id => nil} |
|
1254 | @request.session[:query] = {:id => query.id, :project_id => nil} | |
1255 |
|
1255 | |||
1256 | get :show, :id => 3 |
|
1256 | get :show, :id => 3 | |
1257 | assert_response :success |
|
1257 | assert_response :success | |
1258 |
|
1258 | |||
1259 | assert_equal 2, assigns(:prev_issue_id) |
|
1259 | assert_equal 2, assigns(:prev_issue_id) | |
1260 | assert_equal 1, assigns(:next_issue_id) |
|
1260 | assert_equal 1, assigns(:next_issue_id) | |
1261 |
|
1261 | |||
1262 | assert_select 'div.next-prev-links' do |
|
1262 | assert_select 'div.next-prev-links' do | |
1263 | assert_select 'a[href=/issues/2]', :text => /Previous/ |
|
1263 | assert_select 'a[href=/issues/2]', :text => /Previous/ | |
1264 | assert_select 'a[href=/issues/1]', :text => /Next/ |
|
1264 | assert_select 'a[href=/issues/1]', :text => /Next/ | |
1265 | end |
|
1265 | end | |
1266 | end |
|
1266 | end | |
1267 |
|
1267 | |||
1268 | def test_show_should_display_link_to_the_assignee |
|
1268 | def test_show_should_display_link_to_the_assignee | |
1269 | get :show, :id => 2 |
|
1269 | get :show, :id => 2 | |
1270 | assert_response :success |
|
1270 | assert_response :success | |
1271 | assert_select '.assigned-to' do |
|
1271 | assert_select '.assigned-to' do | |
1272 | assert_select 'a[href=/users/3]' |
|
1272 | assert_select 'a[href=/users/3]' | |
1273 | end |
|
1273 | end | |
1274 | end |
|
1274 | end | |
1275 |
|
1275 | |||
1276 | def test_show_should_display_visible_changesets_from_other_projects |
|
1276 | def test_show_should_display_visible_changesets_from_other_projects | |
1277 | project = Project.find(2) |
|
1277 | project = Project.find(2) | |
1278 | issue = project.issues.first |
|
1278 | issue = project.issues.first | |
1279 | issue.changeset_ids = [102] |
|
1279 | issue.changeset_ids = [102] | |
1280 | issue.save! |
|
1280 | issue.save! | |
1281 | # changesets from other projects should be displayed even if repository |
|
1281 | # changesets from other projects should be displayed even if repository | |
1282 | # is disabled on issue's project |
|
1282 | # is disabled on issue's project | |
1283 | project.disable_module! :repository |
|
1283 | project.disable_module! :repository | |
1284 |
|
1284 | |||
1285 | @request.session[:user_id] = 2 |
|
1285 | @request.session[:user_id] = 2 | |
1286 | get :show, :id => issue.id |
|
1286 | get :show, :id => issue.id | |
1287 |
|
1287 | |||
1288 | assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/3' |
|
1288 | assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/3' | |
1289 | end |
|
1289 | end | |
1290 |
|
1290 | |||
1291 | def test_show_should_display_watchers |
|
1291 | def test_show_should_display_watchers | |
1292 | @request.session[:user_id] = 2 |
|
1292 | @request.session[:user_id] = 2 | |
1293 | Issue.find(1).add_watcher User.find(2) |
|
1293 | Issue.find(1).add_watcher User.find(2) | |
1294 |
|
1294 | |||
1295 | get :show, :id => 1 |
|
1295 | get :show, :id => 1 | |
1296 | assert_select 'div#watchers ul' do |
|
1296 | assert_select 'div#watchers ul' do | |
1297 | assert_select 'li' do |
|
1297 | assert_select 'li' do | |
1298 | assert_select 'a[href=/users/2]' |
|
1298 | assert_select 'a[href=/users/2]' | |
1299 | assert_select 'a img[alt=Delete]' |
|
1299 | assert_select 'a img[alt=Delete]' | |
1300 | end |
|
1300 | end | |
1301 | end |
|
1301 | end | |
1302 | end |
|
1302 | end | |
1303 |
|
1303 | |||
1304 | def test_show_should_display_watchers_with_gravatars |
|
1304 | def test_show_should_display_watchers_with_gravatars | |
1305 | @request.session[:user_id] = 2 |
|
1305 | @request.session[:user_id] = 2 | |
1306 | Issue.find(1).add_watcher User.find(2) |
|
1306 | Issue.find(1).add_watcher User.find(2) | |
1307 |
|
1307 | |||
1308 | with_settings :gravatar_enabled => '1' do |
|
1308 | with_settings :gravatar_enabled => '1' do | |
1309 | get :show, :id => 1 |
|
1309 | get :show, :id => 1 | |
1310 | end |
|
1310 | end | |
1311 |
|
1311 | |||
1312 | assert_select 'div#watchers ul' do |
|
1312 | assert_select 'div#watchers ul' do | |
1313 | assert_select 'li' do |
|
1313 | assert_select 'li' do | |
1314 | assert_select 'img.gravatar' |
|
1314 | assert_select 'img.gravatar' | |
1315 | assert_select 'a[href=/users/2]' |
|
1315 | assert_select 'a[href=/users/2]' | |
1316 | assert_select 'a img[alt=Delete]' |
|
1316 | assert_select 'a img[alt=Delete]' | |
1317 | end |
|
1317 | end | |
1318 | end |
|
1318 | end | |
1319 | end |
|
1319 | end | |
1320 |
|
1320 | |||
1321 | def test_show_with_thumbnails_enabled_should_display_thumbnails |
|
1321 | def test_show_with_thumbnails_enabled_should_display_thumbnails | |
1322 | @request.session[:user_id] = 2 |
|
1322 | @request.session[:user_id] = 2 | |
1323 |
|
1323 | |||
1324 | with_settings :thumbnails_enabled => '1' do |
|
1324 | with_settings :thumbnails_enabled => '1' do | |
1325 | get :show, :id => 14 |
|
1325 | get :show, :id => 14 | |
1326 | assert_response :success |
|
1326 | assert_response :success | |
1327 | end |
|
1327 | end | |
1328 |
|
1328 | |||
1329 | assert_select 'div.thumbnails' do |
|
1329 | assert_select 'div.thumbnails' do | |
1330 | assert_select 'a[href=/attachments/16/testfile.png]' do |
|
1330 | assert_select 'a[href=/attachments/16/testfile.png]' do | |
1331 | assert_select 'img[src=/attachments/thumbnail/16]' |
|
1331 | assert_select 'img[src=/attachments/thumbnail/16]' | |
1332 | end |
|
1332 | end | |
1333 | end |
|
1333 | end | |
1334 | end |
|
1334 | end | |
1335 |
|
1335 | |||
1336 | def test_show_with_thumbnails_disabled_should_not_display_thumbnails |
|
1336 | def test_show_with_thumbnails_disabled_should_not_display_thumbnails | |
1337 | @request.session[:user_id] = 2 |
|
1337 | @request.session[:user_id] = 2 | |
1338 |
|
1338 | |||
1339 | with_settings :thumbnails_enabled => '0' do |
|
1339 | with_settings :thumbnails_enabled => '0' do | |
1340 | get :show, :id => 14 |
|
1340 | get :show, :id => 14 | |
1341 | assert_response :success |
|
1341 | assert_response :success | |
1342 | end |
|
1342 | end | |
1343 |
|
1343 | |||
1344 | assert_select 'div.thumbnails', 0 |
|
1344 | assert_select 'div.thumbnails', 0 | |
1345 | end |
|
1345 | end | |
1346 |
|
1346 | |||
1347 | def test_show_with_multi_custom_field |
|
1347 | def test_show_with_multi_custom_field | |
1348 | field = CustomField.find(1) |
|
1348 | field = CustomField.find(1) | |
1349 | field.update_attribute :multiple, true |
|
1349 | field.update_attribute :multiple, true | |
1350 | issue = Issue.find(1) |
|
1350 | issue = Issue.find(1) | |
1351 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
1351 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} | |
1352 | issue.save! |
|
1352 | issue.save! | |
1353 |
|
1353 | |||
1354 | get :show, :id => 1 |
|
1354 | get :show, :id => 1 | |
1355 | assert_response :success |
|
1355 | assert_response :success | |
1356 |
|
1356 | |||
1357 | assert_select 'td', :text => 'MySQL, Oracle' |
|
1357 | assert_select 'td', :text => 'MySQL, Oracle' | |
1358 | end |
|
1358 | end | |
1359 |
|
1359 | |||
1360 | def test_show_with_multi_user_custom_field |
|
1360 | def test_show_with_multi_user_custom_field | |
1361 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, |
|
1361 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, | |
1362 | :tracker_ids => [1], :is_for_all => true) |
|
1362 | :tracker_ids => [1], :is_for_all => true) | |
1363 | issue = Issue.find(1) |
|
1363 | issue = Issue.find(1) | |
1364 | issue.custom_field_values = {field.id => ['2', '3']} |
|
1364 | issue.custom_field_values = {field.id => ['2', '3']} | |
1365 | issue.save! |
|
1365 | issue.save! | |
1366 |
|
1366 | |||
1367 | get :show, :id => 1 |
|
1367 | get :show, :id => 1 | |
1368 | assert_response :success |
|
1368 | assert_response :success | |
1369 |
|
1369 | |||
1370 | assert_select "td.cf_#{field.id}", :text => 'Dave Lopper, John Smith' do |
|
1370 | assert_select "td.cf_#{field.id}", :text => 'Dave Lopper, John Smith' do | |
1371 | assert_select 'a', :text => 'Dave Lopper' |
|
1371 | assert_select 'a', :text => 'Dave Lopper' | |
1372 | assert_select 'a', :text => 'John Smith' |
|
1372 | assert_select 'a', :text => 'John Smith' | |
1373 | end |
|
1373 | end | |
1374 | end |
|
1374 | end | |
1375 |
|
1375 | |||
1376 | def test_show_should_display_private_notes_with_permission_only |
|
1376 | def test_show_should_display_private_notes_with_permission_only | |
1377 | journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1) |
|
1377 | journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1) | |
1378 | @request.session[:user_id] = 2 |
|
1378 | @request.session[:user_id] = 2 | |
1379 |
|
1379 | |||
1380 | get :show, :id => 2 |
|
1380 | get :show, :id => 2 | |
1381 | assert_response :success |
|
1381 | assert_response :success | |
1382 | assert_include journal, assigns(:journals) |
|
1382 | assert_include journal, assigns(:journals) | |
1383 |
|
1383 | |||
1384 | Role.find(1).remove_permission! :view_private_notes |
|
1384 | Role.find(1).remove_permission! :view_private_notes | |
1385 | get :show, :id => 2 |
|
1385 | get :show, :id => 2 | |
1386 | assert_response :success |
|
1386 | assert_response :success | |
1387 | assert_not_include journal, assigns(:journals) |
|
1387 | assert_not_include journal, assigns(:journals) | |
1388 | end |
|
1388 | end | |
1389 |
|
1389 | |||
1390 | def test_show_atom |
|
1390 | def test_show_atom | |
1391 | get :show, :id => 2, :format => 'atom' |
|
1391 | get :show, :id => 2, :format => 'atom' | |
1392 | assert_response :success |
|
1392 | assert_response :success | |
1393 | assert_template 'journals/index' |
|
1393 | assert_template 'journals/index' | |
1394 | # Inline image |
|
1394 | # Inline image | |
1395 | assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10')) |
|
1395 | assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10')) | |
1396 | end |
|
1396 | end | |
1397 |
|
1397 | |||
1398 | def test_show_export_to_pdf |
|
1398 | def test_show_export_to_pdf | |
1399 | issue = Issue.find(3) |
|
1399 | issue = Issue.find(3) | |
1400 | assert issue.relations.select{|r| r.other_issue(issue).visible?}.present? |
|
1400 | assert issue.relations.select{|r| r.other_issue(issue).visible?}.present? | |
1401 | get :show, :id => 3, :format => 'pdf' |
|
1401 | get :show, :id => 3, :format => 'pdf' | |
1402 | assert_response :success |
|
1402 | assert_response :success | |
1403 | assert_equal 'application/pdf', @response.content_type |
|
1403 | assert_equal 'application/pdf', @response.content_type | |
1404 | assert @response.body.starts_with?('%PDF') |
|
1404 | assert @response.body.starts_with?('%PDF') | |
1405 | assert_not_nil assigns(:issue) |
|
1405 | assert_not_nil assigns(:issue) | |
1406 | end |
|
1406 | end | |
1407 |
|
1407 | |||
|
1408 | def test_export_to_pdf_with_utf8_u_ffdd | |||
|
1409 | # U+FFFD | |||
|
1410 | s = "\xef\xbf\xbd" | |||
|
1411 | s.force_encoding('UTF-8') if s.respond_to?(:force_encoding) | |||
|
1412 | issue = Issue.generate!(:subject => s) | |||
|
1413 | ["en", "zh", "zh-TW", "ja", "ko"].each do |lang| | |||
|
1414 | with_settings :default_language => lang do | |||
|
1415 | get :show, :id => issue.id, :format => 'pdf' | |||
|
1416 | assert_response :success | |||
|
1417 | assert_equal 'application/pdf', @response.content_type | |||
|
1418 | assert @response.body.starts_with?('%PDF') | |||
|
1419 | assert_not_nil assigns(:issue) | |||
|
1420 | end | |||
|
1421 | end | |||
|
1422 | end | |||
|
1423 | ||||
1408 | def test_show_export_to_pdf_with_ancestors |
|
1424 | def test_show_export_to_pdf_with_ancestors | |
1409 | issue = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1) |
|
1425 | issue = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1) | |
1410 |
|
1426 | |||
1411 | get :show, :id => issue.id, :format => 'pdf' |
|
1427 | get :show, :id => issue.id, :format => 'pdf' | |
1412 | assert_response :success |
|
1428 | assert_response :success | |
1413 | assert_equal 'application/pdf', @response.content_type |
|
1429 | assert_equal 'application/pdf', @response.content_type | |
1414 | assert @response.body.starts_with?('%PDF') |
|
1430 | assert @response.body.starts_with?('%PDF') | |
1415 | end |
|
1431 | end | |
1416 |
|
1432 | |||
1417 | def test_show_export_to_pdf_with_descendants |
|
1433 | def test_show_export_to_pdf_with_descendants | |
1418 | c1 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1) |
|
1434 | c1 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1) | |
1419 | c2 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1) |
|
1435 | c2 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1) | |
1420 | c3 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => c1.id) |
|
1436 | c3 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => c1.id) | |
1421 |
|
1437 | |||
1422 | get :show, :id => 1, :format => 'pdf' |
|
1438 | get :show, :id => 1, :format => 'pdf' | |
1423 | assert_response :success |
|
1439 | assert_response :success | |
1424 | assert_equal 'application/pdf', @response.content_type |
|
1440 | assert_equal 'application/pdf', @response.content_type | |
1425 | assert @response.body.starts_with?('%PDF') |
|
1441 | assert @response.body.starts_with?('%PDF') | |
1426 | end |
|
1442 | end | |
1427 |
|
1443 | |||
1428 | def test_show_export_to_pdf_with_journals |
|
1444 | def test_show_export_to_pdf_with_journals | |
1429 | get :show, :id => 1, :format => 'pdf' |
|
1445 | get :show, :id => 1, :format => 'pdf' | |
1430 | assert_response :success |
|
1446 | assert_response :success | |
1431 | assert_equal 'application/pdf', @response.content_type |
|
1447 | assert_equal 'application/pdf', @response.content_type | |
1432 | assert @response.body.starts_with?('%PDF') |
|
1448 | assert @response.body.starts_with?('%PDF') | |
1433 | end |
|
1449 | end | |
1434 |
|
1450 | |||
1435 | def test_show_export_to_pdf_with_changesets |
|
1451 | def test_show_export_to_pdf_with_changesets | |
1436 | [[100], [100, 101], [100, 101, 102]].each do |cs| |
|
1452 | [[100], [100, 101], [100, 101, 102]].each do |cs| | |
1437 | issue1 = Issue.find(3) |
|
1453 | issue1 = Issue.find(3) | |
1438 | issue1.changesets = Changeset.find(cs) |
|
1454 | issue1.changesets = Changeset.find(cs) | |
1439 | issue1.save! |
|
1455 | issue1.save! | |
1440 | issue = Issue.find(3) |
|
1456 | issue = Issue.find(3) | |
1441 | assert_equal issue.changesets.count, cs.size |
|
1457 | assert_equal issue.changesets.count, cs.size | |
1442 | get :show, :id => 3, :format => 'pdf' |
|
1458 | get :show, :id => 3, :format => 'pdf' | |
1443 | assert_response :success |
|
1459 | assert_response :success | |
1444 | assert_equal 'application/pdf', @response.content_type |
|
1460 | assert_equal 'application/pdf', @response.content_type | |
1445 | assert @response.body.starts_with?('%PDF') |
|
1461 | assert @response.body.starts_with?('%PDF') | |
1446 | end |
|
1462 | end | |
1447 | end |
|
1463 | end | |
1448 |
|
1464 | |||
1449 | def test_show_invalid_should_respond_with_404 |
|
1465 | def test_show_invalid_should_respond_with_404 | |
1450 | get :show, :id => 999 |
|
1466 | get :show, :id => 999 | |
1451 | assert_response 404 |
|
1467 | assert_response 404 | |
1452 | end |
|
1468 | end | |
1453 |
|
1469 | |||
1454 | def test_get_new |
|
1470 | def test_get_new | |
1455 | @request.session[:user_id] = 2 |
|
1471 | @request.session[:user_id] = 2 | |
1456 | get :new, :project_id => 1, :tracker_id => 1 |
|
1472 | get :new, :project_id => 1, :tracker_id => 1 | |
1457 | assert_response :success |
|
1473 | assert_response :success | |
1458 | assert_template 'new' |
|
1474 | assert_template 'new' | |
1459 |
|
1475 | |||
1460 | assert_select 'form#issue-form' do |
|
1476 | assert_select 'form#issue-form' do | |
1461 | assert_select 'input[name=?]', 'issue[is_private]' |
|
1477 | assert_select 'input[name=?]', 'issue[is_private]' | |
1462 | assert_select 'select[name=?]', 'issue[project_id]', 0 |
|
1478 | assert_select 'select[name=?]', 'issue[project_id]', 0 | |
1463 | assert_select 'select[name=?]', 'issue[tracker_id]' |
|
1479 | assert_select 'select[name=?]', 'issue[tracker_id]' | |
1464 | assert_select 'input[name=?]', 'issue[subject]' |
|
1480 | assert_select 'input[name=?]', 'issue[subject]' | |
1465 | assert_select 'textarea[name=?]', 'issue[description]' |
|
1481 | assert_select 'textarea[name=?]', 'issue[description]' | |
1466 | assert_select 'select[name=?]', 'issue[status_id]' |
|
1482 | assert_select 'select[name=?]', 'issue[status_id]' | |
1467 | assert_select 'select[name=?]', 'issue[priority_id]' |
|
1483 | assert_select 'select[name=?]', 'issue[priority_id]' | |
1468 | assert_select 'select[name=?]', 'issue[assigned_to_id]' |
|
1484 | assert_select 'select[name=?]', 'issue[assigned_to_id]' | |
1469 | assert_select 'select[name=?]', 'issue[category_id]' |
|
1485 | assert_select 'select[name=?]', 'issue[category_id]' | |
1470 | assert_select 'select[name=?]', 'issue[fixed_version_id]' |
|
1486 | assert_select 'select[name=?]', 'issue[fixed_version_id]' | |
1471 | assert_select 'input[name=?]', 'issue[parent_issue_id]' |
|
1487 | assert_select 'input[name=?]', 'issue[parent_issue_id]' | |
1472 | assert_select 'input[name=?]', 'issue[start_date]' |
|
1488 | assert_select 'input[name=?]', 'issue[start_date]' | |
1473 | assert_select 'input[name=?]', 'issue[due_date]' |
|
1489 | assert_select 'input[name=?]', 'issue[due_date]' | |
1474 | assert_select 'select[name=?]', 'issue[done_ratio]' |
|
1490 | assert_select 'select[name=?]', 'issue[done_ratio]' | |
1475 | assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string' |
|
1491 | assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string' | |
1476 | assert_select 'input[name=?]', 'issue[watcher_user_ids][]' |
|
1492 | assert_select 'input[name=?]', 'issue[watcher_user_ids][]' | |
1477 | end |
|
1493 | end | |
1478 |
|
1494 | |||
1479 | # Be sure we don't display inactive IssuePriorities |
|
1495 | # Be sure we don't display inactive IssuePriorities | |
1480 | assert ! IssuePriority.find(15).active? |
|
1496 | assert ! IssuePriority.find(15).active? | |
1481 | assert_select 'select[name=?]', 'issue[priority_id]' do |
|
1497 | assert_select 'select[name=?]', 'issue[priority_id]' do | |
1482 | assert_select 'option[value=15]', 0 |
|
1498 | assert_select 'option[value=15]', 0 | |
1483 | end |
|
1499 | end | |
1484 | end |
|
1500 | end | |
1485 |
|
1501 | |||
1486 | def test_get_new_with_minimal_permissions |
|
1502 | def test_get_new_with_minimal_permissions | |
1487 | Role.find(1).update_attribute :permissions, [:add_issues] |
|
1503 | Role.find(1).update_attribute :permissions, [:add_issues] | |
1488 | WorkflowTransition.delete_all :role_id => 1 |
|
1504 | WorkflowTransition.delete_all :role_id => 1 | |
1489 |
|
1505 | |||
1490 | @request.session[:user_id] = 2 |
|
1506 | @request.session[:user_id] = 2 | |
1491 | get :new, :project_id => 1, :tracker_id => 1 |
|
1507 | get :new, :project_id => 1, :tracker_id => 1 | |
1492 | assert_response :success |
|
1508 | assert_response :success | |
1493 | assert_template 'new' |
|
1509 | assert_template 'new' | |
1494 |
|
1510 | |||
1495 | assert_select 'form#issue-form' do |
|
1511 | assert_select 'form#issue-form' do | |
1496 | assert_select 'input[name=?]', 'issue[is_private]', 0 |
|
1512 | assert_select 'input[name=?]', 'issue[is_private]', 0 | |
1497 | assert_select 'select[name=?]', 'issue[project_id]', 0 |
|
1513 | assert_select 'select[name=?]', 'issue[project_id]', 0 | |
1498 | assert_select 'select[name=?]', 'issue[tracker_id]' |
|
1514 | assert_select 'select[name=?]', 'issue[tracker_id]' | |
1499 | assert_select 'input[name=?]', 'issue[subject]' |
|
1515 | assert_select 'input[name=?]', 'issue[subject]' | |
1500 | assert_select 'textarea[name=?]', 'issue[description]' |
|
1516 | assert_select 'textarea[name=?]', 'issue[description]' | |
1501 | assert_select 'select[name=?]', 'issue[status_id]' |
|
1517 | assert_select 'select[name=?]', 'issue[status_id]' | |
1502 | assert_select 'select[name=?]', 'issue[priority_id]' |
|
1518 | assert_select 'select[name=?]', 'issue[priority_id]' | |
1503 | assert_select 'select[name=?]', 'issue[assigned_to_id]' |
|
1519 | assert_select 'select[name=?]', 'issue[assigned_to_id]' | |
1504 | assert_select 'select[name=?]', 'issue[category_id]' |
|
1520 | assert_select 'select[name=?]', 'issue[category_id]' | |
1505 | assert_select 'select[name=?]', 'issue[fixed_version_id]' |
|
1521 | assert_select 'select[name=?]', 'issue[fixed_version_id]' | |
1506 | assert_select 'input[name=?]', 'issue[parent_issue_id]', 0 |
|
1522 | assert_select 'input[name=?]', 'issue[parent_issue_id]', 0 | |
1507 | assert_select 'input[name=?]', 'issue[start_date]' |
|
1523 | assert_select 'input[name=?]', 'issue[start_date]' | |
1508 | assert_select 'input[name=?]', 'issue[due_date]' |
|
1524 | assert_select 'input[name=?]', 'issue[due_date]' | |
1509 | assert_select 'select[name=?]', 'issue[done_ratio]' |
|
1525 | assert_select 'select[name=?]', 'issue[done_ratio]' | |
1510 | assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string' |
|
1526 | assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string' | |
1511 | assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0 |
|
1527 | assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0 | |
1512 | end |
|
1528 | end | |
1513 | end |
|
1529 | end | |
1514 |
|
1530 | |||
1515 | def test_get_new_with_list_custom_field |
|
1531 | def test_get_new_with_list_custom_field | |
1516 | @request.session[:user_id] = 2 |
|
1532 | @request.session[:user_id] = 2 | |
1517 | get :new, :project_id => 1, :tracker_id => 1 |
|
1533 | get :new, :project_id => 1, :tracker_id => 1 | |
1518 | assert_response :success |
|
1534 | assert_response :success | |
1519 | assert_template 'new' |
|
1535 | assert_template 'new' | |
1520 |
|
1536 | |||
1521 | assert_select 'select.list_cf[name=?]', 'issue[custom_field_values][1]' do |
|
1537 | assert_select 'select.list_cf[name=?]', 'issue[custom_field_values][1]' do | |
1522 | assert_select 'option', 4 |
|
1538 | assert_select 'option', 4 | |
1523 | assert_select 'option[value=MySQL]', :text => 'MySQL' |
|
1539 | assert_select 'option[value=MySQL]', :text => 'MySQL' | |
1524 | end |
|
1540 | end | |
1525 | end |
|
1541 | end | |
1526 |
|
1542 | |||
1527 | def test_get_new_with_multi_custom_field |
|
1543 | def test_get_new_with_multi_custom_field | |
1528 | field = IssueCustomField.find(1) |
|
1544 | field = IssueCustomField.find(1) | |
1529 | field.update_attribute :multiple, true |
|
1545 | field.update_attribute :multiple, true | |
1530 |
|
1546 | |||
1531 | @request.session[:user_id] = 2 |
|
1547 | @request.session[:user_id] = 2 | |
1532 | get :new, :project_id => 1, :tracker_id => 1 |
|
1548 | get :new, :project_id => 1, :tracker_id => 1 | |
1533 | assert_response :success |
|
1549 | assert_response :success | |
1534 | assert_template 'new' |
|
1550 | assert_template 'new' | |
1535 |
|
1551 | |||
1536 | assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do |
|
1552 | assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do | |
1537 | assert_select 'option', 3 |
|
1553 | assert_select 'option', 3 | |
1538 | assert_select 'option[value=MySQL]', :text => 'MySQL' |
|
1554 | assert_select 'option[value=MySQL]', :text => 'MySQL' | |
1539 | end |
|
1555 | end | |
1540 | assert_select 'input[name=?][type=hidden][value=?]', 'issue[custom_field_values][1][]', '' |
|
1556 | assert_select 'input[name=?][type=hidden][value=?]', 'issue[custom_field_values][1][]', '' | |
1541 | end |
|
1557 | end | |
1542 |
|
1558 | |||
1543 | def test_get_new_with_multi_user_custom_field |
|
1559 | def test_get_new_with_multi_user_custom_field | |
1544 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, |
|
1560 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, | |
1545 | :tracker_ids => [1], :is_for_all => true) |
|
1561 | :tracker_ids => [1], :is_for_all => true) | |
1546 |
|
1562 | |||
1547 | @request.session[:user_id] = 2 |
|
1563 | @request.session[:user_id] = 2 | |
1548 | get :new, :project_id => 1, :tracker_id => 1 |
|
1564 | get :new, :project_id => 1, :tracker_id => 1 | |
1549 | assert_response :success |
|
1565 | assert_response :success | |
1550 | assert_template 'new' |
|
1566 | assert_template 'new' | |
1551 |
|
1567 | |||
1552 | assert_select 'select[name=?][multiple=multiple]', "issue[custom_field_values][#{field.id}][]" do |
|
1568 | assert_select 'select[name=?][multiple=multiple]', "issue[custom_field_values][#{field.id}][]" do | |
1553 | assert_select 'option', Project.find(1).users.count |
|
1569 | assert_select 'option', Project.find(1).users.count | |
1554 | assert_select 'option[value=2]', :text => 'John Smith' |
|
1570 | assert_select 'option[value=2]', :text => 'John Smith' | |
1555 | end |
|
1571 | end | |
1556 | assert_select 'input[name=?][type=hidden][value=?]', "issue[custom_field_values][#{field.id}][]", '' |
|
1572 | assert_select 'input[name=?][type=hidden][value=?]', "issue[custom_field_values][#{field.id}][]", '' | |
1557 | end |
|
1573 | end | |
1558 |
|
1574 | |||
1559 | def test_get_new_with_date_custom_field |
|
1575 | def test_get_new_with_date_custom_field | |
1560 | field = IssueCustomField.create!(:name => 'Date', :field_format => 'date', :tracker_ids => [1], :is_for_all => true) |
|
1576 | field = IssueCustomField.create!(:name => 'Date', :field_format => 'date', :tracker_ids => [1], :is_for_all => true) | |
1561 |
|
1577 | |||
1562 | @request.session[:user_id] = 2 |
|
1578 | @request.session[:user_id] = 2 | |
1563 | get :new, :project_id => 1, :tracker_id => 1 |
|
1579 | get :new, :project_id => 1, :tracker_id => 1 | |
1564 | assert_response :success |
|
1580 | assert_response :success | |
1565 |
|
1581 | |||
1566 | assert_select 'input[name=?]', "issue[custom_field_values][#{field.id}]" |
|
1582 | assert_select 'input[name=?]', "issue[custom_field_values][#{field.id}]" | |
1567 | end |
|
1583 | end | |
1568 |
|
1584 | |||
1569 | def test_get_new_with_text_custom_field |
|
1585 | def test_get_new_with_text_custom_field | |
1570 | field = IssueCustomField.create!(:name => 'Text', :field_format => 'text', :tracker_ids => [1], :is_for_all => true) |
|
1586 | field = IssueCustomField.create!(:name => 'Text', :field_format => 'text', :tracker_ids => [1], :is_for_all => true) | |
1571 |
|
1587 | |||
1572 | @request.session[:user_id] = 2 |
|
1588 | @request.session[:user_id] = 2 | |
1573 | get :new, :project_id => 1, :tracker_id => 1 |
|
1589 | get :new, :project_id => 1, :tracker_id => 1 | |
1574 | assert_response :success |
|
1590 | assert_response :success | |
1575 |
|
1591 | |||
1576 | assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]" |
|
1592 | assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]" | |
1577 | end |
|
1593 | end | |
1578 |
|
1594 | |||
1579 | def test_get_new_without_default_start_date_is_creation_date |
|
1595 | def test_get_new_without_default_start_date_is_creation_date | |
1580 | with_settings :default_issue_start_date_to_creation_date => 0 do |
|
1596 | with_settings :default_issue_start_date_to_creation_date => 0 do | |
1581 | @request.session[:user_id] = 2 |
|
1597 | @request.session[:user_id] = 2 | |
1582 | get :new, :project_id => 1, :tracker_id => 1 |
|
1598 | get :new, :project_id => 1, :tracker_id => 1 | |
1583 | assert_response :success |
|
1599 | assert_response :success | |
1584 | assert_template 'new' |
|
1600 | assert_template 'new' | |
1585 | assert_select 'input[name=?]', 'issue[start_date]' |
|
1601 | assert_select 'input[name=?]', 'issue[start_date]' | |
1586 | assert_select 'input[name=?][value]', 'issue[start_date]', 0 |
|
1602 | assert_select 'input[name=?][value]', 'issue[start_date]', 0 | |
1587 | end |
|
1603 | end | |
1588 | end |
|
1604 | end | |
1589 |
|
1605 | |||
1590 | def test_get_new_with_default_start_date_is_creation_date |
|
1606 | def test_get_new_with_default_start_date_is_creation_date | |
1591 | with_settings :default_issue_start_date_to_creation_date => 1 do |
|
1607 | with_settings :default_issue_start_date_to_creation_date => 1 do | |
1592 | @request.session[:user_id] = 2 |
|
1608 | @request.session[:user_id] = 2 | |
1593 | get :new, :project_id => 1, :tracker_id => 1 |
|
1609 | get :new, :project_id => 1, :tracker_id => 1 | |
1594 | assert_response :success |
|
1610 | assert_response :success | |
1595 | assert_template 'new' |
|
1611 | assert_template 'new' | |
1596 | assert_select 'input[name=?][value=?]', 'issue[start_date]', |
|
1612 | assert_select 'input[name=?][value=?]', 'issue[start_date]', | |
1597 | Date.today.to_s |
|
1613 | Date.today.to_s | |
1598 | end |
|
1614 | end | |
1599 | end |
|
1615 | end | |
1600 |
|
1616 | |||
1601 | def test_get_new_form_should_allow_attachment_upload |
|
1617 | def test_get_new_form_should_allow_attachment_upload | |
1602 | @request.session[:user_id] = 2 |
|
1618 | @request.session[:user_id] = 2 | |
1603 | get :new, :project_id => 1, :tracker_id => 1 |
|
1619 | get :new, :project_id => 1, :tracker_id => 1 | |
1604 |
|
1620 | |||
1605 | assert_select 'form[id=issue-form][method=post][enctype=multipart/form-data]' do |
|
1621 | assert_select 'form[id=issue-form][method=post][enctype=multipart/form-data]' do | |
1606 | assert_select 'input[name=?][type=file]', 'attachments[dummy][file]' |
|
1622 | assert_select 'input[name=?][type=file]', 'attachments[dummy][file]' | |
1607 | end |
|
1623 | end | |
1608 | end |
|
1624 | end | |
1609 |
|
1625 | |||
1610 | def test_get_new_should_prefill_the_form_from_params |
|
1626 | def test_get_new_should_prefill_the_form_from_params | |
1611 | @request.session[:user_id] = 2 |
|
1627 | @request.session[:user_id] = 2 | |
1612 | get :new, :project_id => 1, |
|
1628 | get :new, :project_id => 1, | |
1613 | :issue => {:tracker_id => 3, :description => 'Prefilled', :custom_field_values => {'2' => 'Custom field value'}} |
|
1629 | :issue => {:tracker_id => 3, :description => 'Prefilled', :custom_field_values => {'2' => 'Custom field value'}} | |
1614 |
|
1630 | |||
1615 | issue = assigns(:issue) |
|
1631 | issue = assigns(:issue) | |
1616 | assert_equal 3, issue.tracker_id |
|
1632 | assert_equal 3, issue.tracker_id | |
1617 | assert_equal 'Prefilled', issue.description |
|
1633 | assert_equal 'Prefilled', issue.description | |
1618 | assert_equal 'Custom field value', issue.custom_field_value(2) |
|
1634 | assert_equal 'Custom field value', issue.custom_field_value(2) | |
1619 |
|
1635 | |||
1620 | assert_select 'select[name=?]', 'issue[tracker_id]' do |
|
1636 | assert_select 'select[name=?]', 'issue[tracker_id]' do | |
1621 | assert_select 'option[value=3][selected=selected]' |
|
1637 | assert_select 'option[value=3][selected=selected]' | |
1622 | end |
|
1638 | end | |
1623 | assert_select 'textarea[name=?]', 'issue[description]', :text => /Prefilled/ |
|
1639 | assert_select 'textarea[name=?]', 'issue[description]', :text => /Prefilled/ | |
1624 | assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Custom field value' |
|
1640 | assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Custom field value' | |
1625 | end |
|
1641 | end | |
1626 |
|
1642 | |||
1627 | def test_get_new_should_mark_required_fields |
|
1643 | def test_get_new_should_mark_required_fields | |
1628 | cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
1644 | cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) | |
1629 | cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
1645 | cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) | |
1630 | WorkflowPermission.delete_all |
|
1646 | WorkflowPermission.delete_all | |
1631 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required') |
|
1647 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required') | |
1632 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required') |
|
1648 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required') | |
1633 | @request.session[:user_id] = 2 |
|
1649 | @request.session[:user_id] = 2 | |
1634 |
|
1650 | |||
1635 | get :new, :project_id => 1 |
|
1651 | get :new, :project_id => 1 | |
1636 | assert_response :success |
|
1652 | assert_response :success | |
1637 | assert_template 'new' |
|
1653 | assert_template 'new' | |
1638 |
|
1654 | |||
1639 | assert_select 'label[for=issue_start_date]' do |
|
1655 | assert_select 'label[for=issue_start_date]' do | |
1640 | assert_select 'span[class=required]', 0 |
|
1656 | assert_select 'span[class=required]', 0 | |
1641 | end |
|
1657 | end | |
1642 | assert_select 'label[for=issue_due_date]' do |
|
1658 | assert_select 'label[for=issue_due_date]' do | |
1643 | assert_select 'span[class=required]' |
|
1659 | assert_select 'span[class=required]' | |
1644 | end |
|
1660 | end | |
1645 | assert_select 'label[for=?]', "issue_custom_field_values_#{cf1.id}" do |
|
1661 | assert_select 'label[for=?]', "issue_custom_field_values_#{cf1.id}" do | |
1646 | assert_select 'span[class=required]', 0 |
|
1662 | assert_select 'span[class=required]', 0 | |
1647 | end |
|
1663 | end | |
1648 | assert_select 'label[for=?]', "issue_custom_field_values_#{cf2.id}" do |
|
1664 | assert_select 'label[for=?]', "issue_custom_field_values_#{cf2.id}" do | |
1649 | assert_select 'span[class=required]' |
|
1665 | assert_select 'span[class=required]' | |
1650 | end |
|
1666 | end | |
1651 | end |
|
1667 | end | |
1652 |
|
1668 | |||
1653 | def test_get_new_should_not_display_readonly_fields |
|
1669 | def test_get_new_should_not_display_readonly_fields | |
1654 | cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
1670 | cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) | |
1655 | cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
1671 | cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) | |
1656 | WorkflowPermission.delete_all |
|
1672 | WorkflowPermission.delete_all | |
1657 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly') |
|
1673 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly') | |
1658 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly') |
|
1674 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly') | |
1659 | @request.session[:user_id] = 2 |
|
1675 | @request.session[:user_id] = 2 | |
1660 |
|
1676 | |||
1661 | get :new, :project_id => 1 |
|
1677 | get :new, :project_id => 1 | |
1662 | assert_response :success |
|
1678 | assert_response :success | |
1663 | assert_template 'new' |
|
1679 | assert_template 'new' | |
1664 |
|
1680 | |||
1665 | assert_select 'input[name=?]', 'issue[start_date]' |
|
1681 | assert_select 'input[name=?]', 'issue[start_date]' | |
1666 | assert_select 'input[name=?]', 'issue[due_date]', 0 |
|
1682 | assert_select 'input[name=?]', 'issue[due_date]', 0 | |
1667 | assert_select 'input[name=?]', "issue[custom_field_values][#{cf1.id}]" |
|
1683 | assert_select 'input[name=?]', "issue[custom_field_values][#{cf1.id}]" | |
1668 | assert_select 'input[name=?]', "issue[custom_field_values][#{cf2.id}]", 0 |
|
1684 | assert_select 'input[name=?]', "issue[custom_field_values][#{cf2.id}]", 0 | |
1669 | end |
|
1685 | end | |
1670 |
|
1686 | |||
1671 | def test_get_new_without_tracker_id |
|
1687 | def test_get_new_without_tracker_id | |
1672 | @request.session[:user_id] = 2 |
|
1688 | @request.session[:user_id] = 2 | |
1673 | get :new, :project_id => 1 |
|
1689 | get :new, :project_id => 1 | |
1674 | assert_response :success |
|
1690 | assert_response :success | |
1675 | assert_template 'new' |
|
1691 | assert_template 'new' | |
1676 |
|
1692 | |||
1677 | issue = assigns(:issue) |
|
1693 | issue = assigns(:issue) | |
1678 | assert_not_nil issue |
|
1694 | assert_not_nil issue | |
1679 | assert_equal Project.find(1).trackers.first, issue.tracker |
|
1695 | assert_equal Project.find(1).trackers.first, issue.tracker | |
1680 | end |
|
1696 | end | |
1681 |
|
1697 | |||
1682 | def test_get_new_with_no_default_status_should_display_an_error |
|
1698 | def test_get_new_with_no_default_status_should_display_an_error | |
1683 | @request.session[:user_id] = 2 |
|
1699 | @request.session[:user_id] = 2 | |
1684 | IssueStatus.delete_all |
|
1700 | IssueStatus.delete_all | |
1685 |
|
1701 | |||
1686 | get :new, :project_id => 1 |
|
1702 | get :new, :project_id => 1 | |
1687 | assert_response 500 |
|
1703 | assert_response 500 | |
1688 | assert_error_tag :content => /No default issue/ |
|
1704 | assert_error_tag :content => /No default issue/ | |
1689 | end |
|
1705 | end | |
1690 |
|
1706 | |||
1691 | def test_get_new_with_no_tracker_should_display_an_error |
|
1707 | def test_get_new_with_no_tracker_should_display_an_error | |
1692 | @request.session[:user_id] = 2 |
|
1708 | @request.session[:user_id] = 2 | |
1693 | Tracker.delete_all |
|
1709 | Tracker.delete_all | |
1694 |
|
1710 | |||
1695 | get :new, :project_id => 1 |
|
1711 | get :new, :project_id => 1 | |
1696 | assert_response 500 |
|
1712 | assert_response 500 | |
1697 | assert_error_tag :content => /No tracker/ |
|
1713 | assert_error_tag :content => /No tracker/ | |
1698 | end |
|
1714 | end | |
1699 |
|
1715 | |||
1700 | def test_update_form_for_new_issue |
|
1716 | def test_update_form_for_new_issue | |
1701 | @request.session[:user_id] = 2 |
|
1717 | @request.session[:user_id] = 2 | |
1702 | xhr :post, :update_form, :project_id => 1, |
|
1718 | xhr :post, :update_form, :project_id => 1, | |
1703 | :issue => {:tracker_id => 2, |
|
1719 | :issue => {:tracker_id => 2, | |
1704 | :subject => 'This is the test_new issue', |
|
1720 | :subject => 'This is the test_new issue', | |
1705 | :description => 'This is the description', |
|
1721 | :description => 'This is the description', | |
1706 | :priority_id => 5} |
|
1722 | :priority_id => 5} | |
1707 | assert_response :success |
|
1723 | assert_response :success | |
1708 | assert_template 'update_form' |
|
1724 | assert_template 'update_form' | |
1709 | assert_template :partial => '_form' |
|
1725 | assert_template :partial => '_form' | |
1710 | assert_equal 'text/javascript', response.content_type |
|
1726 | assert_equal 'text/javascript', response.content_type | |
1711 |
|
1727 | |||
1712 | issue = assigns(:issue) |
|
1728 | issue = assigns(:issue) | |
1713 | assert_kind_of Issue, issue |
|
1729 | assert_kind_of Issue, issue | |
1714 | assert_equal 1, issue.project_id |
|
1730 | assert_equal 1, issue.project_id | |
1715 | assert_equal 2, issue.tracker_id |
|
1731 | assert_equal 2, issue.tracker_id | |
1716 | assert_equal 'This is the test_new issue', issue.subject |
|
1732 | assert_equal 'This is the test_new issue', issue.subject | |
1717 | end |
|
1733 | end | |
1718 |
|
1734 | |||
1719 | def test_update_form_for_new_issue_should_propose_transitions_based_on_initial_status |
|
1735 | def test_update_form_for_new_issue_should_propose_transitions_based_on_initial_status | |
1720 | @request.session[:user_id] = 2 |
|
1736 | @request.session[:user_id] = 2 | |
1721 | WorkflowTransition.delete_all |
|
1737 | WorkflowTransition.delete_all | |
1722 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2) |
|
1738 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2) | |
1723 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5) |
|
1739 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5) | |
1724 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4) |
|
1740 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4) | |
1725 |
|
1741 | |||
1726 | xhr :post, :update_form, :project_id => 1, |
|
1742 | xhr :post, :update_form, :project_id => 1, | |
1727 | :issue => {:tracker_id => 1, |
|
1743 | :issue => {:tracker_id => 1, | |
1728 | :status_id => 5, |
|
1744 | :status_id => 5, | |
1729 | :subject => 'This is an issue'} |
|
1745 | :subject => 'This is an issue'} | |
1730 |
|
1746 | |||
1731 | assert_equal 5, assigns(:issue).status_id |
|
1747 | assert_equal 5, assigns(:issue).status_id | |
1732 | assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort |
|
1748 | assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort | |
1733 | end |
|
1749 | end | |
1734 |
|
1750 | |||
1735 | def test_post_create |
|
1751 | def test_post_create | |
1736 | @request.session[:user_id] = 2 |
|
1752 | @request.session[:user_id] = 2 | |
1737 | assert_difference 'Issue.count' do |
|
1753 | assert_difference 'Issue.count' do | |
1738 | post :create, :project_id => 1, |
|
1754 | post :create, :project_id => 1, | |
1739 | :issue => {:tracker_id => 3, |
|
1755 | :issue => {:tracker_id => 3, | |
1740 | :status_id => 2, |
|
1756 | :status_id => 2, | |
1741 | :subject => 'This is the test_new issue', |
|
1757 | :subject => 'This is the test_new issue', | |
1742 | :description => 'This is the description', |
|
1758 | :description => 'This is the description', | |
1743 | :priority_id => 5, |
|
1759 | :priority_id => 5, | |
1744 | :start_date => '2010-11-07', |
|
1760 | :start_date => '2010-11-07', | |
1745 | :estimated_hours => '', |
|
1761 | :estimated_hours => '', | |
1746 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
1762 | :custom_field_values => {'2' => 'Value for field 2'}} | |
1747 | end |
|
1763 | end | |
1748 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
1764 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
1749 |
|
1765 | |||
1750 | issue = Issue.find_by_subject('This is the test_new issue') |
|
1766 | issue = Issue.find_by_subject('This is the test_new issue') | |
1751 | assert_not_nil issue |
|
1767 | assert_not_nil issue | |
1752 | assert_equal 2, issue.author_id |
|
1768 | assert_equal 2, issue.author_id | |
1753 | assert_equal 3, issue.tracker_id |
|
1769 | assert_equal 3, issue.tracker_id | |
1754 | assert_equal 2, issue.status_id |
|
1770 | assert_equal 2, issue.status_id | |
1755 | assert_equal Date.parse('2010-11-07'), issue.start_date |
|
1771 | assert_equal Date.parse('2010-11-07'), issue.start_date | |
1756 | assert_nil issue.estimated_hours |
|
1772 | assert_nil issue.estimated_hours | |
1757 | v = issue.custom_values.where(:custom_field_id => 2).first |
|
1773 | v = issue.custom_values.where(:custom_field_id => 2).first | |
1758 | assert_not_nil v |
|
1774 | assert_not_nil v | |
1759 | assert_equal 'Value for field 2', v.value |
|
1775 | assert_equal 'Value for field 2', v.value | |
1760 | end |
|
1776 | end | |
1761 |
|
1777 | |||
1762 | def test_post_new_with_group_assignment |
|
1778 | def test_post_new_with_group_assignment | |
1763 | group = Group.find(11) |
|
1779 | group = Group.find(11) | |
1764 | project = Project.find(1) |
|
1780 | project = Project.find(1) | |
1765 | project.members << Member.new(:principal => group, :roles => [Role.givable.first]) |
|
1781 | project.members << Member.new(:principal => group, :roles => [Role.givable.first]) | |
1766 |
|
1782 | |||
1767 | with_settings :issue_group_assignment => '1' do |
|
1783 | with_settings :issue_group_assignment => '1' do | |
1768 | @request.session[:user_id] = 2 |
|
1784 | @request.session[:user_id] = 2 | |
1769 | assert_difference 'Issue.count' do |
|
1785 | assert_difference 'Issue.count' do | |
1770 | post :create, :project_id => project.id, |
|
1786 | post :create, :project_id => project.id, | |
1771 | :issue => {:tracker_id => 3, |
|
1787 | :issue => {:tracker_id => 3, | |
1772 | :status_id => 1, |
|
1788 | :status_id => 1, | |
1773 | :subject => 'This is the test_new_with_group_assignment issue', |
|
1789 | :subject => 'This is the test_new_with_group_assignment issue', | |
1774 | :assigned_to_id => group.id} |
|
1790 | :assigned_to_id => group.id} | |
1775 | end |
|
1791 | end | |
1776 | end |
|
1792 | end | |
1777 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
1793 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
1778 |
|
1794 | |||
1779 | issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue') |
|
1795 | issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue') | |
1780 | assert_not_nil issue |
|
1796 | assert_not_nil issue | |
1781 | assert_equal group, issue.assigned_to |
|
1797 | assert_equal group, issue.assigned_to | |
1782 | end |
|
1798 | end | |
1783 |
|
1799 | |||
1784 | def test_post_create_without_start_date_and_default_start_date_is_not_creation_date |
|
1800 | def test_post_create_without_start_date_and_default_start_date_is_not_creation_date | |
1785 | with_settings :default_issue_start_date_to_creation_date => 0 do |
|
1801 | with_settings :default_issue_start_date_to_creation_date => 0 do | |
1786 | @request.session[:user_id] = 2 |
|
1802 | @request.session[:user_id] = 2 | |
1787 | assert_difference 'Issue.count' do |
|
1803 | assert_difference 'Issue.count' do | |
1788 | post :create, :project_id => 1, |
|
1804 | post :create, :project_id => 1, | |
1789 | :issue => {:tracker_id => 3, |
|
1805 | :issue => {:tracker_id => 3, | |
1790 | :status_id => 2, |
|
1806 | :status_id => 2, | |
1791 | :subject => 'This is the test_new issue', |
|
1807 | :subject => 'This is the test_new issue', | |
1792 | :description => 'This is the description', |
|
1808 | :description => 'This is the description', | |
1793 | :priority_id => 5, |
|
1809 | :priority_id => 5, | |
1794 | :estimated_hours => '', |
|
1810 | :estimated_hours => '', | |
1795 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
1811 | :custom_field_values => {'2' => 'Value for field 2'}} | |
1796 | end |
|
1812 | end | |
1797 | assert_redirected_to :controller => 'issues', :action => 'show', |
|
1813 | assert_redirected_to :controller => 'issues', :action => 'show', | |
1798 | :id => Issue.last.id |
|
1814 | :id => Issue.last.id | |
1799 | issue = Issue.find_by_subject('This is the test_new issue') |
|
1815 | issue = Issue.find_by_subject('This is the test_new issue') | |
1800 | assert_not_nil issue |
|
1816 | assert_not_nil issue | |
1801 | assert_nil issue.start_date |
|
1817 | assert_nil issue.start_date | |
1802 | end |
|
1818 | end | |
1803 | end |
|
1819 | end | |
1804 |
|
1820 | |||
1805 | def test_post_create_without_start_date_and_default_start_date_is_creation_date |
|
1821 | def test_post_create_without_start_date_and_default_start_date_is_creation_date | |
1806 | with_settings :default_issue_start_date_to_creation_date => 1 do |
|
1822 | with_settings :default_issue_start_date_to_creation_date => 1 do | |
1807 | @request.session[:user_id] = 2 |
|
1823 | @request.session[:user_id] = 2 | |
1808 | assert_difference 'Issue.count' do |
|
1824 | assert_difference 'Issue.count' do | |
1809 | post :create, :project_id => 1, |
|
1825 | post :create, :project_id => 1, | |
1810 | :issue => {:tracker_id => 3, |
|
1826 | :issue => {:tracker_id => 3, | |
1811 | :status_id => 2, |
|
1827 | :status_id => 2, | |
1812 | :subject => 'This is the test_new issue', |
|
1828 | :subject => 'This is the test_new issue', | |
1813 | :description => 'This is the description', |
|
1829 | :description => 'This is the description', | |
1814 | :priority_id => 5, |
|
1830 | :priority_id => 5, | |
1815 | :estimated_hours => '', |
|
1831 | :estimated_hours => '', | |
1816 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
1832 | :custom_field_values => {'2' => 'Value for field 2'}} | |
1817 | end |
|
1833 | end | |
1818 | assert_redirected_to :controller => 'issues', :action => 'show', |
|
1834 | assert_redirected_to :controller => 'issues', :action => 'show', | |
1819 | :id => Issue.last.id |
|
1835 | :id => Issue.last.id | |
1820 | issue = Issue.find_by_subject('This is the test_new issue') |
|
1836 | issue = Issue.find_by_subject('This is the test_new issue') | |
1821 | assert_not_nil issue |
|
1837 | assert_not_nil issue | |
1822 | assert_equal Date.today, issue.start_date |
|
1838 | assert_equal Date.today, issue.start_date | |
1823 | end |
|
1839 | end | |
1824 | end |
|
1840 | end | |
1825 |
|
1841 | |||
1826 | def test_post_create_and_continue |
|
1842 | def test_post_create_and_continue | |
1827 | @request.session[:user_id] = 2 |
|
1843 | @request.session[:user_id] = 2 | |
1828 | assert_difference 'Issue.count' do |
|
1844 | assert_difference 'Issue.count' do | |
1829 | post :create, :project_id => 1, |
|
1845 | post :create, :project_id => 1, | |
1830 | :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5}, |
|
1846 | :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5}, | |
1831 | :continue => '' |
|
1847 | :continue => '' | |
1832 | end |
|
1848 | end | |
1833 |
|
1849 | |||
1834 | issue = Issue.order('id DESC').first |
|
1850 | issue = Issue.order('id DESC').first | |
1835 | assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3} |
|
1851 | assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3} | |
1836 | assert_not_nil flash[:notice], "flash was not set" |
|
1852 | assert_not_nil flash[:notice], "flash was not set" | |
1837 | assert_include %|<a href="/issues/#{issue.id}" title="This is first issue">##{issue.id}</a>|, flash[:notice], "issue link not found in the flash message" |
|
1853 | assert_include %|<a href="/issues/#{issue.id}" title="This is first issue">##{issue.id}</a>|, flash[:notice], "issue link not found in the flash message" | |
1838 | end |
|
1854 | end | |
1839 |
|
1855 | |||
1840 | def test_post_create_without_custom_fields_param |
|
1856 | def test_post_create_without_custom_fields_param | |
1841 | @request.session[:user_id] = 2 |
|
1857 | @request.session[:user_id] = 2 | |
1842 | assert_difference 'Issue.count' do |
|
1858 | assert_difference 'Issue.count' do | |
1843 | post :create, :project_id => 1, |
|
1859 | post :create, :project_id => 1, | |
1844 | :issue => {:tracker_id => 1, |
|
1860 | :issue => {:tracker_id => 1, | |
1845 | :subject => 'This is the test_new issue', |
|
1861 | :subject => 'This is the test_new issue', | |
1846 | :description => 'This is the description', |
|
1862 | :description => 'This is the description', | |
1847 | :priority_id => 5} |
|
1863 | :priority_id => 5} | |
1848 | end |
|
1864 | end | |
1849 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
1865 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
1850 | end |
|
1866 | end | |
1851 |
|
1867 | |||
1852 | def test_post_create_with_multi_custom_field |
|
1868 | def test_post_create_with_multi_custom_field | |
1853 | field = IssueCustomField.find_by_name('Database') |
|
1869 | field = IssueCustomField.find_by_name('Database') | |
1854 | field.update_attribute(:multiple, true) |
|
1870 | field.update_attribute(:multiple, true) | |
1855 |
|
1871 | |||
1856 | @request.session[:user_id] = 2 |
|
1872 | @request.session[:user_id] = 2 | |
1857 | assert_difference 'Issue.count' do |
|
1873 | assert_difference 'Issue.count' do | |
1858 | post :create, :project_id => 1, |
|
1874 | post :create, :project_id => 1, | |
1859 | :issue => {:tracker_id => 1, |
|
1875 | :issue => {:tracker_id => 1, | |
1860 | :subject => 'This is the test_new issue', |
|
1876 | :subject => 'This is the test_new issue', | |
1861 | :description => 'This is the description', |
|
1877 | :description => 'This is the description', | |
1862 | :priority_id => 5, |
|
1878 | :priority_id => 5, | |
1863 | :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}} |
|
1879 | :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}} | |
1864 | end |
|
1880 | end | |
1865 | assert_response 302 |
|
1881 | assert_response 302 | |
1866 | issue = Issue.order('id DESC').first |
|
1882 | issue = Issue.order('id DESC').first | |
1867 | assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort |
|
1883 | assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort | |
1868 | end |
|
1884 | end | |
1869 |
|
1885 | |||
1870 | def test_post_create_with_empty_multi_custom_field |
|
1886 | def test_post_create_with_empty_multi_custom_field | |
1871 | field = IssueCustomField.find_by_name('Database') |
|
1887 | field = IssueCustomField.find_by_name('Database') | |
1872 | field.update_attribute(:multiple, true) |
|
1888 | field.update_attribute(:multiple, true) | |
1873 |
|
1889 | |||
1874 | @request.session[:user_id] = 2 |
|
1890 | @request.session[:user_id] = 2 | |
1875 | assert_difference 'Issue.count' do |
|
1891 | assert_difference 'Issue.count' do | |
1876 | post :create, :project_id => 1, |
|
1892 | post :create, :project_id => 1, | |
1877 | :issue => {:tracker_id => 1, |
|
1893 | :issue => {:tracker_id => 1, | |
1878 | :subject => 'This is the test_new issue', |
|
1894 | :subject => 'This is the test_new issue', | |
1879 | :description => 'This is the description', |
|
1895 | :description => 'This is the description', | |
1880 | :priority_id => 5, |
|
1896 | :priority_id => 5, | |
1881 | :custom_field_values => {'1' => ['']}} |
|
1897 | :custom_field_values => {'1' => ['']}} | |
1882 | end |
|
1898 | end | |
1883 | assert_response 302 |
|
1899 | assert_response 302 | |
1884 | issue = Issue.order('id DESC').first |
|
1900 | issue = Issue.order('id DESC').first | |
1885 | assert_equal [''], issue.custom_field_value(1).sort |
|
1901 | assert_equal [''], issue.custom_field_value(1).sort | |
1886 | end |
|
1902 | end | |
1887 |
|
1903 | |||
1888 | def test_post_create_with_multi_user_custom_field |
|
1904 | def test_post_create_with_multi_user_custom_field | |
1889 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, |
|
1905 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, | |
1890 | :tracker_ids => [1], :is_for_all => true) |
|
1906 | :tracker_ids => [1], :is_for_all => true) | |
1891 |
|
1907 | |||
1892 | @request.session[:user_id] = 2 |
|
1908 | @request.session[:user_id] = 2 | |
1893 | assert_difference 'Issue.count' do |
|
1909 | assert_difference 'Issue.count' do | |
1894 | post :create, :project_id => 1, |
|
1910 | post :create, :project_id => 1, | |
1895 | :issue => {:tracker_id => 1, |
|
1911 | :issue => {:tracker_id => 1, | |
1896 | :subject => 'This is the test_new issue', |
|
1912 | :subject => 'This is the test_new issue', | |
1897 | :description => 'This is the description', |
|
1913 | :description => 'This is the description', | |
1898 | :priority_id => 5, |
|
1914 | :priority_id => 5, | |
1899 | :custom_field_values => {field.id.to_s => ['', '2', '3']}} |
|
1915 | :custom_field_values => {field.id.to_s => ['', '2', '3']}} | |
1900 | end |
|
1916 | end | |
1901 | assert_response 302 |
|
1917 | assert_response 302 | |
1902 | issue = Issue.order('id DESC').first |
|
1918 | issue = Issue.order('id DESC').first | |
1903 | assert_equal ['2', '3'], issue.custom_field_value(field).sort |
|
1919 | assert_equal ['2', '3'], issue.custom_field_value(field).sort | |
1904 | end |
|
1920 | end | |
1905 |
|
1921 | |||
1906 | def test_post_create_with_required_custom_field_and_without_custom_fields_param |
|
1922 | def test_post_create_with_required_custom_field_and_without_custom_fields_param | |
1907 | field = IssueCustomField.find_by_name('Database') |
|
1923 | field = IssueCustomField.find_by_name('Database') | |
1908 | field.update_attribute(:is_required, true) |
|
1924 | field.update_attribute(:is_required, true) | |
1909 |
|
1925 | |||
1910 | @request.session[:user_id] = 2 |
|
1926 | @request.session[:user_id] = 2 | |
1911 | assert_no_difference 'Issue.count' do |
|
1927 | assert_no_difference 'Issue.count' do | |
1912 | post :create, :project_id => 1, |
|
1928 | post :create, :project_id => 1, | |
1913 | :issue => {:tracker_id => 1, |
|
1929 | :issue => {:tracker_id => 1, | |
1914 | :subject => 'This is the test_new issue', |
|
1930 | :subject => 'This is the test_new issue', | |
1915 | :description => 'This is the description', |
|
1931 | :description => 'This is the description', | |
1916 | :priority_id => 5} |
|
1932 | :priority_id => 5} | |
1917 | end |
|
1933 | end | |
1918 | assert_response :success |
|
1934 | assert_response :success | |
1919 | assert_template 'new' |
|
1935 | assert_template 'new' | |
1920 | issue = assigns(:issue) |
|
1936 | issue = assigns(:issue) | |
1921 | assert_not_nil issue |
|
1937 | assert_not_nil issue | |
1922 | assert_error_tag :content => /Database #{ESCAPED_CANT} be blank/ |
|
1938 | assert_error_tag :content => /Database #{ESCAPED_CANT} be blank/ | |
1923 | end |
|
1939 | end | |
1924 |
|
1940 | |||
1925 | def test_create_should_validate_required_fields |
|
1941 | def test_create_should_validate_required_fields | |
1926 | cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
1942 | cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) | |
1927 | cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
1943 | cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) | |
1928 | WorkflowPermission.delete_all |
|
1944 | WorkflowPermission.delete_all | |
1929 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'required') |
|
1945 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'required') | |
1930 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required') |
|
1946 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required') | |
1931 | @request.session[:user_id] = 2 |
|
1947 | @request.session[:user_id] = 2 | |
1932 |
|
1948 | |||
1933 | assert_no_difference 'Issue.count' do |
|
1949 | assert_no_difference 'Issue.count' do | |
1934 | post :create, :project_id => 1, :issue => { |
|
1950 | post :create, :project_id => 1, :issue => { | |
1935 | :tracker_id => 2, |
|
1951 | :tracker_id => 2, | |
1936 | :status_id => 1, |
|
1952 | :status_id => 1, | |
1937 | :subject => 'Test', |
|
1953 | :subject => 'Test', | |
1938 | :start_date => '', |
|
1954 | :start_date => '', | |
1939 | :due_date => '', |
|
1955 | :due_date => '', | |
1940 | :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ''} |
|
1956 | :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ''} | |
1941 | } |
|
1957 | } | |
1942 | assert_response :success |
|
1958 | assert_response :success | |
1943 | assert_template 'new' |
|
1959 | assert_template 'new' | |
1944 | end |
|
1960 | end | |
1945 |
|
1961 | |||
1946 | assert_error_tag :content => /Due date #{ESCAPED_CANT} be blank/i |
|
1962 | assert_error_tag :content => /Due date #{ESCAPED_CANT} be blank/i | |
1947 | assert_error_tag :content => /Bar #{ESCAPED_CANT} be blank/i |
|
1963 | assert_error_tag :content => /Bar #{ESCAPED_CANT} be blank/i | |
1948 | end |
|
1964 | end | |
1949 |
|
1965 | |||
1950 | def test_create_should_ignore_readonly_fields |
|
1966 | def test_create_should_ignore_readonly_fields | |
1951 | cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
1967 | cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) | |
1952 | cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) |
|
1968 | cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) | |
1953 | WorkflowPermission.delete_all |
|
1969 | WorkflowPermission.delete_all | |
1954 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'readonly') |
|
1970 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'readonly') | |
1955 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly') |
|
1971 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly') | |
1956 | @request.session[:user_id] = 2 |
|
1972 | @request.session[:user_id] = 2 | |
1957 |
|
1973 | |||
1958 | assert_difference 'Issue.count' do |
|
1974 | assert_difference 'Issue.count' do | |
1959 | post :create, :project_id => 1, :issue => { |
|
1975 | post :create, :project_id => 1, :issue => { | |
1960 | :tracker_id => 2, |
|
1976 | :tracker_id => 2, | |
1961 | :status_id => 1, |
|
1977 | :status_id => 1, | |
1962 | :subject => 'Test', |
|
1978 | :subject => 'Test', | |
1963 | :start_date => '2012-07-14', |
|
1979 | :start_date => '2012-07-14', | |
1964 | :due_date => '2012-07-16', |
|
1980 | :due_date => '2012-07-16', | |
1965 | :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'} |
|
1981 | :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'} | |
1966 | } |
|
1982 | } | |
1967 | assert_response 302 |
|
1983 | assert_response 302 | |
1968 | end |
|
1984 | end | |
1969 |
|
1985 | |||
1970 | issue = Issue.order('id DESC').first |
|
1986 | issue = Issue.order('id DESC').first | |
1971 | assert_equal Date.parse('2012-07-14'), issue.start_date |
|
1987 | assert_equal Date.parse('2012-07-14'), issue.start_date | |
1972 | assert_nil issue.due_date |
|
1988 | assert_nil issue.due_date | |
1973 | assert_equal 'value1', issue.custom_field_value(cf1) |
|
1989 | assert_equal 'value1', issue.custom_field_value(cf1) | |
1974 | assert_nil issue.custom_field_value(cf2) |
|
1990 | assert_nil issue.custom_field_value(cf2) | |
1975 | end |
|
1991 | end | |
1976 |
|
1992 | |||
1977 | def test_post_create_with_watchers |
|
1993 | def test_post_create_with_watchers | |
1978 | @request.session[:user_id] = 2 |
|
1994 | @request.session[:user_id] = 2 | |
1979 | ActionMailer::Base.deliveries.clear |
|
1995 | ActionMailer::Base.deliveries.clear | |
1980 |
|
1996 | |||
1981 | assert_difference 'Watcher.count', 2 do |
|
1997 | assert_difference 'Watcher.count', 2 do | |
1982 | post :create, :project_id => 1, |
|
1998 | post :create, :project_id => 1, | |
1983 | :issue => {:tracker_id => 1, |
|
1999 | :issue => {:tracker_id => 1, | |
1984 | :subject => 'This is a new issue with watchers', |
|
2000 | :subject => 'This is a new issue with watchers', | |
1985 | :description => 'This is the description', |
|
2001 | :description => 'This is the description', | |
1986 | :priority_id => 5, |
|
2002 | :priority_id => 5, | |
1987 | :watcher_user_ids => ['2', '3']} |
|
2003 | :watcher_user_ids => ['2', '3']} | |
1988 | end |
|
2004 | end | |
1989 | issue = Issue.find_by_subject('This is a new issue with watchers') |
|
2005 | issue = Issue.find_by_subject('This is a new issue with watchers') | |
1990 | assert_not_nil issue |
|
2006 | assert_not_nil issue | |
1991 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
2007 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue | |
1992 |
|
2008 | |||
1993 | # Watchers added |
|
2009 | # Watchers added | |
1994 | assert_equal [2, 3], issue.watcher_user_ids.sort |
|
2010 | assert_equal [2, 3], issue.watcher_user_ids.sort | |
1995 | assert issue.watched_by?(User.find(3)) |
|
2011 | assert issue.watched_by?(User.find(3)) | |
1996 | # Watchers notified |
|
2012 | # Watchers notified | |
1997 | mail = ActionMailer::Base.deliveries.last |
|
2013 | mail = ActionMailer::Base.deliveries.last | |
1998 | assert_not_nil mail |
|
2014 | assert_not_nil mail | |
1999 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) |
|
2015 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) | |
2000 | end |
|
2016 | end | |
2001 |
|
2017 | |||
2002 | def test_post_create_subissue |
|
2018 | def test_post_create_subissue | |
2003 | @request.session[:user_id] = 2 |
|
2019 | @request.session[:user_id] = 2 | |
2004 |
|
2020 | |||
2005 | assert_difference 'Issue.count' do |
|
2021 | assert_difference 'Issue.count' do | |
2006 | post :create, :project_id => 1, |
|
2022 | post :create, :project_id => 1, | |
2007 | :issue => {:tracker_id => 1, |
|
2023 | :issue => {:tracker_id => 1, | |
2008 | :subject => 'This is a child issue', |
|
2024 | :subject => 'This is a child issue', | |
2009 | :parent_issue_id => '2'} |
|
2025 | :parent_issue_id => '2'} | |
2010 | assert_response 302 |
|
2026 | assert_response 302 | |
2011 | end |
|
2027 | end | |
2012 | issue = Issue.order('id DESC').first |
|
2028 | issue = Issue.order('id DESC').first | |
2013 | assert_equal Issue.find(2), issue.parent |
|
2029 | assert_equal Issue.find(2), issue.parent | |
2014 | end |
|
2030 | end | |
2015 |
|
2031 | |||
2016 | def test_post_create_subissue_with_sharp_parent_id |
|
2032 | def test_post_create_subissue_with_sharp_parent_id | |
2017 | @request.session[:user_id] = 2 |
|
2033 | @request.session[:user_id] = 2 | |
2018 |
|
2034 | |||
2019 | assert_difference 'Issue.count' do |
|
2035 | assert_difference 'Issue.count' do | |
2020 | post :create, :project_id => 1, |
|
2036 | post :create, :project_id => 1, | |
2021 | :issue => {:tracker_id => 1, |
|
2037 | :issue => {:tracker_id => 1, | |
2022 | :subject => 'This is a child issue', |
|
2038 | :subject => 'This is a child issue', | |
2023 | :parent_issue_id => '#2'} |
|
2039 | :parent_issue_id => '#2'} | |
2024 | assert_response 302 |
|
2040 | assert_response 302 | |
2025 | end |
|
2041 | end | |
2026 | issue = Issue.order('id DESC').first |
|
2042 | issue = Issue.order('id DESC').first | |
2027 | assert_equal Issue.find(2), issue.parent |
|
2043 | assert_equal Issue.find(2), issue.parent | |
2028 | end |
|
2044 | end | |
2029 |
|
2045 | |||
2030 | def test_post_create_subissue_with_non_visible_parent_id_should_not_validate |
|
2046 | def test_post_create_subissue_with_non_visible_parent_id_should_not_validate | |
2031 | @request.session[:user_id] = 2 |
|
2047 | @request.session[:user_id] = 2 | |
2032 |
|
2048 | |||
2033 | assert_no_difference 'Issue.count' do |
|
2049 | assert_no_difference 'Issue.count' do | |
2034 | post :create, :project_id => 1, |
|
2050 | post :create, :project_id => 1, | |
2035 | :issue => {:tracker_id => 1, |
|
2051 | :issue => {:tracker_id => 1, | |
2036 | :subject => 'This is a child issue', |
|
2052 | :subject => 'This is a child issue', | |
2037 | :parent_issue_id => '4'} |
|
2053 | :parent_issue_id => '4'} | |
2038 |
|
2054 | |||
2039 | assert_response :success |
|
2055 | assert_response :success | |
2040 | assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '4' |
|
2056 | assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '4' | |
2041 | assert_error_tag :content => /Parent task is invalid/i |
|
2057 | assert_error_tag :content => /Parent task is invalid/i | |
2042 | end |
|
2058 | end | |
2043 | end |
|
2059 | end | |
2044 |
|
2060 | |||
2045 | def test_post_create_subissue_with_non_numeric_parent_id_should_not_validate |
|
2061 | def test_post_create_subissue_with_non_numeric_parent_id_should_not_validate | |
2046 | @request.session[:user_id] = 2 |
|
2062 | @request.session[:user_id] = 2 | |
2047 |
|
2063 | |||
2048 | assert_no_difference 'Issue.count' do |
|
2064 | assert_no_difference 'Issue.count' do | |
2049 | post :create, :project_id => 1, |
|
2065 | post :create, :project_id => 1, | |
2050 | :issue => {:tracker_id => 1, |
|
2066 | :issue => {:tracker_id => 1, | |
2051 | :subject => 'This is a child issue', |
|
2067 | :subject => 'This is a child issue', | |
2052 | :parent_issue_id => '01ABC'} |
|
2068 | :parent_issue_id => '01ABC'} | |
2053 |
|
2069 | |||
2054 | assert_response :success |
|
2070 | assert_response :success | |
2055 | assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '01ABC' |
|
2071 | assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '01ABC' | |
2056 | assert_error_tag :content => /Parent task is invalid/i |
|
2072 | assert_error_tag :content => /Parent task is invalid/i | |
2057 | end |
|
2073 | end | |
2058 | end |
|
2074 | end | |
2059 |
|
2075 | |||
2060 | def test_post_create_private |
|
2076 | def test_post_create_private | |
2061 | @request.session[:user_id] = 2 |
|
2077 | @request.session[:user_id] = 2 | |
2062 |
|
2078 | |||
2063 | assert_difference 'Issue.count' do |
|
2079 | assert_difference 'Issue.count' do | |
2064 | post :create, :project_id => 1, |
|
2080 | post :create, :project_id => 1, | |
2065 | :issue => {:tracker_id => 1, |
|
2081 | :issue => {:tracker_id => 1, | |
2066 | :subject => 'This is a private issue', |
|
2082 | :subject => 'This is a private issue', | |
2067 | :is_private => '1'} |
|
2083 | :is_private => '1'} | |
2068 | end |
|
2084 | end | |
2069 | issue = Issue.order('id DESC').first |
|
2085 | issue = Issue.order('id DESC').first | |
2070 | assert issue.is_private? |
|
2086 | assert issue.is_private? | |
2071 | end |
|
2087 | end | |
2072 |
|
2088 | |||
2073 | def test_post_create_private_with_set_own_issues_private_permission |
|
2089 | def test_post_create_private_with_set_own_issues_private_permission | |
2074 | role = Role.find(1) |
|
2090 | role = Role.find(1) | |
2075 | role.remove_permission! :set_issues_private |
|
2091 | role.remove_permission! :set_issues_private | |
2076 | role.add_permission! :set_own_issues_private |
|
2092 | role.add_permission! :set_own_issues_private | |
2077 |
|
2093 | |||
2078 | @request.session[:user_id] = 2 |
|
2094 | @request.session[:user_id] = 2 | |
2079 |
|
2095 | |||
2080 | assert_difference 'Issue.count' do |
|
2096 | assert_difference 'Issue.count' do | |
2081 | post :create, :project_id => 1, |
|
2097 | post :create, :project_id => 1, | |
2082 | :issue => {:tracker_id => 1, |
|
2098 | :issue => {:tracker_id => 1, | |
2083 | :subject => 'This is a private issue', |
|
2099 | :subject => 'This is a private issue', | |
2084 | :is_private => '1'} |
|
2100 | :is_private => '1'} | |
2085 | end |
|
2101 | end | |
2086 | issue = Issue.order('id DESC').first |
|
2102 | issue = Issue.order('id DESC').first | |
2087 | assert issue.is_private? |
|
2103 | assert issue.is_private? | |
2088 | end |
|
2104 | end | |
2089 |
|
2105 | |||
2090 | def test_post_create_should_send_a_notification |
|
2106 | def test_post_create_should_send_a_notification | |
2091 | ActionMailer::Base.deliveries.clear |
|
2107 | ActionMailer::Base.deliveries.clear | |
2092 | @request.session[:user_id] = 2 |
|
2108 | @request.session[:user_id] = 2 | |
2093 | assert_difference 'Issue.count' do |
|
2109 | assert_difference 'Issue.count' do | |
2094 | post :create, :project_id => 1, |
|
2110 | post :create, :project_id => 1, | |
2095 | :issue => {:tracker_id => 3, |
|
2111 | :issue => {:tracker_id => 3, | |
2096 | :subject => 'This is the test_new issue', |
|
2112 | :subject => 'This is the test_new issue', | |
2097 | :description => 'This is the description', |
|
2113 | :description => 'This is the description', | |
2098 | :priority_id => 5, |
|
2114 | :priority_id => 5, | |
2099 | :estimated_hours => '', |
|
2115 | :estimated_hours => '', | |
2100 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
2116 | :custom_field_values => {'2' => 'Value for field 2'}} | |
2101 | end |
|
2117 | end | |
2102 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
2118 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
2103 |
|
2119 | |||
2104 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
2120 | assert_equal 1, ActionMailer::Base.deliveries.size | |
2105 | end |
|
2121 | end | |
2106 |
|
2122 | |||
2107 | def test_post_create_should_preserve_fields_values_on_validation_failure |
|
2123 | def test_post_create_should_preserve_fields_values_on_validation_failure | |
2108 | @request.session[:user_id] = 2 |
|
2124 | @request.session[:user_id] = 2 | |
2109 | post :create, :project_id => 1, |
|
2125 | post :create, :project_id => 1, | |
2110 | :issue => {:tracker_id => 1, |
|
2126 | :issue => {:tracker_id => 1, | |
2111 | # empty subject |
|
2127 | # empty subject | |
2112 | :subject => '', |
|
2128 | :subject => '', | |
2113 | :description => 'This is a description', |
|
2129 | :description => 'This is a description', | |
2114 | :priority_id => 6, |
|
2130 | :priority_id => 6, | |
2115 | :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} |
|
2131 | :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} | |
2116 | assert_response :success |
|
2132 | assert_response :success | |
2117 | assert_template 'new' |
|
2133 | assert_template 'new' | |
2118 |
|
2134 | |||
2119 | assert_select 'textarea[name=?]', 'issue[description]', :text => 'This is a description' |
|
2135 | assert_select 'textarea[name=?]', 'issue[description]', :text => 'This is a description' | |
2120 | assert_select 'select[name=?]', 'issue[priority_id]' do |
|
2136 | assert_select 'select[name=?]', 'issue[priority_id]' do | |
2121 | assert_select 'option[value=6][selected=selected]', :text => 'High' |
|
2137 | assert_select 'option[value=6][selected=selected]', :text => 'High' | |
2122 | end |
|
2138 | end | |
2123 | # Custom fields |
|
2139 | # Custom fields | |
2124 | assert_select 'select[name=?]', 'issue[custom_field_values][1]' do |
|
2140 | assert_select 'select[name=?]', 'issue[custom_field_values][1]' do | |
2125 | assert_select 'option[value=Oracle][selected=selected]', :text => 'Oracle' |
|
2141 | assert_select 'option[value=Oracle][selected=selected]', :text => 'Oracle' | |
2126 | end |
|
2142 | end | |
2127 | assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Value for field 2' |
|
2143 | assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Value for field 2' | |
2128 | end |
|
2144 | end | |
2129 |
|
2145 | |||
2130 | def test_post_create_with_failure_should_preserve_watchers |
|
2146 | def test_post_create_with_failure_should_preserve_watchers | |
2131 | assert !User.find(8).member_of?(Project.find(1)) |
|
2147 | assert !User.find(8).member_of?(Project.find(1)) | |
2132 |
|
2148 | |||
2133 | @request.session[:user_id] = 2 |
|
2149 | @request.session[:user_id] = 2 | |
2134 | post :create, :project_id => 1, |
|
2150 | post :create, :project_id => 1, | |
2135 | :issue => {:tracker_id => 1, |
|
2151 | :issue => {:tracker_id => 1, | |
2136 | :watcher_user_ids => ['3', '8']} |
|
2152 | :watcher_user_ids => ['3', '8']} | |
2137 | assert_response :success |
|
2153 | assert_response :success | |
2138 | assert_template 'new' |
|
2154 | assert_template 'new' | |
2139 |
|
2155 | |||
2140 | assert_select 'input[name=?][value=2]:not(checked)', 'issue[watcher_user_ids][]' |
|
2156 | assert_select 'input[name=?][value=2]:not(checked)', 'issue[watcher_user_ids][]' | |
2141 | assert_select 'input[name=?][value=3][checked=checked]', 'issue[watcher_user_ids][]' |
|
2157 | assert_select 'input[name=?][value=3][checked=checked]', 'issue[watcher_user_ids][]' | |
2142 | assert_select 'input[name=?][value=8][checked=checked]', 'issue[watcher_user_ids][]' |
|
2158 | assert_select 'input[name=?][value=8][checked=checked]', 'issue[watcher_user_ids][]' | |
2143 | end |
|
2159 | end | |
2144 |
|
2160 | |||
2145 | def test_post_create_should_ignore_non_safe_attributes |
|
2161 | def test_post_create_should_ignore_non_safe_attributes | |
2146 | @request.session[:user_id] = 2 |
|
2162 | @request.session[:user_id] = 2 | |
2147 | assert_nothing_raised do |
|
2163 | assert_nothing_raised do | |
2148 | post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" } |
|
2164 | post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" } | |
2149 | end |
|
2165 | end | |
2150 | end |
|
2166 | end | |
2151 |
|
2167 | |||
2152 | def test_post_create_with_attachment |
|
2168 | def test_post_create_with_attachment | |
2153 | set_tmp_attachments_directory |
|
2169 | set_tmp_attachments_directory | |
2154 | @request.session[:user_id] = 2 |
|
2170 | @request.session[:user_id] = 2 | |
2155 |
|
2171 | |||
2156 | assert_difference 'Issue.count' do |
|
2172 | assert_difference 'Issue.count' do | |
2157 | assert_difference 'Attachment.count' do |
|
2173 | assert_difference 'Attachment.count' do | |
2158 | post :create, :project_id => 1, |
|
2174 | post :create, :project_id => 1, | |
2159 | :issue => { :tracker_id => '1', :subject => 'With attachment' }, |
|
2175 | :issue => { :tracker_id => '1', :subject => 'With attachment' }, | |
2160 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
2176 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | |
2161 | end |
|
2177 | end | |
2162 | end |
|
2178 | end | |
2163 |
|
2179 | |||
2164 | issue = Issue.order('id DESC').first |
|
2180 | issue = Issue.order('id DESC').first | |
2165 | attachment = Attachment.order('id DESC').first |
|
2181 | attachment = Attachment.order('id DESC').first | |
2166 |
|
2182 | |||
2167 | assert_equal issue, attachment.container |
|
2183 | assert_equal issue, attachment.container | |
2168 | assert_equal 2, attachment.author_id |
|
2184 | assert_equal 2, attachment.author_id | |
2169 | assert_equal 'testfile.txt', attachment.filename |
|
2185 | assert_equal 'testfile.txt', attachment.filename | |
2170 | assert_equal 'text/plain', attachment.content_type |
|
2186 | assert_equal 'text/plain', attachment.content_type | |
2171 | assert_equal 'test file', attachment.description |
|
2187 | assert_equal 'test file', attachment.description | |
2172 | assert_equal 59, attachment.filesize |
|
2188 | assert_equal 59, attachment.filesize | |
2173 | assert File.exists?(attachment.diskfile) |
|
2189 | assert File.exists?(attachment.diskfile) | |
2174 | assert_equal 59, File.size(attachment.diskfile) |
|
2190 | assert_equal 59, File.size(attachment.diskfile) | |
2175 | end |
|
2191 | end | |
2176 |
|
2192 | |||
2177 | def test_post_create_with_attachment_should_notify_with_attachments |
|
2193 | def test_post_create_with_attachment_should_notify_with_attachments | |
2178 | ActionMailer::Base.deliveries.clear |
|
2194 | ActionMailer::Base.deliveries.clear | |
2179 | set_tmp_attachments_directory |
|
2195 | set_tmp_attachments_directory | |
2180 | @request.session[:user_id] = 2 |
|
2196 | @request.session[:user_id] = 2 | |
2181 |
|
2197 | |||
2182 | with_settings :host_name => 'mydomain.foo', :protocol => 'http' do |
|
2198 | with_settings :host_name => 'mydomain.foo', :protocol => 'http' do | |
2183 | assert_difference 'Issue.count' do |
|
2199 | assert_difference 'Issue.count' do | |
2184 | post :create, :project_id => 1, |
|
2200 | post :create, :project_id => 1, | |
2185 | :issue => { :tracker_id => '1', :subject => 'With attachment' }, |
|
2201 | :issue => { :tracker_id => '1', :subject => 'With attachment' }, | |
2186 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
2202 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | |
2187 | end |
|
2203 | end | |
2188 | end |
|
2204 | end | |
2189 |
|
2205 | |||
2190 | assert_not_nil ActionMailer::Base.deliveries.last |
|
2206 | assert_not_nil ActionMailer::Base.deliveries.last | |
2191 | assert_select_email do |
|
2207 | assert_select_email do | |
2192 | assert_select 'a[href^=?]', 'http://mydomain.foo/attachments/download', 'testfile.txt' |
|
2208 | assert_select 'a[href^=?]', 'http://mydomain.foo/attachments/download', 'testfile.txt' | |
2193 | end |
|
2209 | end | |
2194 | end |
|
2210 | end | |
2195 |
|
2211 | |||
2196 | def test_post_create_with_failure_should_save_attachments |
|
2212 | def test_post_create_with_failure_should_save_attachments | |
2197 | set_tmp_attachments_directory |
|
2213 | set_tmp_attachments_directory | |
2198 | @request.session[:user_id] = 2 |
|
2214 | @request.session[:user_id] = 2 | |
2199 |
|
2215 | |||
2200 | assert_no_difference 'Issue.count' do |
|
2216 | assert_no_difference 'Issue.count' do | |
2201 | assert_difference 'Attachment.count' do |
|
2217 | assert_difference 'Attachment.count' do | |
2202 | post :create, :project_id => 1, |
|
2218 | post :create, :project_id => 1, | |
2203 | :issue => { :tracker_id => '1', :subject => '' }, |
|
2219 | :issue => { :tracker_id => '1', :subject => '' }, | |
2204 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
2220 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | |
2205 | assert_response :success |
|
2221 | assert_response :success | |
2206 | assert_template 'new' |
|
2222 | assert_template 'new' | |
2207 | end |
|
2223 | end | |
2208 | end |
|
2224 | end | |
2209 |
|
2225 | |||
2210 | attachment = Attachment.order('id DESC').first |
|
2226 | attachment = Attachment.order('id DESC').first | |
2211 | assert_equal 'testfile.txt', attachment.filename |
|
2227 | assert_equal 'testfile.txt', attachment.filename | |
2212 | assert File.exists?(attachment.diskfile) |
|
2228 | assert File.exists?(attachment.diskfile) | |
2213 | assert_nil attachment.container |
|
2229 | assert_nil attachment.container | |
2214 |
|
2230 | |||
2215 | assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token |
|
2231 | assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token | |
2216 | assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' |
|
2232 | assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' | |
2217 | end |
|
2233 | end | |
2218 |
|
2234 | |||
2219 | def test_post_create_with_failure_should_keep_saved_attachments |
|
2235 | def test_post_create_with_failure_should_keep_saved_attachments | |
2220 | set_tmp_attachments_directory |
|
2236 | set_tmp_attachments_directory | |
2221 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
|
2237 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) | |
2222 | @request.session[:user_id] = 2 |
|
2238 | @request.session[:user_id] = 2 | |
2223 |
|
2239 | |||
2224 | assert_no_difference 'Issue.count' do |
|
2240 | assert_no_difference 'Issue.count' do | |
2225 | assert_no_difference 'Attachment.count' do |
|
2241 | assert_no_difference 'Attachment.count' do | |
2226 | post :create, :project_id => 1, |
|
2242 | post :create, :project_id => 1, | |
2227 | :issue => { :tracker_id => '1', :subject => '' }, |
|
2243 | :issue => { :tracker_id => '1', :subject => '' }, | |
2228 | :attachments => {'p0' => {'token' => attachment.token}} |
|
2244 | :attachments => {'p0' => {'token' => attachment.token}} | |
2229 | assert_response :success |
|
2245 | assert_response :success | |
2230 | assert_template 'new' |
|
2246 | assert_template 'new' | |
2231 | end |
|
2247 | end | |
2232 | end |
|
2248 | end | |
2233 |
|
2249 | |||
2234 | assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token |
|
2250 | assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token | |
2235 | assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' |
|
2251 | assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' | |
2236 | end |
|
2252 | end | |
2237 |
|
2253 | |||
2238 | def test_post_create_should_attach_saved_attachments |
|
2254 | def test_post_create_should_attach_saved_attachments | |
2239 | set_tmp_attachments_directory |
|
2255 | set_tmp_attachments_directory | |
2240 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
|
2256 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) | |
2241 | @request.session[:user_id] = 2 |
|
2257 | @request.session[:user_id] = 2 | |
2242 |
|
2258 | |||
2243 | assert_difference 'Issue.count' do |
|
2259 | assert_difference 'Issue.count' do | |
2244 | assert_no_difference 'Attachment.count' do |
|
2260 | assert_no_difference 'Attachment.count' do | |
2245 | post :create, :project_id => 1, |
|
2261 | post :create, :project_id => 1, | |
2246 | :issue => { :tracker_id => '1', :subject => 'Saved attachments' }, |
|
2262 | :issue => { :tracker_id => '1', :subject => 'Saved attachments' }, | |
2247 | :attachments => {'p0' => {'token' => attachment.token}} |
|
2263 | :attachments => {'p0' => {'token' => attachment.token}} | |
2248 | assert_response 302 |
|
2264 | assert_response 302 | |
2249 | end |
|
2265 | end | |
2250 | end |
|
2266 | end | |
2251 |
|
2267 | |||
2252 | issue = Issue.order('id DESC').first |
|
2268 | issue = Issue.order('id DESC').first | |
2253 | assert_equal 1, issue.attachments.count |
|
2269 | assert_equal 1, issue.attachments.count | |
2254 |
|
2270 | |||
2255 | attachment.reload |
|
2271 | attachment.reload | |
2256 | assert_equal issue, attachment.container |
|
2272 | assert_equal issue, attachment.container | |
2257 | end |
|
2273 | end | |
2258 |
|
2274 | |||
2259 | def setup_without_workflow_privilege |
|
2275 | def setup_without_workflow_privilege | |
2260 | WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id]) |
|
2276 | WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id]) | |
2261 | Role.anonymous.add_permission! :add_issues, :add_issue_notes |
|
2277 | Role.anonymous.add_permission! :add_issues, :add_issue_notes | |
2262 | end |
|
2278 | end | |
2263 | private :setup_without_workflow_privilege |
|
2279 | private :setup_without_workflow_privilege | |
2264 |
|
2280 | |||
2265 | test "without workflow privilege #new should propose default status only" do |
|
2281 | test "without workflow privilege #new should propose default status only" do | |
2266 | setup_without_workflow_privilege |
|
2282 | setup_without_workflow_privilege | |
2267 | get :new, :project_id => 1 |
|
2283 | get :new, :project_id => 1 | |
2268 | assert_response :success |
|
2284 | assert_response :success | |
2269 | assert_template 'new' |
|
2285 | assert_template 'new' | |
2270 | assert_select 'select[name=?]', 'issue[status_id]' do |
|
2286 | assert_select 'select[name=?]', 'issue[status_id]' do | |
2271 | assert_select 'option', 1 |
|
2287 | assert_select 'option', 1 | |
2272 | assert_select 'option[value=?]', IssueStatus.default.id.to_s |
|
2288 | assert_select 'option[value=?]', IssueStatus.default.id.to_s | |
2273 | end |
|
2289 | end | |
2274 | end |
|
2290 | end | |
2275 |
|
2291 | |||
2276 | test "without workflow privilege #new should accept default status" do |
|
2292 | test "without workflow privilege #new should accept default status" do | |
2277 | setup_without_workflow_privilege |
|
2293 | setup_without_workflow_privilege | |
2278 | assert_difference 'Issue.count' do |
|
2294 | assert_difference 'Issue.count' do | |
2279 | post :create, :project_id => 1, |
|
2295 | post :create, :project_id => 1, | |
2280 | :issue => {:tracker_id => 1, |
|
2296 | :issue => {:tracker_id => 1, | |
2281 | :subject => 'This is an issue', |
|
2297 | :subject => 'This is an issue', | |
2282 | :status_id => 1} |
|
2298 | :status_id => 1} | |
2283 | end |
|
2299 | end | |
2284 | issue = Issue.order('id').last |
|
2300 | issue = Issue.order('id').last | |
2285 | assert_equal IssueStatus.default, issue.status |
|
2301 | assert_equal IssueStatus.default, issue.status | |
2286 | end |
|
2302 | end | |
2287 |
|
2303 | |||
2288 | test "without workflow privilege #new should ignore unauthorized status" do |
|
2304 | test "without workflow privilege #new should ignore unauthorized status" do | |
2289 | setup_without_workflow_privilege |
|
2305 | setup_without_workflow_privilege | |
2290 | assert_difference 'Issue.count' do |
|
2306 | assert_difference 'Issue.count' do | |
2291 | post :create, :project_id => 1, |
|
2307 | post :create, :project_id => 1, | |
2292 | :issue => {:tracker_id => 1, |
|
2308 | :issue => {:tracker_id => 1, | |
2293 | :subject => 'This is an issue', |
|
2309 | :subject => 'This is an issue', | |
2294 | :status_id => 3} |
|
2310 | :status_id => 3} | |
2295 | end |
|
2311 | end | |
2296 | issue = Issue.order('id').last |
|
2312 | issue = Issue.order('id').last | |
2297 | assert_equal IssueStatus.default, issue.status |
|
2313 | assert_equal IssueStatus.default, issue.status | |
2298 | end |
|
2314 | end | |
2299 |
|
2315 | |||
2300 | test "without workflow privilege #update should ignore status change" do |
|
2316 | test "without workflow privilege #update should ignore status change" do | |
2301 | setup_without_workflow_privilege |
|
2317 | setup_without_workflow_privilege | |
2302 | assert_difference 'Journal.count' do |
|
2318 | assert_difference 'Journal.count' do | |
2303 | put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} |
|
2319 | put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} | |
2304 | end |
|
2320 | end | |
2305 | assert_equal 1, Issue.find(1).status_id |
|
2321 | assert_equal 1, Issue.find(1).status_id | |
2306 | end |
|
2322 | end | |
2307 |
|
2323 | |||
2308 | test "without workflow privilege #update ignore attributes changes" do |
|
2324 | test "without workflow privilege #update ignore attributes changes" do | |
2309 | setup_without_workflow_privilege |
|
2325 | setup_without_workflow_privilege | |
2310 | assert_difference 'Journal.count' do |
|
2326 | assert_difference 'Journal.count' do | |
2311 | put :update, :id => 1, |
|
2327 | put :update, :id => 1, | |
2312 | :issue => {:subject => 'changed', :assigned_to_id => 2, |
|
2328 | :issue => {:subject => 'changed', :assigned_to_id => 2, | |
2313 | :notes => 'just trying'} |
|
2329 | :notes => 'just trying'} | |
2314 | end |
|
2330 | end | |
2315 | issue = Issue.find(1) |
|
2331 | issue = Issue.find(1) | |
2316 | assert_equal "Can't print recipes", issue.subject |
|
2332 | assert_equal "Can't print recipes", issue.subject | |
2317 | assert_nil issue.assigned_to |
|
2333 | assert_nil issue.assigned_to | |
2318 | end |
|
2334 | end | |
2319 |
|
2335 | |||
2320 | def setup_with_workflow_privilege |
|
2336 | def setup_with_workflow_privilege | |
2321 | WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id]) |
|
2337 | WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id]) | |
2322 | WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, |
|
2338 | WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, | |
2323 | :old_status_id => 1, :new_status_id => 3) |
|
2339 | :old_status_id => 1, :new_status_id => 3) | |
2324 | WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, |
|
2340 | WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, | |
2325 | :old_status_id => 1, :new_status_id => 4) |
|
2341 | :old_status_id => 1, :new_status_id => 4) | |
2326 | Role.anonymous.add_permission! :add_issues, :add_issue_notes |
|
2342 | Role.anonymous.add_permission! :add_issues, :add_issue_notes | |
2327 | end |
|
2343 | end | |
2328 | private :setup_with_workflow_privilege |
|
2344 | private :setup_with_workflow_privilege | |
2329 |
|
2345 | |||
2330 | test "with workflow privilege #update should accept authorized status" do |
|
2346 | test "with workflow privilege #update should accept authorized status" do | |
2331 | setup_with_workflow_privilege |
|
2347 | setup_with_workflow_privilege | |
2332 | assert_difference 'Journal.count' do |
|
2348 | assert_difference 'Journal.count' do | |
2333 | put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} |
|
2349 | put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} | |
2334 | end |
|
2350 | end | |
2335 | assert_equal 3, Issue.find(1).status_id |
|
2351 | assert_equal 3, Issue.find(1).status_id | |
2336 | end |
|
2352 | end | |
2337 |
|
2353 | |||
2338 | test "with workflow privilege #update should ignore unauthorized status" do |
|
2354 | test "with workflow privilege #update should ignore unauthorized status" do | |
2339 | setup_with_workflow_privilege |
|
2355 | setup_with_workflow_privilege | |
2340 | assert_difference 'Journal.count' do |
|
2356 | assert_difference 'Journal.count' do | |
2341 | put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'} |
|
2357 | put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'} | |
2342 | end |
|
2358 | end | |
2343 | assert_equal 1, Issue.find(1).status_id |
|
2359 | assert_equal 1, Issue.find(1).status_id | |
2344 | end |
|
2360 | end | |
2345 |
|
2361 | |||
2346 | test "with workflow privilege #update should accept authorized attributes changes" do |
|
2362 | test "with workflow privilege #update should accept authorized attributes changes" do | |
2347 | setup_with_workflow_privilege |
|
2363 | setup_with_workflow_privilege | |
2348 | assert_difference 'Journal.count' do |
|
2364 | assert_difference 'Journal.count' do | |
2349 | put :update, :id => 1, :issue => {:assigned_to_id => 2, :notes => 'just trying'} |
|
2365 | put :update, :id => 1, :issue => {:assigned_to_id => 2, :notes => 'just trying'} | |
2350 | end |
|
2366 | end | |
2351 | issue = Issue.find(1) |
|
2367 | issue = Issue.find(1) | |
2352 | assert_equal 2, issue.assigned_to_id |
|
2368 | assert_equal 2, issue.assigned_to_id | |
2353 | end |
|
2369 | end | |
2354 |
|
2370 | |||
2355 | test "with workflow privilege #update should ignore unauthorized attributes changes" do |
|
2371 | test "with workflow privilege #update should ignore unauthorized attributes changes" do | |
2356 | setup_with_workflow_privilege |
|
2372 | setup_with_workflow_privilege | |
2357 | assert_difference 'Journal.count' do |
|
2373 | assert_difference 'Journal.count' do | |
2358 | put :update, :id => 1, :issue => {:subject => 'changed', :notes => 'just trying'} |
|
2374 | put :update, :id => 1, :issue => {:subject => 'changed', :notes => 'just trying'} | |
2359 | end |
|
2375 | end | |
2360 | issue = Issue.find(1) |
|
2376 | issue = Issue.find(1) | |
2361 | assert_equal "Can't print recipes", issue.subject |
|
2377 | assert_equal "Can't print recipes", issue.subject | |
2362 | end |
|
2378 | end | |
2363 |
|
2379 | |||
2364 | def setup_with_workflow_privilege_and_edit_issues_permission |
|
2380 | def setup_with_workflow_privilege_and_edit_issues_permission | |
2365 | setup_with_workflow_privilege |
|
2381 | setup_with_workflow_privilege | |
2366 | Role.anonymous.add_permission! :add_issues, :edit_issues |
|
2382 | Role.anonymous.add_permission! :add_issues, :edit_issues | |
2367 | end |
|
2383 | end | |
2368 | private :setup_with_workflow_privilege_and_edit_issues_permission |
|
2384 | private :setup_with_workflow_privilege_and_edit_issues_permission | |
2369 |
|
2385 | |||
2370 | test "with workflow privilege and :edit_issues permission should accept authorized status" do |
|
2386 | test "with workflow privilege and :edit_issues permission should accept authorized status" do | |
2371 | setup_with_workflow_privilege_and_edit_issues_permission |
|
2387 | setup_with_workflow_privilege_and_edit_issues_permission | |
2372 | assert_difference 'Journal.count' do |
|
2388 | assert_difference 'Journal.count' do | |
2373 | put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} |
|
2389 | put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} | |
2374 | end |
|
2390 | end | |
2375 | assert_equal 3, Issue.find(1).status_id |
|
2391 | assert_equal 3, Issue.find(1).status_id | |
2376 | end |
|
2392 | end | |
2377 |
|
2393 | |||
2378 | test "with workflow privilege and :edit_issues permission should ignore unauthorized status" do |
|
2394 | test "with workflow privilege and :edit_issues permission should ignore unauthorized status" do | |
2379 | setup_with_workflow_privilege_and_edit_issues_permission |
|
2395 | setup_with_workflow_privilege_and_edit_issues_permission | |
2380 | assert_difference 'Journal.count' do |
|
2396 | assert_difference 'Journal.count' do | |
2381 | put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'} |
|
2397 | put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'} | |
2382 | end |
|
2398 | end | |
2383 | assert_equal 1, Issue.find(1).status_id |
|
2399 | assert_equal 1, Issue.find(1).status_id | |
2384 | end |
|
2400 | end | |
2385 |
|
2401 | |||
2386 | test "with workflow privilege and :edit_issues permission should accept authorized attributes changes" do |
|
2402 | test "with workflow privilege and :edit_issues permission should accept authorized attributes changes" do | |
2387 | setup_with_workflow_privilege_and_edit_issues_permission |
|
2403 | setup_with_workflow_privilege_and_edit_issues_permission | |
2388 | assert_difference 'Journal.count' do |
|
2404 | assert_difference 'Journal.count' do | |
2389 | put :update, :id => 1, |
|
2405 | put :update, :id => 1, | |
2390 | :issue => {:subject => 'changed', :assigned_to_id => 2, |
|
2406 | :issue => {:subject => 'changed', :assigned_to_id => 2, | |
2391 | :notes => 'just trying'} |
|
2407 | :notes => 'just trying'} | |
2392 | end |
|
2408 | end | |
2393 | issue = Issue.find(1) |
|
2409 | issue = Issue.find(1) | |
2394 | assert_equal "changed", issue.subject |
|
2410 | assert_equal "changed", issue.subject | |
2395 | assert_equal 2, issue.assigned_to_id |
|
2411 | assert_equal 2, issue.assigned_to_id | |
2396 | end |
|
2412 | end | |
2397 |
|
2413 | |||
2398 | def test_new_as_copy |
|
2414 | def test_new_as_copy | |
2399 | @request.session[:user_id] = 2 |
|
2415 | @request.session[:user_id] = 2 | |
2400 | get :new, :project_id => 1, :copy_from => 1 |
|
2416 | get :new, :project_id => 1, :copy_from => 1 | |
2401 |
|
2417 | |||
2402 | assert_response :success |
|
2418 | assert_response :success | |
2403 | assert_template 'new' |
|
2419 | assert_template 'new' | |
2404 |
|
2420 | |||
2405 | assert_not_nil assigns(:issue) |
|
2421 | assert_not_nil assigns(:issue) | |
2406 | orig = Issue.find(1) |
|
2422 | orig = Issue.find(1) | |
2407 | assert_equal 1, assigns(:issue).project_id |
|
2423 | assert_equal 1, assigns(:issue).project_id | |
2408 | assert_equal orig.subject, assigns(:issue).subject |
|
2424 | assert_equal orig.subject, assigns(:issue).subject | |
2409 | assert assigns(:issue).copy? |
|
2425 | assert assigns(:issue).copy? | |
2410 |
|
2426 | |||
2411 | assert_select 'form[id=issue-form][action=/projects/ecookbook/issues]' do |
|
2427 | assert_select 'form[id=issue-form][action=/projects/ecookbook/issues]' do | |
2412 | assert_select 'select[name=?]', 'issue[project_id]' do |
|
2428 | assert_select 'select[name=?]', 'issue[project_id]' do | |
2413 | assert_select 'option[value=1][selected=selected]', :text => 'eCookbook' |
|
2429 | assert_select 'option[value=1][selected=selected]', :text => 'eCookbook' | |
2414 | assert_select 'option[value=2]:not([selected])', :text => 'OnlineStore' |
|
2430 | assert_select 'option[value=2]:not([selected])', :text => 'OnlineStore' | |
2415 | end |
|
2431 | end | |
2416 | assert_select 'input[name=copy_from][value=1]' |
|
2432 | assert_select 'input[name=copy_from][value=1]' | |
2417 | end |
|
2433 | end | |
2418 |
|
2434 | |||
2419 | # "New issue" menu item should not link to copy |
|
2435 | # "New issue" menu item should not link to copy | |
2420 | assert_select '#main-menu a.new-issue[href=/projects/ecookbook/issues/new]' |
|
2436 | assert_select '#main-menu a.new-issue[href=/projects/ecookbook/issues/new]' | |
2421 | end |
|
2437 | end | |
2422 |
|
2438 | |||
2423 | def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox |
|
2439 | def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox | |
2424 | @request.session[:user_id] = 2 |
|
2440 | @request.session[:user_id] = 2 | |
2425 | issue = Issue.find(3) |
|
2441 | issue = Issue.find(3) | |
2426 | assert issue.attachments.count > 0 |
|
2442 | assert issue.attachments.count > 0 | |
2427 | get :new, :project_id => 1, :copy_from => 3 |
|
2443 | get :new, :project_id => 1, :copy_from => 3 | |
2428 |
|
2444 | |||
2429 | assert_select 'input[name=copy_attachments][type=checkbox][checked=checked][value=1]' |
|
2445 | assert_select 'input[name=copy_attachments][type=checkbox][checked=checked][value=1]' | |
2430 | end |
|
2446 | end | |
2431 |
|
2447 | |||
2432 | def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox |
|
2448 | def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox | |
2433 | @request.session[:user_id] = 2 |
|
2449 | @request.session[:user_id] = 2 | |
2434 | issue = Issue.find(3) |
|
2450 | issue = Issue.find(3) | |
2435 | issue.attachments.delete_all |
|
2451 | issue.attachments.delete_all | |
2436 | get :new, :project_id => 1, :copy_from => 3 |
|
2452 | get :new, :project_id => 1, :copy_from => 3 | |
2437 |
|
2453 | |||
2438 | assert_select 'input[name=copy_attachments]', 0 |
|
2454 | assert_select 'input[name=copy_attachments]', 0 | |
2439 | end |
|
2455 | end | |
2440 |
|
2456 | |||
2441 | def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox |
|
2457 | def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox | |
2442 | @request.session[:user_id] = 2 |
|
2458 | @request.session[:user_id] = 2 | |
2443 | issue = Issue.generate_with_descendants! |
|
2459 | issue = Issue.generate_with_descendants! | |
2444 | get :new, :project_id => 1, :copy_from => issue.id |
|
2460 | get :new, :project_id => 1, :copy_from => issue.id | |
2445 |
|
2461 | |||
2446 | assert_select 'input[type=checkbox][name=copy_subtasks][checked=checked][value=1]' |
|
2462 | assert_select 'input[type=checkbox][name=copy_subtasks][checked=checked][value=1]' | |
2447 | end |
|
2463 | end | |
2448 |
|
2464 | |||
2449 | def test_new_as_copy_with_invalid_issue_should_respond_with_404 |
|
2465 | def test_new_as_copy_with_invalid_issue_should_respond_with_404 | |
2450 | @request.session[:user_id] = 2 |
|
2466 | @request.session[:user_id] = 2 | |
2451 | get :new, :project_id => 1, :copy_from => 99999 |
|
2467 | get :new, :project_id => 1, :copy_from => 99999 | |
2452 | assert_response 404 |
|
2468 | assert_response 404 | |
2453 | end |
|
2469 | end | |
2454 |
|
2470 | |||
2455 | def test_create_as_copy_on_different_project |
|
2471 | def test_create_as_copy_on_different_project | |
2456 | @request.session[:user_id] = 2 |
|
2472 | @request.session[:user_id] = 2 | |
2457 | assert_difference 'Issue.count' do |
|
2473 | assert_difference 'Issue.count' do | |
2458 | post :create, :project_id => 1, :copy_from => 1, |
|
2474 | post :create, :project_id => 1, :copy_from => 1, | |
2459 | :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} |
|
2475 | :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} | |
2460 |
|
2476 | |||
2461 | assert_not_nil assigns(:issue) |
|
2477 | assert_not_nil assigns(:issue) | |
2462 | assert assigns(:issue).copy? |
|
2478 | assert assigns(:issue).copy? | |
2463 | end |
|
2479 | end | |
2464 | issue = Issue.order('id DESC').first |
|
2480 | issue = Issue.order('id DESC').first | |
2465 | assert_redirected_to "/issues/#{issue.id}" |
|
2481 | assert_redirected_to "/issues/#{issue.id}" | |
2466 |
|
2482 | |||
2467 | assert_equal 2, issue.project_id |
|
2483 | assert_equal 2, issue.project_id | |
2468 | assert_equal 3, issue.tracker_id |
|
2484 | assert_equal 3, issue.tracker_id | |
2469 | assert_equal 'Copy', issue.subject |
|
2485 | assert_equal 'Copy', issue.subject | |
2470 | end |
|
2486 | end | |
2471 |
|
2487 | |||
2472 | def test_create_as_copy_should_copy_attachments |
|
2488 | def test_create_as_copy_should_copy_attachments | |
2473 | @request.session[:user_id] = 2 |
|
2489 | @request.session[:user_id] = 2 | |
2474 | issue = Issue.find(3) |
|
2490 | issue = Issue.find(3) | |
2475 | count = issue.attachments.count |
|
2491 | count = issue.attachments.count | |
2476 | assert count > 0 |
|
2492 | assert count > 0 | |
2477 | assert_difference 'Issue.count' do |
|
2493 | assert_difference 'Issue.count' do | |
2478 | assert_difference 'Attachment.count', count do |
|
2494 | assert_difference 'Attachment.count', count do | |
2479 | assert_difference 'Journal.count', 2 do |
|
2495 | assert_difference 'Journal.count', 2 do | |
2480 | post :create, :project_id => 1, :copy_from => 3, |
|
2496 | post :create, :project_id => 1, :copy_from => 3, | |
2481 | :issue => {:project_id => '1', :tracker_id => '3', |
|
2497 | :issue => {:project_id => '1', :tracker_id => '3', | |
2482 | :status_id => '1', :subject => 'Copy with attachments'}, |
|
2498 | :status_id => '1', :subject => 'Copy with attachments'}, | |
2483 | :copy_attachments => '1' |
|
2499 | :copy_attachments => '1' | |
2484 | end |
|
2500 | end | |
2485 | end |
|
2501 | end | |
2486 | end |
|
2502 | end | |
2487 | copy = Issue.order('id DESC').first |
|
2503 | copy = Issue.order('id DESC').first | |
2488 | assert_equal count, copy.attachments.count |
|
2504 | assert_equal count, copy.attachments.count | |
2489 | assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort |
|
2505 | assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort | |
2490 | end |
|
2506 | end | |
2491 |
|
2507 | |||
2492 | def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments |
|
2508 | def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments | |
2493 | @request.session[:user_id] = 2 |
|
2509 | @request.session[:user_id] = 2 | |
2494 | issue = Issue.find(3) |
|
2510 | issue = Issue.find(3) | |
2495 | count = issue.attachments.count |
|
2511 | count = issue.attachments.count | |
2496 | assert count > 0 |
|
2512 | assert count > 0 | |
2497 | assert_difference 'Issue.count' do |
|
2513 | assert_difference 'Issue.count' do | |
2498 | assert_no_difference 'Attachment.count' do |
|
2514 | assert_no_difference 'Attachment.count' do | |
2499 | assert_difference 'Journal.count', 2 do |
|
2515 | assert_difference 'Journal.count', 2 do | |
2500 | post :create, :project_id => 1, :copy_from => 3, |
|
2516 | post :create, :project_id => 1, :copy_from => 3, | |
2501 | :issue => {:project_id => '1', :tracker_id => '3', |
|
2517 | :issue => {:project_id => '1', :tracker_id => '3', | |
2502 | :status_id => '1', :subject => 'Copy with attachments'} |
|
2518 | :status_id => '1', :subject => 'Copy with attachments'} | |
2503 | end |
|
2519 | end | |
2504 | end |
|
2520 | end | |
2505 | end |
|
2521 | end | |
2506 | copy = Issue.order('id DESC').first |
|
2522 | copy = Issue.order('id DESC').first | |
2507 | assert_equal 0, copy.attachments.count |
|
2523 | assert_equal 0, copy.attachments.count | |
2508 | end |
|
2524 | end | |
2509 |
|
2525 | |||
2510 | def test_create_as_copy_with_attachments_should_add_new_files |
|
2526 | def test_create_as_copy_with_attachments_should_add_new_files | |
2511 | @request.session[:user_id] = 2 |
|
2527 | @request.session[:user_id] = 2 | |
2512 | issue = Issue.find(3) |
|
2528 | issue = Issue.find(3) | |
2513 | count = issue.attachments.count |
|
2529 | count = issue.attachments.count | |
2514 | assert count > 0 |
|
2530 | assert count > 0 | |
2515 | assert_difference 'Issue.count' do |
|
2531 | assert_difference 'Issue.count' do | |
2516 | assert_difference 'Attachment.count', count + 1 do |
|
2532 | assert_difference 'Attachment.count', count + 1 do | |
2517 | assert_difference 'Journal.count', 2 do |
|
2533 | assert_difference 'Journal.count', 2 do | |
2518 | post :create, :project_id => 1, :copy_from => 3, |
|
2534 | post :create, :project_id => 1, :copy_from => 3, | |
2519 | :issue => {:project_id => '1', :tracker_id => '3', |
|
2535 | :issue => {:project_id => '1', :tracker_id => '3', | |
2520 | :status_id => '1', :subject => 'Copy with attachments'}, |
|
2536 | :status_id => '1', :subject => 'Copy with attachments'}, | |
2521 | :copy_attachments => '1', |
|
2537 | :copy_attachments => '1', | |
2522 | :attachments => {'1' => |
|
2538 | :attachments => {'1' => | |
2523 | {'file' => uploaded_test_file('testfile.txt', 'text/plain'), |
|
2539 | {'file' => uploaded_test_file('testfile.txt', 'text/plain'), | |
2524 | 'description' => 'test file'}} |
|
2540 | 'description' => 'test file'}} | |
2525 | end |
|
2541 | end | |
2526 | end |
|
2542 | end | |
2527 | end |
|
2543 | end | |
2528 | copy = Issue.order('id DESC').first |
|
2544 | copy = Issue.order('id DESC').first | |
2529 | assert_equal count + 1, copy.attachments.count |
|
2545 | assert_equal count + 1, copy.attachments.count | |
2530 | end |
|
2546 | end | |
2531 |
|
2547 | |||
2532 | def test_create_as_copy_should_add_relation_with_copied_issue |
|
2548 | def test_create_as_copy_should_add_relation_with_copied_issue | |
2533 | @request.session[:user_id] = 2 |
|
2549 | @request.session[:user_id] = 2 | |
2534 | assert_difference 'Issue.count' do |
|
2550 | assert_difference 'Issue.count' do | |
2535 | assert_difference 'IssueRelation.count' do |
|
2551 | assert_difference 'IssueRelation.count' do | |
2536 | post :create, :project_id => 1, :copy_from => 1, |
|
2552 | post :create, :project_id => 1, :copy_from => 1, | |
2537 | :issue => {:project_id => '1', :tracker_id => '3', |
|
2553 | :issue => {:project_id => '1', :tracker_id => '3', | |
2538 | :status_id => '1', :subject => 'Copy'} |
|
2554 | :status_id => '1', :subject => 'Copy'} | |
2539 | end |
|
2555 | end | |
2540 | end |
|
2556 | end | |
2541 | copy = Issue.order('id DESC').first |
|
2557 | copy = Issue.order('id DESC').first | |
2542 | assert_equal 1, copy.relations.size |
|
2558 | assert_equal 1, copy.relations.size | |
2543 | end |
|
2559 | end | |
2544 |
|
2560 | |||
2545 | def test_create_as_copy_should_copy_subtasks |
|
2561 | def test_create_as_copy_should_copy_subtasks | |
2546 | @request.session[:user_id] = 2 |
|
2562 | @request.session[:user_id] = 2 | |
2547 | issue = Issue.generate_with_descendants! |
|
2563 | issue = Issue.generate_with_descendants! | |
2548 | count = issue.descendants.count |
|
2564 | count = issue.descendants.count | |
2549 | assert_difference 'Issue.count', count + 1 do |
|
2565 | assert_difference 'Issue.count', count + 1 do | |
2550 | assert_difference 'Journal.count', (count + 1) * 2 do |
|
2566 | assert_difference 'Journal.count', (count + 1) * 2 do | |
2551 | post :create, :project_id => 1, :copy_from => issue.id, |
|
2567 | post :create, :project_id => 1, :copy_from => issue.id, | |
2552 | :issue => {:project_id => '1', :tracker_id => '3', |
|
2568 | :issue => {:project_id => '1', :tracker_id => '3', | |
2553 | :status_id => '1', :subject => 'Copy with subtasks'}, |
|
2569 | :status_id => '1', :subject => 'Copy with subtasks'}, | |
2554 | :copy_subtasks => '1' |
|
2570 | :copy_subtasks => '1' | |
2555 | end |
|
2571 | end | |
2556 | end |
|
2572 | end | |
2557 | copy = Issue.where(:parent_id => nil).order('id DESC').first |
|
2573 | copy = Issue.where(:parent_id => nil).order('id DESC').first | |
2558 | assert_equal count, copy.descendants.count |
|
2574 | assert_equal count, copy.descendants.count | |
2559 | assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort |
|
2575 | assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort | |
2560 | end |
|
2576 | end | |
2561 |
|
2577 | |||
2562 | def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks |
|
2578 | def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks | |
2563 | @request.session[:user_id] = 2 |
|
2579 | @request.session[:user_id] = 2 | |
2564 | issue = Issue.generate_with_descendants! |
|
2580 | issue = Issue.generate_with_descendants! | |
2565 | assert_difference 'Issue.count', 1 do |
|
2581 | assert_difference 'Issue.count', 1 do | |
2566 | assert_difference 'Journal.count', 2 do |
|
2582 | assert_difference 'Journal.count', 2 do | |
2567 | post :create, :project_id => 1, :copy_from => 3, |
|
2583 | post :create, :project_id => 1, :copy_from => 3, | |
2568 | :issue => {:project_id => '1', :tracker_id => '3', |
|
2584 | :issue => {:project_id => '1', :tracker_id => '3', | |
2569 | :status_id => '1', :subject => 'Copy with subtasks'} |
|
2585 | :status_id => '1', :subject => 'Copy with subtasks'} | |
2570 | end |
|
2586 | end | |
2571 | end |
|
2587 | end | |
2572 | copy = Issue.where(:parent_id => nil).order('id DESC').first |
|
2588 | copy = Issue.where(:parent_id => nil).order('id DESC').first | |
2573 | assert_equal 0, copy.descendants.count |
|
2589 | assert_equal 0, copy.descendants.count | |
2574 | end |
|
2590 | end | |
2575 |
|
2591 | |||
2576 | def test_create_as_copy_with_failure |
|
2592 | def test_create_as_copy_with_failure | |
2577 | @request.session[:user_id] = 2 |
|
2593 | @request.session[:user_id] = 2 | |
2578 | post :create, :project_id => 1, :copy_from => 1, |
|
2594 | post :create, :project_id => 1, :copy_from => 1, | |
2579 | :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''} |
|
2595 | :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''} | |
2580 |
|
2596 | |||
2581 | assert_response :success |
|
2597 | assert_response :success | |
2582 | assert_template 'new' |
|
2598 | assert_template 'new' | |
2583 |
|
2599 | |||
2584 | assert_not_nil assigns(:issue) |
|
2600 | assert_not_nil assigns(:issue) | |
2585 | assert assigns(:issue).copy? |
|
2601 | assert assigns(:issue).copy? | |
2586 |
|
2602 | |||
2587 | assert_select 'form#issue-form[action=/projects/ecookbook/issues]' do |
|
2603 | assert_select 'form#issue-form[action=/projects/ecookbook/issues]' do | |
2588 | assert_select 'select[name=?]', 'issue[project_id]' do |
|
2604 | assert_select 'select[name=?]', 'issue[project_id]' do | |
2589 | assert_select 'option[value=1]:not([selected])', :text => 'eCookbook' |
|
2605 | assert_select 'option[value=1]:not([selected])', :text => 'eCookbook' | |
2590 | assert_select 'option[value=2][selected=selected]', :text => 'OnlineStore' |
|
2606 | assert_select 'option[value=2][selected=selected]', :text => 'OnlineStore' | |
2591 | end |
|
2607 | end | |
2592 | assert_select 'input[name=copy_from][value=1]' |
|
2608 | assert_select 'input[name=copy_from][value=1]' | |
2593 | end |
|
2609 | end | |
2594 | end |
|
2610 | end | |
2595 |
|
2611 | |||
2596 | def test_create_as_copy_on_project_without_permission_should_ignore_target_project |
|
2612 | def test_create_as_copy_on_project_without_permission_should_ignore_target_project | |
2597 | @request.session[:user_id] = 2 |
|
2613 | @request.session[:user_id] = 2 | |
2598 | assert !User.find(2).member_of?(Project.find(4)) |
|
2614 | assert !User.find(2).member_of?(Project.find(4)) | |
2599 |
|
2615 | |||
2600 | assert_difference 'Issue.count' do |
|
2616 | assert_difference 'Issue.count' do | |
2601 | post :create, :project_id => 1, :copy_from => 1, |
|
2617 | post :create, :project_id => 1, :copy_from => 1, | |
2602 | :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} |
|
2618 | :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} | |
2603 | end |
|
2619 | end | |
2604 | issue = Issue.order('id DESC').first |
|
2620 | issue = Issue.order('id DESC').first | |
2605 | assert_equal 1, issue.project_id |
|
2621 | assert_equal 1, issue.project_id | |
2606 | end |
|
2622 | end | |
2607 |
|
2623 | |||
2608 | def test_get_edit |
|
2624 | def test_get_edit | |
2609 | @request.session[:user_id] = 2 |
|
2625 | @request.session[:user_id] = 2 | |
2610 | get :edit, :id => 1 |
|
2626 | get :edit, :id => 1 | |
2611 | assert_response :success |
|
2627 | assert_response :success | |
2612 | assert_template 'edit' |
|
2628 | assert_template 'edit' | |
2613 | assert_not_nil assigns(:issue) |
|
2629 | assert_not_nil assigns(:issue) | |
2614 | assert_equal Issue.find(1), assigns(:issue) |
|
2630 | assert_equal Issue.find(1), assigns(:issue) | |
2615 |
|
2631 | |||
2616 | # Be sure we don't display inactive IssuePriorities |
|
2632 | # Be sure we don't display inactive IssuePriorities | |
2617 | assert ! IssuePriority.find(15).active? |
|
2633 | assert ! IssuePriority.find(15).active? | |
2618 | assert_select 'select[name=?]', 'issue[priority_id]' do |
|
2634 | assert_select 'select[name=?]', 'issue[priority_id]' do | |
2619 | assert_select 'option[value=15]', 0 |
|
2635 | assert_select 'option[value=15]', 0 | |
2620 | end |
|
2636 | end | |
2621 | end |
|
2637 | end | |
2622 |
|
2638 | |||
2623 | def test_get_edit_should_display_the_time_entry_form_with_log_time_permission |
|
2639 | def test_get_edit_should_display_the_time_entry_form_with_log_time_permission | |
2624 | @request.session[:user_id] = 2 |
|
2640 | @request.session[:user_id] = 2 | |
2625 | Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time] |
|
2641 | Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time] | |
2626 |
|
2642 | |||
2627 | get :edit, :id => 1 |
|
2643 | get :edit, :id => 1 | |
2628 | assert_select 'input[name=?]', 'time_entry[hours]' |
|
2644 | assert_select 'input[name=?]', 'time_entry[hours]' | |
2629 | end |
|
2645 | end | |
2630 |
|
2646 | |||
2631 | def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission |
|
2647 | def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission | |
2632 | @request.session[:user_id] = 2 |
|
2648 | @request.session[:user_id] = 2 | |
2633 | Role.find_by_name('Manager').remove_permission! :log_time |
|
2649 | Role.find_by_name('Manager').remove_permission! :log_time | |
2634 |
|
2650 | |||
2635 | get :edit, :id => 1 |
|
2651 | get :edit, :id => 1 | |
2636 | assert_select 'input[name=?]', 'time_entry[hours]', 0 |
|
2652 | assert_select 'input[name=?]', 'time_entry[hours]', 0 | |
2637 | end |
|
2653 | end | |
2638 |
|
2654 | |||
2639 | def test_get_edit_with_params |
|
2655 | def test_get_edit_with_params | |
2640 | @request.session[:user_id] = 2 |
|
2656 | @request.session[:user_id] = 2 | |
2641 | get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }, |
|
2657 | get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }, | |
2642 | :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => 10 } |
|
2658 | :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => 10 } | |
2643 | assert_response :success |
|
2659 | assert_response :success | |
2644 | assert_template 'edit' |
|
2660 | assert_template 'edit' | |
2645 |
|
2661 | |||
2646 | issue = assigns(:issue) |
|
2662 | issue = assigns(:issue) | |
2647 | assert_not_nil issue |
|
2663 | assert_not_nil issue | |
2648 |
|
2664 | |||
2649 | assert_equal 5, issue.status_id |
|
2665 | assert_equal 5, issue.status_id | |
2650 | assert_select 'select[name=?]', 'issue[status_id]' do |
|
2666 | assert_select 'select[name=?]', 'issue[status_id]' do | |
2651 | assert_select 'option[value=5][selected=selected]', :text => 'Closed' |
|
2667 | assert_select 'option[value=5][selected=selected]', :text => 'Closed' | |
2652 | end |
|
2668 | end | |
2653 |
|
2669 | |||
2654 | assert_equal 7, issue.priority_id |
|
2670 | assert_equal 7, issue.priority_id | |
2655 | assert_select 'select[name=?]', 'issue[priority_id]' do |
|
2671 | assert_select 'select[name=?]', 'issue[priority_id]' do | |
2656 | assert_select 'option[value=7][selected=selected]', :text => 'Urgent' |
|
2672 | assert_select 'option[value=7][selected=selected]', :text => 'Urgent' | |
2657 | end |
|
2673 | end | |
2658 |
|
2674 | |||
2659 | assert_select 'input[name=?][value=2.5]', 'time_entry[hours]' |
|
2675 | assert_select 'input[name=?][value=2.5]', 'time_entry[hours]' | |
2660 | assert_select 'select[name=?]', 'time_entry[activity_id]' do |
|
2676 | assert_select 'select[name=?]', 'time_entry[activity_id]' do | |
2661 | assert_select 'option[value=10][selected=selected]', :text => 'Development' |
|
2677 | assert_select 'option[value=10][selected=selected]', :text => 'Development' | |
2662 | end |
|
2678 | end | |
2663 | assert_select 'input[name=?][value=test_get_edit_with_params]', 'time_entry[comments]' |
|
2679 | assert_select 'input[name=?][value=test_get_edit_with_params]', 'time_entry[comments]' | |
2664 | end |
|
2680 | end | |
2665 |
|
2681 | |||
2666 | def test_get_edit_with_multi_custom_field |
|
2682 | def test_get_edit_with_multi_custom_field | |
2667 | field = CustomField.find(1) |
|
2683 | field = CustomField.find(1) | |
2668 | field.update_attribute :multiple, true |
|
2684 | field.update_attribute :multiple, true | |
2669 | issue = Issue.find(1) |
|
2685 | issue = Issue.find(1) | |
2670 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
2686 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} | |
2671 | issue.save! |
|
2687 | issue.save! | |
2672 |
|
2688 | |||
2673 | @request.session[:user_id] = 2 |
|
2689 | @request.session[:user_id] = 2 | |
2674 | get :edit, :id => 1 |
|
2690 | get :edit, :id => 1 | |
2675 | assert_response :success |
|
2691 | assert_response :success | |
2676 | assert_template 'edit' |
|
2692 | assert_template 'edit' | |
2677 |
|
2693 | |||
2678 | assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do |
|
2694 | assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do | |
2679 | assert_select 'option', 3 |
|
2695 | assert_select 'option', 3 | |
2680 | assert_select 'option[value=MySQL][selected=selected]' |
|
2696 | assert_select 'option[value=MySQL][selected=selected]' | |
2681 | assert_select 'option[value=Oracle][selected=selected]' |
|
2697 | assert_select 'option[value=Oracle][selected=selected]' | |
2682 | assert_select 'option[value=PostgreSQL]:not([selected])' |
|
2698 | assert_select 'option[value=PostgreSQL]:not([selected])' | |
2683 | end |
|
2699 | end | |
2684 | end |
|
2700 | end | |
2685 |
|
2701 | |||
2686 | def test_update_form_for_existing_issue |
|
2702 | def test_update_form_for_existing_issue | |
2687 | @request.session[:user_id] = 2 |
|
2703 | @request.session[:user_id] = 2 | |
2688 | xhr :put, :update_form, :project_id => 1, |
|
2704 | xhr :put, :update_form, :project_id => 1, | |
2689 | :id => 1, |
|
2705 | :id => 1, | |
2690 | :issue => {:tracker_id => 2, |
|
2706 | :issue => {:tracker_id => 2, | |
2691 | :subject => 'This is the test_new issue', |
|
2707 | :subject => 'This is the test_new issue', | |
2692 | :description => 'This is the description', |
|
2708 | :description => 'This is the description', | |
2693 | :priority_id => 5} |
|
2709 | :priority_id => 5} | |
2694 | assert_response :success |
|
2710 | assert_response :success | |
2695 | assert_equal 'text/javascript', response.content_type |
|
2711 | assert_equal 'text/javascript', response.content_type | |
2696 | assert_template 'update_form' |
|
2712 | assert_template 'update_form' | |
2697 | assert_template :partial => '_form' |
|
2713 | assert_template :partial => '_form' | |
2698 |
|
2714 | |||
2699 | issue = assigns(:issue) |
|
2715 | issue = assigns(:issue) | |
2700 | assert_kind_of Issue, issue |
|
2716 | assert_kind_of Issue, issue | |
2701 | assert_equal 1, issue.id |
|
2717 | assert_equal 1, issue.id | |
2702 | assert_equal 1, issue.project_id |
|
2718 | assert_equal 1, issue.project_id | |
2703 | assert_equal 2, issue.tracker_id |
|
2719 | assert_equal 2, issue.tracker_id | |
2704 | assert_equal 'This is the test_new issue', issue.subject |
|
2720 | assert_equal 'This is the test_new issue', issue.subject | |
2705 | end |
|
2721 | end | |
2706 |
|
2722 | |||
2707 | def test_update_form_for_existing_issue_should_keep_issue_author |
|
2723 | def test_update_form_for_existing_issue_should_keep_issue_author | |
2708 | @request.session[:user_id] = 3 |
|
2724 | @request.session[:user_id] = 3 | |
2709 | xhr :put, :update_form, :project_id => 1, :id => 1, :issue => {:subject => 'Changed'} |
|
2725 | xhr :put, :update_form, :project_id => 1, :id => 1, :issue => {:subject => 'Changed'} | |
2710 | assert_response :success |
|
2726 | assert_response :success | |
2711 | assert_equal 'text/javascript', response.content_type |
|
2727 | assert_equal 'text/javascript', response.content_type | |
2712 |
|
2728 | |||
2713 | issue = assigns(:issue) |
|
2729 | issue = assigns(:issue) | |
2714 | assert_equal User.find(2), issue.author |
|
2730 | assert_equal User.find(2), issue.author | |
2715 | assert_equal 2, issue.author_id |
|
2731 | assert_equal 2, issue.author_id | |
2716 | assert_not_equal User.current, issue.author |
|
2732 | assert_not_equal User.current, issue.author | |
2717 | end |
|
2733 | end | |
2718 |
|
2734 | |||
2719 | def test_update_form_for_existing_issue_should_propose_transitions_based_on_initial_status |
|
2735 | def test_update_form_for_existing_issue_should_propose_transitions_based_on_initial_status | |
2720 | @request.session[:user_id] = 2 |
|
2736 | @request.session[:user_id] = 2 | |
2721 | WorkflowTransition.delete_all |
|
2737 | WorkflowTransition.delete_all | |
2722 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1) |
|
2738 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1) | |
2723 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5) |
|
2739 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5) | |
2724 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4) |
|
2740 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4) | |
2725 |
|
2741 | |||
2726 | xhr :put, :update_form, :project_id => 1, |
|
2742 | xhr :put, :update_form, :project_id => 1, | |
2727 | :id => 2, |
|
2743 | :id => 2, | |
2728 | :issue => {:tracker_id => 2, |
|
2744 | :issue => {:tracker_id => 2, | |
2729 | :status_id => 5, |
|
2745 | :status_id => 5, | |
2730 | :subject => 'This is an issue'} |
|
2746 | :subject => 'This is an issue'} | |
2731 |
|
2747 | |||
2732 | assert_equal 5, assigns(:issue).status_id |
|
2748 | assert_equal 5, assigns(:issue).status_id | |
2733 | assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort |
|
2749 | assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort | |
2734 | end |
|
2750 | end | |
2735 |
|
2751 | |||
2736 | def test_update_form_for_existing_issue_with_project_change |
|
2752 | def test_update_form_for_existing_issue_with_project_change | |
2737 | @request.session[:user_id] = 2 |
|
2753 | @request.session[:user_id] = 2 | |
2738 | xhr :put, :update_form, :project_id => 1, |
|
2754 | xhr :put, :update_form, :project_id => 1, | |
2739 | :id => 1, |
|
2755 | :id => 1, | |
2740 | :issue => {:project_id => 2, |
|
2756 | :issue => {:project_id => 2, | |
2741 | :tracker_id => 2, |
|
2757 | :tracker_id => 2, | |
2742 | :subject => 'This is the test_new issue', |
|
2758 | :subject => 'This is the test_new issue', | |
2743 | :description => 'This is the description', |
|
2759 | :description => 'This is the description', | |
2744 | :priority_id => 5} |
|
2760 | :priority_id => 5} | |
2745 | assert_response :success |
|
2761 | assert_response :success | |
2746 | assert_template :partial => '_form' |
|
2762 | assert_template :partial => '_form' | |
2747 |
|
2763 | |||
2748 | issue = assigns(:issue) |
|
2764 | issue = assigns(:issue) | |
2749 | assert_kind_of Issue, issue |
|
2765 | assert_kind_of Issue, issue | |
2750 | assert_equal 1, issue.id |
|
2766 | assert_equal 1, issue.id | |
2751 | assert_equal 2, issue.project_id |
|
2767 | assert_equal 2, issue.project_id | |
2752 | assert_equal 2, issue.tracker_id |
|
2768 | assert_equal 2, issue.tracker_id | |
2753 | assert_equal 'This is the test_new issue', issue.subject |
|
2769 | assert_equal 'This is the test_new issue', issue.subject | |
2754 | end |
|
2770 | end | |
2755 |
|
2771 | |||
2756 | def test_update_form_should_propose_default_status_for_existing_issue |
|
2772 | def test_update_form_should_propose_default_status_for_existing_issue | |
2757 | @request.session[:user_id] = 2 |
|
2773 | @request.session[:user_id] = 2 | |
2758 | WorkflowTransition.delete_all |
|
2774 | WorkflowTransition.delete_all | |
2759 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3) |
|
2775 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3) | |
2760 |
|
2776 | |||
2761 | xhr :put, :update_form, :project_id => 1, :id => 2 |
|
2777 | xhr :put, :update_form, :project_id => 1, :id => 2 | |
2762 | assert_response :success |
|
2778 | assert_response :success | |
2763 | assert_equal [2,3], assigns(:allowed_statuses).map(&:id).sort |
|
2779 | assert_equal [2,3], assigns(:allowed_statuses).map(&:id).sort | |
2764 | end |
|
2780 | end | |
2765 |
|
2781 | |||
2766 | def test_put_update_without_custom_fields_param |
|
2782 | def test_put_update_without_custom_fields_param | |
2767 | @request.session[:user_id] = 2 |
|
2783 | @request.session[:user_id] = 2 | |
2768 | ActionMailer::Base.deliveries.clear |
|
2784 | ActionMailer::Base.deliveries.clear | |
2769 |
|
2785 | |||
2770 | issue = Issue.find(1) |
|
2786 | issue = Issue.find(1) | |
2771 | assert_equal '125', issue.custom_value_for(2).value |
|
2787 | assert_equal '125', issue.custom_value_for(2).value | |
2772 | old_subject = issue.subject |
|
2788 | old_subject = issue.subject | |
2773 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
|
2789 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' | |
2774 |
|
2790 | |||
2775 | assert_difference('Journal.count') do |
|
2791 | assert_difference('Journal.count') do | |
2776 | assert_difference('JournalDetail.count', 2) do |
|
2792 | assert_difference('JournalDetail.count', 2) do | |
2777 | put :update, :id => 1, :issue => {:subject => new_subject, |
|
2793 | put :update, :id => 1, :issue => {:subject => new_subject, | |
2778 | :priority_id => '6', |
|
2794 | :priority_id => '6', | |
2779 | :category_id => '1' # no change |
|
2795 | :category_id => '1' # no change | |
2780 | } |
|
2796 | } | |
2781 | end |
|
2797 | end | |
2782 | end |
|
2798 | end | |
2783 | assert_redirected_to :action => 'show', :id => '1' |
|
2799 | assert_redirected_to :action => 'show', :id => '1' | |
2784 | issue.reload |
|
2800 | issue.reload | |
2785 | assert_equal new_subject, issue.subject |
|
2801 | assert_equal new_subject, issue.subject | |
2786 | # Make sure custom fields were not cleared |
|
2802 | # Make sure custom fields were not cleared | |
2787 | assert_equal '125', issue.custom_value_for(2).value |
|
2803 | assert_equal '125', issue.custom_value_for(2).value | |
2788 |
|
2804 | |||
2789 | mail = ActionMailer::Base.deliveries.last |
|
2805 | mail = ActionMailer::Base.deliveries.last | |
2790 | assert_not_nil mail |
|
2806 | assert_not_nil mail | |
2791 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") |
|
2807 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") | |
2792 | assert_mail_body_match "Subject changed from #{old_subject} to #{new_subject}", mail |
|
2808 | assert_mail_body_match "Subject changed from #{old_subject} to #{new_subject}", mail | |
2793 | end |
|
2809 | end | |
2794 |
|
2810 | |||
2795 | def test_put_update_with_project_change |
|
2811 | def test_put_update_with_project_change | |
2796 | @request.session[:user_id] = 2 |
|
2812 | @request.session[:user_id] = 2 | |
2797 | ActionMailer::Base.deliveries.clear |
|
2813 | ActionMailer::Base.deliveries.clear | |
2798 |
|
2814 | |||
2799 | assert_difference('Journal.count') do |
|
2815 | assert_difference('Journal.count') do | |
2800 | assert_difference('JournalDetail.count', 3) do |
|
2816 | assert_difference('JournalDetail.count', 3) do | |
2801 | put :update, :id => 1, :issue => {:project_id => '2', |
|
2817 | put :update, :id => 1, :issue => {:project_id => '2', | |
2802 | :tracker_id => '1', # no change |
|
2818 | :tracker_id => '1', # no change | |
2803 | :priority_id => '6', |
|
2819 | :priority_id => '6', | |
2804 | :category_id => '3' |
|
2820 | :category_id => '3' | |
2805 | } |
|
2821 | } | |
2806 | end |
|
2822 | end | |
2807 | end |
|
2823 | end | |
2808 | assert_redirected_to :action => 'show', :id => '1' |
|
2824 | assert_redirected_to :action => 'show', :id => '1' | |
2809 | issue = Issue.find(1) |
|
2825 | issue = Issue.find(1) | |
2810 | assert_equal 2, issue.project_id |
|
2826 | assert_equal 2, issue.project_id | |
2811 | assert_equal 1, issue.tracker_id |
|
2827 | assert_equal 1, issue.tracker_id | |
2812 | assert_equal 6, issue.priority_id |
|
2828 | assert_equal 6, issue.priority_id | |
2813 | assert_equal 3, issue.category_id |
|
2829 | assert_equal 3, issue.category_id | |
2814 |
|
2830 | |||
2815 | mail = ActionMailer::Base.deliveries.last |
|
2831 | mail = ActionMailer::Base.deliveries.last | |
2816 | assert_not_nil mail |
|
2832 | assert_not_nil mail | |
2817 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") |
|
2833 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") | |
2818 | assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail |
|
2834 | assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail | |
2819 | end |
|
2835 | end | |
2820 |
|
2836 | |||
2821 | def test_put_update_with_tracker_change |
|
2837 | def test_put_update_with_tracker_change | |
2822 | @request.session[:user_id] = 2 |
|
2838 | @request.session[:user_id] = 2 | |
2823 | ActionMailer::Base.deliveries.clear |
|
2839 | ActionMailer::Base.deliveries.clear | |
2824 |
|
2840 | |||
2825 | assert_difference('Journal.count') do |
|
2841 | assert_difference('Journal.count') do | |
2826 | assert_difference('JournalDetail.count', 2) do |
|
2842 | assert_difference('JournalDetail.count', 2) do | |
2827 | put :update, :id => 1, :issue => {:project_id => '1', |
|
2843 | put :update, :id => 1, :issue => {:project_id => '1', | |
2828 | :tracker_id => '2', |
|
2844 | :tracker_id => '2', | |
2829 | :priority_id => '6' |
|
2845 | :priority_id => '6' | |
2830 | } |
|
2846 | } | |
2831 | end |
|
2847 | end | |
2832 | end |
|
2848 | end | |
2833 | assert_redirected_to :action => 'show', :id => '1' |
|
2849 | assert_redirected_to :action => 'show', :id => '1' | |
2834 | issue = Issue.find(1) |
|
2850 | issue = Issue.find(1) | |
2835 | assert_equal 1, issue.project_id |
|
2851 | assert_equal 1, issue.project_id | |
2836 | assert_equal 2, issue.tracker_id |
|
2852 | assert_equal 2, issue.tracker_id | |
2837 | assert_equal 6, issue.priority_id |
|
2853 | assert_equal 6, issue.priority_id | |
2838 | assert_equal 1, issue.category_id |
|
2854 | assert_equal 1, issue.category_id | |
2839 |
|
2855 | |||
2840 | mail = ActionMailer::Base.deliveries.last |
|
2856 | mail = ActionMailer::Base.deliveries.last | |
2841 | assert_not_nil mail |
|
2857 | assert_not_nil mail | |
2842 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") |
|
2858 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") | |
2843 | assert_mail_body_match "Tracker changed from Bug to Feature request", mail |
|
2859 | assert_mail_body_match "Tracker changed from Bug to Feature request", mail | |
2844 | end |
|
2860 | end | |
2845 |
|
2861 | |||
2846 | def test_put_update_with_custom_field_change |
|
2862 | def test_put_update_with_custom_field_change | |
2847 | @request.session[:user_id] = 2 |
|
2863 | @request.session[:user_id] = 2 | |
2848 | issue = Issue.find(1) |
|
2864 | issue = Issue.find(1) | |
2849 | assert_equal '125', issue.custom_value_for(2).value |
|
2865 | assert_equal '125', issue.custom_value_for(2).value | |
2850 |
|
2866 | |||
2851 | assert_difference('Journal.count') do |
|
2867 | assert_difference('Journal.count') do | |
2852 | assert_difference('JournalDetail.count', 3) do |
|
2868 | assert_difference('JournalDetail.count', 3) do | |
2853 | put :update, :id => 1, :issue => {:subject => 'Custom field change', |
|
2869 | put :update, :id => 1, :issue => {:subject => 'Custom field change', | |
2854 | :priority_id => '6', |
|
2870 | :priority_id => '6', | |
2855 | :category_id => '1', # no change |
|
2871 | :category_id => '1', # no change | |
2856 | :custom_field_values => { '2' => 'New custom value' } |
|
2872 | :custom_field_values => { '2' => 'New custom value' } | |
2857 | } |
|
2873 | } | |
2858 | end |
|
2874 | end | |
2859 | end |
|
2875 | end | |
2860 | assert_redirected_to :action => 'show', :id => '1' |
|
2876 | assert_redirected_to :action => 'show', :id => '1' | |
2861 | issue.reload |
|
2877 | issue.reload | |
2862 | assert_equal 'New custom value', issue.custom_value_for(2).value |
|
2878 | assert_equal 'New custom value', issue.custom_value_for(2).value | |
2863 |
|
2879 | |||
2864 | mail = ActionMailer::Base.deliveries.last |
|
2880 | mail = ActionMailer::Base.deliveries.last | |
2865 | assert_not_nil mail |
|
2881 | assert_not_nil mail | |
2866 | assert_mail_body_match "Searchable field changed from 125 to New custom value", mail |
|
2882 | assert_mail_body_match "Searchable field changed from 125 to New custom value", mail | |
2867 | end |
|
2883 | end | |
2868 |
|
2884 | |||
2869 | def test_put_update_with_multi_custom_field_change |
|
2885 | def test_put_update_with_multi_custom_field_change | |
2870 | field = CustomField.find(1) |
|
2886 | field = CustomField.find(1) | |
2871 | field.update_attribute :multiple, true |
|
2887 | field.update_attribute :multiple, true | |
2872 | issue = Issue.find(1) |
|
2888 | issue = Issue.find(1) | |
2873 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
2889 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} | |
2874 | issue.save! |
|
2890 | issue.save! | |
2875 |
|
2891 | |||
2876 | @request.session[:user_id] = 2 |
|
2892 | @request.session[:user_id] = 2 | |
2877 | assert_difference('Journal.count') do |
|
2893 | assert_difference('Journal.count') do | |
2878 | assert_difference('JournalDetail.count', 3) do |
|
2894 | assert_difference('JournalDetail.count', 3) do | |
2879 | put :update, :id => 1, |
|
2895 | put :update, :id => 1, | |
2880 | :issue => { |
|
2896 | :issue => { | |
2881 | :subject => 'Custom field change', |
|
2897 | :subject => 'Custom field change', | |
2882 | :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] } |
|
2898 | :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] } | |
2883 | } |
|
2899 | } | |
2884 | end |
|
2900 | end | |
2885 | end |
|
2901 | end | |
2886 | assert_redirected_to :action => 'show', :id => '1' |
|
2902 | assert_redirected_to :action => 'show', :id => '1' | |
2887 | assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort |
|
2903 | assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort | |
2888 | end |
|
2904 | end | |
2889 |
|
2905 | |||
2890 | def test_put_update_with_status_and_assignee_change |
|
2906 | def test_put_update_with_status_and_assignee_change | |
2891 | issue = Issue.find(1) |
|
2907 | issue = Issue.find(1) | |
2892 | assert_equal 1, issue.status_id |
|
2908 | assert_equal 1, issue.status_id | |
2893 | @request.session[:user_id] = 2 |
|
2909 | @request.session[:user_id] = 2 | |
2894 | assert_difference('TimeEntry.count', 0) do |
|
2910 | assert_difference('TimeEntry.count', 0) do | |
2895 | put :update, |
|
2911 | put :update, | |
2896 | :id => 1, |
|
2912 | :id => 1, | |
2897 | :issue => { :status_id => 2, :assigned_to_id => 3, :notes => 'Assigned to dlopper' }, |
|
2913 | :issue => { :status_id => 2, :assigned_to_id => 3, :notes => 'Assigned to dlopper' }, | |
2898 | :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } |
|
2914 | :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } | |
2899 | end |
|
2915 | end | |
2900 | assert_redirected_to :action => 'show', :id => '1' |
|
2916 | assert_redirected_to :action => 'show', :id => '1' | |
2901 | issue.reload |
|
2917 | issue.reload | |
2902 | assert_equal 2, issue.status_id |
|
2918 | assert_equal 2, issue.status_id | |
2903 | j = Journal.order('id DESC').first |
|
2919 | j = Journal.order('id DESC').first | |
2904 | assert_equal 'Assigned to dlopper', j.notes |
|
2920 | assert_equal 'Assigned to dlopper', j.notes | |
2905 | assert_equal 2, j.details.size |
|
2921 | assert_equal 2, j.details.size | |
2906 |
|
2922 | |||
2907 | mail = ActionMailer::Base.deliveries.last |
|
2923 | mail = ActionMailer::Base.deliveries.last | |
2908 | assert_mail_body_match "Status changed from New to Assigned", mail |
|
2924 | assert_mail_body_match "Status changed from New to Assigned", mail | |
2909 | # subject should contain the new status |
|
2925 | # subject should contain the new status | |
2910 | assert mail.subject.include?("(#{ IssueStatus.find(2).name })") |
|
2926 | assert mail.subject.include?("(#{ IssueStatus.find(2).name })") | |
2911 | end |
|
2927 | end | |
2912 |
|
2928 | |||
2913 | def test_put_update_with_note_only |
|
2929 | def test_put_update_with_note_only | |
2914 | notes = 'Note added by IssuesControllerTest#test_update_with_note_only' |
|
2930 | notes = 'Note added by IssuesControllerTest#test_update_with_note_only' | |
2915 | # anonymous user |
|
2931 | # anonymous user | |
2916 | put :update, |
|
2932 | put :update, | |
2917 | :id => 1, |
|
2933 | :id => 1, | |
2918 | :issue => { :notes => notes } |
|
2934 | :issue => { :notes => notes } | |
2919 | assert_redirected_to :action => 'show', :id => '1' |
|
2935 | assert_redirected_to :action => 'show', :id => '1' | |
2920 | j = Journal.order('id DESC').first |
|
2936 | j = Journal.order('id DESC').first | |
2921 | assert_equal notes, j.notes |
|
2937 | assert_equal notes, j.notes | |
2922 | assert_equal 0, j.details.size |
|
2938 | assert_equal 0, j.details.size | |
2923 | assert_equal User.anonymous, j.user |
|
2939 | assert_equal User.anonymous, j.user | |
2924 |
|
2940 | |||
2925 | mail = ActionMailer::Base.deliveries.last |
|
2941 | mail = ActionMailer::Base.deliveries.last | |
2926 | assert_mail_body_match notes, mail |
|
2942 | assert_mail_body_match notes, mail | |
2927 | end |
|
2943 | end | |
2928 |
|
2944 | |||
2929 | def test_put_update_with_private_note_only |
|
2945 | def test_put_update_with_private_note_only | |
2930 | notes = 'Private note' |
|
2946 | notes = 'Private note' | |
2931 | @request.session[:user_id] = 2 |
|
2947 | @request.session[:user_id] = 2 | |
2932 |
|
2948 | |||
2933 | assert_difference 'Journal.count' do |
|
2949 | assert_difference 'Journal.count' do | |
2934 | put :update, :id => 1, :issue => {:notes => notes, :private_notes => '1'} |
|
2950 | put :update, :id => 1, :issue => {:notes => notes, :private_notes => '1'} | |
2935 | assert_redirected_to :action => 'show', :id => '1' |
|
2951 | assert_redirected_to :action => 'show', :id => '1' | |
2936 | end |
|
2952 | end | |
2937 |
|
2953 | |||
2938 | j = Journal.order('id DESC').first |
|
2954 | j = Journal.order('id DESC').first | |
2939 | assert_equal notes, j.notes |
|
2955 | assert_equal notes, j.notes | |
2940 | assert_equal true, j.private_notes |
|
2956 | assert_equal true, j.private_notes | |
2941 | end |
|
2957 | end | |
2942 |
|
2958 | |||
2943 | def test_put_update_with_private_note_and_changes |
|
2959 | def test_put_update_with_private_note_and_changes | |
2944 | notes = 'Private note' |
|
2960 | notes = 'Private note' | |
2945 | @request.session[:user_id] = 2 |
|
2961 | @request.session[:user_id] = 2 | |
2946 |
|
2962 | |||
2947 | assert_difference 'Journal.count', 2 do |
|
2963 | assert_difference 'Journal.count', 2 do | |
2948 | put :update, :id => 1, :issue => {:subject => 'New subject', :notes => notes, :private_notes => '1'} |
|
2964 | put :update, :id => 1, :issue => {:subject => 'New subject', :notes => notes, :private_notes => '1'} | |
2949 | assert_redirected_to :action => 'show', :id => '1' |
|
2965 | assert_redirected_to :action => 'show', :id => '1' | |
2950 | end |
|
2966 | end | |
2951 |
|
2967 | |||
2952 | j = Journal.order('id DESC').first |
|
2968 | j = Journal.order('id DESC').first | |
2953 | assert_equal notes, j.notes |
|
2969 | assert_equal notes, j.notes | |
2954 | assert_equal true, j.private_notes |
|
2970 | assert_equal true, j.private_notes | |
2955 | assert_equal 0, j.details.count |
|
2971 | assert_equal 0, j.details.count | |
2956 |
|
2972 | |||
2957 | j = Journal.order('id DESC').offset(1).first |
|
2973 | j = Journal.order('id DESC').offset(1).first | |
2958 | assert_nil j.notes |
|
2974 | assert_nil j.notes | |
2959 | assert_equal false, j.private_notes |
|
2975 | assert_equal false, j.private_notes | |
2960 | assert_equal 1, j.details.count |
|
2976 | assert_equal 1, j.details.count | |
2961 | end |
|
2977 | end | |
2962 |
|
2978 | |||
2963 | def test_put_update_with_note_and_spent_time |
|
2979 | def test_put_update_with_note_and_spent_time | |
2964 | @request.session[:user_id] = 2 |
|
2980 | @request.session[:user_id] = 2 | |
2965 | spent_hours_before = Issue.find(1).spent_hours |
|
2981 | spent_hours_before = Issue.find(1).spent_hours | |
2966 | assert_difference('TimeEntry.count') do |
|
2982 | assert_difference('TimeEntry.count') do | |
2967 | put :update, |
|
2983 | put :update, | |
2968 | :id => 1, |
|
2984 | :id => 1, | |
2969 | :issue => { :notes => '2.5 hours added' }, |
|
2985 | :issue => { :notes => '2.5 hours added' }, | |
2970 | :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id } |
|
2986 | :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id } | |
2971 | end |
|
2987 | end | |
2972 | assert_redirected_to :action => 'show', :id => '1' |
|
2988 | assert_redirected_to :action => 'show', :id => '1' | |
2973 |
|
2989 | |||
2974 | issue = Issue.find(1) |
|
2990 | issue = Issue.find(1) | |
2975 |
|
2991 | |||
2976 | j = Journal.order('id DESC').first |
|
2992 | j = Journal.order('id DESC').first | |
2977 | assert_equal '2.5 hours added', j.notes |
|
2993 | assert_equal '2.5 hours added', j.notes | |
2978 | assert_equal 0, j.details.size |
|
2994 | assert_equal 0, j.details.size | |
2979 |
|
2995 | |||
2980 | t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time') |
|
2996 | t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time') | |
2981 | assert_not_nil t |
|
2997 | assert_not_nil t | |
2982 | assert_equal 2.5, t.hours |
|
2998 | assert_equal 2.5, t.hours | |
2983 | assert_equal spent_hours_before + 2.5, issue.spent_hours |
|
2999 | assert_equal spent_hours_before + 2.5, issue.spent_hours | |
2984 | end |
|
3000 | end | |
2985 |
|
3001 | |||
2986 | def test_put_update_should_preserve_parent_issue_even_if_not_visible |
|
3002 | def test_put_update_should_preserve_parent_issue_even_if_not_visible | |
2987 | parent = Issue.generate!(:project_id => 1, :is_private => true) |
|
3003 | parent = Issue.generate!(:project_id => 1, :is_private => true) | |
2988 | issue = Issue.generate!(:parent_issue_id => parent.id) |
|
3004 | issue = Issue.generate!(:parent_issue_id => parent.id) | |
2989 | assert !parent.visible?(User.find(3)) |
|
3005 | assert !parent.visible?(User.find(3)) | |
2990 | @request.session[:user_id] = 3 |
|
3006 | @request.session[:user_id] = 3 | |
2991 |
|
3007 | |||
2992 | get :edit, :id => issue.id |
|
3008 | get :edit, :id => issue.id | |
2993 | assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', parent.id.to_s |
|
3009 | assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', parent.id.to_s | |
2994 |
|
3010 | |||
2995 | put :update, :id => issue.id, :issue => {:subject => 'New subject', :parent_issue_id => parent.id.to_s} |
|
3011 | put :update, :id => issue.id, :issue => {:subject => 'New subject', :parent_issue_id => parent.id.to_s} | |
2996 | assert_response 302 |
|
3012 | assert_response 302 | |
2997 | assert_equal parent, issue.parent |
|
3013 | assert_equal parent, issue.parent | |
2998 | end |
|
3014 | end | |
2999 |
|
3015 | |||
3000 | def test_put_update_with_attachment_only |
|
3016 | def test_put_update_with_attachment_only | |
3001 | set_tmp_attachments_directory |
|
3017 | set_tmp_attachments_directory | |
3002 |
|
3018 | |||
3003 | # Delete all fixtured journals, a race condition can occur causing the wrong |
|
3019 | # Delete all fixtured journals, a race condition can occur causing the wrong | |
3004 | # journal to get fetched in the next find. |
|
3020 | # journal to get fetched in the next find. | |
3005 | Journal.delete_all |
|
3021 | Journal.delete_all | |
3006 |
|
3022 | |||
3007 | # anonymous user |
|
3023 | # anonymous user | |
3008 | assert_difference 'Attachment.count' do |
|
3024 | assert_difference 'Attachment.count' do | |
3009 | put :update, :id => 1, |
|
3025 | put :update, :id => 1, | |
3010 | :issue => {:notes => ''}, |
|
3026 | :issue => {:notes => ''}, | |
3011 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
3027 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | |
3012 | end |
|
3028 | end | |
3013 |
|
3029 | |||
3014 | assert_redirected_to :action => 'show', :id => '1' |
|
3030 | assert_redirected_to :action => 'show', :id => '1' | |
3015 | j = Issue.find(1).journals.reorder('id DESC').first |
|
3031 | j = Issue.find(1).journals.reorder('id DESC').first | |
3016 | assert j.notes.blank? |
|
3032 | assert j.notes.blank? | |
3017 | assert_equal 1, j.details.size |
|
3033 | assert_equal 1, j.details.size | |
3018 | assert_equal 'testfile.txt', j.details.first.value |
|
3034 | assert_equal 'testfile.txt', j.details.first.value | |
3019 | assert_equal User.anonymous, j.user |
|
3035 | assert_equal User.anonymous, j.user | |
3020 |
|
3036 | |||
3021 | attachment = Attachment.order('id DESC').first |
|
3037 | attachment = Attachment.order('id DESC').first | |
3022 | assert_equal Issue.find(1), attachment.container |
|
3038 | assert_equal Issue.find(1), attachment.container | |
3023 | assert_equal User.anonymous, attachment.author |
|
3039 | assert_equal User.anonymous, attachment.author | |
3024 | assert_equal 'testfile.txt', attachment.filename |
|
3040 | assert_equal 'testfile.txt', attachment.filename | |
3025 | assert_equal 'text/plain', attachment.content_type |
|
3041 | assert_equal 'text/plain', attachment.content_type | |
3026 | assert_equal 'test file', attachment.description |
|
3042 | assert_equal 'test file', attachment.description | |
3027 | assert_equal 59, attachment.filesize |
|
3043 | assert_equal 59, attachment.filesize | |
3028 | assert File.exists?(attachment.diskfile) |
|
3044 | assert File.exists?(attachment.diskfile) | |
3029 | assert_equal 59, File.size(attachment.diskfile) |
|
3045 | assert_equal 59, File.size(attachment.diskfile) | |
3030 |
|
3046 | |||
3031 | mail = ActionMailer::Base.deliveries.last |
|
3047 | mail = ActionMailer::Base.deliveries.last | |
3032 | assert_mail_body_match 'testfile.txt', mail |
|
3048 | assert_mail_body_match 'testfile.txt', mail | |
3033 | end |
|
3049 | end | |
3034 |
|
3050 | |||
3035 | def test_put_update_with_failure_should_save_attachments |
|
3051 | def test_put_update_with_failure_should_save_attachments | |
3036 | set_tmp_attachments_directory |
|
3052 | set_tmp_attachments_directory | |
3037 | @request.session[:user_id] = 2 |
|
3053 | @request.session[:user_id] = 2 | |
3038 |
|
3054 | |||
3039 | assert_no_difference 'Journal.count' do |
|
3055 | assert_no_difference 'Journal.count' do | |
3040 | assert_difference 'Attachment.count' do |
|
3056 | assert_difference 'Attachment.count' do | |
3041 | put :update, :id => 1, |
|
3057 | put :update, :id => 1, | |
3042 | :issue => { :subject => '' }, |
|
3058 | :issue => { :subject => '' }, | |
3043 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
3059 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | |
3044 | assert_response :success |
|
3060 | assert_response :success | |
3045 | assert_template 'edit' |
|
3061 | assert_template 'edit' | |
3046 | end |
|
3062 | end | |
3047 | end |
|
3063 | end | |
3048 |
|
3064 | |||
3049 | attachment = Attachment.order('id DESC').first |
|
3065 | attachment = Attachment.order('id DESC').first | |
3050 | assert_equal 'testfile.txt', attachment.filename |
|
3066 | assert_equal 'testfile.txt', attachment.filename | |
3051 | assert File.exists?(attachment.diskfile) |
|
3067 | assert File.exists?(attachment.diskfile) | |
3052 | assert_nil attachment.container |
|
3068 | assert_nil attachment.container | |
3053 |
|
3069 | |||
3054 | assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token |
|
3070 | assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token | |
3055 | assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' |
|
3071 | assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' | |
3056 | end |
|
3072 | end | |
3057 |
|
3073 | |||
3058 | def test_put_update_with_failure_should_keep_saved_attachments |
|
3074 | def test_put_update_with_failure_should_keep_saved_attachments | |
3059 | set_tmp_attachments_directory |
|
3075 | set_tmp_attachments_directory | |
3060 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
|
3076 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) | |
3061 | @request.session[:user_id] = 2 |
|
3077 | @request.session[:user_id] = 2 | |
3062 |
|
3078 | |||
3063 | assert_no_difference 'Journal.count' do |
|
3079 | assert_no_difference 'Journal.count' do | |
3064 | assert_no_difference 'Attachment.count' do |
|
3080 | assert_no_difference 'Attachment.count' do | |
3065 | put :update, :id => 1, |
|
3081 | put :update, :id => 1, | |
3066 | :issue => { :subject => '' }, |
|
3082 | :issue => { :subject => '' }, | |
3067 | :attachments => {'p0' => {'token' => attachment.token}} |
|
3083 | :attachments => {'p0' => {'token' => attachment.token}} | |
3068 | assert_response :success |
|
3084 | assert_response :success | |
3069 | assert_template 'edit' |
|
3085 | assert_template 'edit' | |
3070 | end |
|
3086 | end | |
3071 | end |
|
3087 | end | |
3072 |
|
3088 | |||
3073 | assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token |
|
3089 | assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token | |
3074 | assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' |
|
3090 | assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' | |
3075 | end |
|
3091 | end | |
3076 |
|
3092 | |||
3077 | def test_put_update_should_attach_saved_attachments |
|
3093 | def test_put_update_should_attach_saved_attachments | |
3078 | set_tmp_attachments_directory |
|
3094 | set_tmp_attachments_directory | |
3079 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
|
3095 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) | |
3080 | @request.session[:user_id] = 2 |
|
3096 | @request.session[:user_id] = 2 | |
3081 |
|
3097 | |||
3082 | assert_difference 'Journal.count' do |
|
3098 | assert_difference 'Journal.count' do | |
3083 | assert_difference 'JournalDetail.count' do |
|
3099 | assert_difference 'JournalDetail.count' do | |
3084 | assert_no_difference 'Attachment.count' do |
|
3100 | assert_no_difference 'Attachment.count' do | |
3085 | put :update, :id => 1, |
|
3101 | put :update, :id => 1, | |
3086 | :issue => {:notes => 'Attachment added'}, |
|
3102 | :issue => {:notes => 'Attachment added'}, | |
3087 | :attachments => {'p0' => {'token' => attachment.token}} |
|
3103 | :attachments => {'p0' => {'token' => attachment.token}} | |
3088 | assert_redirected_to '/issues/1' |
|
3104 | assert_redirected_to '/issues/1' | |
3089 | end |
|
3105 | end | |
3090 | end |
|
3106 | end | |
3091 | end |
|
3107 | end | |
3092 |
|
3108 | |||
3093 | attachment.reload |
|
3109 | attachment.reload | |
3094 | assert_equal Issue.find(1), attachment.container |
|
3110 | assert_equal Issue.find(1), attachment.container | |
3095 |
|
3111 | |||
3096 | journal = Journal.order('id DESC').first |
|
3112 | journal = Journal.order('id DESC').first | |
3097 | assert_equal 1, journal.details.size |
|
3113 | assert_equal 1, journal.details.size | |
3098 | assert_equal 'testfile.txt', journal.details.first.value |
|
3114 | assert_equal 'testfile.txt', journal.details.first.value | |
3099 | end |
|
3115 | end | |
3100 |
|
3116 | |||
3101 | def test_put_update_with_attachment_that_fails_to_save |
|
3117 | def test_put_update_with_attachment_that_fails_to_save | |
3102 | set_tmp_attachments_directory |
|
3118 | set_tmp_attachments_directory | |
3103 |
|
3119 | |||
3104 | # Delete all fixtured journals, a race condition can occur causing the wrong |
|
3120 | # Delete all fixtured journals, a race condition can occur causing the wrong | |
3105 | # journal to get fetched in the next find. |
|
3121 | # journal to get fetched in the next find. | |
3106 | Journal.delete_all |
|
3122 | Journal.delete_all | |
3107 |
|
3123 | |||
3108 | # Mock out the unsaved attachment |
|
3124 | # Mock out the unsaved attachment | |
3109 | Attachment.any_instance.stubs(:create).returns(Attachment.new) |
|
3125 | Attachment.any_instance.stubs(:create).returns(Attachment.new) | |
3110 |
|
3126 | |||
3111 | # anonymous user |
|
3127 | # anonymous user | |
3112 | put :update, |
|
3128 | put :update, | |
3113 | :id => 1, |
|
3129 | :id => 1, | |
3114 | :issue => {:notes => ''}, |
|
3130 | :issue => {:notes => ''}, | |
3115 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
3131 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
3116 | assert_redirected_to :action => 'show', :id => '1' |
|
3132 | assert_redirected_to :action => 'show', :id => '1' | |
3117 | assert_equal '1 file(s) could not be saved.', flash[:warning] |
|
3133 | assert_equal '1 file(s) could not be saved.', flash[:warning] | |
3118 | end |
|
3134 | end | |
3119 |
|
3135 | |||
3120 | def test_put_update_with_no_change |
|
3136 | def test_put_update_with_no_change | |
3121 | issue = Issue.find(1) |
|
3137 | issue = Issue.find(1) | |
3122 | issue.journals.clear |
|
3138 | issue.journals.clear | |
3123 | ActionMailer::Base.deliveries.clear |
|
3139 | ActionMailer::Base.deliveries.clear | |
3124 |
|
3140 | |||
3125 | put :update, |
|
3141 | put :update, | |
3126 | :id => 1, |
|
3142 | :id => 1, | |
3127 | :issue => {:notes => ''} |
|
3143 | :issue => {:notes => ''} | |
3128 | assert_redirected_to :action => 'show', :id => '1' |
|
3144 | assert_redirected_to :action => 'show', :id => '1' | |
3129 |
|
3145 | |||
3130 | issue.reload |
|
3146 | issue.reload | |
3131 | assert issue.journals.empty? |
|
3147 | assert issue.journals.empty? | |
3132 | # No email should be sent |
|
3148 | # No email should be sent | |
3133 | assert ActionMailer::Base.deliveries.empty? |
|
3149 | assert ActionMailer::Base.deliveries.empty? | |
3134 | end |
|
3150 | end | |
3135 |
|
3151 | |||
3136 | def test_put_update_should_send_a_notification |
|
3152 | def test_put_update_should_send_a_notification | |
3137 | @request.session[:user_id] = 2 |
|
3153 | @request.session[:user_id] = 2 | |
3138 | ActionMailer::Base.deliveries.clear |
|
3154 | ActionMailer::Base.deliveries.clear | |
3139 | issue = Issue.find(1) |
|
3155 | issue = Issue.find(1) | |
3140 | old_subject = issue.subject |
|
3156 | old_subject = issue.subject | |
3141 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
|
3157 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' | |
3142 |
|
3158 | |||
3143 | put :update, :id => 1, :issue => {:subject => new_subject, |
|
3159 | put :update, :id => 1, :issue => {:subject => new_subject, | |
3144 | :priority_id => '6', |
|
3160 | :priority_id => '6', | |
3145 | :category_id => '1' # no change |
|
3161 | :category_id => '1' # no change | |
3146 | } |
|
3162 | } | |
3147 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
3163 | assert_equal 1, ActionMailer::Base.deliveries.size | |
3148 | end |
|
3164 | end | |
3149 |
|
3165 | |||
3150 | def test_put_update_with_invalid_spent_time_hours_only |
|
3166 | def test_put_update_with_invalid_spent_time_hours_only | |
3151 | @request.session[:user_id] = 2 |
|
3167 | @request.session[:user_id] = 2 | |
3152 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' |
|
3168 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' | |
3153 |
|
3169 | |||
3154 | assert_no_difference('Journal.count') do |
|
3170 | assert_no_difference('Journal.count') do | |
3155 | put :update, |
|
3171 | put :update, | |
3156 | :id => 1, |
|
3172 | :id => 1, | |
3157 | :issue => {:notes => notes}, |
|
3173 | :issue => {:notes => notes}, | |
3158 | :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} |
|
3174 | :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} | |
3159 | end |
|
3175 | end | |
3160 | assert_response :success |
|
3176 | assert_response :success | |
3161 | assert_template 'edit' |
|
3177 | assert_template 'edit' | |
3162 |
|
3178 | |||
3163 | assert_error_tag :descendant => {:content => /Activity #{ESCAPED_CANT} be blank/} |
|
3179 | assert_error_tag :descendant => {:content => /Activity #{ESCAPED_CANT} be blank/} | |
3164 | assert_select 'textarea[name=?]', 'issue[notes]', :text => notes |
|
3180 | assert_select 'textarea[name=?]', 'issue[notes]', :text => notes | |
3165 | assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2z' |
|
3181 | assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2z' | |
3166 | end |
|
3182 | end | |
3167 |
|
3183 | |||
3168 | def test_put_update_with_invalid_spent_time_comments_only |
|
3184 | def test_put_update_with_invalid_spent_time_comments_only | |
3169 | @request.session[:user_id] = 2 |
|
3185 | @request.session[:user_id] = 2 | |
3170 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' |
|
3186 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' | |
3171 |
|
3187 | |||
3172 | assert_no_difference('Journal.count') do |
|
3188 | assert_no_difference('Journal.count') do | |
3173 | put :update, |
|
3189 | put :update, | |
3174 | :id => 1, |
|
3190 | :id => 1, | |
3175 | :issue => {:notes => notes}, |
|
3191 | :issue => {:notes => notes}, | |
3176 | :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""} |
|
3192 | :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""} | |
3177 | end |
|
3193 | end | |
3178 | assert_response :success |
|
3194 | assert_response :success | |
3179 | assert_template 'edit' |
|
3195 | assert_template 'edit' | |
3180 |
|
3196 | |||
3181 | assert_error_tag :descendant => {:content => /Activity #{ESCAPED_CANT} be blank/} |
|
3197 | assert_error_tag :descendant => {:content => /Activity #{ESCAPED_CANT} be blank/} | |
3182 | assert_error_tag :descendant => {:content => /Hours #{ESCAPED_CANT} be blank/} |
|
3198 | assert_error_tag :descendant => {:content => /Hours #{ESCAPED_CANT} be blank/} | |
3183 | assert_select 'textarea[name=?]', 'issue[notes]', :text => notes |
|
3199 | assert_select 'textarea[name=?]', 'issue[notes]', :text => notes | |
3184 | assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'this is my comment' |
|
3200 | assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'this is my comment' | |
3185 | end |
|
3201 | end | |
3186 |
|
3202 | |||
3187 | def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject |
|
3203 | def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject | |
3188 | issue = Issue.find(2) |
|
3204 | issue = Issue.find(2) | |
3189 | @request.session[:user_id] = 2 |
|
3205 | @request.session[:user_id] = 2 | |
3190 |
|
3206 | |||
3191 | put :update, |
|
3207 | put :update, | |
3192 | :id => issue.id, |
|
3208 | :id => issue.id, | |
3193 | :issue => { |
|
3209 | :issue => { | |
3194 | :fixed_version_id => 4 |
|
3210 | :fixed_version_id => 4 | |
3195 | } |
|
3211 | } | |
3196 |
|
3212 | |||
3197 | assert_response :redirect |
|
3213 | assert_response :redirect | |
3198 | issue.reload |
|
3214 | issue.reload | |
3199 | assert_equal 4, issue.fixed_version_id |
|
3215 | assert_equal 4, issue.fixed_version_id | |
3200 | assert_not_equal issue.project_id, issue.fixed_version.project_id |
|
3216 | assert_not_equal issue.project_id, issue.fixed_version.project_id | |
3201 | end |
|
3217 | end | |
3202 |
|
3218 | |||
3203 | def test_put_update_should_redirect_back_using_the_back_url_parameter |
|
3219 | def test_put_update_should_redirect_back_using_the_back_url_parameter | |
3204 | issue = Issue.find(2) |
|
3220 | issue = Issue.find(2) | |
3205 | @request.session[:user_id] = 2 |
|
3221 | @request.session[:user_id] = 2 | |
3206 |
|
3222 | |||
3207 | put :update, |
|
3223 | put :update, | |
3208 | :id => issue.id, |
|
3224 | :id => issue.id, | |
3209 | :issue => { |
|
3225 | :issue => { | |
3210 | :fixed_version_id => 4 |
|
3226 | :fixed_version_id => 4 | |
3211 | }, |
|
3227 | }, | |
3212 | :back_url => '/issues' |
|
3228 | :back_url => '/issues' | |
3213 |
|
3229 | |||
3214 | assert_response :redirect |
|
3230 | assert_response :redirect | |
3215 | assert_redirected_to '/issues' |
|
3231 | assert_redirected_to '/issues' | |
3216 | end |
|
3232 | end | |
3217 |
|
3233 | |||
3218 | def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
3234 | def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host | |
3219 | issue = Issue.find(2) |
|
3235 | issue = Issue.find(2) | |
3220 | @request.session[:user_id] = 2 |
|
3236 | @request.session[:user_id] = 2 | |
3221 |
|
3237 | |||
3222 | put :update, |
|
3238 | put :update, | |
3223 | :id => issue.id, |
|
3239 | :id => issue.id, | |
3224 | :issue => { |
|
3240 | :issue => { | |
3225 | :fixed_version_id => 4 |
|
3241 | :fixed_version_id => 4 | |
3226 | }, |
|
3242 | }, | |
3227 | :back_url => 'http://google.com' |
|
3243 | :back_url => 'http://google.com' | |
3228 |
|
3244 | |||
3229 | assert_response :redirect |
|
3245 | assert_response :redirect | |
3230 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id |
|
3246 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id | |
3231 | end |
|
3247 | end | |
3232 |
|
3248 | |||
3233 | def test_get_bulk_edit |
|
3249 | def test_get_bulk_edit | |
3234 | @request.session[:user_id] = 2 |
|
3250 | @request.session[:user_id] = 2 | |
3235 | get :bulk_edit, :ids => [1, 2] |
|
3251 | get :bulk_edit, :ids => [1, 2] | |
3236 | assert_response :success |
|
3252 | assert_response :success | |
3237 | assert_template 'bulk_edit' |
|
3253 | assert_template 'bulk_edit' | |
3238 |
|
3254 | |||
3239 | assert_select 'ul#bulk-selection' do |
|
3255 | assert_select 'ul#bulk-selection' do | |
3240 | assert_select 'li', 2 |
|
3256 | assert_select 'li', 2 | |
3241 | assert_select 'li a', :text => 'Bug #1' |
|
3257 | assert_select 'li a', :text => 'Bug #1' | |
3242 | end |
|
3258 | end | |
3243 |
|
3259 | |||
3244 | assert_select 'form#bulk_edit_form[action=?]', '/issues/bulk_update' do |
|
3260 | assert_select 'form#bulk_edit_form[action=?]', '/issues/bulk_update' do | |
3245 | assert_select 'input[name=?]', 'ids[]', 2 |
|
3261 | assert_select 'input[name=?]', 'ids[]', 2 | |
3246 | assert_select 'input[name=?][value=1][type=hidden]', 'ids[]' |
|
3262 | assert_select 'input[name=?][value=1][type=hidden]', 'ids[]' | |
3247 |
|
3263 | |||
3248 | assert_select 'select[name=?]', 'issue[project_id]' |
|
3264 | assert_select 'select[name=?]', 'issue[project_id]' | |
3249 | assert_select 'input[name=?]', 'issue[parent_issue_id]' |
|
3265 | assert_select 'input[name=?]', 'issue[parent_issue_id]' | |
3250 |
|
3266 | |||
3251 | # Project specific custom field, date type |
|
3267 | # Project specific custom field, date type | |
3252 | field = CustomField.find(9) |
|
3268 | field = CustomField.find(9) | |
3253 | assert !field.is_for_all? |
|
3269 | assert !field.is_for_all? | |
3254 | assert_equal 'date', field.field_format |
|
3270 | assert_equal 'date', field.field_format | |
3255 | assert_select 'input[name=?]', 'issue[custom_field_values][9]' |
|
3271 | assert_select 'input[name=?]', 'issue[custom_field_values][9]' | |
3256 |
|
3272 | |||
3257 | # System wide custom field |
|
3273 | # System wide custom field | |
3258 | assert CustomField.find(1).is_for_all? |
|
3274 | assert CustomField.find(1).is_for_all? | |
3259 | assert_select 'select[name=?]', 'issue[custom_field_values][1]' |
|
3275 | assert_select 'select[name=?]', 'issue[custom_field_values][1]' | |
3260 |
|
3276 | |||
3261 | # Be sure we don't display inactive IssuePriorities |
|
3277 | # Be sure we don't display inactive IssuePriorities | |
3262 | assert ! IssuePriority.find(15).active? |
|
3278 | assert ! IssuePriority.find(15).active? | |
3263 | assert_select 'select[name=?]', 'issue[priority_id]' do |
|
3279 | assert_select 'select[name=?]', 'issue[priority_id]' do | |
3264 | assert_select 'option[value=15]', 0 |
|
3280 | assert_select 'option[value=15]', 0 | |
3265 | end |
|
3281 | end | |
3266 | end |
|
3282 | end | |
3267 | end |
|
3283 | end | |
3268 |
|
3284 | |||
3269 | def test_get_bulk_edit_on_different_projects |
|
3285 | def test_get_bulk_edit_on_different_projects | |
3270 | @request.session[:user_id] = 2 |
|
3286 | @request.session[:user_id] = 2 | |
3271 | get :bulk_edit, :ids => [1, 2, 6] |
|
3287 | get :bulk_edit, :ids => [1, 2, 6] | |
3272 | assert_response :success |
|
3288 | assert_response :success | |
3273 | assert_template 'bulk_edit' |
|
3289 | assert_template 'bulk_edit' | |
3274 |
|
3290 | |||
3275 | # Can not set issues from different projects as children of an issue |
|
3291 | # Can not set issues from different projects as children of an issue | |
3276 | assert_select 'input[name=?]', 'issue[parent_issue_id]', 0 |
|
3292 | assert_select 'input[name=?]', 'issue[parent_issue_id]', 0 | |
3277 |
|
3293 | |||
3278 | # Project specific custom field, date type |
|
3294 | # Project specific custom field, date type | |
3279 | field = CustomField.find(9) |
|
3295 | field = CustomField.find(9) | |
3280 | assert !field.is_for_all? |
|
3296 | assert !field.is_for_all? | |
3281 | assert !field.project_ids.include?(Issue.find(6).project_id) |
|
3297 | assert !field.project_ids.include?(Issue.find(6).project_id) | |
3282 | assert_select 'input[name=?]', 'issue[custom_field_values][9]', 0 |
|
3298 | assert_select 'input[name=?]', 'issue[custom_field_values][9]', 0 | |
3283 | end |
|
3299 | end | |
3284 |
|
3300 | |||
3285 | def test_get_bulk_edit_with_user_custom_field |
|
3301 | def test_get_bulk_edit_with_user_custom_field | |
3286 | field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true) |
|
3302 | field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true) | |
3287 |
|
3303 | |||
3288 | @request.session[:user_id] = 2 |
|
3304 | @request.session[:user_id] = 2 | |
3289 | get :bulk_edit, :ids => [1, 2] |
|
3305 | get :bulk_edit, :ids => [1, 2] | |
3290 | assert_response :success |
|
3306 | assert_response :success | |
3291 | assert_template 'bulk_edit' |
|
3307 | assert_template 'bulk_edit' | |
3292 |
|
3308 | |||
3293 | assert_select 'select.user_cf[name=?]', "issue[custom_field_values][#{field.id}]" do |
|
3309 | assert_select 'select.user_cf[name=?]', "issue[custom_field_values][#{field.id}]" do | |
3294 | assert_select 'option', Project.find(1).users.count + 2 # "no change" + "none" options |
|
3310 | assert_select 'option', Project.find(1).users.count + 2 # "no change" + "none" options | |
3295 | end |
|
3311 | end | |
3296 | end |
|
3312 | end | |
3297 |
|
3313 | |||
3298 | def test_get_bulk_edit_with_version_custom_field |
|
3314 | def test_get_bulk_edit_with_version_custom_field | |
3299 | field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true) |
|
3315 | field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true) | |
3300 |
|
3316 | |||
3301 | @request.session[:user_id] = 2 |
|
3317 | @request.session[:user_id] = 2 | |
3302 | get :bulk_edit, :ids => [1, 2] |
|
3318 | get :bulk_edit, :ids => [1, 2] | |
3303 | assert_response :success |
|
3319 | assert_response :success | |
3304 | assert_template 'bulk_edit' |
|
3320 | assert_template 'bulk_edit' | |
3305 |
|
3321 | |||
3306 | assert_select 'select.version_cf[name=?]', "issue[custom_field_values][#{field.id}]" do |
|
3322 | assert_select 'select.version_cf[name=?]', "issue[custom_field_values][#{field.id}]" do | |
3307 | assert_select 'option', Project.find(1).shared_versions.count + 2 # "no change" + "none" options |
|
3323 | assert_select 'option', Project.find(1).shared_versions.count + 2 # "no change" + "none" options | |
3308 | end |
|
3324 | end | |
3309 | end |
|
3325 | end | |
3310 |
|
3326 | |||
3311 | def test_get_bulk_edit_with_multi_custom_field |
|
3327 | def test_get_bulk_edit_with_multi_custom_field | |
3312 | field = CustomField.find(1) |
|
3328 | field = CustomField.find(1) | |
3313 | field.update_attribute :multiple, true |
|
3329 | field.update_attribute :multiple, true | |
3314 |
|
3330 | |||
3315 | @request.session[:user_id] = 2 |
|
3331 | @request.session[:user_id] = 2 | |
3316 | get :bulk_edit, :ids => [1, 2] |
|
3332 | get :bulk_edit, :ids => [1, 2] | |
3317 | assert_response :success |
|
3333 | assert_response :success | |
3318 | assert_template 'bulk_edit' |
|
3334 | assert_template 'bulk_edit' | |
3319 |
|
3335 | |||
3320 | assert_select 'select[name=?]', 'issue[custom_field_values][1][]' do |
|
3336 | assert_select 'select[name=?]', 'issue[custom_field_values][1][]' do | |
3321 | assert_select 'option', field.possible_values.size + 1 # "none" options |
|
3337 | assert_select 'option', field.possible_values.size + 1 # "none" options | |
3322 | end |
|
3338 | end | |
3323 | end |
|
3339 | end | |
3324 |
|
3340 | |||
3325 | def test_bulk_edit_should_propose_to_clear_text_custom_fields |
|
3341 | def test_bulk_edit_should_propose_to_clear_text_custom_fields | |
3326 | @request.session[:user_id] = 2 |
|
3342 | @request.session[:user_id] = 2 | |
3327 | get :bulk_edit, :ids => [1, 3] |
|
3343 | get :bulk_edit, :ids => [1, 3] | |
3328 | assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', '__none__' |
|
3344 | assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', '__none__' | |
3329 | end |
|
3345 | end | |
3330 |
|
3346 | |||
3331 | def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues |
|
3347 | def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues | |
3332 | WorkflowTransition.delete_all |
|
3348 | WorkflowTransition.delete_all | |
3333 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, |
|
3349 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, | |
3334 | :old_status_id => 1, :new_status_id => 1) |
|
3350 | :old_status_id => 1, :new_status_id => 1) | |
3335 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, |
|
3351 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, | |
3336 | :old_status_id => 1, :new_status_id => 3) |
|
3352 | :old_status_id => 1, :new_status_id => 3) | |
3337 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, |
|
3353 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, | |
3338 | :old_status_id => 1, :new_status_id => 4) |
|
3354 | :old_status_id => 1, :new_status_id => 4) | |
3339 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, |
|
3355 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, | |
3340 | :old_status_id => 2, :new_status_id => 1) |
|
3356 | :old_status_id => 2, :new_status_id => 1) | |
3341 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, |
|
3357 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, | |
3342 | :old_status_id => 2, :new_status_id => 3) |
|
3358 | :old_status_id => 2, :new_status_id => 3) | |
3343 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, |
|
3359 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, | |
3344 | :old_status_id => 2, :new_status_id => 5) |
|
3360 | :old_status_id => 2, :new_status_id => 5) | |
3345 | @request.session[:user_id] = 2 |
|
3361 | @request.session[:user_id] = 2 | |
3346 | get :bulk_edit, :ids => [1, 2] |
|
3362 | get :bulk_edit, :ids => [1, 2] | |
3347 |
|
3363 | |||
3348 | assert_response :success |
|
3364 | assert_response :success | |
3349 | statuses = assigns(:available_statuses) |
|
3365 | statuses = assigns(:available_statuses) | |
3350 | assert_not_nil statuses |
|
3366 | assert_not_nil statuses | |
3351 | assert_equal [1, 3], statuses.map(&:id).sort |
|
3367 | assert_equal [1, 3], statuses.map(&:id).sort | |
3352 |
|
3368 | |||
3353 | assert_select 'select[name=?]', 'issue[status_id]' do |
|
3369 | assert_select 'select[name=?]', 'issue[status_id]' do | |
3354 | assert_select 'option', 3 # 2 statuses + "no change" option |
|
3370 | assert_select 'option', 3 # 2 statuses + "no change" option | |
3355 | end |
|
3371 | end | |
3356 | end |
|
3372 | end | |
3357 |
|
3373 | |||
3358 | def test_bulk_edit_should_propose_target_project_open_shared_versions |
|
3374 | def test_bulk_edit_should_propose_target_project_open_shared_versions | |
3359 | @request.session[:user_id] = 2 |
|
3375 | @request.session[:user_id] = 2 | |
3360 | post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} |
|
3376 | post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} | |
3361 | assert_response :success |
|
3377 | assert_response :success | |
3362 | assert_template 'bulk_edit' |
|
3378 | assert_template 'bulk_edit' | |
3363 | assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort |
|
3379 | assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort | |
3364 |
|
3380 | |||
3365 | assert_select 'select[name=?]', 'issue[fixed_version_id]' do |
|
3381 | assert_select 'select[name=?]', 'issue[fixed_version_id]' do | |
3366 | assert_select 'option', :text => '2.0' |
|
3382 | assert_select 'option', :text => '2.0' | |
3367 | end |
|
3383 | end | |
3368 | end |
|
3384 | end | |
3369 |
|
3385 | |||
3370 | def test_bulk_edit_should_propose_target_project_categories |
|
3386 | def test_bulk_edit_should_propose_target_project_categories | |
3371 | @request.session[:user_id] = 2 |
|
3387 | @request.session[:user_id] = 2 | |
3372 | post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} |
|
3388 | post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} | |
3373 | assert_response :success |
|
3389 | assert_response :success | |
3374 | assert_template 'bulk_edit' |
|
3390 | assert_template 'bulk_edit' | |
3375 | assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort |
|
3391 | assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort | |
3376 |
|
3392 | |||
3377 | assert_select 'select[name=?]', 'issue[category_id]' do |
|
3393 | assert_select 'select[name=?]', 'issue[category_id]' do | |
3378 | assert_select 'option', :text => 'Recipes' |
|
3394 | assert_select 'option', :text => 'Recipes' | |
3379 | end |
|
3395 | end | |
3380 | end |
|
3396 | end | |
3381 |
|
3397 | |||
3382 | def test_bulk_update |
|
3398 | def test_bulk_update | |
3383 | @request.session[:user_id] = 2 |
|
3399 | @request.session[:user_id] = 2 | |
3384 | # update issues priority |
|
3400 | # update issues priority | |
3385 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', |
|
3401 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', | |
3386 | :issue => {:priority_id => 7, |
|
3402 | :issue => {:priority_id => 7, | |
3387 | :assigned_to_id => '', |
|
3403 | :assigned_to_id => '', | |
3388 | :custom_field_values => {'2' => ''}} |
|
3404 | :custom_field_values => {'2' => ''}} | |
3389 |
|
3405 | |||
3390 | assert_response 302 |
|
3406 | assert_response 302 | |
3391 | # check that the issues were updated |
|
3407 | # check that the issues were updated | |
3392 | assert_equal [7, 7], Issue.where(:id =>[1, 2]).collect {|i| i.priority.id} |
|
3408 | assert_equal [7, 7], Issue.where(:id =>[1, 2]).collect {|i| i.priority.id} | |
3393 |
|
3409 | |||
3394 | issue = Issue.find(1) |
|
3410 | issue = Issue.find(1) | |
3395 | journal = issue.journals.reorder('created_on DESC').first |
|
3411 | journal = issue.journals.reorder('created_on DESC').first | |
3396 | assert_equal '125', issue.custom_value_for(2).value |
|
3412 | assert_equal '125', issue.custom_value_for(2).value | |
3397 | assert_equal 'Bulk editing', journal.notes |
|
3413 | assert_equal 'Bulk editing', journal.notes | |
3398 | assert_equal 1, journal.details.size |
|
3414 | assert_equal 1, journal.details.size | |
3399 | end |
|
3415 | end | |
3400 |
|
3416 | |||
3401 | def test_bulk_update_with_group_assignee |
|
3417 | def test_bulk_update_with_group_assignee | |
3402 | group = Group.find(11) |
|
3418 | group = Group.find(11) | |
3403 | project = Project.find(1) |
|
3419 | project = Project.find(1) | |
3404 | project.members << Member.new(:principal => group, :roles => [Role.givable.first]) |
|
3420 | project.members << Member.new(:principal => group, :roles => [Role.givable.first]) | |
3405 |
|
3421 | |||
3406 | @request.session[:user_id] = 2 |
|
3422 | @request.session[:user_id] = 2 | |
3407 | # update issues assignee |
|
3423 | # update issues assignee | |
3408 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', |
|
3424 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', | |
3409 | :issue => {:priority_id => '', |
|
3425 | :issue => {:priority_id => '', | |
3410 | :assigned_to_id => group.id, |
|
3426 | :assigned_to_id => group.id, | |
3411 | :custom_field_values => {'2' => ''}} |
|
3427 | :custom_field_values => {'2' => ''}} | |
3412 |
|
3428 | |||
3413 | assert_response 302 |
|
3429 | assert_response 302 | |
3414 | assert_equal [group, group], Issue.where(:id => [1, 2]).collect {|i| i.assigned_to} |
|
3430 | assert_equal [group, group], Issue.where(:id => [1, 2]).collect {|i| i.assigned_to} | |
3415 | end |
|
3431 | end | |
3416 |
|
3432 | |||
3417 | def test_bulk_update_on_different_projects |
|
3433 | def test_bulk_update_on_different_projects | |
3418 | @request.session[:user_id] = 2 |
|
3434 | @request.session[:user_id] = 2 | |
3419 | # update issues priority |
|
3435 | # update issues priority | |
3420 | post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing', |
|
3436 | post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing', | |
3421 | :issue => {:priority_id => 7, |
|
3437 | :issue => {:priority_id => 7, | |
3422 | :assigned_to_id => '', |
|
3438 | :assigned_to_id => '', | |
3423 | :custom_field_values => {'2' => ''}} |
|
3439 | :custom_field_values => {'2' => ''}} | |
3424 |
|
3440 | |||
3425 | assert_response 302 |
|
3441 | assert_response 302 | |
3426 | # check that the issues were updated |
|
3442 | # check that the issues were updated | |
3427 | assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id) |
|
3443 | assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id) | |
3428 |
|
3444 | |||
3429 | issue = Issue.find(1) |
|
3445 | issue = Issue.find(1) | |
3430 | journal = issue.journals.reorder('created_on DESC').first |
|
3446 | journal = issue.journals.reorder('created_on DESC').first | |
3431 | assert_equal '125', issue.custom_value_for(2).value |
|
3447 | assert_equal '125', issue.custom_value_for(2).value | |
3432 | assert_equal 'Bulk editing', journal.notes |
|
3448 | assert_equal 'Bulk editing', journal.notes | |
3433 | assert_equal 1, journal.details.size |
|
3449 | assert_equal 1, journal.details.size | |
3434 | end |
|
3450 | end | |
3435 |
|
3451 | |||
3436 | def test_bulk_update_on_different_projects_without_rights |
|
3452 | def test_bulk_update_on_different_projects_without_rights | |
3437 | @request.session[:user_id] = 3 |
|
3453 | @request.session[:user_id] = 3 | |
3438 | user = User.find(3) |
|
3454 | user = User.find(3) | |
3439 | action = { :controller => "issues", :action => "bulk_update" } |
|
3455 | action = { :controller => "issues", :action => "bulk_update" } | |
3440 | assert user.allowed_to?(action, Issue.find(1).project) |
|
3456 | assert user.allowed_to?(action, Issue.find(1).project) | |
3441 | assert ! user.allowed_to?(action, Issue.find(6).project) |
|
3457 | assert ! user.allowed_to?(action, Issue.find(6).project) | |
3442 | post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail', |
|
3458 | post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail', | |
3443 | :issue => {:priority_id => 7, |
|
3459 | :issue => {:priority_id => 7, | |
3444 | :assigned_to_id => '', |
|
3460 | :assigned_to_id => '', | |
3445 | :custom_field_values => {'2' => ''}} |
|
3461 | :custom_field_values => {'2' => ''}} | |
3446 | assert_response 403 |
|
3462 | assert_response 403 | |
3447 | assert_not_equal "Bulk should fail", Journal.last.notes |
|
3463 | assert_not_equal "Bulk should fail", Journal.last.notes | |
3448 | end |
|
3464 | end | |
3449 |
|
3465 | |||
3450 | def test_bullk_update_should_send_a_notification |
|
3466 | def test_bullk_update_should_send_a_notification | |
3451 | @request.session[:user_id] = 2 |
|
3467 | @request.session[:user_id] = 2 | |
3452 | ActionMailer::Base.deliveries.clear |
|
3468 | ActionMailer::Base.deliveries.clear | |
3453 | post(:bulk_update, |
|
3469 | post(:bulk_update, | |
3454 | { |
|
3470 | { | |
3455 | :ids => [1, 2], |
|
3471 | :ids => [1, 2], | |
3456 | :notes => 'Bulk editing', |
|
3472 | :notes => 'Bulk editing', | |
3457 | :issue => { |
|
3473 | :issue => { | |
3458 | :priority_id => 7, |
|
3474 | :priority_id => 7, | |
3459 | :assigned_to_id => '', |
|
3475 | :assigned_to_id => '', | |
3460 | :custom_field_values => {'2' => ''} |
|
3476 | :custom_field_values => {'2' => ''} | |
3461 | } |
|
3477 | } | |
3462 | }) |
|
3478 | }) | |
3463 |
|
3479 | |||
3464 | assert_response 302 |
|
3480 | assert_response 302 | |
3465 | assert_equal 2, ActionMailer::Base.deliveries.size |
|
3481 | assert_equal 2, ActionMailer::Base.deliveries.size | |
3466 | end |
|
3482 | end | |
3467 |
|
3483 | |||
3468 | def test_bulk_update_project |
|
3484 | def test_bulk_update_project | |
3469 | @request.session[:user_id] = 2 |
|
3485 | @request.session[:user_id] = 2 | |
3470 | post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'} |
|
3486 | post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'} | |
3471 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
3487 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' | |
3472 | # Issues moved to project 2 |
|
3488 | # Issues moved to project 2 | |
3473 | assert_equal 2, Issue.find(1).project_id |
|
3489 | assert_equal 2, Issue.find(1).project_id | |
3474 | assert_equal 2, Issue.find(2).project_id |
|
3490 | assert_equal 2, Issue.find(2).project_id | |
3475 | # No tracker change |
|
3491 | # No tracker change | |
3476 | assert_equal 1, Issue.find(1).tracker_id |
|
3492 | assert_equal 1, Issue.find(1).tracker_id | |
3477 | assert_equal 2, Issue.find(2).tracker_id |
|
3493 | assert_equal 2, Issue.find(2).tracker_id | |
3478 | end |
|
3494 | end | |
3479 |
|
3495 | |||
3480 | def test_bulk_update_project_on_single_issue_should_follow_when_needed |
|
3496 | def test_bulk_update_project_on_single_issue_should_follow_when_needed | |
3481 | @request.session[:user_id] = 2 |
|
3497 | @request.session[:user_id] = 2 | |
3482 | post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1' |
|
3498 | post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1' | |
3483 | assert_redirected_to '/issues/1' |
|
3499 | assert_redirected_to '/issues/1' | |
3484 | end |
|
3500 | end | |
3485 |
|
3501 | |||
3486 | def test_bulk_update_project_on_multiple_issues_should_follow_when_needed |
|
3502 | def test_bulk_update_project_on_multiple_issues_should_follow_when_needed | |
3487 | @request.session[:user_id] = 2 |
|
3503 | @request.session[:user_id] = 2 | |
3488 | post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1' |
|
3504 | post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1' | |
3489 | assert_redirected_to '/projects/onlinestore/issues' |
|
3505 | assert_redirected_to '/projects/onlinestore/issues' | |
3490 | end |
|
3506 | end | |
3491 |
|
3507 | |||
3492 | def test_bulk_update_tracker |
|
3508 | def test_bulk_update_tracker | |
3493 | @request.session[:user_id] = 2 |
|
3509 | @request.session[:user_id] = 2 | |
3494 | post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'} |
|
3510 | post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'} | |
3495 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
3511 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' | |
3496 | assert_equal 2, Issue.find(1).tracker_id |
|
3512 | assert_equal 2, Issue.find(1).tracker_id | |
3497 | assert_equal 2, Issue.find(2).tracker_id |
|
3513 | assert_equal 2, Issue.find(2).tracker_id | |
3498 | end |
|
3514 | end | |
3499 |
|
3515 | |||
3500 | def test_bulk_update_status |
|
3516 | def test_bulk_update_status | |
3501 | @request.session[:user_id] = 2 |
|
3517 | @request.session[:user_id] = 2 | |
3502 | # update issues priority |
|
3518 | # update issues priority | |
3503 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status', |
|
3519 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status', | |
3504 | :issue => {:priority_id => '', |
|
3520 | :issue => {:priority_id => '', | |
3505 | :assigned_to_id => '', |
|
3521 | :assigned_to_id => '', | |
3506 | :status_id => '5'} |
|
3522 | :status_id => '5'} | |
3507 |
|
3523 | |||
3508 | assert_response 302 |
|
3524 | assert_response 302 | |
3509 | issue = Issue.find(1) |
|
3525 | issue = Issue.find(1) | |
3510 | assert issue.closed? |
|
3526 | assert issue.closed? | |
3511 | end |
|
3527 | end | |
3512 |
|
3528 | |||
3513 | def test_bulk_update_priority |
|
3529 | def test_bulk_update_priority | |
3514 | @request.session[:user_id] = 2 |
|
3530 | @request.session[:user_id] = 2 | |
3515 | post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6} |
|
3531 | post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6} | |
3516 |
|
3532 | |||
3517 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
3533 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' | |
3518 | assert_equal 6, Issue.find(1).priority_id |
|
3534 | assert_equal 6, Issue.find(1).priority_id | |
3519 | assert_equal 6, Issue.find(2).priority_id |
|
3535 | assert_equal 6, Issue.find(2).priority_id | |
3520 | end |
|
3536 | end | |
3521 |
|
3537 | |||
3522 | def test_bulk_update_with_notes |
|
3538 | def test_bulk_update_with_notes | |
3523 | @request.session[:user_id] = 2 |
|
3539 | @request.session[:user_id] = 2 | |
3524 | post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues' |
|
3540 | post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues' | |
3525 |
|
3541 | |||
3526 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
3542 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' | |
3527 | assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes |
|
3543 | assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes | |
3528 | assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes |
|
3544 | assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes | |
3529 | end |
|
3545 | end | |
3530 |
|
3546 | |||
3531 | def test_bulk_update_parent_id |
|
3547 | def test_bulk_update_parent_id | |
3532 | IssueRelation.delete_all |
|
3548 | IssueRelation.delete_all | |
3533 | @request.session[:user_id] = 2 |
|
3549 | @request.session[:user_id] = 2 | |
3534 | post :bulk_update, :ids => [1, 3], |
|
3550 | post :bulk_update, :ids => [1, 3], | |
3535 | :notes => 'Bulk editing parent', |
|
3551 | :notes => 'Bulk editing parent', | |
3536 | :issue => {:priority_id => '', :assigned_to_id => '', |
|
3552 | :issue => {:priority_id => '', :assigned_to_id => '', | |
3537 | :status_id => '', :parent_issue_id => '2'} |
|
3553 | :status_id => '', :parent_issue_id => '2'} | |
3538 | assert_response 302 |
|
3554 | assert_response 302 | |
3539 | parent = Issue.find(2) |
|
3555 | parent = Issue.find(2) | |
3540 | assert_equal parent.id, Issue.find(1).parent_id |
|
3556 | assert_equal parent.id, Issue.find(1).parent_id | |
3541 | assert_equal parent.id, Issue.find(3).parent_id |
|
3557 | assert_equal parent.id, Issue.find(3).parent_id | |
3542 | assert_equal [1, 3], parent.children.collect(&:id).sort |
|
3558 | assert_equal [1, 3], parent.children.collect(&:id).sort | |
3543 | end |
|
3559 | end | |
3544 |
|
3560 | |||
3545 | def test_bulk_update_custom_field |
|
3561 | def test_bulk_update_custom_field | |
3546 | @request.session[:user_id] = 2 |
|
3562 | @request.session[:user_id] = 2 | |
3547 | # update issues priority |
|
3563 | # update issues priority | |
3548 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field', |
|
3564 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field', | |
3549 | :issue => {:priority_id => '', |
|
3565 | :issue => {:priority_id => '', | |
3550 | :assigned_to_id => '', |
|
3566 | :assigned_to_id => '', | |
3551 | :custom_field_values => {'2' => '777'}} |
|
3567 | :custom_field_values => {'2' => '777'}} | |
3552 |
|
3568 | |||
3553 | assert_response 302 |
|
3569 | assert_response 302 | |
3554 |
|
3570 | |||
3555 | issue = Issue.find(1) |
|
3571 | issue = Issue.find(1) | |
3556 | journal = issue.journals.reorder('created_on DESC').first |
|
3572 | journal = issue.journals.reorder('created_on DESC').first | |
3557 | assert_equal '777', issue.custom_value_for(2).value |
|
3573 | assert_equal '777', issue.custom_value_for(2).value | |
3558 | assert_equal 1, journal.details.size |
|
3574 | assert_equal 1, journal.details.size | |
3559 | assert_equal '125', journal.details.first.old_value |
|
3575 | assert_equal '125', journal.details.first.old_value | |
3560 | assert_equal '777', journal.details.first.value |
|
3576 | assert_equal '777', journal.details.first.value | |
3561 | end |
|
3577 | end | |
3562 |
|
3578 | |||
3563 | def test_bulk_update_custom_field_to_blank |
|
3579 | def test_bulk_update_custom_field_to_blank | |
3564 | @request.session[:user_id] = 2 |
|
3580 | @request.session[:user_id] = 2 | |
3565 | post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing custom field', |
|
3581 | post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing custom field', | |
3566 | :issue => {:priority_id => '', |
|
3582 | :issue => {:priority_id => '', | |
3567 | :assigned_to_id => '', |
|
3583 | :assigned_to_id => '', | |
3568 | :custom_field_values => {'1' => '__none__'}} |
|
3584 | :custom_field_values => {'1' => '__none__'}} | |
3569 | assert_response 302 |
|
3585 | assert_response 302 | |
3570 | assert_equal '', Issue.find(1).custom_field_value(1) |
|
3586 | assert_equal '', Issue.find(1).custom_field_value(1) | |
3571 | assert_equal '', Issue.find(3).custom_field_value(1) |
|
3587 | assert_equal '', Issue.find(3).custom_field_value(1) | |
3572 | end |
|
3588 | end | |
3573 |
|
3589 | |||
3574 | def test_bulk_update_multi_custom_field |
|
3590 | def test_bulk_update_multi_custom_field | |
3575 | field = CustomField.find(1) |
|
3591 | field = CustomField.find(1) | |
3576 | field.update_attribute :multiple, true |
|
3592 | field.update_attribute :multiple, true | |
3577 |
|
3593 | |||
3578 | @request.session[:user_id] = 2 |
|
3594 | @request.session[:user_id] = 2 | |
3579 | post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field', |
|
3595 | post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field', | |
3580 | :issue => {:priority_id => '', |
|
3596 | :issue => {:priority_id => '', | |
3581 | :assigned_to_id => '', |
|
3597 | :assigned_to_id => '', | |
3582 | :custom_field_values => {'1' => ['MySQL', 'Oracle']}} |
|
3598 | :custom_field_values => {'1' => ['MySQL', 'Oracle']}} | |
3583 |
|
3599 | |||
3584 | assert_response 302 |
|
3600 | assert_response 302 | |
3585 |
|
3601 | |||
3586 | assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort |
|
3602 | assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort | |
3587 | assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort |
|
3603 | assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort | |
3588 | # the custom field is not associated with the issue tracker |
|
3604 | # the custom field is not associated with the issue tracker | |
3589 | assert_nil Issue.find(2).custom_field_value(1) |
|
3605 | assert_nil Issue.find(2).custom_field_value(1) | |
3590 | end |
|
3606 | end | |
3591 |
|
3607 | |||
3592 | def test_bulk_update_multi_custom_field_to_blank |
|
3608 | def test_bulk_update_multi_custom_field_to_blank | |
3593 | field = CustomField.find(1) |
|
3609 | field = CustomField.find(1) | |
3594 | field.update_attribute :multiple, true |
|
3610 | field.update_attribute :multiple, true | |
3595 |
|
3611 | |||
3596 | @request.session[:user_id] = 2 |
|
3612 | @request.session[:user_id] = 2 | |
3597 | post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing multi custom field', |
|
3613 | post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing multi custom field', | |
3598 | :issue => {:priority_id => '', |
|
3614 | :issue => {:priority_id => '', | |
3599 | :assigned_to_id => '', |
|
3615 | :assigned_to_id => '', | |
3600 | :custom_field_values => {'1' => ['__none__']}} |
|
3616 | :custom_field_values => {'1' => ['__none__']}} | |
3601 | assert_response 302 |
|
3617 | assert_response 302 | |
3602 | assert_equal [''], Issue.find(1).custom_field_value(1) |
|
3618 | assert_equal [''], Issue.find(1).custom_field_value(1) | |
3603 | assert_equal [''], Issue.find(3).custom_field_value(1) |
|
3619 | assert_equal [''], Issue.find(3).custom_field_value(1) | |
3604 | end |
|
3620 | end | |
3605 |
|
3621 | |||
3606 | def test_bulk_update_unassign |
|
3622 | def test_bulk_update_unassign | |
3607 | assert_not_nil Issue.find(2).assigned_to |
|
3623 | assert_not_nil Issue.find(2).assigned_to | |
3608 | @request.session[:user_id] = 2 |
|
3624 | @request.session[:user_id] = 2 | |
3609 | # unassign issues |
|
3625 | # unassign issues | |
3610 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'} |
|
3626 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'} | |
3611 | assert_response 302 |
|
3627 | assert_response 302 | |
3612 | # check that the issues were updated |
|
3628 | # check that the issues were updated | |
3613 | assert_nil Issue.find(2).assigned_to |
|
3629 | assert_nil Issue.find(2).assigned_to | |
3614 | end |
|
3630 | end | |
3615 |
|
3631 | |||
3616 | def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject |
|
3632 | def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject | |
3617 | @request.session[:user_id] = 2 |
|
3633 | @request.session[:user_id] = 2 | |
3618 |
|
3634 | |||
3619 | post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4} |
|
3635 | post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4} | |
3620 |
|
3636 | |||
3621 | assert_response :redirect |
|
3637 | assert_response :redirect | |
3622 | issues = Issue.find([1,2]) |
|
3638 | issues = Issue.find([1,2]) | |
3623 | issues.each do |issue| |
|
3639 | issues.each do |issue| | |
3624 | assert_equal 4, issue.fixed_version_id |
|
3640 | assert_equal 4, issue.fixed_version_id | |
3625 | assert_not_equal issue.project_id, issue.fixed_version.project_id |
|
3641 | assert_not_equal issue.project_id, issue.fixed_version.project_id | |
3626 | end |
|
3642 | end | |
3627 | end |
|
3643 | end | |
3628 |
|
3644 | |||
3629 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter |
|
3645 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter | |
3630 | @request.session[:user_id] = 2 |
|
3646 | @request.session[:user_id] = 2 | |
3631 | post :bulk_update, :ids => [1,2], :back_url => '/issues' |
|
3647 | post :bulk_update, :ids => [1,2], :back_url => '/issues' | |
3632 |
|
3648 | |||
3633 | assert_response :redirect |
|
3649 | assert_response :redirect | |
3634 | assert_redirected_to '/issues' |
|
3650 | assert_redirected_to '/issues' | |
3635 | end |
|
3651 | end | |
3636 |
|
3652 | |||
3637 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
3653 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host | |
3638 | @request.session[:user_id] = 2 |
|
3654 | @request.session[:user_id] = 2 | |
3639 | post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' |
|
3655 | post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' | |
3640 |
|
3656 | |||
3641 | assert_response :redirect |
|
3657 | assert_response :redirect | |
3642 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier |
|
3658 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier | |
3643 | end |
|
3659 | end | |
3644 |
|
3660 | |||
3645 | def test_bulk_update_with_all_failures_should_show_errors |
|
3661 | def test_bulk_update_with_all_failures_should_show_errors | |
3646 | @request.session[:user_id] = 2 |
|
3662 | @request.session[:user_id] = 2 | |
3647 | post :bulk_update, :ids => [1, 2], :issue => {:start_date => 'foo'} |
|
3663 | post :bulk_update, :ids => [1, 2], :issue => {:start_date => 'foo'} | |
3648 |
|
3664 | |||
3649 | assert_response :success |
|
3665 | assert_response :success | |
3650 | assert_template 'bulk_edit' |
|
3666 | assert_template 'bulk_edit' | |
3651 | assert_select '#errorExplanation span', :text => 'Failed to save 2 issue(s) on 2 selected: #1, #2.' |
|
3667 | assert_select '#errorExplanation span', :text => 'Failed to save 2 issue(s) on 2 selected: #1, #2.' | |
3652 | assert_select '#errorExplanation ul li', :text => 'Start date is not a valid date: #1, #2' |
|
3668 | assert_select '#errorExplanation ul li', :text => 'Start date is not a valid date: #1, #2' | |
3653 |
|
3669 | |||
3654 | assert_equal [1, 2], assigns[:issues].map(&:id) |
|
3670 | assert_equal [1, 2], assigns[:issues].map(&:id) | |
3655 | end |
|
3671 | end | |
3656 |
|
3672 | |||
3657 | def test_bulk_update_with_some_failures_should_show_errors |
|
3673 | def test_bulk_update_with_some_failures_should_show_errors | |
3658 | issue1 = Issue.generate!(:start_date => '2013-05-12') |
|
3674 | issue1 = Issue.generate!(:start_date => '2013-05-12') | |
3659 | issue2 = Issue.generate!(:start_date => '2013-05-15') |
|
3675 | issue2 = Issue.generate!(:start_date => '2013-05-15') | |
3660 | issue3 = Issue.generate! |
|
3676 | issue3 = Issue.generate! | |
3661 | @request.session[:user_id] = 2 |
|
3677 | @request.session[:user_id] = 2 | |
3662 | post :bulk_update, :ids => [issue1.id, issue2.id, issue3.id], |
|
3678 | post :bulk_update, :ids => [issue1.id, issue2.id, issue3.id], | |
3663 | :issue => {:due_date => '2013-05-01'} |
|
3679 | :issue => {:due_date => '2013-05-01'} | |
3664 | assert_response :success |
|
3680 | assert_response :success | |
3665 | assert_template 'bulk_edit' |
|
3681 | assert_template 'bulk_edit' | |
3666 | assert_select '#errorExplanation span', |
|
3682 | assert_select '#errorExplanation span', | |
3667 | :text => "Failed to save 2 issue(s) on 3 selected: ##{issue1.id}, ##{issue2.id}." |
|
3683 | :text => "Failed to save 2 issue(s) on 3 selected: ##{issue1.id}, ##{issue2.id}." | |
3668 | assert_select '#errorExplanation ul li', |
|
3684 | assert_select '#errorExplanation ul li', | |
3669 | :text => "Due date must be greater than start date: ##{issue1.id}, ##{issue2.id}" |
|
3685 | :text => "Due date must be greater than start date: ##{issue1.id}, ##{issue2.id}" | |
3670 | assert_equal [issue1.id, issue2.id], assigns[:issues].map(&:id) |
|
3686 | assert_equal [issue1.id, issue2.id], assigns[:issues].map(&:id) | |
3671 | end |
|
3687 | end | |
3672 |
|
3688 | |||
3673 | def test_bulk_update_with_failure_should_preserved_form_values |
|
3689 | def test_bulk_update_with_failure_should_preserved_form_values | |
3674 | @request.session[:user_id] = 2 |
|
3690 | @request.session[:user_id] = 2 | |
3675 | post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2', :start_date => 'foo'} |
|
3691 | post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2', :start_date => 'foo'} | |
3676 |
|
3692 | |||
3677 | assert_response :success |
|
3693 | assert_response :success | |
3678 | assert_template 'bulk_edit' |
|
3694 | assert_template 'bulk_edit' | |
3679 | assert_select 'select[name=?]', 'issue[tracker_id]' do |
|
3695 | assert_select 'select[name=?]', 'issue[tracker_id]' do | |
3680 | assert_select 'option[value=2][selected=selected]' |
|
3696 | assert_select 'option[value=2][selected=selected]' | |
3681 | end |
|
3697 | end | |
3682 | assert_select 'input[name=?][value=?]', 'issue[start_date]', 'foo' |
|
3698 | assert_select 'input[name=?][value=?]', 'issue[start_date]', 'foo' | |
3683 | end |
|
3699 | end | |
3684 |
|
3700 | |||
3685 | def test_get_bulk_copy |
|
3701 | def test_get_bulk_copy | |
3686 | @request.session[:user_id] = 2 |
|
3702 | @request.session[:user_id] = 2 | |
3687 | get :bulk_edit, :ids => [1, 2, 3], :copy => '1' |
|
3703 | get :bulk_edit, :ids => [1, 2, 3], :copy => '1' | |
3688 | assert_response :success |
|
3704 | assert_response :success | |
3689 | assert_template 'bulk_edit' |
|
3705 | assert_template 'bulk_edit' | |
3690 |
|
3706 | |||
3691 | issues = assigns(:issues) |
|
3707 | issues = assigns(:issues) | |
3692 | assert_not_nil issues |
|
3708 | assert_not_nil issues | |
3693 | assert_equal [1, 2, 3], issues.map(&:id).sort |
|
3709 | assert_equal [1, 2, 3], issues.map(&:id).sort | |
3694 |
|
3710 | |||
3695 | assert_select 'input[name=copy_attachments]' |
|
3711 | assert_select 'input[name=copy_attachments]' | |
3696 | end |
|
3712 | end | |
3697 |
|
3713 | |||
3698 | def test_bulk_copy_to_another_project |
|
3714 | def test_bulk_copy_to_another_project | |
3699 | @request.session[:user_id] = 2 |
|
3715 | @request.session[:user_id] = 2 | |
3700 | assert_difference 'Issue.count', 2 do |
|
3716 | assert_difference 'Issue.count', 2 do | |
3701 | assert_no_difference 'Project.find(1).issues.count' do |
|
3717 | assert_no_difference 'Project.find(1).issues.count' do | |
3702 | post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1' |
|
3718 | post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1' | |
3703 | end |
|
3719 | end | |
3704 | end |
|
3720 | end | |
3705 | assert_redirected_to '/projects/ecookbook/issues' |
|
3721 | assert_redirected_to '/projects/ecookbook/issues' | |
3706 |
|
3722 | |||
3707 | copies = Issue.order('id DESC').limit(issues.size) |
|
3723 | copies = Issue.order('id DESC').limit(issues.size) | |
3708 | copies.each do |copy| |
|
3724 | copies.each do |copy| | |
3709 | assert_equal 2, copy.project_id |
|
3725 | assert_equal 2, copy.project_id | |
3710 | end |
|
3726 | end | |
3711 | end |
|
3727 | end | |
3712 |
|
3728 | |||
3713 | def test_bulk_copy_should_allow_not_changing_the_issue_attributes |
|
3729 | def test_bulk_copy_should_allow_not_changing_the_issue_attributes | |
3714 | @request.session[:user_id] = 2 |
|
3730 | @request.session[:user_id] = 2 | |
3715 | issues = [ |
|
3731 | issues = [ | |
3716 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, |
|
3732 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, | |
3717 | :priority_id => 2, :subject => 'issue 1', :author_id => 1, |
|
3733 | :priority_id => 2, :subject => 'issue 1', :author_id => 1, | |
3718 | :assigned_to_id => nil), |
|
3734 | :assigned_to_id => nil), | |
3719 | Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2, |
|
3735 | Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2, | |
3720 | :priority_id => 1, :subject => 'issue 2', :author_id => 2, |
|
3736 | :priority_id => 1, :subject => 'issue 2', :author_id => 2, | |
3721 | :assigned_to_id => 3) |
|
3737 | :assigned_to_id => 3) | |
3722 | ] |
|
3738 | ] | |
3723 | assert_difference 'Issue.count', issues.size do |
|
3739 | assert_difference 'Issue.count', issues.size do | |
3724 | post :bulk_update, :ids => issues.map(&:id), :copy => '1', |
|
3740 | post :bulk_update, :ids => issues.map(&:id), :copy => '1', | |
3725 | :issue => { |
|
3741 | :issue => { | |
3726 | :project_id => '', :tracker_id => '', :assigned_to_id => '', |
|
3742 | :project_id => '', :tracker_id => '', :assigned_to_id => '', | |
3727 | :status_id => '', :start_date => '', :due_date => '' |
|
3743 | :status_id => '', :start_date => '', :due_date => '' | |
3728 | } |
|
3744 | } | |
3729 | end |
|
3745 | end | |
3730 |
|
3746 | |||
3731 | copies = Issue.order('id DESC').limit(issues.size) |
|
3747 | copies = Issue.order('id DESC').limit(issues.size) | |
3732 | issues.each do |orig| |
|
3748 | issues.each do |orig| | |
3733 | copy = copies.detect {|c| c.subject == orig.subject} |
|
3749 | copy = copies.detect {|c| c.subject == orig.subject} | |
3734 | assert_not_nil copy |
|
3750 | assert_not_nil copy | |
3735 | assert_equal orig.project_id, copy.project_id |
|
3751 | assert_equal orig.project_id, copy.project_id | |
3736 | assert_equal orig.tracker_id, copy.tracker_id |
|
3752 | assert_equal orig.tracker_id, copy.tracker_id | |
3737 | assert_equal orig.status_id, copy.status_id |
|
3753 | assert_equal orig.status_id, copy.status_id | |
3738 | assert_equal orig.assigned_to_id, copy.assigned_to_id |
|
3754 | assert_equal orig.assigned_to_id, copy.assigned_to_id | |
3739 | assert_equal orig.priority_id, copy.priority_id |
|
3755 | assert_equal orig.priority_id, copy.priority_id | |
3740 | end |
|
3756 | end | |
3741 | end |
|
3757 | end | |
3742 |
|
3758 | |||
3743 | def test_bulk_copy_should_allow_changing_the_issue_attributes |
|
3759 | def test_bulk_copy_should_allow_changing_the_issue_attributes | |
3744 | # Fixes random test failure with Mysql |
|
3760 | # Fixes random test failure with Mysql | |
3745 | # where Issue.where(:project_id => 2).limit(2).order('id desc') |
|
3761 | # where Issue.where(:project_id => 2).limit(2).order('id desc') | |
3746 | # doesn't return the expected results |
|
3762 | # doesn't return the expected results | |
3747 | Issue.delete_all("project_id=2") |
|
3763 | Issue.delete_all("project_id=2") | |
3748 |
|
3764 | |||
3749 | @request.session[:user_id] = 2 |
|
3765 | @request.session[:user_id] = 2 | |
3750 | assert_difference 'Issue.count', 2 do |
|
3766 | assert_difference 'Issue.count', 2 do | |
3751 | assert_no_difference 'Project.find(1).issues.count' do |
|
3767 | assert_no_difference 'Project.find(1).issues.count' do | |
3752 | post :bulk_update, :ids => [1, 2], :copy => '1', |
|
3768 | post :bulk_update, :ids => [1, 2], :copy => '1', | |
3753 | :issue => { |
|
3769 | :issue => { | |
3754 | :project_id => '2', :tracker_id => '', :assigned_to_id => '4', |
|
3770 | :project_id => '2', :tracker_id => '', :assigned_to_id => '4', | |
3755 | :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31' |
|
3771 | :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31' | |
3756 | } |
|
3772 | } | |
3757 | end |
|
3773 | end | |
3758 | end |
|
3774 | end | |
3759 |
|
3775 | |||
3760 | copied_issues = Issue.where(:project_id => 2).limit(2).order('id desc').to_a |
|
3776 | copied_issues = Issue.where(:project_id => 2).limit(2).order('id desc').to_a | |
3761 | assert_equal 2, copied_issues.size |
|
3777 | assert_equal 2, copied_issues.size | |
3762 | copied_issues.each do |issue| |
|
3778 | copied_issues.each do |issue| | |
3763 | assert_equal 2, issue.project_id, "Project is incorrect" |
|
3779 | assert_equal 2, issue.project_id, "Project is incorrect" | |
3764 | assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" |
|
3780 | assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" | |
3765 | assert_equal 1, issue.status_id, "Status is incorrect" |
|
3781 | assert_equal 1, issue.status_id, "Status is incorrect" | |
3766 | assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect" |
|
3782 | assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect" | |
3767 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" |
|
3783 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" | |
3768 | end |
|
3784 | end | |
3769 | end |
|
3785 | end | |
3770 |
|
3786 | |||
3771 | def test_bulk_copy_should_allow_adding_a_note |
|
3787 | def test_bulk_copy_should_allow_adding_a_note | |
3772 | @request.session[:user_id] = 2 |
|
3788 | @request.session[:user_id] = 2 | |
3773 | assert_difference 'Issue.count', 1 do |
|
3789 | assert_difference 'Issue.count', 1 do | |
3774 | post :bulk_update, :ids => [1], :copy => '1', |
|
3790 | post :bulk_update, :ids => [1], :copy => '1', | |
3775 | :notes => 'Copying one issue', |
|
3791 | :notes => 'Copying one issue', | |
3776 | :issue => { |
|
3792 | :issue => { | |
3777 | :project_id => '', :tracker_id => '', :assigned_to_id => '4', |
|
3793 | :project_id => '', :tracker_id => '', :assigned_to_id => '4', | |
3778 | :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31' |
|
3794 | :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31' | |
3779 | } |
|
3795 | } | |
3780 | end |
|
3796 | end | |
3781 | issue = Issue.order('id DESC').first |
|
3797 | issue = Issue.order('id DESC').first | |
3782 | assert_equal 1, issue.journals.size |
|
3798 | assert_equal 1, issue.journals.size | |
3783 | journal = issue.journals.first |
|
3799 | journal = issue.journals.first | |
3784 | assert_equal 1, journal.details.size |
|
3800 | assert_equal 1, journal.details.size | |
3785 | assert_equal 'Copying one issue', journal.notes |
|
3801 | assert_equal 'Copying one issue', journal.notes | |
3786 | end |
|
3802 | end | |
3787 |
|
3803 | |||
3788 | def test_bulk_copy_should_allow_not_copying_the_attachments |
|
3804 | def test_bulk_copy_should_allow_not_copying_the_attachments | |
3789 | attachment_count = Issue.find(3).attachments.size |
|
3805 | attachment_count = Issue.find(3).attachments.size | |
3790 | assert attachment_count > 0 |
|
3806 | assert attachment_count > 0 | |
3791 | @request.session[:user_id] = 2 |
|
3807 | @request.session[:user_id] = 2 | |
3792 |
|
3808 | |||
3793 | assert_difference 'Issue.count', 1 do |
|
3809 | assert_difference 'Issue.count', 1 do | |
3794 | assert_no_difference 'Attachment.count' do |
|
3810 | assert_no_difference 'Attachment.count' do | |
3795 | post :bulk_update, :ids => [3], :copy => '1', |
|
3811 | post :bulk_update, :ids => [3], :copy => '1', | |
3796 | :issue => { |
|
3812 | :issue => { | |
3797 | :project_id => '' |
|
3813 | :project_id => '' | |
3798 | } |
|
3814 | } | |
3799 | end |
|
3815 | end | |
3800 | end |
|
3816 | end | |
3801 | end |
|
3817 | end | |
3802 |
|
3818 | |||
3803 | def test_bulk_copy_should_allow_copying_the_attachments |
|
3819 | def test_bulk_copy_should_allow_copying_the_attachments | |
3804 | attachment_count = Issue.find(3).attachments.size |
|
3820 | attachment_count = Issue.find(3).attachments.size | |
3805 | assert attachment_count > 0 |
|
3821 | assert attachment_count > 0 | |
3806 | @request.session[:user_id] = 2 |
|
3822 | @request.session[:user_id] = 2 | |
3807 |
|
3823 | |||
3808 | assert_difference 'Issue.count', 1 do |
|
3824 | assert_difference 'Issue.count', 1 do | |
3809 | assert_difference 'Attachment.count', attachment_count do |
|
3825 | assert_difference 'Attachment.count', attachment_count do | |
3810 | post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '1', |
|
3826 | post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '1', | |
3811 | :issue => { |
|
3827 | :issue => { | |
3812 | :project_id => '' |
|
3828 | :project_id => '' | |
3813 | } |
|
3829 | } | |
3814 | end |
|
3830 | end | |
3815 | end |
|
3831 | end | |
3816 | end |
|
3832 | end | |
3817 |
|
3833 | |||
3818 | def test_bulk_copy_should_add_relations_with_copied_issues |
|
3834 | def test_bulk_copy_should_add_relations_with_copied_issues | |
3819 | @request.session[:user_id] = 2 |
|
3835 | @request.session[:user_id] = 2 | |
3820 |
|
3836 | |||
3821 | assert_difference 'Issue.count', 2 do |
|
3837 | assert_difference 'Issue.count', 2 do | |
3822 | assert_difference 'IssueRelation.count', 2 do |
|
3838 | assert_difference 'IssueRelation.count', 2 do | |
3823 | post :bulk_update, :ids => [1, 3], :copy => '1', |
|
3839 | post :bulk_update, :ids => [1, 3], :copy => '1', | |
3824 | :issue => { |
|
3840 | :issue => { | |
3825 | :project_id => '1' |
|
3841 | :project_id => '1' | |
3826 | } |
|
3842 | } | |
3827 | end |
|
3843 | end | |
3828 | end |
|
3844 | end | |
3829 | end |
|
3845 | end | |
3830 |
|
3846 | |||
3831 | def test_bulk_copy_should_allow_not_copying_the_subtasks |
|
3847 | def test_bulk_copy_should_allow_not_copying_the_subtasks | |
3832 | issue = Issue.generate_with_descendants! |
|
3848 | issue = Issue.generate_with_descendants! | |
3833 | @request.session[:user_id] = 2 |
|
3849 | @request.session[:user_id] = 2 | |
3834 |
|
3850 | |||
3835 | assert_difference 'Issue.count', 1 do |
|
3851 | assert_difference 'Issue.count', 1 do | |
3836 | post :bulk_update, :ids => [issue.id], :copy => '1', |
|
3852 | post :bulk_update, :ids => [issue.id], :copy => '1', | |
3837 | :issue => { |
|
3853 | :issue => { | |
3838 | :project_id => '' |
|
3854 | :project_id => '' | |
3839 | } |
|
3855 | } | |
3840 | end |
|
3856 | end | |
3841 | end |
|
3857 | end | |
3842 |
|
3858 | |||
3843 | def test_bulk_copy_should_allow_copying_the_subtasks |
|
3859 | def test_bulk_copy_should_allow_copying_the_subtasks | |
3844 | issue = Issue.generate_with_descendants! |
|
3860 | issue = Issue.generate_with_descendants! | |
3845 | count = issue.descendants.count |
|
3861 | count = issue.descendants.count | |
3846 | @request.session[:user_id] = 2 |
|
3862 | @request.session[:user_id] = 2 | |
3847 |
|
3863 | |||
3848 | assert_difference 'Issue.count', count+1 do |
|
3864 | assert_difference 'Issue.count', count+1 do | |
3849 | post :bulk_update, :ids => [issue.id], :copy => '1', :copy_subtasks => '1', |
|
3865 | post :bulk_update, :ids => [issue.id], :copy => '1', :copy_subtasks => '1', | |
3850 | :issue => { |
|
3866 | :issue => { | |
3851 | :project_id => '' |
|
3867 | :project_id => '' | |
3852 | } |
|
3868 | } | |
3853 | end |
|
3869 | end | |
3854 | copy = Issue.where(:parent_id => nil).order("id DESC").first |
|
3870 | copy = Issue.where(:parent_id => nil).order("id DESC").first | |
3855 | assert_equal count, copy.descendants.count |
|
3871 | assert_equal count, copy.descendants.count | |
3856 | end |
|
3872 | end | |
3857 |
|
3873 | |||
3858 | def test_bulk_copy_should_not_copy_selected_subtasks_twice |
|
3874 | def test_bulk_copy_should_not_copy_selected_subtasks_twice | |
3859 | issue = Issue.generate_with_descendants! |
|
3875 | issue = Issue.generate_with_descendants! | |
3860 | count = issue.descendants.count |
|
3876 | count = issue.descendants.count | |
3861 | @request.session[:user_id] = 2 |
|
3877 | @request.session[:user_id] = 2 | |
3862 |
|
3878 | |||
3863 | assert_difference 'Issue.count', count+1 do |
|
3879 | assert_difference 'Issue.count', count+1 do | |
3864 | post :bulk_update, :ids => issue.self_and_descendants.map(&:id), :copy => '1', :copy_subtasks => '1', |
|
3880 | post :bulk_update, :ids => issue.self_and_descendants.map(&:id), :copy => '1', :copy_subtasks => '1', | |
3865 | :issue => { |
|
3881 | :issue => { | |
3866 | :project_id => '' |
|
3882 | :project_id => '' | |
3867 | } |
|
3883 | } | |
3868 | end |
|
3884 | end | |
3869 | copy = Issue.where(:parent_id => nil).order("id DESC").first |
|
3885 | copy = Issue.where(:parent_id => nil).order("id DESC").first | |
3870 | assert_equal count, copy.descendants.count |
|
3886 | assert_equal count, copy.descendants.count | |
3871 | end |
|
3887 | end | |
3872 |
|
3888 | |||
3873 | def test_bulk_copy_to_another_project_should_follow_when_needed |
|
3889 | def test_bulk_copy_to_another_project_should_follow_when_needed | |
3874 | @request.session[:user_id] = 2 |
|
3890 | @request.session[:user_id] = 2 | |
3875 | post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1' |
|
3891 | post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1' | |
3876 | issue = Issue.order('id DESC').first |
|
3892 | issue = Issue.order('id DESC').first | |
3877 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
3893 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue | |
3878 | end |
|
3894 | end | |
3879 |
|
3895 | |||
3880 | def test_bulk_copy_with_all_failures_should_display_errors |
|
3896 | def test_bulk_copy_with_all_failures_should_display_errors | |
3881 | @request.session[:user_id] = 2 |
|
3897 | @request.session[:user_id] = 2 | |
3882 | post :bulk_update, :ids => [1, 2], :copy => '1', :issue => {:start_date => 'foo'} |
|
3898 | post :bulk_update, :ids => [1, 2], :copy => '1', :issue => {:start_date => 'foo'} | |
3883 |
|
3899 | |||
3884 | assert_response :success |
|
3900 | assert_response :success | |
3885 | end |
|
3901 | end | |
3886 |
|
3902 | |||
3887 | def test_destroy_issue_with_no_time_entries |
|
3903 | def test_destroy_issue_with_no_time_entries | |
3888 | assert_nil TimeEntry.find_by_issue_id(2) |
|
3904 | assert_nil TimeEntry.find_by_issue_id(2) | |
3889 | @request.session[:user_id] = 2 |
|
3905 | @request.session[:user_id] = 2 | |
3890 |
|
3906 | |||
3891 | assert_difference 'Issue.count', -1 do |
|
3907 | assert_difference 'Issue.count', -1 do | |
3892 | delete :destroy, :id => 2 |
|
3908 | delete :destroy, :id => 2 | |
3893 | end |
|
3909 | end | |
3894 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
3910 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
3895 | assert_nil Issue.find_by_id(2) |
|
3911 | assert_nil Issue.find_by_id(2) | |
3896 | end |
|
3912 | end | |
3897 |
|
3913 | |||
3898 | def test_destroy_issues_with_time_entries |
|
3914 | def test_destroy_issues_with_time_entries | |
3899 | @request.session[:user_id] = 2 |
|
3915 | @request.session[:user_id] = 2 | |
3900 |
|
3916 | |||
3901 | assert_no_difference 'Issue.count' do |
|
3917 | assert_no_difference 'Issue.count' do | |
3902 | delete :destroy, :ids => [1, 3] |
|
3918 | delete :destroy, :ids => [1, 3] | |
3903 | end |
|
3919 | end | |
3904 | assert_response :success |
|
3920 | assert_response :success | |
3905 | assert_template 'destroy' |
|
3921 | assert_template 'destroy' | |
3906 | assert_not_nil assigns(:hours) |
|
3922 | assert_not_nil assigns(:hours) | |
3907 | assert Issue.find_by_id(1) && Issue.find_by_id(3) |
|
3923 | assert Issue.find_by_id(1) && Issue.find_by_id(3) | |
3908 |
|
3924 | |||
3909 | assert_select 'form' do |
|
3925 | assert_select 'form' do | |
3910 | assert_select 'input[name=_method][value=delete]' |
|
3926 | assert_select 'input[name=_method][value=delete]' | |
3911 | end |
|
3927 | end | |
3912 | end |
|
3928 | end | |
3913 |
|
3929 | |||
3914 | def test_destroy_issues_and_destroy_time_entries |
|
3930 | def test_destroy_issues_and_destroy_time_entries | |
3915 | @request.session[:user_id] = 2 |
|
3931 | @request.session[:user_id] = 2 | |
3916 |
|
3932 | |||
3917 | assert_difference 'Issue.count', -2 do |
|
3933 | assert_difference 'Issue.count', -2 do | |
3918 | assert_difference 'TimeEntry.count', -3 do |
|
3934 | assert_difference 'TimeEntry.count', -3 do | |
3919 | delete :destroy, :ids => [1, 3], :todo => 'destroy' |
|
3935 | delete :destroy, :ids => [1, 3], :todo => 'destroy' | |
3920 | end |
|
3936 | end | |
3921 | end |
|
3937 | end | |
3922 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
3938 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
3923 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
3939 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
3924 | assert_nil TimeEntry.find_by_id([1, 2]) |
|
3940 | assert_nil TimeEntry.find_by_id([1, 2]) | |
3925 | end |
|
3941 | end | |
3926 |
|
3942 | |||
3927 | def test_destroy_issues_and_assign_time_entries_to_project |
|
3943 | def test_destroy_issues_and_assign_time_entries_to_project | |
3928 | @request.session[:user_id] = 2 |
|
3944 | @request.session[:user_id] = 2 | |
3929 |
|
3945 | |||
3930 | assert_difference 'Issue.count', -2 do |
|
3946 | assert_difference 'Issue.count', -2 do | |
3931 | assert_no_difference 'TimeEntry.count' do |
|
3947 | assert_no_difference 'TimeEntry.count' do | |
3932 | delete :destroy, :ids => [1, 3], :todo => 'nullify' |
|
3948 | delete :destroy, :ids => [1, 3], :todo => 'nullify' | |
3933 | end |
|
3949 | end | |
3934 | end |
|
3950 | end | |
3935 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
3951 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
3936 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
3952 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
3937 | assert_nil TimeEntry.find(1).issue_id |
|
3953 | assert_nil TimeEntry.find(1).issue_id | |
3938 | assert_nil TimeEntry.find(2).issue_id |
|
3954 | assert_nil TimeEntry.find(2).issue_id | |
3939 | end |
|
3955 | end | |
3940 |
|
3956 | |||
3941 | def test_destroy_issues_and_reassign_time_entries_to_another_issue |
|
3957 | def test_destroy_issues_and_reassign_time_entries_to_another_issue | |
3942 | @request.session[:user_id] = 2 |
|
3958 | @request.session[:user_id] = 2 | |
3943 |
|
3959 | |||
3944 | assert_difference 'Issue.count', -2 do |
|
3960 | assert_difference 'Issue.count', -2 do | |
3945 | assert_no_difference 'TimeEntry.count' do |
|
3961 | assert_no_difference 'TimeEntry.count' do | |
3946 | delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 |
|
3962 | delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 | |
3947 | end |
|
3963 | end | |
3948 | end |
|
3964 | end | |
3949 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
3965 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
3950 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
3966 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
3951 | assert_equal 2, TimeEntry.find(1).issue_id |
|
3967 | assert_equal 2, TimeEntry.find(1).issue_id | |
3952 | assert_equal 2, TimeEntry.find(2).issue_id |
|
3968 | assert_equal 2, TimeEntry.find(2).issue_id | |
3953 | end |
|
3969 | end | |
3954 |
|
3970 | |||
3955 | def test_destroy_issues_from_different_projects |
|
3971 | def test_destroy_issues_from_different_projects | |
3956 | @request.session[:user_id] = 2 |
|
3972 | @request.session[:user_id] = 2 | |
3957 |
|
3973 | |||
3958 | assert_difference 'Issue.count', -3 do |
|
3974 | assert_difference 'Issue.count', -3 do | |
3959 | delete :destroy, :ids => [1, 2, 6], :todo => 'destroy' |
|
3975 | delete :destroy, :ids => [1, 2, 6], :todo => 'destroy' | |
3960 | end |
|
3976 | end | |
3961 | assert_redirected_to :controller => 'issues', :action => 'index' |
|
3977 | assert_redirected_to :controller => 'issues', :action => 'index' | |
3962 | assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6)) |
|
3978 | assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6)) | |
3963 | end |
|
3979 | end | |
3964 |
|
3980 | |||
3965 | def test_destroy_parent_and_child_issues |
|
3981 | def test_destroy_parent_and_child_issues | |
3966 | parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue') |
|
3982 | parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue') | |
3967 | child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id) |
|
3983 | child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id) | |
3968 | assert child.is_descendant_of?(parent.reload) |
|
3984 | assert child.is_descendant_of?(parent.reload) | |
3969 |
|
3985 | |||
3970 | @request.session[:user_id] = 2 |
|
3986 | @request.session[:user_id] = 2 | |
3971 | assert_difference 'Issue.count', -2 do |
|
3987 | assert_difference 'Issue.count', -2 do | |
3972 | delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy' |
|
3988 | delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy' | |
3973 | end |
|
3989 | end | |
3974 | assert_response 302 |
|
3990 | assert_response 302 | |
3975 | end |
|
3991 | end | |
3976 |
|
3992 | |||
3977 | def test_destroy_invalid_should_respond_with_404 |
|
3993 | def test_destroy_invalid_should_respond_with_404 | |
3978 | @request.session[:user_id] = 2 |
|
3994 | @request.session[:user_id] = 2 | |
3979 | assert_no_difference 'Issue.count' do |
|
3995 | assert_no_difference 'Issue.count' do | |
3980 | delete :destroy, :id => 999 |
|
3996 | delete :destroy, :id => 999 | |
3981 | end |
|
3997 | end | |
3982 | assert_response 404 |
|
3998 | assert_response 404 | |
3983 | end |
|
3999 | end | |
3984 |
|
4000 | |||
3985 | def test_default_search_scope |
|
4001 | def test_default_search_scope | |
3986 | get :index |
|
4002 | get :index | |
3987 |
|
4003 | |||
3988 | assert_select 'div#quick-search form' do |
|
4004 | assert_select 'div#quick-search form' do | |
3989 | assert_select 'input[name=issues][value=1][type=hidden]' |
|
4005 | assert_select 'input[name=issues][value=1][type=hidden]' | |
3990 | end |
|
4006 | end | |
3991 | end |
|
4007 | end | |
3992 | end |
|
4008 | end |
General Comments 0
You need to be logged in to leave comments.
Login now