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