@@ -1,3110 +1,3129 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 | require 'issues_controller' |
|
19 | require 'issues_controller' | |
20 |
|
20 | |||
21 | class IssuesControllerTest < ActionController::TestCase |
|
21 | class IssuesControllerTest < ActionController::TestCase | |
22 | fixtures :projects, |
|
22 | fixtures :projects, | |
23 | :users, |
|
23 | :users, | |
24 | :roles, |
|
24 | :roles, | |
25 | :members, |
|
25 | :members, | |
26 | :member_roles, |
|
26 | :member_roles, | |
27 | :issues, |
|
27 | :issues, | |
28 | :issue_statuses, |
|
28 | :issue_statuses, | |
29 | :versions, |
|
29 | :versions, | |
30 | :trackers, |
|
30 | :trackers, | |
31 | :projects_trackers, |
|
31 | :projects_trackers, | |
32 | :issue_categories, |
|
32 | :issue_categories, | |
33 | :enabled_modules, |
|
33 | :enabled_modules, | |
34 | :enumerations, |
|
34 | :enumerations, | |
35 | :attachments, |
|
35 | :attachments, | |
36 | :workflows, |
|
36 | :workflows, | |
37 | :custom_fields, |
|
37 | :custom_fields, | |
38 | :custom_values, |
|
38 | :custom_values, | |
39 | :custom_fields_projects, |
|
39 | :custom_fields_projects, | |
40 | :custom_fields_trackers, |
|
40 | :custom_fields_trackers, | |
41 | :time_entries, |
|
41 | :time_entries, | |
42 | :journals, |
|
42 | :journals, | |
43 | :journal_details, |
|
43 | :journal_details, | |
44 | :queries, |
|
44 | :queries, | |
45 | :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 | @controller = IssuesController.new |
|
51 | @controller = IssuesController.new | |
52 | @request = ActionController::TestRequest.new |
|
52 | @request = ActionController::TestRequest.new | |
53 | @response = ActionController::TestResponse.new |
|
53 | @response = ActionController::TestResponse.new | |
54 | User.current = nil |
|
54 | User.current = nil | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | def test_index |
|
57 | def test_index | |
58 | with_settings :default_language => "en" do |
|
58 | with_settings :default_language => "en" do | |
59 | get :index |
|
59 | get :index | |
60 | assert_response :success |
|
60 | assert_response :success | |
61 | assert_template 'index' |
|
61 | assert_template 'index' | |
62 | assert_not_nil assigns(:issues) |
|
62 | assert_not_nil assigns(:issues) | |
63 | assert_nil assigns(:project) |
|
63 | assert_nil assigns(:project) | |
64 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
64 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
65 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
65 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
66 | # private projects hidden |
|
66 | # private projects hidden | |
67 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
67 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ | |
68 | assert_no_tag :tag => 'a', :content => /Issue on project 2/ |
|
68 | assert_no_tag :tag => 'a', :content => /Issue on project 2/ | |
69 | # project column |
|
69 | # project column | |
70 | assert_tag :tag => 'th', :content => /Project/ |
|
70 | assert_tag :tag => 'th', :content => /Project/ | |
71 | end |
|
71 | end | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def test_index_should_not_list_issues_when_module_disabled |
|
74 | def test_index_should_not_list_issues_when_module_disabled | |
75 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") |
|
75 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") | |
76 | get :index |
|
76 | get :index | |
77 | assert_response :success |
|
77 | assert_response :success | |
78 | assert_template 'index' |
|
78 | assert_template 'index' | |
79 | assert_not_nil assigns(:issues) |
|
79 | assert_not_nil assigns(:issues) | |
80 | assert_nil assigns(:project) |
|
80 | assert_nil assigns(:project) | |
81 | assert_no_tag :tag => 'a', :content => /Can't print recipes/ |
|
81 | assert_no_tag :tag => 'a', :content => /Can't print recipes/ | |
82 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
82 | assert_tag :tag => 'a', :content => /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 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
98 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
99 | assert_no_tag :tag => 'a', :content => /Subproject issue/ |
|
99 | assert_no_tag :tag => 'a', :content => /Subproject issue/ | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | def test_index_with_project_and_subprojects |
|
102 | def test_index_with_project_and_subprojects | |
103 | Setting.display_subprojects_issues = 1 |
|
103 | Setting.display_subprojects_issues = 1 | |
104 | get :index, :project_id => 1 |
|
104 | get :index, :project_id => 1 | |
105 | assert_response :success |
|
105 | assert_response :success | |
106 | assert_template 'index' |
|
106 | assert_template 'index' | |
107 | assert_not_nil assigns(:issues) |
|
107 | assert_not_nil assigns(:issues) | |
108 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
108 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
109 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
109 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
110 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
110 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ | |
111 | end |
|
111 | end | |
112 |
|
112 | |||
113 | def test_index_with_project_and_subprojects_should_show_private_subprojects |
|
113 | def test_index_with_project_and_subprojects_should_show_private_subprojects | |
114 | @request.session[:user_id] = 2 |
|
114 | @request.session[:user_id] = 2 | |
115 | Setting.display_subprojects_issues = 1 |
|
115 | Setting.display_subprojects_issues = 1 | |
116 | get :index, :project_id => 1 |
|
116 | get :index, :project_id => 1 | |
117 | assert_response :success |
|
117 | assert_response :success | |
118 | assert_template 'index' |
|
118 | assert_template 'index' | |
119 | assert_not_nil assigns(:issues) |
|
119 | assert_not_nil assigns(:issues) | |
120 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
120 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
121 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
121 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
122 | assert_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
122 | assert_tag :tag => 'a', :content => /Issue of a private subproject/ | |
123 | end |
|
123 | end | |
124 |
|
124 | |||
125 | def test_index_with_project_and_default_filter |
|
125 | def test_index_with_project_and_default_filter | |
126 | get :index, :project_id => 1, :set_filter => 1 |
|
126 | get :index, :project_id => 1, :set_filter => 1 | |
127 | assert_response :success |
|
127 | assert_response :success | |
128 | assert_template 'index' |
|
128 | assert_template 'index' | |
129 | assert_not_nil assigns(:issues) |
|
129 | assert_not_nil assigns(:issues) | |
130 |
|
130 | |||
131 | query = assigns(:query) |
|
131 | query = assigns(:query) | |
132 | assert_not_nil query |
|
132 | assert_not_nil query | |
133 | # default filter |
|
133 | # default filter | |
134 | assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters) |
|
134 | assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters) | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | def test_index_with_project_and_filter |
|
137 | def test_index_with_project_and_filter | |
138 | get :index, :project_id => 1, :set_filter => 1, |
|
138 | get :index, :project_id => 1, :set_filter => 1, | |
139 | :f => ['tracker_id'], |
|
139 | :f => ['tracker_id'], | |
140 | :op => {'tracker_id' => '='}, |
|
140 | :op => {'tracker_id' => '='}, | |
141 | :v => {'tracker_id' => ['1']} |
|
141 | :v => {'tracker_id' => ['1']} | |
142 | assert_response :success |
|
142 | assert_response :success | |
143 | assert_template 'index' |
|
143 | assert_template 'index' | |
144 | assert_not_nil assigns(:issues) |
|
144 | assert_not_nil assigns(:issues) | |
145 |
|
145 | |||
146 | query = assigns(:query) |
|
146 | query = assigns(:query) | |
147 | assert_not_nil query |
|
147 | assert_not_nil query | |
148 | assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters) |
|
148 | assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters) | |
149 | end |
|
149 | end | |
150 |
|
150 | |||
151 | def test_index_with_short_filters |
|
151 | def test_index_with_short_filters | |
152 | to_test = { |
|
152 | to_test = { | |
153 | 'status_id' => { |
|
153 | 'status_id' => { | |
154 | 'o' => { :op => 'o', :values => [''] }, |
|
154 | 'o' => { :op => 'o', :values => [''] }, | |
155 | 'c' => { :op => 'c', :values => [''] }, |
|
155 | 'c' => { :op => 'c', :values => [''] }, | |
156 | '7' => { :op => '=', :values => ['7'] }, |
|
156 | '7' => { :op => '=', :values => ['7'] }, | |
157 | '7|3|4' => { :op => '=', :values => ['7', '3', '4'] }, |
|
157 | '7|3|4' => { :op => '=', :values => ['7', '3', '4'] }, | |
158 | '=7' => { :op => '=', :values => ['7'] }, |
|
158 | '=7' => { :op => '=', :values => ['7'] }, | |
159 | '!3' => { :op => '!', :values => ['3'] }, |
|
159 | '!3' => { :op => '!', :values => ['3'] }, | |
160 | '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }}, |
|
160 | '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }}, | |
161 | 'subject' => { |
|
161 | 'subject' => { | |
162 | 'This is a subject' => { :op => '=', :values => ['This is a subject'] }, |
|
162 | 'This is a subject' => { :op => '=', :values => ['This is a subject'] }, | |
163 | 'o' => { :op => '=', :values => ['o'] }, |
|
163 | 'o' => { :op => '=', :values => ['o'] }, | |
164 | '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] }, |
|
164 | '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] }, | |
165 | '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }}, |
|
165 | '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }}, | |
166 | 'tracker_id' => { |
|
166 | 'tracker_id' => { | |
167 | '3' => { :op => '=', :values => ['3'] }, |
|
167 | '3' => { :op => '=', :values => ['3'] }, | |
168 | '=3' => { :op => '=', :values => ['3'] }}, |
|
168 | '=3' => { :op => '=', :values => ['3'] }}, | |
169 | 'start_date' => { |
|
169 | 'start_date' => { | |
170 | '2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, |
|
170 | '2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, | |
171 | '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, |
|
171 | '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, | |
172 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, |
|
172 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, | |
173 | '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] }, |
|
173 | '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] }, | |
174 | '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] }, |
|
174 | '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] }, | |
175 | '<t+2' => { :op => '<t+', :values => ['2'] }, |
|
175 | '<t+2' => { :op => '<t+', :values => ['2'] }, | |
176 | '>t+2' => { :op => '>t+', :values => ['2'] }, |
|
176 | '>t+2' => { :op => '>t+', :values => ['2'] }, | |
177 | 't+2' => { :op => 't+', :values => ['2'] }, |
|
177 | 't+2' => { :op => 't+', :values => ['2'] }, | |
178 | 't' => { :op => 't', :values => [''] }, |
|
178 | 't' => { :op => 't', :values => [''] }, | |
179 | 'w' => { :op => 'w', :values => [''] }, |
|
179 | 'w' => { :op => 'w', :values => [''] }, | |
180 | '>t-2' => { :op => '>t-', :values => ['2'] }, |
|
180 | '>t-2' => { :op => '>t-', :values => ['2'] }, | |
181 | '<t-2' => { :op => '<t-', :values => ['2'] }, |
|
181 | '<t-2' => { :op => '<t-', :values => ['2'] }, | |
182 | 't-2' => { :op => 't-', :values => ['2'] }}, |
|
182 | 't-2' => { :op => 't-', :values => ['2'] }}, | |
183 | 'created_on' => { |
|
183 | 'created_on' => { | |
184 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, |
|
184 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, | |
185 | '<t-2' => { :op => '<t-', :values => ['2'] }, |
|
185 | '<t-2' => { :op => '<t-', :values => ['2'] }, | |
186 | '>t-2' => { :op => '>t-', :values => ['2'] }, |
|
186 | '>t-2' => { :op => '>t-', :values => ['2'] }, | |
187 | 't-2' => { :op => 't-', :values => ['2'] }}, |
|
187 | 't-2' => { :op => 't-', :values => ['2'] }}, | |
188 | 'cf_1' => { |
|
188 | 'cf_1' => { | |
189 | 'c' => { :op => '=', :values => ['c'] }, |
|
189 | 'c' => { :op => '=', :values => ['c'] }, | |
190 | '!c' => { :op => '!', :values => ['c'] }, |
|
190 | '!c' => { :op => '!', :values => ['c'] }, | |
191 | '!*' => { :op => '!*', :values => [''] }, |
|
191 | '!*' => { :op => '!*', :values => [''] }, | |
192 | '*' => { :op => '*', :values => [''] }}, |
|
192 | '*' => { :op => '*', :values => [''] }}, | |
193 | 'estimated_hours' => { |
|
193 | 'estimated_hours' => { | |
194 | '=13.4' => { :op => '=', :values => ['13.4'] }, |
|
194 | '=13.4' => { :op => '=', :values => ['13.4'] }, | |
195 | '>=45' => { :op => '>=', :values => ['45'] }, |
|
195 | '>=45' => { :op => '>=', :values => ['45'] }, | |
196 | '<=125' => { :op => '<=', :values => ['125'] }, |
|
196 | '<=125' => { :op => '<=', :values => ['125'] }, | |
197 | '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] }, |
|
197 | '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] }, | |
198 | '!*' => { :op => '!*', :values => [''] }, |
|
198 | '!*' => { :op => '!*', :values => [''] }, | |
199 | '*' => { :op => '*', :values => [''] }} |
|
199 | '*' => { :op => '*', :values => [''] }} | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | default_filter = { 'status_id' => {:operator => 'o', :values => [''] }} |
|
202 | default_filter = { 'status_id' => {:operator => 'o', :values => [''] }} | |
203 |
|
203 | |||
204 | to_test.each do |field, expression_and_expected| |
|
204 | to_test.each do |field, expression_and_expected| | |
205 | expression_and_expected.each do |filter_expression, expected| |
|
205 | expression_and_expected.each do |filter_expression, expected| | |
206 |
|
206 | |||
207 | get :index, :set_filter => 1, field => filter_expression |
|
207 | get :index, :set_filter => 1, field => filter_expression | |
208 |
|
208 | |||
209 | assert_response :success |
|
209 | assert_response :success | |
210 | assert_template 'index' |
|
210 | assert_template 'index' | |
211 | assert_not_nil assigns(:issues) |
|
211 | assert_not_nil assigns(:issues) | |
212 |
|
212 | |||
213 | query = assigns(:query) |
|
213 | query = assigns(:query) | |
214 | assert_not_nil query |
|
214 | assert_not_nil query | |
215 | assert query.has_filter?(field) |
|
215 | assert query.has_filter?(field) | |
216 | assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters) |
|
216 | assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters) | |
217 | end |
|
217 | end | |
218 | end |
|
218 | end | |
219 | end |
|
219 | end | |
220 |
|
220 | |||
221 | def test_index_with_project_and_empty_filters |
|
221 | def test_index_with_project_and_empty_filters | |
222 | get :index, :project_id => 1, :set_filter => 1, :fields => [''] |
|
222 | get :index, :project_id => 1, :set_filter => 1, :fields => [''] | |
223 | assert_response :success |
|
223 | assert_response :success | |
224 | assert_template 'index' |
|
224 | assert_template 'index' | |
225 | assert_not_nil assigns(:issues) |
|
225 | assert_not_nil assigns(:issues) | |
226 |
|
226 | |||
227 | query = assigns(:query) |
|
227 | query = assigns(:query) | |
228 | assert_not_nil query |
|
228 | assert_not_nil query | |
229 | # no filter |
|
229 | # no filter | |
230 | assert_equal({}, query.filters) |
|
230 | assert_equal({}, query.filters) | |
231 | end |
|
231 | end | |
232 |
|
232 | |||
233 | def test_index_with_query |
|
233 | def test_index_with_query | |
234 | get :index, :project_id => 1, :query_id => 5 |
|
234 | get :index, :project_id => 1, :query_id => 5 | |
235 | assert_response :success |
|
235 | assert_response :success | |
236 | assert_template 'index' |
|
236 | assert_template 'index' | |
237 | assert_not_nil assigns(:issues) |
|
237 | assert_not_nil assigns(:issues) | |
238 | assert_nil assigns(:issue_count_by_group) |
|
238 | assert_nil assigns(:issue_count_by_group) | |
239 | end |
|
239 | end | |
240 |
|
240 | |||
241 | def test_index_with_query_grouped_by_tracker |
|
241 | def test_index_with_query_grouped_by_tracker | |
242 | get :index, :project_id => 1, :query_id => 6 |
|
242 | get :index, :project_id => 1, :query_id => 6 | |
243 | assert_response :success |
|
243 | assert_response :success | |
244 | assert_template 'index' |
|
244 | assert_template 'index' | |
245 | assert_not_nil assigns(:issues) |
|
245 | assert_not_nil assigns(:issues) | |
246 | assert_not_nil assigns(:issue_count_by_group) |
|
246 | assert_not_nil assigns(:issue_count_by_group) | |
247 | end |
|
247 | end | |
248 |
|
248 | |||
249 | def test_index_with_query_grouped_by_list_custom_field |
|
249 | def test_index_with_query_grouped_by_list_custom_field | |
250 | get :index, :project_id => 1, :query_id => 9 |
|
250 | get :index, :project_id => 1, :query_id => 9 | |
251 | assert_response :success |
|
251 | assert_response :success | |
252 | assert_template 'index' |
|
252 | assert_template 'index' | |
253 | assert_not_nil assigns(:issues) |
|
253 | assert_not_nil assigns(:issues) | |
254 | assert_not_nil assigns(:issue_count_by_group) |
|
254 | assert_not_nil assigns(:issue_count_by_group) | |
255 | end |
|
255 | end | |
256 |
|
256 | |||
257 | def test_index_with_query_id_and_project_id_should_set_session_query |
|
257 | def test_index_with_query_id_and_project_id_should_set_session_query | |
258 | get :index, :project_id => 1, :query_id => 4 |
|
258 | get :index, :project_id => 1, :query_id => 4 | |
259 | assert_response :success |
|
259 | assert_response :success | |
260 | assert_kind_of Hash, session[:query] |
|
260 | assert_kind_of Hash, session[:query] | |
261 | assert_equal 4, session[:query][:id] |
|
261 | assert_equal 4, session[:query][:id] | |
262 | assert_equal 1, session[:query][:project_id] |
|
262 | assert_equal 1, session[:query][:project_id] | |
263 | end |
|
263 | end | |
264 |
|
264 | |||
265 | def test_index_with_invalid_query_id_should_respond_404 |
|
265 | def test_index_with_invalid_query_id_should_respond_404 | |
266 | get :index, :project_id => 1, :query_id => 999 |
|
266 | get :index, :project_id => 1, :query_id => 999 | |
267 | assert_response 404 |
|
267 | assert_response 404 | |
268 | end |
|
268 | end | |
269 |
|
269 | |||
270 | def test_index_with_cross_project_query_in_session_should_show_project_issues |
|
270 | def test_index_with_cross_project_query_in_session_should_show_project_issues | |
271 | q = Query.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil) |
|
271 | q = Query.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil) | |
272 | @request.session[:query] = {:id => q.id, :project_id => 1} |
|
272 | @request.session[:query] = {:id => q.id, :project_id => 1} | |
273 |
|
273 | |||
274 | with_settings :display_subprojects_issues => '0' do |
|
274 | with_settings :display_subprojects_issues => '0' do | |
275 | get :index, :project_id => 1 |
|
275 | get :index, :project_id => 1 | |
276 | end |
|
276 | end | |
277 | assert_response :success |
|
277 | assert_response :success | |
278 | assert_not_nil assigns(:query) |
|
278 | assert_not_nil assigns(:query) | |
279 | assert_equal q.id, assigns(:query).id |
|
279 | assert_equal q.id, assigns(:query).id | |
280 | assert_equal 1, assigns(:query).project_id |
|
280 | assert_equal 1, assigns(:query).project_id | |
281 | assert_equal [1], assigns(:issues).map(&:project_id).uniq |
|
281 | assert_equal [1], assigns(:issues).map(&:project_id).uniq | |
282 | end |
|
282 | end | |
283 |
|
283 | |||
284 | def test_private_query_should_not_be_available_to_other_users |
|
284 | def test_private_query_should_not_be_available_to_other_users | |
285 | q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil) |
|
285 | q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil) | |
286 | @request.session[:user_id] = 3 |
|
286 | @request.session[:user_id] = 3 | |
287 |
|
287 | |||
288 | get :index, :query_id => q.id |
|
288 | get :index, :query_id => q.id | |
289 | assert_response 403 |
|
289 | assert_response 403 | |
290 | end |
|
290 | end | |
291 |
|
291 | |||
292 | def test_private_query_should_be_available_to_its_user |
|
292 | def test_private_query_should_be_available_to_its_user | |
293 | q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil) |
|
293 | q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil) | |
294 | @request.session[:user_id] = 2 |
|
294 | @request.session[:user_id] = 2 | |
295 |
|
295 | |||
296 | get :index, :query_id => q.id |
|
296 | get :index, :query_id => q.id | |
297 | assert_response :success |
|
297 | assert_response :success | |
298 | end |
|
298 | end | |
299 |
|
299 | |||
300 | def test_public_query_should_be_available_to_other_users |
|
300 | def test_public_query_should_be_available_to_other_users | |
301 | q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil) |
|
301 | q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil) | |
302 | @request.session[:user_id] = 3 |
|
302 | @request.session[:user_id] = 3 | |
303 |
|
303 | |||
304 | get :index, :query_id => q.id |
|
304 | get :index, :query_id => q.id | |
305 | assert_response :success |
|
305 | assert_response :success | |
306 | end |
|
306 | end | |
307 |
|
307 | |||
308 | def test_index_csv |
|
308 | def test_index_csv | |
309 | get :index, :format => 'csv' |
|
309 | get :index, :format => 'csv' | |
310 | assert_response :success |
|
310 | assert_response :success | |
311 | assert_not_nil assigns(:issues) |
|
311 | assert_not_nil assigns(:issues) | |
312 | assert_equal 'text/csv', @response.content_type |
|
312 | assert_equal 'text/csv', @response.content_type | |
313 | assert @response.body.starts_with?("#,") |
|
313 | assert @response.body.starts_with?("#,") | |
314 | lines = @response.body.chomp.split("\n") |
|
314 | lines = @response.body.chomp.split("\n") | |
315 | assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size |
|
315 | assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size | |
316 | end |
|
316 | end | |
317 |
|
317 | |||
318 | def test_index_csv_with_project |
|
318 | def test_index_csv_with_project | |
319 | get :index, :project_id => 1, :format => 'csv' |
|
319 | get :index, :project_id => 1, :format => 'csv' | |
320 | assert_response :success |
|
320 | assert_response :success | |
321 | assert_not_nil assigns(:issues) |
|
321 | assert_not_nil assigns(:issues) | |
322 | assert_equal 'text/csv', @response.content_type |
|
322 | assert_equal 'text/csv', @response.content_type | |
323 | end |
|
323 | end | |
324 |
|
324 | |||
325 | def test_index_csv_with_description |
|
325 | def test_index_csv_with_description | |
326 | get :index, :format => 'csv', :description => '1' |
|
326 | get :index, :format => 'csv', :description => '1' | |
327 | assert_response :success |
|
327 | assert_response :success | |
328 | assert_not_nil assigns(:issues) |
|
328 | assert_not_nil assigns(:issues) | |
329 | assert_equal 'text/csv', @response.content_type |
|
329 | assert_equal 'text/csv', @response.content_type | |
330 | assert @response.body.starts_with?("#,") |
|
330 | assert @response.body.starts_with?("#,") | |
331 | lines = @response.body.chomp.split("\n") |
|
331 | lines = @response.body.chomp.split("\n") | |
332 | assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size |
|
332 | assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size | |
333 | end |
|
333 | end | |
334 |
|
334 | |||
335 | def test_index_csv_with_spent_time_column |
|
335 | def test_index_csv_with_spent_time_column | |
336 | issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2) |
|
336 | issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2) | |
337 | TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today) |
|
337 | TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today) | |
338 |
|
338 | |||
339 | get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours) |
|
339 | get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours) | |
340 | assert_response :success |
|
340 | assert_response :success | |
341 | assert_equal 'text/csv', @response.content_type |
|
341 | assert_equal 'text/csv', @response.content_type | |
342 | lines = @response.body.chomp.split("\n") |
|
342 | lines = @response.body.chomp.split("\n") | |
343 | assert_include "#{issue.id},#{issue.subject},7.33", lines |
|
343 | assert_include "#{issue.id},#{issue.subject},7.33", lines | |
344 | end |
|
344 | end | |
345 |
|
345 | |||
346 | def test_index_csv_with_all_columns |
|
346 | def test_index_csv_with_all_columns | |
347 | get :index, :format => 'csv', :columns => 'all' |
|
347 | get :index, :format => 'csv', :columns => 'all' | |
348 | assert_response :success |
|
348 | assert_response :success | |
349 | assert_not_nil assigns(:issues) |
|
349 | assert_not_nil assigns(:issues) | |
350 | assert_equal 'text/csv', @response.content_type |
|
350 | assert_equal 'text/csv', @response.content_type | |
351 | assert @response.body.starts_with?("#,") |
|
351 | assert @response.body.starts_with?("#,") | |
352 | lines = @response.body.chomp.split("\n") |
|
352 | lines = @response.body.chomp.split("\n") | |
353 | assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size |
|
353 | assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size | |
354 | end |
|
354 | end | |
355 |
|
355 | |||
356 | def test_index_csv_with_multi_column_field |
|
356 | def test_index_csv_with_multi_column_field | |
357 | CustomField.find(1).update_attribute :multiple, true |
|
357 | CustomField.find(1).update_attribute :multiple, true | |
358 | issue = Issue.find(1) |
|
358 | issue = Issue.find(1) | |
359 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
359 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} | |
360 | issue.save! |
|
360 | issue.save! | |
361 |
|
361 | |||
362 | get :index, :format => 'csv', :columns => 'all' |
|
362 | get :index, :format => 'csv', :columns => 'all' | |
363 | assert_response :success |
|
363 | assert_response :success | |
364 | lines = @response.body.chomp.split("\n") |
|
364 | lines = @response.body.chomp.split("\n") | |
365 | assert lines.detect {|line| line.include?('"MySQL, Oracle"')} |
|
365 | assert lines.detect {|line| line.include?('"MySQL, Oracle"')} | |
366 | end |
|
366 | end | |
367 |
|
367 | |||
368 | def test_index_csv_big_5 |
|
368 | def test_index_csv_big_5 | |
369 | with_settings :default_language => "zh-TW" do |
|
369 | with_settings :default_language => "zh-TW" do | |
370 | str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" |
|
370 | str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" | |
371 | str_big5 = "\xa4@\xa4\xeb" |
|
371 | str_big5 = "\xa4@\xa4\xeb" | |
372 | if str_utf8.respond_to?(:force_encoding) |
|
372 | if str_utf8.respond_to?(:force_encoding) | |
373 | str_utf8.force_encoding('UTF-8') |
|
373 | str_utf8.force_encoding('UTF-8') | |
374 | str_big5.force_encoding('Big5') |
|
374 | str_big5.force_encoding('Big5') | |
375 | end |
|
375 | end | |
376 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, |
|
376 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, | |
377 | :status_id => 1, :priority => IssuePriority.all.first, |
|
377 | :status_id => 1, :priority => IssuePriority.all.first, | |
378 | :subject => str_utf8) |
|
378 | :subject => str_utf8) | |
379 | assert issue.save |
|
379 | assert issue.save | |
380 |
|
380 | |||
381 | get :index, :project_id => 1, |
|
381 | get :index, :project_id => 1, | |
382 | :f => ['subject'], |
|
382 | :f => ['subject'], | |
383 | :op => '=', :values => [str_utf8], |
|
383 | :op => '=', :values => [str_utf8], | |
384 | :format => 'csv' |
|
384 | :format => 'csv' | |
385 | assert_equal 'text/csv', @response.content_type |
|
385 | assert_equal 'text/csv', @response.content_type | |
386 | lines = @response.body.chomp.split("\n") |
|
386 | lines = @response.body.chomp.split("\n") | |
387 | s1 = "\xaa\xac\xbaA" |
|
387 | s1 = "\xaa\xac\xbaA" | |
388 | if str_utf8.respond_to?(:force_encoding) |
|
388 | if str_utf8.respond_to?(:force_encoding) | |
389 | s1.force_encoding('Big5') |
|
389 | s1.force_encoding('Big5') | |
390 | end |
|
390 | end | |
391 | assert lines[0].include?(s1) |
|
391 | assert lines[0].include?(s1) | |
392 | assert lines[1].include?(str_big5) |
|
392 | assert lines[1].include?(str_big5) | |
393 | end |
|
393 | end | |
394 | end |
|
394 | end | |
395 |
|
395 | |||
396 | def test_index_csv_cannot_convert_should_be_replaced_big_5 |
|
396 | def test_index_csv_cannot_convert_should_be_replaced_big_5 | |
397 | with_settings :default_language => "zh-TW" do |
|
397 | with_settings :default_language => "zh-TW" do | |
398 | str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85" |
|
398 | str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85" | |
399 | if str_utf8.respond_to?(:force_encoding) |
|
399 | if str_utf8.respond_to?(:force_encoding) | |
400 | str_utf8.force_encoding('UTF-8') |
|
400 | str_utf8.force_encoding('UTF-8') | |
401 | end |
|
401 | end | |
402 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, |
|
402 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, | |
403 | :status_id => 1, :priority => IssuePriority.all.first, |
|
403 | :status_id => 1, :priority => IssuePriority.all.first, | |
404 | :subject => str_utf8) |
|
404 | :subject => str_utf8) | |
405 | assert issue.save |
|
405 | assert issue.save | |
406 |
|
406 | |||
407 | get :index, :project_id => 1, |
|
407 | get :index, :project_id => 1, | |
408 | :f => ['subject'], |
|
408 | :f => ['subject'], | |
409 | :op => '=', :values => [str_utf8], |
|
409 | :op => '=', :values => [str_utf8], | |
410 | :c => ['status', 'subject'], |
|
410 | :c => ['status', 'subject'], | |
411 | :format => 'csv', |
|
411 | :format => 'csv', | |
412 | :set_filter => 1 |
|
412 | :set_filter => 1 | |
413 | assert_equal 'text/csv', @response.content_type |
|
413 | assert_equal 'text/csv', @response.content_type | |
414 | lines = @response.body.chomp.split("\n") |
|
414 | lines = @response.body.chomp.split("\n") | |
415 | s1 = "\xaa\xac\xbaA" # status |
|
415 | s1 = "\xaa\xac\xbaA" # status | |
416 | if str_utf8.respond_to?(:force_encoding) |
|
416 | if str_utf8.respond_to?(:force_encoding) | |
417 | s1.force_encoding('Big5') |
|
417 | s1.force_encoding('Big5') | |
418 | end |
|
418 | end | |
419 | assert lines[0].include?(s1) |
|
419 | assert lines[0].include?(s1) | |
420 | s2 = lines[1].split(",")[2] |
|
420 | s2 = lines[1].split(",")[2] | |
421 | if s1.respond_to?(:force_encoding) |
|
421 | if s1.respond_to?(:force_encoding) | |
422 | s3 = "\xa5H?" # subject |
|
422 | s3 = "\xa5H?" # subject | |
423 | s3.force_encoding('Big5') |
|
423 | s3.force_encoding('Big5') | |
424 | assert_equal s3, s2 |
|
424 | assert_equal s3, s2 | |
425 | elsif RUBY_PLATFORM == 'java' |
|
425 | elsif RUBY_PLATFORM == 'java' | |
426 | assert_equal "??", s2 |
|
426 | assert_equal "??", s2 | |
427 | else |
|
427 | else | |
428 | assert_equal "\xa5H???", s2 |
|
428 | assert_equal "\xa5H???", s2 | |
429 | end |
|
429 | end | |
430 | end |
|
430 | end | |
431 | end |
|
431 | end | |
432 |
|
432 | |||
433 | def test_index_csv_tw |
|
433 | def test_index_csv_tw | |
434 | with_settings :default_language => "zh-TW" do |
|
434 | with_settings :default_language => "zh-TW" do | |
435 | str1 = "test_index_csv_tw" |
|
435 | str1 = "test_index_csv_tw" | |
436 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, |
|
436 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, | |
437 | :status_id => 1, :priority => IssuePriority.all.first, |
|
437 | :status_id => 1, :priority => IssuePriority.all.first, | |
438 | :subject => str1, :estimated_hours => '1234.5') |
|
438 | :subject => str1, :estimated_hours => '1234.5') | |
439 | assert issue.save |
|
439 | assert issue.save | |
440 | assert_equal 1234.5, issue.estimated_hours |
|
440 | assert_equal 1234.5, issue.estimated_hours | |
441 |
|
441 | |||
442 | get :index, :project_id => 1, |
|
442 | get :index, :project_id => 1, | |
443 | :f => ['subject'], |
|
443 | :f => ['subject'], | |
444 | :op => '=', :values => [str1], |
|
444 | :op => '=', :values => [str1], | |
445 | :c => ['estimated_hours', 'subject'], |
|
445 | :c => ['estimated_hours', 'subject'], | |
446 | :format => 'csv', |
|
446 | :format => 'csv', | |
447 | :set_filter => 1 |
|
447 | :set_filter => 1 | |
448 | assert_equal 'text/csv', @response.content_type |
|
448 | assert_equal 'text/csv', @response.content_type | |
449 | lines = @response.body.chomp.split("\n") |
|
449 | lines = @response.body.chomp.split("\n") | |
450 | assert_equal "#{issue.id},1234.50,#{str1}", lines[1] |
|
450 | assert_equal "#{issue.id},1234.50,#{str1}", lines[1] | |
451 |
|
451 | |||
452 | str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)" |
|
452 | str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)" | |
453 | if str_tw.respond_to?(:force_encoding) |
|
453 | if str_tw.respond_to?(:force_encoding) | |
454 | str_tw.force_encoding('UTF-8') |
|
454 | str_tw.force_encoding('UTF-8') | |
455 | end |
|
455 | end | |
456 | assert_equal str_tw, l(:general_lang_name) |
|
456 | assert_equal str_tw, l(:general_lang_name) | |
457 | assert_equal ',', l(:general_csv_separator) |
|
457 | assert_equal ',', l(:general_csv_separator) | |
458 | assert_equal '.', l(:general_csv_decimal_separator) |
|
458 | assert_equal '.', l(:general_csv_decimal_separator) | |
459 | end |
|
459 | end | |
460 | end |
|
460 | end | |
461 |
|
461 | |||
462 | def test_index_csv_fr |
|
462 | def test_index_csv_fr | |
463 | with_settings :default_language => "fr" do |
|
463 | with_settings :default_language => "fr" do | |
464 | str1 = "test_index_csv_fr" |
|
464 | str1 = "test_index_csv_fr" | |
465 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, |
|
465 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, | |
466 | :status_id => 1, :priority => IssuePriority.all.first, |
|
466 | :status_id => 1, :priority => IssuePriority.all.first, | |
467 | :subject => str1, :estimated_hours => '1234.5') |
|
467 | :subject => str1, :estimated_hours => '1234.5') | |
468 | assert issue.save |
|
468 | assert issue.save | |
469 | assert_equal 1234.5, issue.estimated_hours |
|
469 | assert_equal 1234.5, issue.estimated_hours | |
470 |
|
470 | |||
471 | get :index, :project_id => 1, |
|
471 | get :index, :project_id => 1, | |
472 | :f => ['subject'], |
|
472 | :f => ['subject'], | |
473 | :op => '=', :values => [str1], |
|
473 | :op => '=', :values => [str1], | |
474 | :c => ['estimated_hours', 'subject'], |
|
474 | :c => ['estimated_hours', 'subject'], | |
475 | :format => 'csv', |
|
475 | :format => 'csv', | |
476 | :set_filter => 1 |
|
476 | :set_filter => 1 | |
477 | assert_equal 'text/csv', @response.content_type |
|
477 | assert_equal 'text/csv', @response.content_type | |
478 | lines = @response.body.chomp.split("\n") |
|
478 | lines = @response.body.chomp.split("\n") | |
479 | assert_equal "#{issue.id};1234,50;#{str1}", lines[1] |
|
479 | assert_equal "#{issue.id};1234,50;#{str1}", lines[1] | |
480 |
|
480 | |||
481 | str_fr = "Fran\xc3\xa7ais" |
|
481 | str_fr = "Fran\xc3\xa7ais" | |
482 | if str_fr.respond_to?(:force_encoding) |
|
482 | if str_fr.respond_to?(:force_encoding) | |
483 | str_fr.force_encoding('UTF-8') |
|
483 | str_fr.force_encoding('UTF-8') | |
484 | end |
|
484 | end | |
485 | assert_equal str_fr, l(:general_lang_name) |
|
485 | assert_equal str_fr, l(:general_lang_name) | |
486 | assert_equal ';', l(:general_csv_separator) |
|
486 | assert_equal ';', l(:general_csv_separator) | |
487 | assert_equal ',', l(:general_csv_decimal_separator) |
|
487 | assert_equal ',', l(:general_csv_decimal_separator) | |
488 | end |
|
488 | end | |
489 | end |
|
489 | end | |
490 |
|
490 | |||
491 | def test_index_pdf |
|
491 | def test_index_pdf | |
492 | ["en", "zh", "zh-TW", "ja", "ko"].each do |lang| |
|
492 | ["en", "zh", "zh-TW", "ja", "ko"].each do |lang| | |
493 | with_settings :default_language => lang do |
|
493 | with_settings :default_language => lang do | |
494 |
|
494 | |||
495 | get :index |
|
495 | get :index | |
496 | assert_response :success |
|
496 | assert_response :success | |
497 | assert_template 'index' |
|
497 | assert_template 'index' | |
498 |
|
498 | |||
499 | if lang == "ja" |
|
499 | if lang == "ja" | |
500 | if RUBY_PLATFORM != 'java' |
|
500 | if RUBY_PLATFORM != 'java' | |
501 | assert_equal "CP932", l(:general_pdf_encoding) |
|
501 | assert_equal "CP932", l(:general_pdf_encoding) | |
502 | end |
|
502 | end | |
503 | if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932" |
|
503 | if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932" | |
504 | next |
|
504 | next | |
505 | end |
|
505 | end | |
506 | end |
|
506 | end | |
507 |
|
507 | |||
508 | get :index, :format => 'pdf' |
|
508 | get :index, :format => 'pdf' | |
509 | assert_response :success |
|
509 | assert_response :success | |
510 | assert_not_nil assigns(:issues) |
|
510 | assert_not_nil assigns(:issues) | |
511 | assert_equal 'application/pdf', @response.content_type |
|
511 | assert_equal 'application/pdf', @response.content_type | |
512 |
|
512 | |||
513 | get :index, :project_id => 1, :format => 'pdf' |
|
513 | get :index, :project_id => 1, :format => 'pdf' | |
514 | assert_response :success |
|
514 | assert_response :success | |
515 | assert_not_nil assigns(:issues) |
|
515 | assert_not_nil assigns(:issues) | |
516 | assert_equal 'application/pdf', @response.content_type |
|
516 | assert_equal 'application/pdf', @response.content_type | |
517 |
|
517 | |||
518 | get :index, :project_id => 1, :query_id => 6, :format => 'pdf' |
|
518 | get :index, :project_id => 1, :query_id => 6, :format => 'pdf' | |
519 | assert_response :success |
|
519 | assert_response :success | |
520 | assert_not_nil assigns(:issues) |
|
520 | assert_not_nil assigns(:issues) | |
521 | assert_equal 'application/pdf', @response.content_type |
|
521 | assert_equal 'application/pdf', @response.content_type | |
522 | end |
|
522 | end | |
523 | end |
|
523 | end | |
524 | end |
|
524 | end | |
525 |
|
525 | |||
526 | def test_index_pdf_with_query_grouped_by_list_custom_field |
|
526 | def test_index_pdf_with_query_grouped_by_list_custom_field | |
527 | get :index, :project_id => 1, :query_id => 9, :format => 'pdf' |
|
527 | get :index, :project_id => 1, :query_id => 9, :format => 'pdf' | |
528 | assert_response :success |
|
528 | assert_response :success | |
529 | assert_not_nil assigns(:issues) |
|
529 | assert_not_nil assigns(:issues) | |
530 | assert_not_nil assigns(:issue_count_by_group) |
|
530 | assert_not_nil assigns(:issue_count_by_group) | |
531 | assert_equal 'application/pdf', @response.content_type |
|
531 | assert_equal 'application/pdf', @response.content_type | |
532 | end |
|
532 | end | |
533 |
|
533 | |||
534 | def test_index_sort |
|
534 | def test_index_sort | |
535 | get :index, :sort => 'tracker,id:desc' |
|
535 | get :index, :sort => 'tracker,id:desc' | |
536 | assert_response :success |
|
536 | assert_response :success | |
537 |
|
537 | |||
538 | sort_params = @request.session['issues_index_sort'] |
|
538 | sort_params = @request.session['issues_index_sort'] | |
539 | assert sort_params.is_a?(String) |
|
539 | assert sort_params.is_a?(String) | |
540 | assert_equal 'tracker,id:desc', sort_params |
|
540 | assert_equal 'tracker,id:desc', sort_params | |
541 |
|
541 | |||
542 | issues = assigns(:issues) |
|
542 | issues = assigns(:issues) | |
543 | assert_not_nil issues |
|
543 | assert_not_nil issues | |
544 | assert !issues.empty? |
|
544 | assert !issues.empty? | |
545 | assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id) |
|
545 | assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id) | |
546 | end |
|
546 | end | |
547 |
|
547 | |||
548 | def test_index_sort_by_field_not_included_in_columns |
|
548 | def test_index_sort_by_field_not_included_in_columns | |
549 | Setting.issue_list_default_columns = %w(subject author) |
|
549 | Setting.issue_list_default_columns = %w(subject author) | |
550 | get :index, :sort => 'tracker' |
|
550 | get :index, :sort => 'tracker' | |
551 | end |
|
551 | end | |
552 |
|
552 | |||
553 | def test_index_sort_by_assigned_to |
|
553 | def test_index_sort_by_assigned_to | |
554 | get :index, :sort => 'assigned_to' |
|
554 | get :index, :sort => 'assigned_to' | |
555 | assert_response :success |
|
555 | assert_response :success | |
556 | assignees = assigns(:issues).collect(&:assigned_to).compact |
|
556 | assignees = assigns(:issues).collect(&:assigned_to).compact | |
557 | assert_equal assignees.sort, assignees |
|
557 | assert_equal assignees.sort, assignees | |
558 | end |
|
558 | end | |
559 |
|
559 | |||
560 | def test_index_sort_by_assigned_to_desc |
|
560 | def test_index_sort_by_assigned_to_desc | |
561 | get :index, :sort => 'assigned_to:desc' |
|
561 | get :index, :sort => 'assigned_to:desc' | |
562 | assert_response :success |
|
562 | assert_response :success | |
563 | assignees = assigns(:issues).collect(&:assigned_to).compact |
|
563 | assignees = assigns(:issues).collect(&:assigned_to).compact | |
564 | assert_equal assignees.sort.reverse, assignees |
|
564 | assert_equal assignees.sort.reverse, assignees | |
565 | end |
|
565 | end | |
566 |
|
566 | |||
567 | def test_index_group_by_assigned_to |
|
567 | def test_index_group_by_assigned_to | |
568 | get :index, :group_by => 'assigned_to', :sort => 'priority' |
|
568 | get :index, :group_by => 'assigned_to', :sort => 'priority' | |
569 | assert_response :success |
|
569 | assert_response :success | |
570 | end |
|
570 | end | |
571 |
|
571 | |||
572 | def test_index_sort_by_author |
|
572 | def test_index_sort_by_author | |
573 | get :index, :sort => 'author' |
|
573 | get :index, :sort => 'author' | |
574 | assert_response :success |
|
574 | assert_response :success | |
575 | authors = assigns(:issues).collect(&:author) |
|
575 | authors = assigns(:issues).collect(&:author) | |
576 | assert_equal authors.sort, authors |
|
576 | assert_equal authors.sort, authors | |
577 | end |
|
577 | end | |
578 |
|
578 | |||
579 | def test_index_sort_by_author_desc |
|
579 | def test_index_sort_by_author_desc | |
580 | get :index, :sort => 'author:desc' |
|
580 | get :index, :sort => 'author:desc' | |
581 | assert_response :success |
|
581 | assert_response :success | |
582 | authors = assigns(:issues).collect(&:author) |
|
582 | authors = assigns(:issues).collect(&:author) | |
583 | assert_equal authors.sort.reverse, authors |
|
583 | assert_equal authors.sort.reverse, authors | |
584 | end |
|
584 | end | |
585 |
|
585 | |||
586 | def test_index_group_by_author |
|
586 | def test_index_group_by_author | |
587 | get :index, :group_by => 'author', :sort => 'priority' |
|
587 | get :index, :group_by => 'author', :sort => 'priority' | |
588 | assert_response :success |
|
588 | assert_response :success | |
589 | end |
|
589 | end | |
590 |
|
590 | |||
591 | def test_index_sort_by_spent_hours |
|
591 | def test_index_sort_by_spent_hours | |
592 | get :index, :sort => 'spent_hours:desc' |
|
592 | get :index, :sort => 'spent_hours:desc' | |
593 | assert_response :success |
|
593 | assert_response :success | |
594 | hours = assigns(:issues).collect(&:spent_hours) |
|
594 | hours = assigns(:issues).collect(&:spent_hours) | |
595 | assert_equal hours.sort.reverse, hours |
|
595 | assert_equal hours.sort.reverse, hours | |
596 | end |
|
596 | end | |
597 |
|
597 | |||
598 | def test_index_with_columns |
|
598 | def test_index_with_columns | |
599 | columns = ['tracker', 'subject', 'assigned_to'] |
|
599 | columns = ['tracker', 'subject', 'assigned_to'] | |
600 | get :index, :set_filter => 1, :c => columns |
|
600 | get :index, :set_filter => 1, :c => columns | |
601 | assert_response :success |
|
601 | assert_response :success | |
602 |
|
602 | |||
603 | # query should use specified columns |
|
603 | # query should use specified columns | |
604 | query = assigns(:query) |
|
604 | query = assigns(:query) | |
605 | assert_kind_of Query, query |
|
605 | assert_kind_of Query, query | |
606 | assert_equal columns, query.column_names.map(&:to_s) |
|
606 | assert_equal columns, query.column_names.map(&:to_s) | |
607 |
|
607 | |||
608 | # columns should be stored in session |
|
608 | # columns should be stored in session | |
609 | assert_kind_of Hash, session[:query] |
|
609 | assert_kind_of Hash, session[:query] | |
610 | assert_kind_of Array, session[:query][:column_names] |
|
610 | assert_kind_of Array, session[:query][:column_names] | |
611 | assert_equal columns, session[:query][:column_names].map(&:to_s) |
|
611 | assert_equal columns, session[:query][:column_names].map(&:to_s) | |
612 |
|
612 | |||
613 | # ensure only these columns are kept in the selected columns list |
|
613 | # ensure only these columns are kept in the selected columns list | |
614 | assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' }, |
|
614 | assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' }, | |
615 | :children => { :count => 3 } |
|
615 | :children => { :count => 3 } | |
616 | assert_no_tag :tag => 'option', :attributes => { :value => 'project' }, |
|
616 | assert_no_tag :tag => 'option', :attributes => { :value => 'project' }, | |
617 | :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } } |
|
617 | :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } } | |
618 | end |
|
618 | end | |
619 |
|
619 | |||
620 | def test_index_without_project_should_implicitly_add_project_column_to_default_columns |
|
620 | def test_index_without_project_should_implicitly_add_project_column_to_default_columns | |
621 | Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] |
|
621 | Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] | |
622 | get :index, :set_filter => 1 |
|
622 | get :index, :set_filter => 1 | |
623 |
|
623 | |||
624 | # query should use specified columns |
|
624 | # query should use specified columns | |
625 | query = assigns(:query) |
|
625 | query = assigns(:query) | |
626 | assert_kind_of Query, query |
|
626 | assert_kind_of Query, query | |
627 | assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name) |
|
627 | assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name) | |
628 | end |
|
628 | end | |
629 |
|
629 | |||
630 | def test_index_without_project_and_explicit_default_columns_should_not_add_project_column |
|
630 | def test_index_without_project_and_explicit_default_columns_should_not_add_project_column | |
631 | Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] |
|
631 | Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] | |
632 | columns = ['tracker', 'subject', 'assigned_to'] |
|
632 | columns = ['tracker', 'subject', 'assigned_to'] | |
633 | get :index, :set_filter => 1, :c => columns |
|
633 | get :index, :set_filter => 1, :c => columns | |
634 |
|
634 | |||
635 | # query should use specified columns |
|
635 | # query should use specified columns | |
636 | query = assigns(:query) |
|
636 | query = assigns(:query) | |
637 | assert_kind_of Query, query |
|
637 | assert_kind_of Query, query | |
638 | assert_equal columns.map(&:to_sym), query.columns.map(&:name) |
|
638 | assert_equal columns.map(&:to_sym), query.columns.map(&:name) | |
639 | end |
|
639 | end | |
640 |
|
640 | |||
641 | def test_index_with_custom_field_column |
|
641 | def test_index_with_custom_field_column | |
642 | columns = %w(tracker subject cf_2) |
|
642 | columns = %w(tracker subject cf_2) | |
643 | get :index, :set_filter => 1, :c => columns |
|
643 | get :index, :set_filter => 1, :c => columns | |
644 | assert_response :success |
|
644 | assert_response :success | |
645 |
|
645 | |||
646 | # query should use specified columns |
|
646 | # query should use specified columns | |
647 | query = assigns(:query) |
|
647 | query = assigns(:query) | |
648 | assert_kind_of Query, query |
|
648 | assert_kind_of Query, query | |
649 | assert_equal columns, query.column_names.map(&:to_s) |
|
649 | assert_equal columns, query.column_names.map(&:to_s) | |
650 |
|
650 | |||
651 | assert_tag :td, |
|
651 | assert_tag :td, | |
652 | :attributes => {:class => 'cf_2 string'}, |
|
652 | :attributes => {:class => 'cf_2 string'}, | |
653 | :ancestor => {:tag => 'table', :attributes => {:class => /issues/}} |
|
653 | :ancestor => {:tag => 'table', :attributes => {:class => /issues/}} | |
654 | end |
|
654 | end | |
655 |
|
655 | |||
656 | def test_index_with_multi_custom_field_column |
|
656 | def test_index_with_multi_custom_field_column | |
657 | field = CustomField.find(1) |
|
657 | field = CustomField.find(1) | |
658 | field.update_attribute :multiple, true |
|
658 | field.update_attribute :multiple, true | |
659 | issue = Issue.find(1) |
|
659 | issue = Issue.find(1) | |
660 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
660 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} | |
661 | issue.save! |
|
661 | issue.save! | |
662 |
|
662 | |||
663 | get :index, :set_filter => 1, :c => %w(tracker subject cf_1) |
|
663 | get :index, :set_filter => 1, :c => %w(tracker subject cf_1) | |
664 | assert_response :success |
|
664 | assert_response :success | |
665 |
|
665 | |||
666 | assert_tag :td, |
|
666 | assert_tag :td, | |
667 | :attributes => {:class => /cf_1/}, |
|
667 | :attributes => {:class => /cf_1/}, | |
668 | :content => 'MySQL, Oracle' |
|
668 | :content => 'MySQL, Oracle' | |
669 | end |
|
669 | end | |
670 |
|
670 | |||
671 | def test_index_with_multi_user_custom_field_column |
|
671 | def test_index_with_multi_user_custom_field_column | |
672 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, |
|
672 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, | |
673 | :tracker_ids => [1], :is_for_all => true) |
|
673 | :tracker_ids => [1], :is_for_all => true) | |
674 | issue = Issue.find(1) |
|
674 | issue = Issue.find(1) | |
675 | issue.custom_field_values = {field.id => ['2', '3']} |
|
675 | issue.custom_field_values = {field.id => ['2', '3']} | |
676 | issue.save! |
|
676 | issue.save! | |
677 |
|
677 | |||
678 | get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"] |
|
678 | get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"] | |
679 | assert_response :success |
|
679 | assert_response :success | |
680 |
|
680 | |||
681 | assert_tag :td, |
|
681 | assert_tag :td, | |
682 | :attributes => {:class => /cf_#{field.id}/}, |
|
682 | :attributes => {:class => /cf_#{field.id}/}, | |
683 | :child => {:tag => 'a', :content => 'John Smith'} |
|
683 | :child => {:tag => 'a', :content => 'John Smith'} | |
684 | end |
|
684 | end | |
685 |
|
685 | |||
686 | def test_index_with_date_column |
|
686 | def test_index_with_date_column | |
687 | Issue.find(1).update_attribute :start_date, '1987-08-24' |
|
687 | Issue.find(1).update_attribute :start_date, '1987-08-24' | |
688 |
|
688 | |||
689 | with_settings :date_format => '%d/%m/%Y' do |
|
689 | with_settings :date_format => '%d/%m/%Y' do | |
690 | get :index, :set_filter => 1, :c => %w(start_date) |
|
690 | get :index, :set_filter => 1, :c => %w(start_date) | |
691 | assert_tag 'td', :attributes => {:class => /start_date/}, :content => '24/08/1987' |
|
691 | assert_tag 'td', :attributes => {:class => /start_date/}, :content => '24/08/1987' | |
692 | end |
|
692 | end | |
693 | end |
|
693 | end | |
694 |
|
694 | |||
695 | def test_index_with_done_ratio |
|
695 | def test_index_with_done_ratio | |
696 | Issue.find(1).update_attribute :done_ratio, 40 |
|
696 | Issue.find(1).update_attribute :done_ratio, 40 | |
697 |
|
697 | |||
698 | get :index, :set_filter => 1, :c => %w(done_ratio) |
|
698 | get :index, :set_filter => 1, :c => %w(done_ratio) | |
699 | assert_tag 'td', :attributes => {:class => /done_ratio/}, |
|
699 | assert_tag 'td', :attributes => {:class => /done_ratio/}, | |
700 | :child => {:tag => 'table', :attributes => {:class => 'progress'}, |
|
700 | :child => {:tag => 'table', :attributes => {:class => 'progress'}, | |
701 | :descendant => {:tag => 'td', :attributes => {:class => 'closed', :style => 'width: 40%;'}} |
|
701 | :descendant => {:tag => 'td', :attributes => {:class => 'closed', :style => 'width: 40%;'}} | |
702 | } |
|
702 | } | |
703 | end |
|
703 | end | |
704 |
|
704 | |||
705 | def test_index_with_spent_hours_column |
|
705 | def test_index_with_spent_hours_column | |
706 | get :index, :set_filter => 1, :c => %w(subject spent_hours) |
|
706 | get :index, :set_filter => 1, :c => %w(subject spent_hours) | |
707 |
|
707 | |||
708 | assert_tag 'tr', :attributes => {:id => 'issue-3'}, |
|
708 | assert_tag 'tr', :attributes => {:id => 'issue-3'}, | |
709 | :child => { |
|
709 | :child => { | |
710 | :tag => 'td', :attributes => {:class => /spent_hours/}, :content => '1.00' |
|
710 | :tag => 'td', :attributes => {:class => /spent_hours/}, :content => '1.00' | |
711 | } |
|
711 | } | |
712 | end |
|
712 | end | |
713 |
|
713 | |||
714 | def test_index_should_not_show_spent_hours_column_without_permission |
|
714 | def test_index_should_not_show_spent_hours_column_without_permission | |
715 | Role.anonymous.remove_permission! :view_time_entries |
|
715 | Role.anonymous.remove_permission! :view_time_entries | |
716 | get :index, :set_filter => 1, :c => %w(subject spent_hours) |
|
716 | get :index, :set_filter => 1, :c => %w(subject spent_hours) | |
717 |
|
717 | |||
718 | assert_no_tag 'td', :attributes => {:class => /spent_hours/} |
|
718 | assert_no_tag 'td', :attributes => {:class => /spent_hours/} | |
719 | end |
|
719 | end | |
720 |
|
720 | |||
721 | def test_index_with_fixed_version |
|
721 | def test_index_with_fixed_version | |
722 | get :index, :set_filter => 1, :c => %w(fixed_version) |
|
722 | get :index, :set_filter => 1, :c => %w(fixed_version) | |
723 | assert_tag 'td', :attributes => {:class => /fixed_version/}, |
|
723 | assert_tag 'td', :attributes => {:class => /fixed_version/}, | |
724 | :child => {:tag => 'a', :content => '1.0', :attributes => {:href => '/versions/2'}} |
|
724 | :child => {:tag => 'a', :content => '1.0', :attributes => {:href => '/versions/2'}} | |
725 | end |
|
725 | end | |
726 |
|
726 | |||
727 | def test_index_send_html_if_query_is_invalid |
|
727 | def test_index_send_html_if_query_is_invalid | |
728 | get :index, :f => ['start_date'], :op => {:start_date => '='} |
|
728 | get :index, :f => ['start_date'], :op => {:start_date => '='} | |
729 | assert_equal 'text/html', @response.content_type |
|
729 | assert_equal 'text/html', @response.content_type | |
730 | assert_template 'index' |
|
730 | assert_template 'index' | |
731 | end |
|
731 | end | |
732 |
|
732 | |||
733 | def test_index_send_nothing_if_query_is_invalid |
|
733 | def test_index_send_nothing_if_query_is_invalid | |
734 | get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv' |
|
734 | get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv' | |
735 | assert_equal 'text/csv', @response.content_type |
|
735 | assert_equal 'text/csv', @response.content_type | |
736 | assert @response.body.blank? |
|
736 | assert @response.body.blank? | |
737 | end |
|
737 | end | |
738 |
|
738 | |||
739 | def test_show_by_anonymous |
|
739 | def test_show_by_anonymous | |
740 | get :show, :id => 1 |
|
740 | get :show, :id => 1 | |
741 | assert_response :success |
|
741 | assert_response :success | |
742 | assert_template 'show' |
|
742 | assert_template 'show' | |
743 | assert_not_nil assigns(:issue) |
|
743 | assert_not_nil assigns(:issue) | |
744 | assert_equal Issue.find(1), assigns(:issue) |
|
744 | assert_equal Issue.find(1), assigns(:issue) | |
745 |
|
745 | |||
746 | # anonymous role is allowed to add a note |
|
746 | # anonymous role is allowed to add a note | |
747 | assert_tag :tag => 'form', |
|
747 | assert_tag :tag => 'form', | |
748 | :descendant => { :tag => 'fieldset', |
|
748 | :descendant => { :tag => 'fieldset', | |
749 | :child => { :tag => 'legend', |
|
749 | :child => { :tag => 'legend', | |
750 | :content => /Notes/ } } |
|
750 | :content => /Notes/ } } | |
751 | assert_tag :tag => 'title', |
|
751 | assert_tag :tag => 'title', | |
752 | :content => "Bug #1: Can't print recipes - eCookbook - Redmine" |
|
752 | :content => "Bug #1: Can't print recipes - eCookbook - Redmine" | |
753 | end |
|
753 | end | |
754 |
|
754 | |||
755 | def test_show_by_manager |
|
755 | def test_show_by_manager | |
756 | @request.session[:user_id] = 2 |
|
756 | @request.session[:user_id] = 2 | |
757 | get :show, :id => 1 |
|
757 | get :show, :id => 1 | |
758 | assert_response :success |
|
758 | assert_response :success | |
759 |
|
759 | |||
760 | assert_tag :tag => 'a', |
|
760 | assert_tag :tag => 'a', | |
761 | :content => /Quote/ |
|
761 | :content => /Quote/ | |
762 |
|
762 | |||
763 | assert_tag :tag => 'form', |
|
763 | assert_tag :tag => 'form', | |
764 | :descendant => { :tag => 'fieldset', |
|
764 | :descendant => { :tag => 'fieldset', | |
765 | :child => { :tag => 'legend', |
|
765 | :child => { :tag => 'legend', | |
766 | :content => /Change properties/ } }, |
|
766 | :content => /Change properties/ } }, | |
767 | :descendant => { :tag => 'fieldset', |
|
767 | :descendant => { :tag => 'fieldset', | |
768 | :child => { :tag => 'legend', |
|
768 | :child => { :tag => 'legend', | |
769 | :content => /Log time/ } }, |
|
769 | :content => /Log time/ } }, | |
770 | :descendant => { :tag => 'fieldset', |
|
770 | :descendant => { :tag => 'fieldset', | |
771 | :child => { :tag => 'legend', |
|
771 | :child => { :tag => 'legend', | |
772 | :content => /Notes/ } } |
|
772 | :content => /Notes/ } } | |
773 | end |
|
773 | end | |
774 |
|
774 | |||
775 | def test_show_should_display_update_form |
|
775 | def test_show_should_display_update_form | |
776 | @request.session[:user_id] = 2 |
|
776 | @request.session[:user_id] = 2 | |
777 | get :show, :id => 1 |
|
777 | get :show, :id => 1 | |
778 | assert_response :success |
|
778 | assert_response :success | |
779 |
|
779 | |||
780 | assert_tag 'form', :attributes => {:id => 'issue-form'} |
|
780 | assert_tag 'form', :attributes => {:id => 'issue-form'} | |
781 | assert_tag 'input', :attributes => {:name => 'issue[is_private]'} |
|
781 | assert_tag 'input', :attributes => {:name => 'issue[is_private]'} | |
782 | assert_tag 'select', :attributes => {:name => 'issue[project_id]'} |
|
782 | assert_tag 'select', :attributes => {:name => 'issue[project_id]'} | |
783 | assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'} |
|
783 | assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'} | |
784 | assert_tag 'input', :attributes => {:name => 'issue[subject]'} |
|
784 | assert_tag 'input', :attributes => {:name => 'issue[subject]'} | |
785 | assert_tag 'textarea', :attributes => {:name => 'issue[description]'} |
|
785 | assert_tag 'textarea', :attributes => {:name => 'issue[description]'} | |
786 | assert_tag 'select', :attributes => {:name => 'issue[status_id]'} |
|
786 | assert_tag 'select', :attributes => {:name => 'issue[status_id]'} | |
787 | assert_tag 'select', :attributes => {:name => 'issue[priority_id]'} |
|
787 | assert_tag 'select', :attributes => {:name => 'issue[priority_id]'} | |
788 | assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} |
|
788 | assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} | |
789 | assert_tag 'select', :attributes => {:name => 'issue[category_id]'} |
|
789 | assert_tag 'select', :attributes => {:name => 'issue[category_id]'} | |
790 | assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} |
|
790 | assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} | |
791 | assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} |
|
791 | assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} | |
792 | assert_tag 'input', :attributes => {:name => 'issue[start_date]'} |
|
792 | assert_tag 'input', :attributes => {:name => 'issue[start_date]'} | |
793 | assert_tag 'input', :attributes => {:name => 'issue[due_date]'} |
|
793 | assert_tag 'input', :attributes => {:name => 'issue[due_date]'} | |
794 | assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} |
|
794 | assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} | |
795 | assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' } |
|
795 | assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' } | |
796 | assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} |
|
796 | assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} | |
797 | assert_tag 'textarea', :attributes => {:name => 'notes'} |
|
797 | assert_tag 'textarea', :attributes => {:name => 'notes'} | |
798 | end |
|
798 | end | |
799 |
|
799 | |||
800 | def test_show_should_display_update_form_with_minimal_permissions |
|
800 | def test_show_should_display_update_form_with_minimal_permissions | |
801 | Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] |
|
801 | Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] | |
802 | Workflow.delete_all :role_id => 1 |
|
802 | Workflow.delete_all :role_id => 1 | |
803 |
|
803 | |||
804 | @request.session[:user_id] = 2 |
|
804 | @request.session[:user_id] = 2 | |
805 | get :show, :id => 1 |
|
805 | get :show, :id => 1 | |
806 | assert_response :success |
|
806 | assert_response :success | |
807 |
|
807 | |||
808 | assert_tag 'form', :attributes => {:id => 'issue-form'} |
|
808 | assert_tag 'form', :attributes => {:id => 'issue-form'} | |
809 | assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'} |
|
809 | assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'} | |
810 | assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} |
|
810 | assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} | |
811 | assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'} |
|
811 | assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'} | |
812 | assert_no_tag 'input', :attributes => {:name => 'issue[subject]'} |
|
812 | assert_no_tag 'input', :attributes => {:name => 'issue[subject]'} | |
813 | assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'} |
|
813 | assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'} | |
814 | assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'} |
|
814 | assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'} | |
815 | assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'} |
|
815 | assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'} | |
816 | assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} |
|
816 | assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} | |
817 | assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'} |
|
817 | assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'} | |
818 | assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} |
|
818 | assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} | |
819 | assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} |
|
819 | assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} | |
820 | assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'} |
|
820 | assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'} | |
821 | assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'} |
|
821 | assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'} | |
822 | assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'} |
|
822 | assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'} | |
823 | assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' } |
|
823 | assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' } | |
824 | assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} |
|
824 | assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} | |
825 | assert_tag 'textarea', :attributes => {:name => 'notes'} |
|
825 | assert_tag 'textarea', :attributes => {:name => 'notes'} | |
826 | end |
|
826 | end | |
827 |
|
827 | |||
828 | def test_show_should_display_update_form_with_workflow_permissions |
|
828 | def test_show_should_display_update_form_with_workflow_permissions | |
829 | Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] |
|
829 | Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] | |
830 |
|
830 | |||
831 | @request.session[:user_id] = 2 |
|
831 | @request.session[:user_id] = 2 | |
832 | get :show, :id => 1 |
|
832 | get :show, :id => 1 | |
833 | assert_response :success |
|
833 | assert_response :success | |
834 |
|
834 | |||
835 | assert_tag 'form', :attributes => {:id => 'issue-form'} |
|
835 | assert_tag 'form', :attributes => {:id => 'issue-form'} | |
836 | assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'} |
|
836 | assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'} | |
837 | assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} |
|
837 | assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} | |
838 | assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'} |
|
838 | assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'} | |
839 | assert_no_tag 'input', :attributes => {:name => 'issue[subject]'} |
|
839 | assert_no_tag 'input', :attributes => {:name => 'issue[subject]'} | |
840 | assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'} |
|
840 | assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'} | |
841 | assert_tag 'select', :attributes => {:name => 'issue[status_id]'} |
|
841 | assert_tag 'select', :attributes => {:name => 'issue[status_id]'} | |
842 | assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'} |
|
842 | assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'} | |
843 | assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} |
|
843 | assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} | |
844 | assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'} |
|
844 | assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'} | |
845 | assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} |
|
845 | assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} | |
846 | assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} |
|
846 | assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} | |
847 | assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'} |
|
847 | assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'} | |
848 | assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'} |
|
848 | assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'} | |
849 | assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} |
|
849 | assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} | |
850 | assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' } |
|
850 | assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' } | |
851 | assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} |
|
851 | assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} | |
852 | assert_tag 'textarea', :attributes => {:name => 'notes'} |
|
852 | assert_tag 'textarea', :attributes => {:name => 'notes'} | |
853 | end |
|
853 | end | |
854 |
|
854 | |||
855 | def test_show_should_not_display_update_form_without_permissions |
|
855 | def test_show_should_not_display_update_form_without_permissions | |
856 | Role.find(1).update_attribute :permissions, [:view_issues] |
|
856 | Role.find(1).update_attribute :permissions, [:view_issues] | |
857 |
|
857 | |||
858 | @request.session[:user_id] = 2 |
|
858 | @request.session[:user_id] = 2 | |
859 | get :show, :id => 1 |
|
859 | get :show, :id => 1 | |
860 | assert_response :success |
|
860 | assert_response :success | |
861 |
|
861 | |||
862 | assert_no_tag 'form', :attributes => {:id => 'issue-form'} |
|
862 | assert_no_tag 'form', :attributes => {:id => 'issue-form'} | |
863 | end |
|
863 | end | |
864 |
|
864 | |||
865 | def test_update_form_should_not_display_inactive_enumerations |
|
865 | def test_update_form_should_not_display_inactive_enumerations | |
866 | @request.session[:user_id] = 2 |
|
866 | @request.session[:user_id] = 2 | |
867 | get :show, :id => 1 |
|
867 | get :show, :id => 1 | |
868 | assert_response :success |
|
868 | assert_response :success | |
869 |
|
869 | |||
870 | assert ! IssuePriority.find(15).active? |
|
870 | assert ! IssuePriority.find(15).active? | |
871 | assert_no_tag :option, :attributes => {:value => '15'}, |
|
871 | assert_no_tag :option, :attributes => {:value => '15'}, | |
872 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } |
|
872 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } | |
873 | end |
|
873 | end | |
874 |
|
874 | |||
875 | def test_update_form_should_allow_attachment_upload |
|
875 | def test_update_form_should_allow_attachment_upload | |
876 | @request.session[:user_id] = 2 |
|
876 | @request.session[:user_id] = 2 | |
877 | get :show, :id => 1 |
|
877 | get :show, :id => 1 | |
878 |
|
878 | |||
879 | assert_tag :tag => 'form', |
|
879 | assert_tag :tag => 'form', | |
880 | :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'}, |
|
880 | :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'}, | |
881 | :descendant => { |
|
881 | :descendant => { | |
882 | :tag => 'input', |
|
882 | :tag => 'input', | |
883 | :attributes => {:type => 'file', :name => 'attachments[1][file]'} |
|
883 | :attributes => {:type => 'file', :name => 'attachments[1][file]'} | |
884 | } |
|
884 | } | |
885 | end |
|
885 | end | |
886 |
|
886 | |||
887 | def test_show_should_deny_anonymous_access_without_permission |
|
887 | def test_show_should_deny_anonymous_access_without_permission | |
888 | Role.anonymous.remove_permission!(:view_issues) |
|
888 | Role.anonymous.remove_permission!(:view_issues) | |
889 | get :show, :id => 1 |
|
889 | get :show, :id => 1 | |
890 | assert_response :redirect |
|
890 | assert_response :redirect | |
891 | end |
|
891 | end | |
892 |
|
892 | |||
893 | def test_show_should_deny_anonymous_access_to_private_issue |
|
893 | def test_show_should_deny_anonymous_access_to_private_issue | |
894 | Issue.update_all(["is_private = ?", true], "id = 1") |
|
894 | Issue.update_all(["is_private = ?", true], "id = 1") | |
895 | get :show, :id => 1 |
|
895 | get :show, :id => 1 | |
896 | assert_response :redirect |
|
896 | assert_response :redirect | |
897 | end |
|
897 | end | |
898 |
|
898 | |||
899 | def test_show_should_deny_non_member_access_without_permission |
|
899 | def test_show_should_deny_non_member_access_without_permission | |
900 | Role.non_member.remove_permission!(:view_issues) |
|
900 | Role.non_member.remove_permission!(:view_issues) | |
901 | @request.session[:user_id] = 9 |
|
901 | @request.session[:user_id] = 9 | |
902 | get :show, :id => 1 |
|
902 | get :show, :id => 1 | |
903 | assert_response 403 |
|
903 | assert_response 403 | |
904 | end |
|
904 | end | |
905 |
|
905 | |||
906 | def test_show_should_deny_non_member_access_to_private_issue |
|
906 | def test_show_should_deny_non_member_access_to_private_issue | |
907 | Issue.update_all(["is_private = ?", true], "id = 1") |
|
907 | Issue.update_all(["is_private = ?", true], "id = 1") | |
908 | @request.session[:user_id] = 9 |
|
908 | @request.session[:user_id] = 9 | |
909 | get :show, :id => 1 |
|
909 | get :show, :id => 1 | |
910 | assert_response 403 |
|
910 | assert_response 403 | |
911 | end |
|
911 | end | |
912 |
|
912 | |||
913 | def test_show_should_deny_member_access_without_permission |
|
913 | def test_show_should_deny_member_access_without_permission | |
914 | Role.find(1).remove_permission!(:view_issues) |
|
914 | Role.find(1).remove_permission!(:view_issues) | |
915 | @request.session[:user_id] = 2 |
|
915 | @request.session[:user_id] = 2 | |
916 | get :show, :id => 1 |
|
916 | get :show, :id => 1 | |
917 | assert_response 403 |
|
917 | assert_response 403 | |
918 | end |
|
918 | end | |
919 |
|
919 | |||
920 | def test_show_should_deny_member_access_to_private_issue_without_permission |
|
920 | def test_show_should_deny_member_access_to_private_issue_without_permission | |
921 | Issue.update_all(["is_private = ?", true], "id = 1") |
|
921 | Issue.update_all(["is_private = ?", true], "id = 1") | |
922 | @request.session[:user_id] = 3 |
|
922 | @request.session[:user_id] = 3 | |
923 | get :show, :id => 1 |
|
923 | get :show, :id => 1 | |
924 | assert_response 403 |
|
924 | assert_response 403 | |
925 | end |
|
925 | end | |
926 |
|
926 | |||
927 | def test_show_should_allow_author_access_to_private_issue |
|
927 | def test_show_should_allow_author_access_to_private_issue | |
928 | Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1") |
|
928 | Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1") | |
929 | @request.session[:user_id] = 3 |
|
929 | @request.session[:user_id] = 3 | |
930 | get :show, :id => 1 |
|
930 | get :show, :id => 1 | |
931 | assert_response :success |
|
931 | assert_response :success | |
932 | end |
|
932 | end | |
933 |
|
933 | |||
934 | def test_show_should_allow_assignee_access_to_private_issue |
|
934 | def test_show_should_allow_assignee_access_to_private_issue | |
935 | Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1") |
|
935 | Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1") | |
936 | @request.session[:user_id] = 3 |
|
936 | @request.session[:user_id] = 3 | |
937 | get :show, :id => 1 |
|
937 | get :show, :id => 1 | |
938 | assert_response :success |
|
938 | assert_response :success | |
939 | end |
|
939 | end | |
940 |
|
940 | |||
941 | def test_show_should_allow_member_access_to_private_issue_with_permission |
|
941 | def test_show_should_allow_member_access_to_private_issue_with_permission | |
942 | Issue.update_all(["is_private = ?", true], "id = 1") |
|
942 | Issue.update_all(["is_private = ?", true], "id = 1") | |
943 | User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all' |
|
943 | User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all' | |
944 | @request.session[:user_id] = 3 |
|
944 | @request.session[:user_id] = 3 | |
945 | get :show, :id => 1 |
|
945 | get :show, :id => 1 | |
946 | assert_response :success |
|
946 | assert_response :success | |
947 | end |
|
947 | end | |
948 |
|
948 | |||
949 | def test_show_should_not_disclose_relations_to_invisible_issues |
|
949 | def test_show_should_not_disclose_relations_to_invisible_issues | |
950 | Setting.cross_project_issue_relations = '1' |
|
950 | Setting.cross_project_issue_relations = '1' | |
951 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates') |
|
951 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates') | |
952 | # Relation to a private project issue |
|
952 | # Relation to a private project issue | |
953 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates') |
|
953 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates') | |
954 |
|
954 | |||
955 | get :show, :id => 1 |
|
955 | get :show, :id => 1 | |
956 | assert_response :success |
|
956 | assert_response :success | |
957 |
|
957 | |||
958 | assert_tag :div, :attributes => { :id => 'relations' }, |
|
958 | assert_tag :div, :attributes => { :id => 'relations' }, | |
959 | :descendant => { :tag => 'a', :content => /#2$/ } |
|
959 | :descendant => { :tag => 'a', :content => /#2$/ } | |
960 | assert_no_tag :div, :attributes => { :id => 'relations' }, |
|
960 | assert_no_tag :div, :attributes => { :id => 'relations' }, | |
961 | :descendant => { :tag => 'a', :content => /#4$/ } |
|
961 | :descendant => { :tag => 'a', :content => /#4$/ } | |
962 | end |
|
962 | end | |
963 |
|
963 | |||
964 | def test_show_should_list_subtasks |
|
964 | def test_show_should_list_subtasks | |
965 | Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue') |
|
965 | Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue') | |
966 |
|
966 | |||
967 | get :show, :id => 1 |
|
967 | get :show, :id => 1 | |
968 | assert_response :success |
|
968 | assert_response :success | |
969 | assert_tag 'div', :attributes => {:id => 'issue_tree'}, |
|
969 | assert_tag 'div', :attributes => {:id => 'issue_tree'}, | |
970 | :descendant => {:tag => 'td', :content => /Child Issue/, :attributes => {:class => /subject/}} |
|
970 | :descendant => {:tag => 'td', :content => /Child Issue/, :attributes => {:class => /subject/}} | |
971 | end |
|
971 | end | |
972 |
|
972 | |||
973 | def test_show_should_list_parents |
|
973 | def test_show_should_list_parents | |
974 | issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue') |
|
974 | issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue') | |
975 |
|
975 | |||
976 | get :show, :id => issue.id |
|
976 | get :show, :id => issue.id | |
977 | assert_response :success |
|
977 | assert_response :success | |
978 | assert_tag 'div', :attributes => {:class => 'subject'}, |
|
978 | assert_tag 'div', :attributes => {:class => 'subject'}, | |
979 | :descendant => {:tag => 'h3', :content => 'Child Issue'} |
|
979 | :descendant => {:tag => 'h3', :content => 'Child Issue'} | |
980 | assert_tag 'div', :attributes => {:class => 'subject'}, |
|
980 | assert_tag 'div', :attributes => {:class => 'subject'}, | |
981 | :descendant => {:tag => 'a', :attributes => {:href => '/issues/1'}} |
|
981 | :descendant => {:tag => 'a', :attributes => {:href => '/issues/1'}} | |
982 | end |
|
982 | end | |
983 |
|
983 | |||
984 | def test_show_should_not_display_prev_next_links_without_query_in_session |
|
984 | def test_show_should_not_display_prev_next_links_without_query_in_session | |
985 | get :show, :id => 1 |
|
985 | get :show, :id => 1 | |
986 | assert_response :success |
|
986 | assert_response :success | |
987 | assert_nil assigns(:prev_issue_id) |
|
987 | assert_nil assigns(:prev_issue_id) | |
988 | assert_nil assigns(:next_issue_id) |
|
988 | assert_nil assigns(:next_issue_id) | |
989 |
|
989 | |||
990 | assert_no_tag 'div', :attributes => {:class => /next-prev-links/} |
|
990 | assert_no_tag 'div', :attributes => {:class => /next-prev-links/} | |
991 | end |
|
991 | end | |
992 |
|
992 | |||
993 | def test_show_should_display_prev_next_links_with_query_in_session |
|
993 | def test_show_should_display_prev_next_links_with_query_in_session | |
994 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil} |
|
994 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil} | |
995 | @request.session['issues_index_sort'] = 'id' |
|
995 | @request.session['issues_index_sort'] = 'id' | |
996 |
|
996 | |||
997 | with_settings :display_subprojects_issues => '0' do |
|
997 | with_settings :display_subprojects_issues => '0' do | |
998 | get :show, :id => 3 |
|
998 | get :show, :id => 3 | |
999 | end |
|
999 | end | |
1000 |
|
1000 | |||
1001 | assert_response :success |
|
1001 | assert_response :success | |
1002 | # Previous and next issues for all projects |
|
1002 | # Previous and next issues for all projects | |
1003 | assert_equal 2, assigns(:prev_issue_id) |
|
1003 | assert_equal 2, assigns(:prev_issue_id) | |
1004 | assert_equal 5, assigns(:next_issue_id) |
|
1004 | assert_equal 5, assigns(:next_issue_id) | |
1005 |
|
1005 | |||
1006 | assert_tag 'div', :attributes => {:class => /next-prev-links/} |
|
1006 | assert_tag 'div', :attributes => {:class => /next-prev-links/} | |
1007 | assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/ |
|
1007 | assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/ | |
1008 | assert_tag 'a', :attributes => {:href => '/issues/5'}, :content => /Next/ |
|
1008 | assert_tag 'a', :attributes => {:href => '/issues/5'}, :content => /Next/ | |
1009 |
|
1009 | |||
1010 | count = Issue.open.visible.count |
|
1010 | count = Issue.open.visible.count | |
1011 | assert_tag 'span', :attributes => {:class => 'position'}, :content => "3 of #{count}" |
|
1011 | assert_tag 'span', :attributes => {:class => 'position'}, :content => "3 of #{count}" | |
1012 | end |
|
1012 | end | |
1013 |
|
1013 | |||
1014 | def test_show_should_display_prev_next_links_with_saved_query_in_session |
|
1014 | def test_show_should_display_prev_next_links_with_saved_query_in_session | |
1015 | query = Query.create!(:name => 'test', :is_public => true, :user_id => 1, |
|
1015 | query = Query.create!(:name => 'test', :is_public => true, :user_id => 1, | |
1016 | :filters => {'status_id' => {:values => ['5'], :operator => '='}}, |
|
1016 | :filters => {'status_id' => {:values => ['5'], :operator => '='}}, | |
1017 | :sort_criteria => [['id', 'asc']]) |
|
1017 | :sort_criteria => [['id', 'asc']]) | |
1018 | @request.session[:query] = {:id => query.id, :project_id => nil} |
|
1018 | @request.session[:query] = {:id => query.id, :project_id => nil} | |
1019 |
|
1019 | |||
1020 | get :show, :id => 11 |
|
1020 | get :show, :id => 11 | |
1021 |
|
1021 | |||
1022 | assert_response :success |
|
1022 | assert_response :success | |
1023 | assert_equal query, assigns(:query) |
|
1023 | assert_equal query, assigns(:query) | |
1024 | # Previous and next issues for all projects |
|
1024 | # Previous and next issues for all projects | |
1025 | assert_equal 8, assigns(:prev_issue_id) |
|
1025 | assert_equal 8, assigns(:prev_issue_id) | |
1026 | assert_equal 12, assigns(:next_issue_id) |
|
1026 | assert_equal 12, assigns(:next_issue_id) | |
1027 |
|
1027 | |||
1028 | assert_tag 'a', :attributes => {:href => '/issues/8'}, :content => /Previous/ |
|
1028 | assert_tag 'a', :attributes => {:href => '/issues/8'}, :content => /Previous/ | |
1029 | assert_tag 'a', :attributes => {:href => '/issues/12'}, :content => /Next/ |
|
1029 | assert_tag 'a', :attributes => {:href => '/issues/12'}, :content => /Next/ | |
1030 | end |
|
1030 | end | |
1031 |
|
1031 | |||
1032 | def test_show_should_display_prev_next_links_with_query_and_sort_on_association |
|
1032 | def test_show_should_display_prev_next_links_with_query_and_sort_on_association | |
1033 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil} |
|
1033 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil} | |
1034 |
|
1034 | |||
1035 | %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort| |
|
1035 | %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort| | |
1036 | @request.session['issues_index_sort'] = assoc_sort |
|
1036 | @request.session['issues_index_sort'] = assoc_sort | |
1037 |
|
1037 | |||
1038 | get :show, :id => 3 |
|
1038 | get :show, :id => 3 | |
1039 | assert_response :success, "Wrong response status for #{assoc_sort} sort" |
|
1039 | assert_response :success, "Wrong response status for #{assoc_sort} sort" | |
1040 |
|
1040 | |||
1041 | assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Previous/ |
|
1041 | assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Previous/ | |
1042 | assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Next/ |
|
1042 | assert_tag 'div', :attributes => {:class => /next-prev-links/}, :content => /Next/ | |
1043 | end |
|
1043 | end | |
1044 | end |
|
1044 | end | |
1045 |
|
1045 | |||
1046 | def test_show_should_display_prev_next_links_with_project_query_in_session |
|
1046 | def test_show_should_display_prev_next_links_with_project_query_in_session | |
1047 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1} |
|
1047 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1} | |
1048 | @request.session['issues_index_sort'] = 'id' |
|
1048 | @request.session['issues_index_sort'] = 'id' | |
1049 |
|
1049 | |||
1050 | with_settings :display_subprojects_issues => '0' do |
|
1050 | with_settings :display_subprojects_issues => '0' do | |
1051 | get :show, :id => 3 |
|
1051 | get :show, :id => 3 | |
1052 | end |
|
1052 | end | |
1053 |
|
1053 | |||
1054 | assert_response :success |
|
1054 | assert_response :success | |
1055 | # Previous and next issues inside project |
|
1055 | # Previous and next issues inside project | |
1056 | assert_equal 2, assigns(:prev_issue_id) |
|
1056 | assert_equal 2, assigns(:prev_issue_id) | |
1057 | assert_equal 7, assigns(:next_issue_id) |
|
1057 | assert_equal 7, assigns(:next_issue_id) | |
1058 |
|
1058 | |||
1059 | assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/ |
|
1059 | assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/ | |
1060 | assert_tag 'a', :attributes => {:href => '/issues/7'}, :content => /Next/ |
|
1060 | assert_tag 'a', :attributes => {:href => '/issues/7'}, :content => /Next/ | |
1061 | end |
|
1061 | end | |
1062 |
|
1062 | |||
1063 | def test_show_should_not_display_prev_link_for_first_issue |
|
1063 | def test_show_should_not_display_prev_link_for_first_issue | |
1064 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1} |
|
1064 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1} | |
1065 | @request.session['issues_index_sort'] = 'id' |
|
1065 | @request.session['issues_index_sort'] = 'id' | |
1066 |
|
1066 | |||
1067 | with_settings :display_subprojects_issues => '0' do |
|
1067 | with_settings :display_subprojects_issues => '0' do | |
1068 | get :show, :id => 1 |
|
1068 | get :show, :id => 1 | |
1069 | end |
|
1069 | end | |
1070 |
|
1070 | |||
1071 | assert_response :success |
|
1071 | assert_response :success | |
1072 | assert_nil assigns(:prev_issue_id) |
|
1072 | assert_nil assigns(:prev_issue_id) | |
1073 | assert_equal 2, assigns(:next_issue_id) |
|
1073 | assert_equal 2, assigns(:next_issue_id) | |
1074 |
|
1074 | |||
1075 | assert_no_tag 'a', :content => /Previous/ |
|
1075 | assert_no_tag 'a', :content => /Previous/ | |
1076 | assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Next/ |
|
1076 | assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Next/ | |
1077 | end |
|
1077 | end | |
1078 |
|
1078 | |||
1079 | def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results |
|
1079 | def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results | |
1080 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1} |
|
1080 | @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1} | |
1081 | @request.session['issues_index_sort'] = 'id' |
|
1081 | @request.session['issues_index_sort'] = 'id' | |
1082 |
|
1082 | |||
1083 | get :show, :id => 1 |
|
1083 | get :show, :id => 1 | |
1084 |
|
1084 | |||
1085 | assert_response :success |
|
1085 | assert_response :success | |
1086 | assert_nil assigns(:prev_issue_id) |
|
1086 | assert_nil assigns(:prev_issue_id) | |
1087 | assert_nil assigns(:next_issue_id) |
|
1087 | assert_nil assigns(:next_issue_id) | |
1088 |
|
1088 | |||
1089 | assert_no_tag 'a', :content => /Previous/ |
|
1089 | assert_no_tag 'a', :content => /Previous/ | |
1090 | assert_no_tag 'a', :content => /Next/ |
|
1090 | assert_no_tag 'a', :content => /Next/ | |
1091 | end |
|
1091 | end | |
1092 |
|
1092 | |||
1093 | def test_show_should_display_visible_changesets_from_other_projects |
|
1093 | def test_show_should_display_visible_changesets_from_other_projects | |
1094 | project = Project.find(2) |
|
1094 | project = Project.find(2) | |
1095 | issue = project.issues.first |
|
1095 | issue = project.issues.first | |
1096 | issue.changeset_ids = [102] |
|
1096 | issue.changeset_ids = [102] | |
1097 | issue.save! |
|
1097 | issue.save! | |
1098 | project.disable_module! :repository |
|
1098 | project.disable_module! :repository | |
1099 |
|
1099 | |||
1100 | @request.session[:user_id] = 2 |
|
1100 | @request.session[:user_id] = 2 | |
1101 | get :show, :id => issue.id |
|
1101 | get :show, :id => issue.id | |
1102 | assert_tag 'a', :attributes => {:href => "/projects/ecookbook/repository/revisions/3"} |
|
1102 | assert_tag 'a', :attributes => {:href => "/projects/ecookbook/repository/revisions/3"} | |
1103 | end |
|
1103 | end | |
1104 |
|
1104 | |||
1105 | def test_show_with_multi_custom_field |
|
1105 | def test_show_with_multi_custom_field | |
1106 | field = CustomField.find(1) |
|
1106 | field = CustomField.find(1) | |
1107 | field.update_attribute :multiple, true |
|
1107 | field.update_attribute :multiple, true | |
1108 | issue = Issue.find(1) |
|
1108 | issue = Issue.find(1) | |
1109 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
1109 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} | |
1110 | issue.save! |
|
1110 | issue.save! | |
1111 |
|
1111 | |||
1112 | get :show, :id => 1 |
|
1112 | get :show, :id => 1 | |
1113 | assert_response :success |
|
1113 | assert_response :success | |
1114 |
|
1114 | |||
1115 | assert_tag :td, :content => 'MySQL, Oracle' |
|
1115 | assert_tag :td, :content => 'MySQL, Oracle' | |
1116 | end |
|
1116 | end | |
1117 |
|
1117 | |||
1118 | def test_show_with_multi_user_custom_field |
|
1118 | def test_show_with_multi_user_custom_field | |
1119 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, |
|
1119 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, | |
1120 | :tracker_ids => [1], :is_for_all => true) |
|
1120 | :tracker_ids => [1], :is_for_all => true) | |
1121 | issue = Issue.find(1) |
|
1121 | issue = Issue.find(1) | |
1122 | issue.custom_field_values = {field.id => ['2', '3']} |
|
1122 | issue.custom_field_values = {field.id => ['2', '3']} | |
1123 | issue.save! |
|
1123 | issue.save! | |
1124 |
|
1124 | |||
1125 | get :show, :id => 1 |
|
1125 | get :show, :id => 1 | |
1126 | assert_response :success |
|
1126 | assert_response :success | |
1127 |
|
1127 | |||
1128 | # TODO: should display links |
|
1128 | # TODO: should display links | |
1129 | assert_tag :td, :content => 'Dave Lopper, John Smith' |
|
1129 | assert_tag :td, :content => 'Dave Lopper, John Smith' | |
1130 | end |
|
1130 | end | |
1131 |
|
1131 | |||
1132 | def test_show_atom |
|
1132 | def test_show_atom | |
1133 | get :show, :id => 2, :format => 'atom' |
|
1133 | get :show, :id => 2, :format => 'atom' | |
1134 | assert_response :success |
|
1134 | assert_response :success | |
1135 | assert_template 'journals/index' |
|
1135 | assert_template 'journals/index' | |
1136 | # Inline image |
|
1136 | # Inline image | |
1137 | assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10')) |
|
1137 | assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10')) | |
1138 | end |
|
1138 | end | |
1139 |
|
1139 | |||
1140 | def test_show_export_to_pdf |
|
1140 | def test_show_export_to_pdf | |
1141 | get :show, :id => 3, :format => 'pdf' |
|
1141 | get :show, :id => 3, :format => 'pdf' | |
1142 | assert_response :success |
|
1142 | assert_response :success | |
1143 | assert_equal 'application/pdf', @response.content_type |
|
1143 | assert_equal 'application/pdf', @response.content_type | |
1144 | assert @response.body.starts_with?('%PDF') |
|
1144 | assert @response.body.starts_with?('%PDF') | |
1145 | assert_not_nil assigns(:issue) |
|
1145 | assert_not_nil assigns(:issue) | |
1146 | end |
|
1146 | end | |
1147 |
|
1147 | |||
1148 | def test_get_new |
|
1148 | def test_get_new | |
1149 | @request.session[:user_id] = 2 |
|
1149 | @request.session[:user_id] = 2 | |
1150 | get :new, :project_id => 1, :tracker_id => 1 |
|
1150 | get :new, :project_id => 1, :tracker_id => 1 | |
1151 | assert_response :success |
|
1151 | assert_response :success | |
1152 | assert_template 'new' |
|
1152 | assert_template 'new' | |
1153 |
|
1153 | |||
1154 | assert_tag 'input', :attributes => {:name => 'issue[is_private]'} |
|
1154 | assert_tag 'input', :attributes => {:name => 'issue[is_private]'} | |
1155 | assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} |
|
1155 | assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} | |
1156 | assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'} |
|
1156 | assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'} | |
1157 | assert_tag 'input', :attributes => {:name => 'issue[subject]'} |
|
1157 | assert_tag 'input', :attributes => {:name => 'issue[subject]'} | |
1158 | assert_tag 'textarea', :attributes => {:name => 'issue[description]'} |
|
1158 | assert_tag 'textarea', :attributes => {:name => 'issue[description]'} | |
1159 | assert_tag 'select', :attributes => {:name => 'issue[status_id]'} |
|
1159 | assert_tag 'select', :attributes => {:name => 'issue[status_id]'} | |
1160 | assert_tag 'select', :attributes => {:name => 'issue[priority_id]'} |
|
1160 | assert_tag 'select', :attributes => {:name => 'issue[priority_id]'} | |
1161 | assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} |
|
1161 | assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} | |
1162 | assert_tag 'select', :attributes => {:name => 'issue[category_id]'} |
|
1162 | assert_tag 'select', :attributes => {:name => 'issue[category_id]'} | |
1163 | assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} |
|
1163 | assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} | |
1164 | assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} |
|
1164 | assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} | |
1165 | assert_tag 'input', :attributes => {:name => 'issue[start_date]'} |
|
1165 | assert_tag 'input', :attributes => {:name => 'issue[start_date]'} | |
1166 | assert_tag 'input', :attributes => {:name => 'issue[due_date]'} |
|
1166 | assert_tag 'input', :attributes => {:name => 'issue[due_date]'} | |
1167 | assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} |
|
1167 | assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} | |
1168 | assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' } |
|
1168 | assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' } | |
1169 | assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} |
|
1169 | assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} | |
1170 |
|
1170 | |||
1171 | # Be sure we don't display inactive IssuePriorities |
|
1171 | # Be sure we don't display inactive IssuePriorities | |
1172 | assert ! IssuePriority.find(15).active? |
|
1172 | assert ! IssuePriority.find(15).active? | |
1173 | assert_no_tag :option, :attributes => {:value => '15'}, |
|
1173 | assert_no_tag :option, :attributes => {:value => '15'}, | |
1174 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } |
|
1174 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } | |
1175 | end |
|
1175 | end | |
1176 |
|
1176 | |||
1177 | def test_get_new_with_minimal_permissions |
|
1177 | def test_get_new_with_minimal_permissions | |
1178 | Role.find(1).update_attribute :permissions, [:add_issues] |
|
1178 | Role.find(1).update_attribute :permissions, [:add_issues] | |
1179 | Workflow.delete_all :role_id => 1 |
|
1179 | Workflow.delete_all :role_id => 1 | |
1180 |
|
1180 | |||
1181 | @request.session[:user_id] = 2 |
|
1181 | @request.session[:user_id] = 2 | |
1182 | get :new, :project_id => 1, :tracker_id => 1 |
|
1182 | get :new, :project_id => 1, :tracker_id => 1 | |
1183 | assert_response :success |
|
1183 | assert_response :success | |
1184 | assert_template 'new' |
|
1184 | assert_template 'new' | |
1185 |
|
1185 | |||
1186 | assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'} |
|
1186 | assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'} | |
1187 | assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} |
|
1187 | assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} | |
1188 | assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'} |
|
1188 | assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'} | |
1189 | assert_tag 'input', :attributes => {:name => 'issue[subject]'} |
|
1189 | assert_tag 'input', :attributes => {:name => 'issue[subject]'} | |
1190 | assert_tag 'textarea', :attributes => {:name => 'issue[description]'} |
|
1190 | assert_tag 'textarea', :attributes => {:name => 'issue[description]'} | |
1191 | assert_tag 'select', :attributes => {:name => 'issue[status_id]'} |
|
1191 | assert_tag 'select', :attributes => {:name => 'issue[status_id]'} | |
1192 | assert_tag 'select', :attributes => {:name => 'issue[priority_id]'} |
|
1192 | assert_tag 'select', :attributes => {:name => 'issue[priority_id]'} | |
1193 | assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} |
|
1193 | assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} | |
1194 | assert_tag 'select', :attributes => {:name => 'issue[category_id]'} |
|
1194 | assert_tag 'select', :attributes => {:name => 'issue[category_id]'} | |
1195 | assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} |
|
1195 | assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} | |
1196 | assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} |
|
1196 | assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} | |
1197 | assert_tag 'input', :attributes => {:name => 'issue[start_date]'} |
|
1197 | assert_tag 'input', :attributes => {:name => 'issue[start_date]'} | |
1198 | assert_tag 'input', :attributes => {:name => 'issue[due_date]'} |
|
1198 | assert_tag 'input', :attributes => {:name => 'issue[due_date]'} | |
1199 | assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} |
|
1199 | assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} | |
1200 | assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' } |
|
1200 | assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' } | |
1201 | assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} |
|
1201 | assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} | |
1202 | end |
|
1202 | end | |
1203 |
|
1203 | |||
1204 | def test_get_new_with_list_custom_field |
|
1204 | def test_get_new_with_list_custom_field | |
1205 | @request.session[:user_id] = 2 |
|
1205 | @request.session[:user_id] = 2 | |
1206 | get :new, :project_id => 1, :tracker_id => 1 |
|
1206 | get :new, :project_id => 1, :tracker_id => 1 | |
1207 | assert_response :success |
|
1207 | assert_response :success | |
1208 | assert_template 'new' |
|
1208 | assert_template 'new' | |
1209 |
|
1209 | |||
1210 | assert_tag 'select', |
|
1210 | assert_tag 'select', | |
1211 | :attributes => {:name => 'issue[custom_field_values][1]'}, |
|
1211 | :attributes => {:name => 'issue[custom_field_values][1]'}, | |
1212 | :children => {:count => 4}, |
|
1212 | :children => {:count => 4}, | |
1213 | :child => {:tag => 'option', :attributes => {:value => 'MySQL'}, :content => 'MySQL'} |
|
1213 | :child => {:tag => 'option', :attributes => {:value => 'MySQL'}, :content => 'MySQL'} | |
1214 | end |
|
1214 | end | |
1215 |
|
1215 | |||
1216 | def test_get_new_with_multi_custom_field |
|
1216 | def test_get_new_with_multi_custom_field | |
1217 | field = IssueCustomField.find(1) |
|
1217 | field = IssueCustomField.find(1) | |
1218 | field.update_attribute :multiple, true |
|
1218 | field.update_attribute :multiple, true | |
1219 |
|
1219 | |||
1220 | @request.session[:user_id] = 2 |
|
1220 | @request.session[:user_id] = 2 | |
1221 | get :new, :project_id => 1, :tracker_id => 1 |
|
1221 | get :new, :project_id => 1, :tracker_id => 1 | |
1222 | assert_response :success |
|
1222 | assert_response :success | |
1223 | assert_template 'new' |
|
1223 | assert_template 'new' | |
1224 |
|
1224 | |||
1225 | assert_tag 'select', |
|
1225 | assert_tag 'select', | |
1226 | :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'}, |
|
1226 | :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'}, | |
1227 | :children => {:count => 3}, |
|
1227 | :children => {:count => 3}, | |
1228 | :child => {:tag => 'option', :attributes => {:value => 'MySQL'}, :content => 'MySQL'} |
|
1228 | :child => {:tag => 'option', :attributes => {:value => 'MySQL'}, :content => 'MySQL'} | |
1229 | assert_tag 'input', |
|
1229 | assert_tag 'input', | |
1230 | :attributes => {:name => 'issue[custom_field_values][1][]', :value => ''} |
|
1230 | :attributes => {:name => 'issue[custom_field_values][1][]', :value => ''} | |
1231 | end |
|
1231 | end | |
1232 |
|
1232 | |||
1233 | def test_get_new_with_multi_user_custom_field |
|
1233 | def test_get_new_with_multi_user_custom_field | |
1234 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, |
|
1234 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, | |
1235 | :tracker_ids => [1], :is_for_all => true) |
|
1235 | :tracker_ids => [1], :is_for_all => true) | |
1236 |
|
1236 | |||
1237 | @request.session[:user_id] = 2 |
|
1237 | @request.session[:user_id] = 2 | |
1238 | get :new, :project_id => 1, :tracker_id => 1 |
|
1238 | get :new, :project_id => 1, :tracker_id => 1 | |
1239 | assert_response :success |
|
1239 | assert_response :success | |
1240 | assert_template 'new' |
|
1240 | assert_template 'new' | |
1241 |
|
1241 | |||
1242 | assert_tag 'select', |
|
1242 | assert_tag 'select', | |
1243 | :attributes => {:name => "issue[custom_field_values][#{field.id}][]", :multiple => 'multiple'}, |
|
1243 | :attributes => {:name => "issue[custom_field_values][#{field.id}][]", :multiple => 'multiple'}, | |
1244 | :children => {:count => Project.find(1).users.count}, |
|
1244 | :children => {:count => Project.find(1).users.count}, | |
1245 | :child => {:tag => 'option', :attributes => {:value => '2'}, :content => 'John Smith'} |
|
1245 | :child => {:tag => 'option', :attributes => {:value => '2'}, :content => 'John Smith'} | |
1246 | assert_tag 'input', |
|
1246 | assert_tag 'input', | |
1247 | :attributes => {:name => "issue[custom_field_values][#{field.id}][]", :value => ''} |
|
1247 | :attributes => {:name => "issue[custom_field_values][#{field.id}][]", :value => ''} | |
1248 | end |
|
1248 | end | |
1249 |
|
1249 | |||
1250 | def test_get_new_without_default_start_date_is_creation_date |
|
1250 | def test_get_new_without_default_start_date_is_creation_date | |
1251 | Setting.default_issue_start_date_to_creation_date = 0 |
|
1251 | Setting.default_issue_start_date_to_creation_date = 0 | |
1252 |
|
1252 | |||
1253 | @request.session[:user_id] = 2 |
|
1253 | @request.session[:user_id] = 2 | |
1254 | get :new, :project_id => 1, :tracker_id => 1 |
|
1254 | get :new, :project_id => 1, :tracker_id => 1 | |
1255 | assert_response :success |
|
1255 | assert_response :success | |
1256 | assert_template 'new' |
|
1256 | assert_template 'new' | |
1257 |
|
1257 | |||
1258 | assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]', |
|
1258 | assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]', | |
1259 | :value => nil } |
|
1259 | :value => nil } | |
1260 | end |
|
1260 | end | |
1261 |
|
1261 | |||
1262 | def test_get_new_with_default_start_date_is_creation_date |
|
1262 | def test_get_new_with_default_start_date_is_creation_date | |
1263 | Setting.default_issue_start_date_to_creation_date = 1 |
|
1263 | Setting.default_issue_start_date_to_creation_date = 1 | |
1264 |
|
1264 | |||
1265 | @request.session[:user_id] = 2 |
|
1265 | @request.session[:user_id] = 2 | |
1266 | get :new, :project_id => 1, :tracker_id => 1 |
|
1266 | get :new, :project_id => 1, :tracker_id => 1 | |
1267 | assert_response :success |
|
1267 | assert_response :success | |
1268 | assert_template 'new' |
|
1268 | assert_template 'new' | |
1269 |
|
1269 | |||
1270 | assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]', |
|
1270 | assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]', | |
1271 | :value => Date.today.to_s } |
|
1271 | :value => Date.today.to_s } | |
1272 | end |
|
1272 | end | |
1273 |
|
1273 | |||
1274 | def test_get_new_form_should_allow_attachment_upload |
|
1274 | def test_get_new_form_should_allow_attachment_upload | |
1275 | @request.session[:user_id] = 2 |
|
1275 | @request.session[:user_id] = 2 | |
1276 | get :new, :project_id => 1, :tracker_id => 1 |
|
1276 | get :new, :project_id => 1, :tracker_id => 1 | |
1277 |
|
1277 | |||
1278 | assert_tag :tag => 'form', |
|
1278 | assert_tag :tag => 'form', | |
1279 | :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'}, |
|
1279 | :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'}, | |
1280 | :descendant => { |
|
1280 | :descendant => { | |
1281 | :tag => 'input', |
|
1281 | :tag => 'input', | |
1282 | :attributes => {:type => 'file', :name => 'attachments[1][file]'} |
|
1282 | :attributes => {:type => 'file', :name => 'attachments[1][file]'} | |
1283 | } |
|
1283 | } | |
1284 | end |
|
1284 | end | |
1285 |
|
1285 | |||
|
1286 | def test_get_new_should_prefill_the_form_from_params | |||
|
1287 | @request.session[:user_id] = 2 | |||
|
1288 | get :new, :project_id => 1, | |||
|
1289 | :issue => {:tracker_id => 3, :description => 'Prefilled', :custom_field_values => {'2' => 'Custom field value'}} | |||
|
1290 | ||||
|
1291 | issue = assigns(:issue) | |||
|
1292 | assert_equal 3, issue.tracker_id | |||
|
1293 | assert_equal 'Prefilled', issue.description | |||
|
1294 | assert_equal 'Custom field value', issue.custom_field_value(2) | |||
|
1295 | ||||
|
1296 | assert_tag 'select', | |||
|
1297 | :attributes => {:name => 'issue[tracker_id]'}, | |||
|
1298 | :child => {:tag => 'option', :attributes => {:value => '3', :selected => 'selected'}} | |||
|
1299 | assert_tag 'textarea', | |||
|
1300 | :attributes => {:name => 'issue[description]'}, :content => 'Prefilled' | |||
|
1301 | assert_tag 'input', | |||
|
1302 | :attributes => {:name => 'issue[custom_field_values][2]', :value => 'Custom field value'} | |||
|
1303 | end | |||
|
1304 | ||||
1286 | def test_get_new_without_tracker_id |
|
1305 | def test_get_new_without_tracker_id | |
1287 | @request.session[:user_id] = 2 |
|
1306 | @request.session[:user_id] = 2 | |
1288 | get :new, :project_id => 1 |
|
1307 | get :new, :project_id => 1 | |
1289 | assert_response :success |
|
1308 | assert_response :success | |
1290 | assert_template 'new' |
|
1309 | assert_template 'new' | |
1291 |
|
1310 | |||
1292 | issue = assigns(:issue) |
|
1311 | issue = assigns(:issue) | |
1293 | assert_not_nil issue |
|
1312 | assert_not_nil issue | |
1294 | assert_equal Project.find(1).trackers.first, issue.tracker |
|
1313 | assert_equal Project.find(1).trackers.first, issue.tracker | |
1295 | end |
|
1314 | end | |
1296 |
|
1315 | |||
1297 | def test_get_new_with_no_default_status_should_display_an_error |
|
1316 | def test_get_new_with_no_default_status_should_display_an_error | |
1298 | @request.session[:user_id] = 2 |
|
1317 | @request.session[:user_id] = 2 | |
1299 | IssueStatus.delete_all |
|
1318 | IssueStatus.delete_all | |
1300 |
|
1319 | |||
1301 | get :new, :project_id => 1 |
|
1320 | get :new, :project_id => 1 | |
1302 | assert_response 500 |
|
1321 | assert_response 500 | |
1303 | assert_error_tag :content => /No default issue/ |
|
1322 | assert_error_tag :content => /No default issue/ | |
1304 | end |
|
1323 | end | |
1305 |
|
1324 | |||
1306 | def test_get_new_with_no_tracker_should_display_an_error |
|
1325 | def test_get_new_with_no_tracker_should_display_an_error | |
1307 | @request.session[:user_id] = 2 |
|
1326 | @request.session[:user_id] = 2 | |
1308 | Tracker.delete_all |
|
1327 | Tracker.delete_all | |
1309 |
|
1328 | |||
1310 | get :new, :project_id => 1 |
|
1329 | get :new, :project_id => 1 | |
1311 | assert_response 500 |
|
1330 | assert_response 500 | |
1312 | assert_error_tag :content => /No tracker/ |
|
1331 | assert_error_tag :content => /No tracker/ | |
1313 | end |
|
1332 | end | |
1314 |
|
1333 | |||
1315 | def test_update_new_form |
|
1334 | def test_update_new_form | |
1316 | @request.session[:user_id] = 2 |
|
1335 | @request.session[:user_id] = 2 | |
1317 | xhr :post, :new, :project_id => 1, |
|
1336 | xhr :post, :new, :project_id => 1, | |
1318 | :issue => {:tracker_id => 2, |
|
1337 | :issue => {:tracker_id => 2, | |
1319 | :subject => 'This is the test_new issue', |
|
1338 | :subject => 'This is the test_new issue', | |
1320 | :description => 'This is the description', |
|
1339 | :description => 'This is the description', | |
1321 | :priority_id => 5} |
|
1340 | :priority_id => 5} | |
1322 | assert_response :success |
|
1341 | assert_response :success | |
1323 | assert_template 'attributes' |
|
1342 | assert_template 'attributes' | |
1324 |
|
1343 | |||
1325 | issue = assigns(:issue) |
|
1344 | issue = assigns(:issue) | |
1326 | assert_kind_of Issue, issue |
|
1345 | assert_kind_of Issue, issue | |
1327 | assert_equal 1, issue.project_id |
|
1346 | assert_equal 1, issue.project_id | |
1328 | assert_equal 2, issue.tracker_id |
|
1347 | assert_equal 2, issue.tracker_id | |
1329 | assert_equal 'This is the test_new issue', issue.subject |
|
1348 | assert_equal 'This is the test_new issue', issue.subject | |
1330 | end |
|
1349 | end | |
1331 |
|
1350 | |||
1332 | def test_post_create |
|
1351 | def test_post_create | |
1333 | @request.session[:user_id] = 2 |
|
1352 | @request.session[:user_id] = 2 | |
1334 | assert_difference 'Issue.count' do |
|
1353 | assert_difference 'Issue.count' do | |
1335 | post :create, :project_id => 1, |
|
1354 | post :create, :project_id => 1, | |
1336 | :issue => {:tracker_id => 3, |
|
1355 | :issue => {:tracker_id => 3, | |
1337 | :status_id => 2, |
|
1356 | :status_id => 2, | |
1338 | :subject => 'This is the test_new issue', |
|
1357 | :subject => 'This is the test_new issue', | |
1339 | :description => 'This is the description', |
|
1358 | :description => 'This is the description', | |
1340 | :priority_id => 5, |
|
1359 | :priority_id => 5, | |
1341 | :start_date => '2010-11-07', |
|
1360 | :start_date => '2010-11-07', | |
1342 | :estimated_hours => '', |
|
1361 | :estimated_hours => '', | |
1343 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
1362 | :custom_field_values => {'2' => 'Value for field 2'}} | |
1344 | end |
|
1363 | end | |
1345 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
1364 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
1346 |
|
1365 | |||
1347 | issue = Issue.find_by_subject('This is the test_new issue') |
|
1366 | issue = Issue.find_by_subject('This is the test_new issue') | |
1348 | assert_not_nil issue |
|
1367 | assert_not_nil issue | |
1349 | assert_equal 2, issue.author_id |
|
1368 | assert_equal 2, issue.author_id | |
1350 | assert_equal 3, issue.tracker_id |
|
1369 | assert_equal 3, issue.tracker_id | |
1351 | assert_equal 2, issue.status_id |
|
1370 | assert_equal 2, issue.status_id | |
1352 | assert_equal Date.parse('2010-11-07'), issue.start_date |
|
1371 | assert_equal Date.parse('2010-11-07'), issue.start_date | |
1353 | assert_nil issue.estimated_hours |
|
1372 | assert_nil issue.estimated_hours | |
1354 | v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) |
|
1373 | v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) | |
1355 | assert_not_nil v |
|
1374 | assert_not_nil v | |
1356 | assert_equal 'Value for field 2', v.value |
|
1375 | assert_equal 'Value for field 2', v.value | |
1357 | end |
|
1376 | end | |
1358 |
|
1377 | |||
1359 | def test_post_new_with_group_assignment |
|
1378 | def test_post_new_with_group_assignment | |
1360 | group = Group.find(11) |
|
1379 | group = Group.find(11) | |
1361 | project = Project.find(1) |
|
1380 | project = Project.find(1) | |
1362 | project.members << Member.new(:principal => group, :roles => [Role.givable.first]) |
|
1381 | project.members << Member.new(:principal => group, :roles => [Role.givable.first]) | |
1363 |
|
1382 | |||
1364 | with_settings :issue_group_assignment => '1' do |
|
1383 | with_settings :issue_group_assignment => '1' do | |
1365 | @request.session[:user_id] = 2 |
|
1384 | @request.session[:user_id] = 2 | |
1366 | assert_difference 'Issue.count' do |
|
1385 | assert_difference 'Issue.count' do | |
1367 | post :create, :project_id => project.id, |
|
1386 | post :create, :project_id => project.id, | |
1368 | :issue => {:tracker_id => 3, |
|
1387 | :issue => {:tracker_id => 3, | |
1369 | :status_id => 1, |
|
1388 | :status_id => 1, | |
1370 | :subject => 'This is the test_new_with_group_assignment issue', |
|
1389 | :subject => 'This is the test_new_with_group_assignment issue', | |
1371 | :assigned_to_id => group.id} |
|
1390 | :assigned_to_id => group.id} | |
1372 | end |
|
1391 | end | |
1373 | end |
|
1392 | end | |
1374 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
1393 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
1375 |
|
1394 | |||
1376 | issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue') |
|
1395 | issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue') | |
1377 | assert_not_nil issue |
|
1396 | assert_not_nil issue | |
1378 | assert_equal group, issue.assigned_to |
|
1397 | assert_equal group, issue.assigned_to | |
1379 | end |
|
1398 | end | |
1380 |
|
1399 | |||
1381 | def test_post_create_without_start_date_and_default_start_date_is_not_creation_date |
|
1400 | def test_post_create_without_start_date_and_default_start_date_is_not_creation_date | |
1382 | Setting.default_issue_start_date_to_creation_date = 0 |
|
1401 | Setting.default_issue_start_date_to_creation_date = 0 | |
1383 |
|
1402 | |||
1384 | @request.session[:user_id] = 2 |
|
1403 | @request.session[:user_id] = 2 | |
1385 | assert_difference 'Issue.count' do |
|
1404 | assert_difference 'Issue.count' do | |
1386 | post :create, :project_id => 1, |
|
1405 | post :create, :project_id => 1, | |
1387 | :issue => {:tracker_id => 3, |
|
1406 | :issue => {:tracker_id => 3, | |
1388 | :status_id => 2, |
|
1407 | :status_id => 2, | |
1389 | :subject => 'This is the test_new issue', |
|
1408 | :subject => 'This is the test_new issue', | |
1390 | :description => 'This is the description', |
|
1409 | :description => 'This is the description', | |
1391 | :priority_id => 5, |
|
1410 | :priority_id => 5, | |
1392 | :estimated_hours => '', |
|
1411 | :estimated_hours => '', | |
1393 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
1412 | :custom_field_values => {'2' => 'Value for field 2'}} | |
1394 | end |
|
1413 | end | |
1395 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
1414 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
1396 |
|
1415 | |||
1397 | issue = Issue.find_by_subject('This is the test_new issue') |
|
1416 | issue = Issue.find_by_subject('This is the test_new issue') | |
1398 | assert_not_nil issue |
|
1417 | assert_not_nil issue | |
1399 | assert_nil issue.start_date |
|
1418 | assert_nil issue.start_date | |
1400 | end |
|
1419 | end | |
1401 |
|
1420 | |||
1402 | def test_post_create_without_start_date_and_default_start_date_is_creation_date |
|
1421 | def test_post_create_without_start_date_and_default_start_date_is_creation_date | |
1403 | Setting.default_issue_start_date_to_creation_date = 1 |
|
1422 | Setting.default_issue_start_date_to_creation_date = 1 | |
1404 |
|
1423 | |||
1405 | @request.session[:user_id] = 2 |
|
1424 | @request.session[:user_id] = 2 | |
1406 | assert_difference 'Issue.count' do |
|
1425 | assert_difference 'Issue.count' do | |
1407 | post :create, :project_id => 1, |
|
1426 | post :create, :project_id => 1, | |
1408 | :issue => {:tracker_id => 3, |
|
1427 | :issue => {:tracker_id => 3, | |
1409 | :status_id => 2, |
|
1428 | :status_id => 2, | |
1410 | :subject => 'This is the test_new issue', |
|
1429 | :subject => 'This is the test_new issue', | |
1411 | :description => 'This is the description', |
|
1430 | :description => 'This is the description', | |
1412 | :priority_id => 5, |
|
1431 | :priority_id => 5, | |
1413 | :estimated_hours => '', |
|
1432 | :estimated_hours => '', | |
1414 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
1433 | :custom_field_values => {'2' => 'Value for field 2'}} | |
1415 | end |
|
1434 | end | |
1416 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
1435 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
1417 |
|
1436 | |||
1418 | issue = Issue.find_by_subject('This is the test_new issue') |
|
1437 | issue = Issue.find_by_subject('This is the test_new issue') | |
1419 | assert_not_nil issue |
|
1438 | assert_not_nil issue | |
1420 | assert_equal Date.today, issue.start_date |
|
1439 | assert_equal Date.today, issue.start_date | |
1421 | end |
|
1440 | end | |
1422 |
|
1441 | |||
1423 | def test_post_create_and_continue |
|
1442 | def test_post_create_and_continue | |
1424 | @request.session[:user_id] = 2 |
|
1443 | @request.session[:user_id] = 2 | |
1425 | assert_difference 'Issue.count' do |
|
1444 | assert_difference 'Issue.count' do | |
1426 | post :create, :project_id => 1, |
|
1445 | post :create, :project_id => 1, | |
1427 | :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5}, |
|
1446 | :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5}, | |
1428 | :continue => '' |
|
1447 | :continue => '' | |
1429 | end |
|
1448 | end | |
1430 |
|
1449 | |||
1431 | issue = Issue.first(:order => 'id DESC') |
|
1450 | issue = Issue.first(:order => 'id DESC') | |
1432 | assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3} |
|
1451 | assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3} | |
1433 | assert_not_nil flash[:notice], "flash was not set" |
|
1452 | assert_not_nil flash[:notice], "flash was not set" | |
1434 | assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}" |
|
1453 | assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}" | |
1435 | end |
|
1454 | end | |
1436 |
|
1455 | |||
1437 | def test_post_create_without_custom_fields_param |
|
1456 | def test_post_create_without_custom_fields_param | |
1438 | @request.session[:user_id] = 2 |
|
1457 | @request.session[:user_id] = 2 | |
1439 | assert_difference 'Issue.count' do |
|
1458 | assert_difference 'Issue.count' do | |
1440 | post :create, :project_id => 1, |
|
1459 | post :create, :project_id => 1, | |
1441 | :issue => {:tracker_id => 1, |
|
1460 | :issue => {:tracker_id => 1, | |
1442 | :subject => 'This is the test_new issue', |
|
1461 | :subject => 'This is the test_new issue', | |
1443 | :description => 'This is the description', |
|
1462 | :description => 'This is the description', | |
1444 | :priority_id => 5} |
|
1463 | :priority_id => 5} | |
1445 | end |
|
1464 | end | |
1446 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
1465 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
1447 | end |
|
1466 | end | |
1448 |
|
1467 | |||
1449 | def test_post_create_with_multi_custom_field |
|
1468 | def test_post_create_with_multi_custom_field | |
1450 | field = IssueCustomField.find_by_name('Database') |
|
1469 | field = IssueCustomField.find_by_name('Database') | |
1451 | field.update_attribute(:multiple, true) |
|
1470 | field.update_attribute(:multiple, true) | |
1452 |
|
1471 | |||
1453 | @request.session[:user_id] = 2 |
|
1472 | @request.session[:user_id] = 2 | |
1454 | assert_difference 'Issue.count' do |
|
1473 | assert_difference 'Issue.count' do | |
1455 | post :create, :project_id => 1, |
|
1474 | post :create, :project_id => 1, | |
1456 | :issue => {:tracker_id => 1, |
|
1475 | :issue => {:tracker_id => 1, | |
1457 | :subject => 'This is the test_new issue', |
|
1476 | :subject => 'This is the test_new issue', | |
1458 | :description => 'This is the description', |
|
1477 | :description => 'This is the description', | |
1459 | :priority_id => 5, |
|
1478 | :priority_id => 5, | |
1460 | :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}} |
|
1479 | :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}} | |
1461 | end |
|
1480 | end | |
1462 | assert_response 302 |
|
1481 | assert_response 302 | |
1463 | issue = Issue.first(:order => 'id DESC') |
|
1482 | issue = Issue.first(:order => 'id DESC') | |
1464 | assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort |
|
1483 | assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort | |
1465 | end |
|
1484 | end | |
1466 |
|
1485 | |||
1467 | def test_post_create_with_empty_multi_custom_field |
|
1486 | def test_post_create_with_empty_multi_custom_field | |
1468 | field = IssueCustomField.find_by_name('Database') |
|
1487 | field = IssueCustomField.find_by_name('Database') | |
1469 | field.update_attribute(:multiple, true) |
|
1488 | field.update_attribute(:multiple, true) | |
1470 |
|
1489 | |||
1471 | @request.session[:user_id] = 2 |
|
1490 | @request.session[:user_id] = 2 | |
1472 | assert_difference 'Issue.count' do |
|
1491 | assert_difference 'Issue.count' do | |
1473 | post :create, :project_id => 1, |
|
1492 | post :create, :project_id => 1, | |
1474 | :issue => {:tracker_id => 1, |
|
1493 | :issue => {:tracker_id => 1, | |
1475 | :subject => 'This is the test_new issue', |
|
1494 | :subject => 'This is the test_new issue', | |
1476 | :description => 'This is the description', |
|
1495 | :description => 'This is the description', | |
1477 | :priority_id => 5, |
|
1496 | :priority_id => 5, | |
1478 | :custom_field_values => {'1' => ['']}} |
|
1497 | :custom_field_values => {'1' => ['']}} | |
1479 | end |
|
1498 | end | |
1480 | assert_response 302 |
|
1499 | assert_response 302 | |
1481 | issue = Issue.first(:order => 'id DESC') |
|
1500 | issue = Issue.first(:order => 'id DESC') | |
1482 | assert_equal [''], issue.custom_field_value(1).sort |
|
1501 | assert_equal [''], issue.custom_field_value(1).sort | |
1483 | end |
|
1502 | end | |
1484 |
|
1503 | |||
1485 | def test_post_create_with_multi_user_custom_field |
|
1504 | def test_post_create_with_multi_user_custom_field | |
1486 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, |
|
1505 | field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, | |
1487 | :tracker_ids => [1], :is_for_all => true) |
|
1506 | :tracker_ids => [1], :is_for_all => true) | |
1488 |
|
1507 | |||
1489 | @request.session[:user_id] = 2 |
|
1508 | @request.session[:user_id] = 2 | |
1490 | assert_difference 'Issue.count' do |
|
1509 | assert_difference 'Issue.count' do | |
1491 | post :create, :project_id => 1, |
|
1510 | post :create, :project_id => 1, | |
1492 | :issue => {:tracker_id => 1, |
|
1511 | :issue => {:tracker_id => 1, | |
1493 | :subject => 'This is the test_new issue', |
|
1512 | :subject => 'This is the test_new issue', | |
1494 | :description => 'This is the description', |
|
1513 | :description => 'This is the description', | |
1495 | :priority_id => 5, |
|
1514 | :priority_id => 5, | |
1496 | :custom_field_values => {field.id.to_s => ['', '2', '3']}} |
|
1515 | :custom_field_values => {field.id.to_s => ['', '2', '3']}} | |
1497 | end |
|
1516 | end | |
1498 | assert_response 302 |
|
1517 | assert_response 302 | |
1499 | issue = Issue.first(:order => 'id DESC') |
|
1518 | issue = Issue.first(:order => 'id DESC') | |
1500 | assert_equal ['2', '3'], issue.custom_field_value(field).sort |
|
1519 | assert_equal ['2', '3'], issue.custom_field_value(field).sort | |
1501 | end |
|
1520 | end | |
1502 |
|
1521 | |||
1503 | def test_post_create_with_required_custom_field_and_without_custom_fields_param |
|
1522 | def test_post_create_with_required_custom_field_and_without_custom_fields_param | |
1504 | field = IssueCustomField.find_by_name('Database') |
|
1523 | field = IssueCustomField.find_by_name('Database') | |
1505 | field.update_attribute(:is_required, true) |
|
1524 | field.update_attribute(:is_required, true) | |
1506 |
|
1525 | |||
1507 | @request.session[:user_id] = 2 |
|
1526 | @request.session[:user_id] = 2 | |
1508 | assert_no_difference 'Issue.count' do |
|
1527 | assert_no_difference 'Issue.count' do | |
1509 | post :create, :project_id => 1, |
|
1528 | post :create, :project_id => 1, | |
1510 | :issue => {:tracker_id => 1, |
|
1529 | :issue => {:tracker_id => 1, | |
1511 | :subject => 'This is the test_new issue', |
|
1530 | :subject => 'This is the test_new issue', | |
1512 | :description => 'This is the description', |
|
1531 | :description => 'This is the description', | |
1513 | :priority_id => 5} |
|
1532 | :priority_id => 5} | |
1514 | end |
|
1533 | end | |
1515 | assert_response :success |
|
1534 | assert_response :success | |
1516 | assert_template 'new' |
|
1535 | assert_template 'new' | |
1517 | issue = assigns(:issue) |
|
1536 | issue = assigns(:issue) | |
1518 | assert_not_nil issue |
|
1537 | assert_not_nil issue | |
1519 | assert_error_tag :content => /Database can't be blank/ |
|
1538 | assert_error_tag :content => /Database can't be blank/ | |
1520 | end |
|
1539 | end | |
1521 |
|
1540 | |||
1522 | def test_post_create_with_watchers |
|
1541 | def test_post_create_with_watchers | |
1523 | @request.session[:user_id] = 2 |
|
1542 | @request.session[:user_id] = 2 | |
1524 | ActionMailer::Base.deliveries.clear |
|
1543 | ActionMailer::Base.deliveries.clear | |
1525 |
|
1544 | |||
1526 | assert_difference 'Watcher.count', 2 do |
|
1545 | assert_difference 'Watcher.count', 2 do | |
1527 | post :create, :project_id => 1, |
|
1546 | post :create, :project_id => 1, | |
1528 | :issue => {:tracker_id => 1, |
|
1547 | :issue => {:tracker_id => 1, | |
1529 | :subject => 'This is a new issue with watchers', |
|
1548 | :subject => 'This is a new issue with watchers', | |
1530 | :description => 'This is the description', |
|
1549 | :description => 'This is the description', | |
1531 | :priority_id => 5, |
|
1550 | :priority_id => 5, | |
1532 | :watcher_user_ids => ['2', '3']} |
|
1551 | :watcher_user_ids => ['2', '3']} | |
1533 | end |
|
1552 | end | |
1534 | issue = Issue.find_by_subject('This is a new issue with watchers') |
|
1553 | issue = Issue.find_by_subject('This is a new issue with watchers') | |
1535 | assert_not_nil issue |
|
1554 | assert_not_nil issue | |
1536 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
1555 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue | |
1537 |
|
1556 | |||
1538 | # Watchers added |
|
1557 | # Watchers added | |
1539 | assert_equal [2, 3], issue.watcher_user_ids.sort |
|
1558 | assert_equal [2, 3], issue.watcher_user_ids.sort | |
1540 | assert issue.watched_by?(User.find(3)) |
|
1559 | assert issue.watched_by?(User.find(3)) | |
1541 | # Watchers notified |
|
1560 | # Watchers notified | |
1542 | mail = ActionMailer::Base.deliveries.last |
|
1561 | mail = ActionMailer::Base.deliveries.last | |
1543 | assert_not_nil mail |
|
1562 | assert_not_nil mail | |
1544 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) |
|
1563 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) | |
1545 | end |
|
1564 | end | |
1546 |
|
1565 | |||
1547 | def test_post_create_subissue |
|
1566 | def test_post_create_subissue | |
1548 | @request.session[:user_id] = 2 |
|
1567 | @request.session[:user_id] = 2 | |
1549 |
|
1568 | |||
1550 | assert_difference 'Issue.count' do |
|
1569 | assert_difference 'Issue.count' do | |
1551 | post :create, :project_id => 1, |
|
1570 | post :create, :project_id => 1, | |
1552 | :issue => {:tracker_id => 1, |
|
1571 | :issue => {:tracker_id => 1, | |
1553 | :subject => 'This is a child issue', |
|
1572 | :subject => 'This is a child issue', | |
1554 | :parent_issue_id => 2} |
|
1573 | :parent_issue_id => 2} | |
1555 | end |
|
1574 | end | |
1556 | issue = Issue.find_by_subject('This is a child issue') |
|
1575 | issue = Issue.find_by_subject('This is a child issue') | |
1557 | assert_not_nil issue |
|
1576 | assert_not_nil issue | |
1558 | assert_equal Issue.find(2), issue.parent |
|
1577 | assert_equal Issue.find(2), issue.parent | |
1559 | end |
|
1578 | end | |
1560 |
|
1579 | |||
1561 | def test_post_create_subissue_with_non_numeric_parent_id |
|
1580 | def test_post_create_subissue_with_non_numeric_parent_id | |
1562 | @request.session[:user_id] = 2 |
|
1581 | @request.session[:user_id] = 2 | |
1563 |
|
1582 | |||
1564 | assert_difference 'Issue.count' do |
|
1583 | assert_difference 'Issue.count' do | |
1565 | post :create, :project_id => 1, |
|
1584 | post :create, :project_id => 1, | |
1566 | :issue => {:tracker_id => 1, |
|
1585 | :issue => {:tracker_id => 1, | |
1567 | :subject => 'This is a child issue', |
|
1586 | :subject => 'This is a child issue', | |
1568 | :parent_issue_id => 'ABC'} |
|
1587 | :parent_issue_id => 'ABC'} | |
1569 | end |
|
1588 | end | |
1570 | issue = Issue.find_by_subject('This is a child issue') |
|
1589 | issue = Issue.find_by_subject('This is a child issue') | |
1571 | assert_not_nil issue |
|
1590 | assert_not_nil issue | |
1572 | assert_nil issue.parent |
|
1591 | assert_nil issue.parent | |
1573 | end |
|
1592 | end | |
1574 |
|
1593 | |||
1575 | def test_post_create_private |
|
1594 | def test_post_create_private | |
1576 | @request.session[:user_id] = 2 |
|
1595 | @request.session[:user_id] = 2 | |
1577 |
|
1596 | |||
1578 | assert_difference 'Issue.count' do |
|
1597 | assert_difference 'Issue.count' do | |
1579 | post :create, :project_id => 1, |
|
1598 | post :create, :project_id => 1, | |
1580 | :issue => {:tracker_id => 1, |
|
1599 | :issue => {:tracker_id => 1, | |
1581 | :subject => 'This is a private issue', |
|
1600 | :subject => 'This is a private issue', | |
1582 | :is_private => '1'} |
|
1601 | :is_private => '1'} | |
1583 | end |
|
1602 | end | |
1584 | issue = Issue.first(:order => 'id DESC') |
|
1603 | issue = Issue.first(:order => 'id DESC') | |
1585 | assert issue.is_private? |
|
1604 | assert issue.is_private? | |
1586 | end |
|
1605 | end | |
1587 |
|
1606 | |||
1588 | def test_post_create_private_with_set_own_issues_private_permission |
|
1607 | def test_post_create_private_with_set_own_issues_private_permission | |
1589 | role = Role.find(1) |
|
1608 | role = Role.find(1) | |
1590 | role.remove_permission! :set_issues_private |
|
1609 | role.remove_permission! :set_issues_private | |
1591 | role.add_permission! :set_own_issues_private |
|
1610 | role.add_permission! :set_own_issues_private | |
1592 |
|
1611 | |||
1593 | @request.session[:user_id] = 2 |
|
1612 | @request.session[:user_id] = 2 | |
1594 |
|
1613 | |||
1595 | assert_difference 'Issue.count' do |
|
1614 | assert_difference 'Issue.count' do | |
1596 | post :create, :project_id => 1, |
|
1615 | post :create, :project_id => 1, | |
1597 | :issue => {:tracker_id => 1, |
|
1616 | :issue => {:tracker_id => 1, | |
1598 | :subject => 'This is a private issue', |
|
1617 | :subject => 'This is a private issue', | |
1599 | :is_private => '1'} |
|
1618 | :is_private => '1'} | |
1600 | end |
|
1619 | end | |
1601 | issue = Issue.first(:order => 'id DESC') |
|
1620 | issue = Issue.first(:order => 'id DESC') | |
1602 | assert issue.is_private? |
|
1621 | assert issue.is_private? | |
1603 | end |
|
1622 | end | |
1604 |
|
1623 | |||
1605 | def test_post_create_should_send_a_notification |
|
1624 | def test_post_create_should_send_a_notification | |
1606 | ActionMailer::Base.deliveries.clear |
|
1625 | ActionMailer::Base.deliveries.clear | |
1607 | @request.session[:user_id] = 2 |
|
1626 | @request.session[:user_id] = 2 | |
1608 | assert_difference 'Issue.count' do |
|
1627 | assert_difference 'Issue.count' do | |
1609 | post :create, :project_id => 1, |
|
1628 | post :create, :project_id => 1, | |
1610 | :issue => {:tracker_id => 3, |
|
1629 | :issue => {:tracker_id => 3, | |
1611 | :subject => 'This is the test_new issue', |
|
1630 | :subject => 'This is the test_new issue', | |
1612 | :description => 'This is the description', |
|
1631 | :description => 'This is the description', | |
1613 | :priority_id => 5, |
|
1632 | :priority_id => 5, | |
1614 | :estimated_hours => '', |
|
1633 | :estimated_hours => '', | |
1615 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
1634 | :custom_field_values => {'2' => 'Value for field 2'}} | |
1616 | end |
|
1635 | end | |
1617 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
1636 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
1618 |
|
1637 | |||
1619 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
1638 | assert_equal 1, ActionMailer::Base.deliveries.size | |
1620 | end |
|
1639 | end | |
1621 |
|
1640 | |||
1622 | def test_post_create_should_preserve_fields_values_on_validation_failure |
|
1641 | def test_post_create_should_preserve_fields_values_on_validation_failure | |
1623 | @request.session[:user_id] = 2 |
|
1642 | @request.session[:user_id] = 2 | |
1624 | post :create, :project_id => 1, |
|
1643 | post :create, :project_id => 1, | |
1625 | :issue => {:tracker_id => 1, |
|
1644 | :issue => {:tracker_id => 1, | |
1626 | # empty subject |
|
1645 | # empty subject | |
1627 | :subject => '', |
|
1646 | :subject => '', | |
1628 | :description => 'This is a description', |
|
1647 | :description => 'This is a description', | |
1629 | :priority_id => 6, |
|
1648 | :priority_id => 6, | |
1630 | :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} |
|
1649 | :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} | |
1631 | assert_response :success |
|
1650 | assert_response :success | |
1632 | assert_template 'new' |
|
1651 | assert_template 'new' | |
1633 |
|
1652 | |||
1634 | assert_tag :textarea, :attributes => { :name => 'issue[description]' }, |
|
1653 | assert_tag :textarea, :attributes => { :name => 'issue[description]' }, | |
1635 | :content => 'This is a description' |
|
1654 | :content => 'This is a description' | |
1636 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
|
1655 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, | |
1637 | :child => { :tag => 'option', :attributes => { :selected => 'selected', |
|
1656 | :child => { :tag => 'option', :attributes => { :selected => 'selected', | |
1638 | :value => '6' }, |
|
1657 | :value => '6' }, | |
1639 | :content => 'High' } |
|
1658 | :content => 'High' } | |
1640 | # Custom fields |
|
1659 | # Custom fields | |
1641 | assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, |
|
1660 | assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, | |
1642 | :child => { :tag => 'option', :attributes => { :selected => 'selected', |
|
1661 | :child => { :tag => 'option', :attributes => { :selected => 'selected', | |
1643 | :value => 'Oracle' }, |
|
1662 | :value => 'Oracle' }, | |
1644 | :content => 'Oracle' } |
|
1663 | :content => 'Oracle' } | |
1645 | assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]', |
|
1664 | assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]', | |
1646 | :value => 'Value for field 2'} |
|
1665 | :value => 'Value for field 2'} | |
1647 | end |
|
1666 | end | |
1648 |
|
1667 | |||
1649 | def test_post_create_should_ignore_non_safe_attributes |
|
1668 | def test_post_create_should_ignore_non_safe_attributes | |
1650 | @request.session[:user_id] = 2 |
|
1669 | @request.session[:user_id] = 2 | |
1651 | assert_nothing_raised do |
|
1670 | assert_nothing_raised do | |
1652 | post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" } |
|
1671 | post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" } | |
1653 | end |
|
1672 | end | |
1654 | end |
|
1673 | end | |
1655 |
|
1674 | |||
1656 | def test_post_create_with_attachment |
|
1675 | def test_post_create_with_attachment | |
1657 | set_tmp_attachments_directory |
|
1676 | set_tmp_attachments_directory | |
1658 | @request.session[:user_id] = 2 |
|
1677 | @request.session[:user_id] = 2 | |
1659 |
|
1678 | |||
1660 | assert_difference 'Issue.count' do |
|
1679 | assert_difference 'Issue.count' do | |
1661 | assert_difference 'Attachment.count' do |
|
1680 | assert_difference 'Attachment.count' do | |
1662 | post :create, :project_id => 1, |
|
1681 | post :create, :project_id => 1, | |
1663 | :issue => { :tracker_id => '1', :subject => 'With attachment' }, |
|
1682 | :issue => { :tracker_id => '1', :subject => 'With attachment' }, | |
1664 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
1683 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | |
1665 | end |
|
1684 | end | |
1666 | end |
|
1685 | end | |
1667 |
|
1686 | |||
1668 | issue = Issue.first(:order => 'id DESC') |
|
1687 | issue = Issue.first(:order => 'id DESC') | |
1669 | attachment = Attachment.first(:order => 'id DESC') |
|
1688 | attachment = Attachment.first(:order => 'id DESC') | |
1670 |
|
1689 | |||
1671 | assert_equal issue, attachment.container |
|
1690 | assert_equal issue, attachment.container | |
1672 | assert_equal 2, attachment.author_id |
|
1691 | assert_equal 2, attachment.author_id | |
1673 | assert_equal 'testfile.txt', attachment.filename |
|
1692 | assert_equal 'testfile.txt', attachment.filename | |
1674 | assert_equal 'text/plain', attachment.content_type |
|
1693 | assert_equal 'text/plain', attachment.content_type | |
1675 | assert_equal 'test file', attachment.description |
|
1694 | assert_equal 'test file', attachment.description | |
1676 | assert_equal 59, attachment.filesize |
|
1695 | assert_equal 59, attachment.filesize | |
1677 | assert File.exists?(attachment.diskfile) |
|
1696 | assert File.exists?(attachment.diskfile) | |
1678 | assert_equal 59, File.size(attachment.diskfile) |
|
1697 | assert_equal 59, File.size(attachment.diskfile) | |
1679 | end |
|
1698 | end | |
1680 |
|
1699 | |||
1681 | def test_post_create_with_failure_should_save_attachments |
|
1700 | def test_post_create_with_failure_should_save_attachments | |
1682 | set_tmp_attachments_directory |
|
1701 | set_tmp_attachments_directory | |
1683 | @request.session[:user_id] = 2 |
|
1702 | @request.session[:user_id] = 2 | |
1684 |
|
1703 | |||
1685 | assert_no_difference 'Issue.count' do |
|
1704 | assert_no_difference 'Issue.count' do | |
1686 | assert_difference 'Attachment.count' do |
|
1705 | assert_difference 'Attachment.count' do | |
1687 | post :create, :project_id => 1, |
|
1706 | post :create, :project_id => 1, | |
1688 | :issue => { :tracker_id => '1', :subject => '' }, |
|
1707 | :issue => { :tracker_id => '1', :subject => '' }, | |
1689 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
1708 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | |
1690 | assert_response :success |
|
1709 | assert_response :success | |
1691 | assert_template 'new' |
|
1710 | assert_template 'new' | |
1692 | end |
|
1711 | end | |
1693 | end |
|
1712 | end | |
1694 |
|
1713 | |||
1695 | attachment = Attachment.first(:order => 'id DESC') |
|
1714 | attachment = Attachment.first(:order => 'id DESC') | |
1696 | assert_equal 'testfile.txt', attachment.filename |
|
1715 | assert_equal 'testfile.txt', attachment.filename | |
1697 | assert File.exists?(attachment.diskfile) |
|
1716 | assert File.exists?(attachment.diskfile) | |
1698 | assert_nil attachment.container |
|
1717 | assert_nil attachment.container | |
1699 |
|
1718 | |||
1700 | assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} |
|
1719 | assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} | |
1701 | assert_tag 'span', :content => /testfile.txt/ |
|
1720 | assert_tag 'span', :content => /testfile.txt/ | |
1702 | end |
|
1721 | end | |
1703 |
|
1722 | |||
1704 | def test_post_create_with_failure_should_keep_saved_attachments |
|
1723 | def test_post_create_with_failure_should_keep_saved_attachments | |
1705 | set_tmp_attachments_directory |
|
1724 | set_tmp_attachments_directory | |
1706 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
|
1725 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) | |
1707 | @request.session[:user_id] = 2 |
|
1726 | @request.session[:user_id] = 2 | |
1708 |
|
1727 | |||
1709 | assert_no_difference 'Issue.count' do |
|
1728 | assert_no_difference 'Issue.count' do | |
1710 | assert_no_difference 'Attachment.count' do |
|
1729 | assert_no_difference 'Attachment.count' do | |
1711 | post :create, :project_id => 1, |
|
1730 | post :create, :project_id => 1, | |
1712 | :issue => { :tracker_id => '1', :subject => '' }, |
|
1731 | :issue => { :tracker_id => '1', :subject => '' }, | |
1713 | :attachments => {'p0' => {'token' => attachment.token}} |
|
1732 | :attachments => {'p0' => {'token' => attachment.token}} | |
1714 | assert_response :success |
|
1733 | assert_response :success | |
1715 | assert_template 'new' |
|
1734 | assert_template 'new' | |
1716 | end |
|
1735 | end | |
1717 | end |
|
1736 | end | |
1718 |
|
1737 | |||
1719 | assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} |
|
1738 | assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} | |
1720 | assert_tag 'span', :content => /testfile.txt/ |
|
1739 | assert_tag 'span', :content => /testfile.txt/ | |
1721 | end |
|
1740 | end | |
1722 |
|
1741 | |||
1723 | def test_post_create_should_attach_saved_attachments |
|
1742 | def test_post_create_should_attach_saved_attachments | |
1724 | set_tmp_attachments_directory |
|
1743 | set_tmp_attachments_directory | |
1725 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
|
1744 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) | |
1726 | @request.session[:user_id] = 2 |
|
1745 | @request.session[:user_id] = 2 | |
1727 |
|
1746 | |||
1728 | assert_difference 'Issue.count' do |
|
1747 | assert_difference 'Issue.count' do | |
1729 | assert_no_difference 'Attachment.count' do |
|
1748 | assert_no_difference 'Attachment.count' do | |
1730 | post :create, :project_id => 1, |
|
1749 | post :create, :project_id => 1, | |
1731 | :issue => { :tracker_id => '1', :subject => 'Saved attachments' }, |
|
1750 | :issue => { :tracker_id => '1', :subject => 'Saved attachments' }, | |
1732 | :attachments => {'p0' => {'token' => attachment.token}} |
|
1751 | :attachments => {'p0' => {'token' => attachment.token}} | |
1733 | assert_response 302 |
|
1752 | assert_response 302 | |
1734 | end |
|
1753 | end | |
1735 | end |
|
1754 | end | |
1736 |
|
1755 | |||
1737 | issue = Issue.first(:order => 'id DESC') |
|
1756 | issue = Issue.first(:order => 'id DESC') | |
1738 | assert_equal 1, issue.attachments.count |
|
1757 | assert_equal 1, issue.attachments.count | |
1739 |
|
1758 | |||
1740 | attachment.reload |
|
1759 | attachment.reload | |
1741 | assert_equal issue, attachment.container |
|
1760 | assert_equal issue, attachment.container | |
1742 | end |
|
1761 | end | |
1743 |
|
1762 | |||
1744 | context "without workflow privilege" do |
|
1763 | context "without workflow privilege" do | |
1745 | setup do |
|
1764 | setup do | |
1746 | Workflow.delete_all(["role_id = ?", Role.anonymous.id]) |
|
1765 | Workflow.delete_all(["role_id = ?", Role.anonymous.id]) | |
1747 | Role.anonymous.add_permission! :add_issues, :add_issue_notes |
|
1766 | Role.anonymous.add_permission! :add_issues, :add_issue_notes | |
1748 | end |
|
1767 | end | |
1749 |
|
1768 | |||
1750 | context "#new" do |
|
1769 | context "#new" do | |
1751 | should "propose default status only" do |
|
1770 | should "propose default status only" do | |
1752 | get :new, :project_id => 1 |
|
1771 | get :new, :project_id => 1 | |
1753 | assert_response :success |
|
1772 | assert_response :success | |
1754 | assert_template 'new' |
|
1773 | assert_template 'new' | |
1755 | assert_tag :tag => 'select', |
|
1774 | assert_tag :tag => 'select', | |
1756 | :attributes => {:name => 'issue[status_id]'}, |
|
1775 | :attributes => {:name => 'issue[status_id]'}, | |
1757 | :children => {:count => 1}, |
|
1776 | :children => {:count => 1}, | |
1758 | :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}} |
|
1777 | :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}} | |
1759 | end |
|
1778 | end | |
1760 |
|
1779 | |||
1761 | should "accept default status" do |
|
1780 | should "accept default status" do | |
1762 | assert_difference 'Issue.count' do |
|
1781 | assert_difference 'Issue.count' do | |
1763 | post :create, :project_id => 1, |
|
1782 | post :create, :project_id => 1, | |
1764 | :issue => {:tracker_id => 1, |
|
1783 | :issue => {:tracker_id => 1, | |
1765 | :subject => 'This is an issue', |
|
1784 | :subject => 'This is an issue', | |
1766 | :status_id => 1} |
|
1785 | :status_id => 1} | |
1767 | end |
|
1786 | end | |
1768 | issue = Issue.last(:order => 'id') |
|
1787 | issue = Issue.last(:order => 'id') | |
1769 | assert_equal IssueStatus.default, issue.status |
|
1788 | assert_equal IssueStatus.default, issue.status | |
1770 | end |
|
1789 | end | |
1771 |
|
1790 | |||
1772 | should "ignore unauthorized status" do |
|
1791 | should "ignore unauthorized status" do | |
1773 | assert_difference 'Issue.count' do |
|
1792 | assert_difference 'Issue.count' do | |
1774 | post :create, :project_id => 1, |
|
1793 | post :create, :project_id => 1, | |
1775 | :issue => {:tracker_id => 1, |
|
1794 | :issue => {:tracker_id => 1, | |
1776 | :subject => 'This is an issue', |
|
1795 | :subject => 'This is an issue', | |
1777 | :status_id => 3} |
|
1796 | :status_id => 3} | |
1778 | end |
|
1797 | end | |
1779 | issue = Issue.last(:order => 'id') |
|
1798 | issue = Issue.last(:order => 'id') | |
1780 | assert_equal IssueStatus.default, issue.status |
|
1799 | assert_equal IssueStatus.default, issue.status | |
1781 | end |
|
1800 | end | |
1782 | end |
|
1801 | end | |
1783 |
|
1802 | |||
1784 | context "#update" do |
|
1803 | context "#update" do | |
1785 | should "ignore status change" do |
|
1804 | should "ignore status change" do | |
1786 | assert_difference 'Journal.count' do |
|
1805 | assert_difference 'Journal.count' do | |
1787 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} |
|
1806 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} | |
1788 | end |
|
1807 | end | |
1789 | assert_equal 1, Issue.find(1).status_id |
|
1808 | assert_equal 1, Issue.find(1).status_id | |
1790 | end |
|
1809 | end | |
1791 |
|
1810 | |||
1792 | should "ignore attributes changes" do |
|
1811 | should "ignore attributes changes" do | |
1793 | assert_difference 'Journal.count' do |
|
1812 | assert_difference 'Journal.count' do | |
1794 | put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} |
|
1813 | put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} | |
1795 | end |
|
1814 | end | |
1796 | issue = Issue.find(1) |
|
1815 | issue = Issue.find(1) | |
1797 | assert_equal "Can't print recipes", issue.subject |
|
1816 | assert_equal "Can't print recipes", issue.subject | |
1798 | assert_nil issue.assigned_to |
|
1817 | assert_nil issue.assigned_to | |
1799 | end |
|
1818 | end | |
1800 | end |
|
1819 | end | |
1801 | end |
|
1820 | end | |
1802 |
|
1821 | |||
1803 | context "with workflow privilege" do |
|
1822 | context "with workflow privilege" do | |
1804 | setup do |
|
1823 | setup do | |
1805 | Workflow.delete_all(["role_id = ?", Role.anonymous.id]) |
|
1824 | Workflow.delete_all(["role_id = ?", Role.anonymous.id]) | |
1806 | Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3) |
|
1825 | Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3) | |
1807 | Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4) |
|
1826 | Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4) | |
1808 | Role.anonymous.add_permission! :add_issues, :add_issue_notes |
|
1827 | Role.anonymous.add_permission! :add_issues, :add_issue_notes | |
1809 | end |
|
1828 | end | |
1810 |
|
1829 | |||
1811 | context "#update" do |
|
1830 | context "#update" do | |
1812 | should "accept authorized status" do |
|
1831 | should "accept authorized status" do | |
1813 | assert_difference 'Journal.count' do |
|
1832 | assert_difference 'Journal.count' do | |
1814 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} |
|
1833 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} | |
1815 | end |
|
1834 | end | |
1816 | assert_equal 3, Issue.find(1).status_id |
|
1835 | assert_equal 3, Issue.find(1).status_id | |
1817 | end |
|
1836 | end | |
1818 |
|
1837 | |||
1819 | should "ignore unauthorized status" do |
|
1838 | should "ignore unauthorized status" do | |
1820 | assert_difference 'Journal.count' do |
|
1839 | assert_difference 'Journal.count' do | |
1821 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} |
|
1840 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} | |
1822 | end |
|
1841 | end | |
1823 | assert_equal 1, Issue.find(1).status_id |
|
1842 | assert_equal 1, Issue.find(1).status_id | |
1824 | end |
|
1843 | end | |
1825 |
|
1844 | |||
1826 | should "accept authorized attributes changes" do |
|
1845 | should "accept authorized attributes changes" do | |
1827 | assert_difference 'Journal.count' do |
|
1846 | assert_difference 'Journal.count' do | |
1828 | put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2} |
|
1847 | put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2} | |
1829 | end |
|
1848 | end | |
1830 | issue = Issue.find(1) |
|
1849 | issue = Issue.find(1) | |
1831 | assert_equal 2, issue.assigned_to_id |
|
1850 | assert_equal 2, issue.assigned_to_id | |
1832 | end |
|
1851 | end | |
1833 |
|
1852 | |||
1834 | should "ignore unauthorized attributes changes" do |
|
1853 | should "ignore unauthorized attributes changes" do | |
1835 | assert_difference 'Journal.count' do |
|
1854 | assert_difference 'Journal.count' do | |
1836 | put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'} |
|
1855 | put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'} | |
1837 | end |
|
1856 | end | |
1838 | issue = Issue.find(1) |
|
1857 | issue = Issue.find(1) | |
1839 | assert_equal "Can't print recipes", issue.subject |
|
1858 | assert_equal "Can't print recipes", issue.subject | |
1840 | end |
|
1859 | end | |
1841 | end |
|
1860 | end | |
1842 |
|
1861 | |||
1843 | context "and :edit_issues permission" do |
|
1862 | context "and :edit_issues permission" do | |
1844 | setup do |
|
1863 | setup do | |
1845 | Role.anonymous.add_permission! :add_issues, :edit_issues |
|
1864 | Role.anonymous.add_permission! :add_issues, :edit_issues | |
1846 | end |
|
1865 | end | |
1847 |
|
1866 | |||
1848 | should "accept authorized status" do |
|
1867 | should "accept authorized status" do | |
1849 | assert_difference 'Journal.count' do |
|
1868 | assert_difference 'Journal.count' do | |
1850 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} |
|
1869 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} | |
1851 | end |
|
1870 | end | |
1852 | assert_equal 3, Issue.find(1).status_id |
|
1871 | assert_equal 3, Issue.find(1).status_id | |
1853 | end |
|
1872 | end | |
1854 |
|
1873 | |||
1855 | should "ignore unauthorized status" do |
|
1874 | should "ignore unauthorized status" do | |
1856 | assert_difference 'Journal.count' do |
|
1875 | assert_difference 'Journal.count' do | |
1857 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} |
|
1876 | put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} | |
1858 | end |
|
1877 | end | |
1859 | assert_equal 1, Issue.find(1).status_id |
|
1878 | assert_equal 1, Issue.find(1).status_id | |
1860 | end |
|
1879 | end | |
1861 |
|
1880 | |||
1862 | should "accept authorized attributes changes" do |
|
1881 | should "accept authorized attributes changes" do | |
1863 | assert_difference 'Journal.count' do |
|
1882 | assert_difference 'Journal.count' do | |
1864 | put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} |
|
1883 | put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} | |
1865 | end |
|
1884 | end | |
1866 | issue = Issue.find(1) |
|
1885 | issue = Issue.find(1) | |
1867 | assert_equal "changed", issue.subject |
|
1886 | assert_equal "changed", issue.subject | |
1868 | assert_equal 2, issue.assigned_to_id |
|
1887 | assert_equal 2, issue.assigned_to_id | |
1869 | end |
|
1888 | end | |
1870 | end |
|
1889 | end | |
1871 | end |
|
1890 | end | |
1872 |
|
1891 | |||
1873 | def test_new_as_copy |
|
1892 | def test_new_as_copy | |
1874 | @request.session[:user_id] = 2 |
|
1893 | @request.session[:user_id] = 2 | |
1875 | get :new, :project_id => 1, :copy_from => 1 |
|
1894 | get :new, :project_id => 1, :copy_from => 1 | |
1876 |
|
1895 | |||
1877 | assert_response :success |
|
1896 | assert_response :success | |
1878 | assert_template 'new' |
|
1897 | assert_template 'new' | |
1879 |
|
1898 | |||
1880 | assert_not_nil assigns(:issue) |
|
1899 | assert_not_nil assigns(:issue) | |
1881 | orig = Issue.find(1) |
|
1900 | orig = Issue.find(1) | |
1882 | assert_equal 1, assigns(:issue).project_id |
|
1901 | assert_equal 1, assigns(:issue).project_id | |
1883 | assert_equal orig.subject, assigns(:issue).subject |
|
1902 | assert_equal orig.subject, assigns(:issue).subject | |
1884 | assert assigns(:issue).copy? |
|
1903 | assert assigns(:issue).copy? | |
1885 |
|
1904 | |||
1886 | assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'} |
|
1905 | assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'} | |
1887 | assert_tag 'select', :attributes => {:name => 'issue[project_id]'} |
|
1906 | assert_tag 'select', :attributes => {:name => 'issue[project_id]'} | |
1888 | assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, |
|
1907 | assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, | |
1889 | :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'} |
|
1908 | :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'} | |
1890 | assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, |
|
1909 | assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, | |
1891 | :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'} |
|
1910 | :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'} | |
1892 | assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'} |
|
1911 | assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'} | |
1893 | end |
|
1912 | end | |
1894 |
|
1913 | |||
1895 | def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox |
|
1914 | def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox | |
1896 | @request.session[:user_id] = 2 |
|
1915 | @request.session[:user_id] = 2 | |
1897 | issue = Issue.find(3) |
|
1916 | issue = Issue.find(3) | |
1898 | assert issue.attachments.count > 0 |
|
1917 | assert issue.attachments.count > 0 | |
1899 | get :new, :project_id => 1, :copy_from => 3 |
|
1918 | get :new, :project_id => 1, :copy_from => 3 | |
1900 |
|
1919 | |||
1901 | assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'} |
|
1920 | assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'} | |
1902 | end |
|
1921 | end | |
1903 |
|
1922 | |||
1904 | def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox |
|
1923 | def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox | |
1905 | @request.session[:user_id] = 2 |
|
1924 | @request.session[:user_id] = 2 | |
1906 | issue = Issue.find(3) |
|
1925 | issue = Issue.find(3) | |
1907 | issue.attachments.delete_all |
|
1926 | issue.attachments.delete_all | |
1908 | get :new, :project_id => 1, :copy_from => 3 |
|
1927 | get :new, :project_id => 1, :copy_from => 3 | |
1909 |
|
1928 | |||
1910 | assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'} |
|
1929 | assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'} | |
1911 | end |
|
1930 | end | |
1912 |
|
1931 | |||
1913 | def test_new_as_copy_with_invalid_issue_should_respond_with_404 |
|
1932 | def test_new_as_copy_with_invalid_issue_should_respond_with_404 | |
1914 | @request.session[:user_id] = 2 |
|
1933 | @request.session[:user_id] = 2 | |
1915 | get :new, :project_id => 1, :copy_from => 99999 |
|
1934 | get :new, :project_id => 1, :copy_from => 99999 | |
1916 | assert_response 404 |
|
1935 | assert_response 404 | |
1917 | end |
|
1936 | end | |
1918 |
|
1937 | |||
1919 | def test_create_as_copy_on_different_project |
|
1938 | def test_create_as_copy_on_different_project | |
1920 | @request.session[:user_id] = 2 |
|
1939 | @request.session[:user_id] = 2 | |
1921 | assert_difference 'Issue.count' do |
|
1940 | assert_difference 'Issue.count' do | |
1922 | post :create, :project_id => 1, :copy_from => 1, |
|
1941 | post :create, :project_id => 1, :copy_from => 1, | |
1923 | :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} |
|
1942 | :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} | |
1924 |
|
1943 | |||
1925 | assert_not_nil assigns(:issue) |
|
1944 | assert_not_nil assigns(:issue) | |
1926 | assert assigns(:issue).copy? |
|
1945 | assert assigns(:issue).copy? | |
1927 | end |
|
1946 | end | |
1928 | issue = Issue.first(:order => 'id DESC') |
|
1947 | issue = Issue.first(:order => 'id DESC') | |
1929 | assert_redirected_to "/issues/#{issue.id}" |
|
1948 | assert_redirected_to "/issues/#{issue.id}" | |
1930 |
|
1949 | |||
1931 | assert_equal 2, issue.project_id |
|
1950 | assert_equal 2, issue.project_id | |
1932 | assert_equal 3, issue.tracker_id |
|
1951 | assert_equal 3, issue.tracker_id | |
1933 | assert_equal 'Copy', issue.subject |
|
1952 | assert_equal 'Copy', issue.subject | |
1934 | end |
|
1953 | end | |
1935 |
|
1954 | |||
1936 | def test_create_as_copy_should_copy_attachments |
|
1955 | def test_create_as_copy_should_copy_attachments | |
1937 | @request.session[:user_id] = 2 |
|
1956 | @request.session[:user_id] = 2 | |
1938 | issue = Issue.find(3) |
|
1957 | issue = Issue.find(3) | |
1939 | count = issue.attachments.count |
|
1958 | count = issue.attachments.count | |
1940 | assert count > 0 |
|
1959 | assert count > 0 | |
1941 |
|
1960 | |||
1942 | assert_difference 'Issue.count' do |
|
1961 | assert_difference 'Issue.count' do | |
1943 | assert_difference 'Attachment.count', count do |
|
1962 | assert_difference 'Attachment.count', count do | |
1944 | assert_no_difference 'Journal.count' do |
|
1963 | assert_no_difference 'Journal.count' do | |
1945 | post :create, :project_id => 1, :copy_from => 3, |
|
1964 | post :create, :project_id => 1, :copy_from => 3, | |
1946 | :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}, |
|
1965 | :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}, | |
1947 | :copy_attachments => '1' |
|
1966 | :copy_attachments => '1' | |
1948 | end |
|
1967 | end | |
1949 | end |
|
1968 | end | |
1950 | end |
|
1969 | end | |
1951 | copy = Issue.first(:order => 'id DESC') |
|
1970 | copy = Issue.first(:order => 'id DESC') | |
1952 | assert_equal count, copy.attachments.count |
|
1971 | assert_equal count, copy.attachments.count | |
1953 | assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort |
|
1972 | assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort | |
1954 | end |
|
1973 | end | |
1955 |
|
1974 | |||
1956 | def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments |
|
1975 | def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments | |
1957 | @request.session[:user_id] = 2 |
|
1976 | @request.session[:user_id] = 2 | |
1958 | issue = Issue.find(3) |
|
1977 | issue = Issue.find(3) | |
1959 | count = issue.attachments.count |
|
1978 | count = issue.attachments.count | |
1960 | assert count > 0 |
|
1979 | assert count > 0 | |
1961 |
|
1980 | |||
1962 | assert_difference 'Issue.count' do |
|
1981 | assert_difference 'Issue.count' do | |
1963 | assert_no_difference 'Attachment.count' do |
|
1982 | assert_no_difference 'Attachment.count' do | |
1964 | assert_no_difference 'Journal.count' do |
|
1983 | assert_no_difference 'Journal.count' do | |
1965 | post :create, :project_id => 1, :copy_from => 3, |
|
1984 | post :create, :project_id => 1, :copy_from => 3, | |
1966 | :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'} |
|
1985 | :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'} | |
1967 | end |
|
1986 | end | |
1968 | end |
|
1987 | end | |
1969 | end |
|
1988 | end | |
1970 | copy = Issue.first(:order => 'id DESC') |
|
1989 | copy = Issue.first(:order => 'id DESC') | |
1971 | assert_equal 0, copy.attachments.count |
|
1990 | assert_equal 0, copy.attachments.count | |
1972 | end |
|
1991 | end | |
1973 |
|
1992 | |||
1974 | def test_create_as_copy_with_attachments_should_add_new_files |
|
1993 | def test_create_as_copy_with_attachments_should_add_new_files | |
1975 | @request.session[:user_id] = 2 |
|
1994 | @request.session[:user_id] = 2 | |
1976 | issue = Issue.find(3) |
|
1995 | issue = Issue.find(3) | |
1977 | count = issue.attachments.count |
|
1996 | count = issue.attachments.count | |
1978 | assert count > 0 |
|
1997 | assert count > 0 | |
1979 |
|
1998 | |||
1980 | assert_difference 'Issue.count' do |
|
1999 | assert_difference 'Issue.count' do | |
1981 | assert_difference 'Attachment.count', count + 1 do |
|
2000 | assert_difference 'Attachment.count', count + 1 do | |
1982 | assert_no_difference 'Journal.count' do |
|
2001 | assert_no_difference 'Journal.count' do | |
1983 | post :create, :project_id => 1, :copy_from => 3, |
|
2002 | post :create, :project_id => 1, :copy_from => 3, | |
1984 | :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}, |
|
2003 | :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}, | |
1985 | :copy_attachments => '1', |
|
2004 | :copy_attachments => '1', | |
1986 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
2005 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | |
1987 | end |
|
2006 | end | |
1988 | end |
|
2007 | end | |
1989 | end |
|
2008 | end | |
1990 | copy = Issue.first(:order => 'id DESC') |
|
2009 | copy = Issue.first(:order => 'id DESC') | |
1991 | assert_equal count + 1, copy.attachments.count |
|
2010 | assert_equal count + 1, copy.attachments.count | |
1992 | end |
|
2011 | end | |
1993 |
|
2012 | |||
1994 | def test_create_as_copy_with_failure |
|
2013 | def test_create_as_copy_with_failure | |
1995 | @request.session[:user_id] = 2 |
|
2014 | @request.session[:user_id] = 2 | |
1996 | post :create, :project_id => 1, :copy_from => 1, |
|
2015 | post :create, :project_id => 1, :copy_from => 1, | |
1997 | :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''} |
|
2016 | :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''} | |
1998 |
|
2017 | |||
1999 | assert_response :success |
|
2018 | assert_response :success | |
2000 | assert_template 'new' |
|
2019 | assert_template 'new' | |
2001 |
|
2020 | |||
2002 | assert_not_nil assigns(:issue) |
|
2021 | assert_not_nil assigns(:issue) | |
2003 | assert assigns(:issue).copy? |
|
2022 | assert assigns(:issue).copy? | |
2004 |
|
2023 | |||
2005 | assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'} |
|
2024 | assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'} | |
2006 | assert_tag 'select', :attributes => {:name => 'issue[project_id]'} |
|
2025 | assert_tag 'select', :attributes => {:name => 'issue[project_id]'} | |
2007 | assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, |
|
2026 | assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, | |
2008 | :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'} |
|
2027 | :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'} | |
2009 | assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, |
|
2028 | assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, | |
2010 | :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'} |
|
2029 | :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'} | |
2011 | assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'} |
|
2030 | assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'} | |
2012 | end |
|
2031 | end | |
2013 |
|
2032 | |||
2014 | def test_create_as_copy_on_project_without_permission_should_ignore_target_project |
|
2033 | def test_create_as_copy_on_project_without_permission_should_ignore_target_project | |
2015 | @request.session[:user_id] = 2 |
|
2034 | @request.session[:user_id] = 2 | |
2016 | assert !User.find(2).member_of?(Project.find(4)) |
|
2035 | assert !User.find(2).member_of?(Project.find(4)) | |
2017 |
|
2036 | |||
2018 | assert_difference 'Issue.count' do |
|
2037 | assert_difference 'Issue.count' do | |
2019 | post :create, :project_id => 1, :copy_from => 1, |
|
2038 | post :create, :project_id => 1, :copy_from => 1, | |
2020 | :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} |
|
2039 | :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} | |
2021 | end |
|
2040 | end | |
2022 | issue = Issue.first(:order => 'id DESC') |
|
2041 | issue = Issue.first(:order => 'id DESC') | |
2023 | assert_equal 1, issue.project_id |
|
2042 | assert_equal 1, issue.project_id | |
2024 | end |
|
2043 | end | |
2025 |
|
2044 | |||
2026 | def test_get_edit |
|
2045 | def test_get_edit | |
2027 | @request.session[:user_id] = 2 |
|
2046 | @request.session[:user_id] = 2 | |
2028 | get :edit, :id => 1 |
|
2047 | get :edit, :id => 1 | |
2029 | assert_response :success |
|
2048 | assert_response :success | |
2030 | assert_template 'edit' |
|
2049 | assert_template 'edit' | |
2031 | assert_not_nil assigns(:issue) |
|
2050 | assert_not_nil assigns(:issue) | |
2032 | assert_equal Issue.find(1), assigns(:issue) |
|
2051 | assert_equal Issue.find(1), assigns(:issue) | |
2033 |
|
2052 | |||
2034 | # Be sure we don't display inactive IssuePriorities |
|
2053 | # Be sure we don't display inactive IssuePriorities | |
2035 | assert ! IssuePriority.find(15).active? |
|
2054 | assert ! IssuePriority.find(15).active? | |
2036 | assert_no_tag :option, :attributes => {:value => '15'}, |
|
2055 | assert_no_tag :option, :attributes => {:value => '15'}, | |
2037 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } |
|
2056 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } | |
2038 | end |
|
2057 | end | |
2039 |
|
2058 | |||
2040 | def test_get_edit_should_display_the_time_entry_form_with_log_time_permission |
|
2059 | def test_get_edit_should_display_the_time_entry_form_with_log_time_permission | |
2041 | @request.session[:user_id] = 2 |
|
2060 | @request.session[:user_id] = 2 | |
2042 | Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time] |
|
2061 | Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time] | |
2043 |
|
2062 | |||
2044 | get :edit, :id => 1 |
|
2063 | get :edit, :id => 1 | |
2045 | assert_tag 'input', :attributes => {:name => 'time_entry[hours]'} |
|
2064 | assert_tag 'input', :attributes => {:name => 'time_entry[hours]'} | |
2046 | end |
|
2065 | end | |
2047 |
|
2066 | |||
2048 | def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission |
|
2067 | def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission | |
2049 | @request.session[:user_id] = 2 |
|
2068 | @request.session[:user_id] = 2 | |
2050 | Role.find_by_name('Manager').remove_permission! :log_time |
|
2069 | Role.find_by_name('Manager').remove_permission! :log_time | |
2051 |
|
2070 | |||
2052 | get :edit, :id => 1 |
|
2071 | get :edit, :id => 1 | |
2053 | assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'} |
|
2072 | assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'} | |
2054 | end |
|
2073 | end | |
2055 |
|
2074 | |||
2056 | def test_get_edit_with_params |
|
2075 | def test_get_edit_with_params | |
2057 | @request.session[:user_id] = 2 |
|
2076 | @request.session[:user_id] = 2 | |
2058 | get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }, |
|
2077 | get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }, | |
2059 | :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id } |
|
2078 | :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id } | |
2060 | assert_response :success |
|
2079 | assert_response :success | |
2061 | assert_template 'edit' |
|
2080 | assert_template 'edit' | |
2062 |
|
2081 | |||
2063 | issue = assigns(:issue) |
|
2082 | issue = assigns(:issue) | |
2064 | assert_not_nil issue |
|
2083 | assert_not_nil issue | |
2065 |
|
2084 | |||
2066 | assert_equal 5, issue.status_id |
|
2085 | assert_equal 5, issue.status_id | |
2067 | assert_tag :select, :attributes => { :name => 'issue[status_id]' }, |
|
2086 | assert_tag :select, :attributes => { :name => 'issue[status_id]' }, | |
2068 | :child => { :tag => 'option', |
|
2087 | :child => { :tag => 'option', | |
2069 | :content => 'Closed', |
|
2088 | :content => 'Closed', | |
2070 | :attributes => { :selected => 'selected' } } |
|
2089 | :attributes => { :selected => 'selected' } } | |
2071 |
|
2090 | |||
2072 | assert_equal 7, issue.priority_id |
|
2091 | assert_equal 7, issue.priority_id | |
2073 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
|
2092 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, | |
2074 | :child => { :tag => 'option', |
|
2093 | :child => { :tag => 'option', | |
2075 | :content => 'Urgent', |
|
2094 | :content => 'Urgent', | |
2076 | :attributes => { :selected => 'selected' } } |
|
2095 | :attributes => { :selected => 'selected' } } | |
2077 |
|
2096 | |||
2078 | assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' } |
|
2097 | assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' } | |
2079 | assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' }, |
|
2098 | assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' }, | |
2080 | :child => { :tag => 'option', |
|
2099 | :child => { :tag => 'option', | |
2081 | :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } } |
|
2100 | :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } } | |
2082 | assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' } |
|
2101 | assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' } | |
2083 | end |
|
2102 | end | |
2084 |
|
2103 | |||
2085 | def test_get_edit_with_multi_custom_field |
|
2104 | def test_get_edit_with_multi_custom_field | |
2086 | field = CustomField.find(1) |
|
2105 | field = CustomField.find(1) | |
2087 | field.update_attribute :multiple, true |
|
2106 | field.update_attribute :multiple, true | |
2088 | issue = Issue.find(1) |
|
2107 | issue = Issue.find(1) | |
2089 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
2108 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} | |
2090 | issue.save! |
|
2109 | issue.save! | |
2091 |
|
2110 | |||
2092 | @request.session[:user_id] = 2 |
|
2111 | @request.session[:user_id] = 2 | |
2093 | get :edit, :id => 1 |
|
2112 | get :edit, :id => 1 | |
2094 | assert_response :success |
|
2113 | assert_response :success | |
2095 | assert_template 'edit' |
|
2114 | assert_template 'edit' | |
2096 |
|
2115 | |||
2097 | assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'} |
|
2116 | assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'} | |
2098 | assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'}, |
|
2117 | assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'}, | |
2099 | :child => {:tag => 'option', :attributes => {:value => 'MySQL', :selected => 'selected'}} |
|
2118 | :child => {:tag => 'option', :attributes => {:value => 'MySQL', :selected => 'selected'}} | |
2100 | assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'}, |
|
2119 | assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'}, | |
2101 | :child => {:tag => 'option', :attributes => {:value => 'PostgreSQL', :selected => nil}} |
|
2120 | :child => {:tag => 'option', :attributes => {:value => 'PostgreSQL', :selected => nil}} | |
2102 | assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'}, |
|
2121 | assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'}, | |
2103 | :child => {:tag => 'option', :attributes => {:value => 'Oracle', :selected => 'selected'}} |
|
2122 | :child => {:tag => 'option', :attributes => {:value => 'Oracle', :selected => 'selected'}} | |
2104 | end |
|
2123 | end | |
2105 |
|
2124 | |||
2106 | def test_update_edit_form |
|
2125 | def test_update_edit_form | |
2107 | @request.session[:user_id] = 2 |
|
2126 | @request.session[:user_id] = 2 | |
2108 | xhr :put, :new, :project_id => 1, |
|
2127 | xhr :put, :new, :project_id => 1, | |
2109 | :id => 1, |
|
2128 | :id => 1, | |
2110 | :issue => {:tracker_id => 2, |
|
2129 | :issue => {:tracker_id => 2, | |
2111 | :subject => 'This is the test_new issue', |
|
2130 | :subject => 'This is the test_new issue', | |
2112 | :description => 'This is the description', |
|
2131 | :description => 'This is the description', | |
2113 | :priority_id => 5} |
|
2132 | :priority_id => 5} | |
2114 | assert_response :success |
|
2133 | assert_response :success | |
2115 | assert_template 'attributes' |
|
2134 | assert_template 'attributes' | |
2116 |
|
2135 | |||
2117 | issue = assigns(:issue) |
|
2136 | issue = assigns(:issue) | |
2118 | assert_kind_of Issue, issue |
|
2137 | assert_kind_of Issue, issue | |
2119 | assert_equal 1, issue.id |
|
2138 | assert_equal 1, issue.id | |
2120 | assert_equal 1, issue.project_id |
|
2139 | assert_equal 1, issue.project_id | |
2121 | assert_equal 2, issue.tracker_id |
|
2140 | assert_equal 2, issue.tracker_id | |
2122 | assert_equal 'This is the test_new issue', issue.subject |
|
2141 | assert_equal 'This is the test_new issue', issue.subject | |
2123 | end |
|
2142 | end | |
2124 |
|
2143 | |||
2125 | def test_update_edit_form_with_project_change |
|
2144 | def test_update_edit_form_with_project_change | |
2126 | @request.session[:user_id] = 2 |
|
2145 | @request.session[:user_id] = 2 | |
2127 | xhr :put, :new, :project_id => 1, |
|
2146 | xhr :put, :new, :project_id => 1, | |
2128 | :id => 1, |
|
2147 | :id => 1, | |
2129 | :project_change => '1', |
|
2148 | :project_change => '1', | |
2130 | :issue => {:project_id => 2, |
|
2149 | :issue => {:project_id => 2, | |
2131 | :tracker_id => 2, |
|
2150 | :tracker_id => 2, | |
2132 | :subject => 'This is the test_new issue', |
|
2151 | :subject => 'This is the test_new issue', | |
2133 | :description => 'This is the description', |
|
2152 | :description => 'This is the description', | |
2134 | :priority_id => 5} |
|
2153 | :priority_id => 5} | |
2135 | assert_response :success |
|
2154 | assert_response :success | |
2136 | assert_template 'form' |
|
2155 | assert_template 'form' | |
2137 |
|
2156 | |||
2138 | issue = assigns(:issue) |
|
2157 | issue = assigns(:issue) | |
2139 | assert_kind_of Issue, issue |
|
2158 | assert_kind_of Issue, issue | |
2140 | assert_equal 1, issue.id |
|
2159 | assert_equal 1, issue.id | |
2141 | assert_equal 2, issue.project_id |
|
2160 | assert_equal 2, issue.project_id | |
2142 | assert_equal 2, issue.tracker_id |
|
2161 | assert_equal 2, issue.tracker_id | |
2143 | assert_equal 'This is the test_new issue', issue.subject |
|
2162 | assert_equal 'This is the test_new issue', issue.subject | |
2144 | end |
|
2163 | end | |
2145 |
|
2164 | |||
2146 | def test_put_update_without_custom_fields_param |
|
2165 | def test_put_update_without_custom_fields_param | |
2147 | @request.session[:user_id] = 2 |
|
2166 | @request.session[:user_id] = 2 | |
2148 | ActionMailer::Base.deliveries.clear |
|
2167 | ActionMailer::Base.deliveries.clear | |
2149 |
|
2168 | |||
2150 | issue = Issue.find(1) |
|
2169 | issue = Issue.find(1) | |
2151 | assert_equal '125', issue.custom_value_for(2).value |
|
2170 | assert_equal '125', issue.custom_value_for(2).value | |
2152 | old_subject = issue.subject |
|
2171 | old_subject = issue.subject | |
2153 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
|
2172 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' | |
2154 |
|
2173 | |||
2155 | assert_difference('Journal.count') do |
|
2174 | assert_difference('Journal.count') do | |
2156 | assert_difference('JournalDetail.count', 2) do |
|
2175 | assert_difference('JournalDetail.count', 2) do | |
2157 | put :update, :id => 1, :issue => {:subject => new_subject, |
|
2176 | put :update, :id => 1, :issue => {:subject => new_subject, | |
2158 | :priority_id => '6', |
|
2177 | :priority_id => '6', | |
2159 | :category_id => '1' # no change |
|
2178 | :category_id => '1' # no change | |
2160 | } |
|
2179 | } | |
2161 | end |
|
2180 | end | |
2162 | end |
|
2181 | end | |
2163 | assert_redirected_to :action => 'show', :id => '1' |
|
2182 | assert_redirected_to :action => 'show', :id => '1' | |
2164 | issue.reload |
|
2183 | issue.reload | |
2165 | assert_equal new_subject, issue.subject |
|
2184 | assert_equal new_subject, issue.subject | |
2166 | # Make sure custom fields were not cleared |
|
2185 | # Make sure custom fields were not cleared | |
2167 | assert_equal '125', issue.custom_value_for(2).value |
|
2186 | assert_equal '125', issue.custom_value_for(2).value | |
2168 |
|
2187 | |||
2169 | mail = ActionMailer::Base.deliveries.last |
|
2188 | mail = ActionMailer::Base.deliveries.last | |
2170 | assert_not_nil mail |
|
2189 | assert_not_nil mail | |
2171 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") |
|
2190 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") | |
2172 | assert_mail_body_match "Subject changed from #{old_subject} to #{new_subject}", mail |
|
2191 | assert_mail_body_match "Subject changed from #{old_subject} to #{new_subject}", mail | |
2173 | end |
|
2192 | end | |
2174 |
|
2193 | |||
2175 | def test_put_update_with_project_change |
|
2194 | def test_put_update_with_project_change | |
2176 | @request.session[:user_id] = 2 |
|
2195 | @request.session[:user_id] = 2 | |
2177 | ActionMailer::Base.deliveries.clear |
|
2196 | ActionMailer::Base.deliveries.clear | |
2178 |
|
2197 | |||
2179 | assert_difference('Journal.count') do |
|
2198 | assert_difference('Journal.count') do | |
2180 | assert_difference('JournalDetail.count', 3) do |
|
2199 | assert_difference('JournalDetail.count', 3) do | |
2181 | put :update, :id => 1, :issue => {:project_id => '2', |
|
2200 | put :update, :id => 1, :issue => {:project_id => '2', | |
2182 | :tracker_id => '1', # no change |
|
2201 | :tracker_id => '1', # no change | |
2183 | :priority_id => '6', |
|
2202 | :priority_id => '6', | |
2184 | :category_id => '3' |
|
2203 | :category_id => '3' | |
2185 | } |
|
2204 | } | |
2186 | end |
|
2205 | end | |
2187 | end |
|
2206 | end | |
2188 | assert_redirected_to :action => 'show', :id => '1' |
|
2207 | assert_redirected_to :action => 'show', :id => '1' | |
2189 | issue = Issue.find(1) |
|
2208 | issue = Issue.find(1) | |
2190 | assert_equal 2, issue.project_id |
|
2209 | assert_equal 2, issue.project_id | |
2191 | assert_equal 1, issue.tracker_id |
|
2210 | assert_equal 1, issue.tracker_id | |
2192 | assert_equal 6, issue.priority_id |
|
2211 | assert_equal 6, issue.priority_id | |
2193 | assert_equal 3, issue.category_id |
|
2212 | assert_equal 3, issue.category_id | |
2194 |
|
2213 | |||
2195 | mail = ActionMailer::Base.deliveries.last |
|
2214 | mail = ActionMailer::Base.deliveries.last | |
2196 | assert_not_nil mail |
|
2215 | assert_not_nil mail | |
2197 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") |
|
2216 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") | |
2198 | assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail |
|
2217 | assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail | |
2199 | end |
|
2218 | end | |
2200 |
|
2219 | |||
2201 | def test_put_update_with_tracker_change |
|
2220 | def test_put_update_with_tracker_change | |
2202 | @request.session[:user_id] = 2 |
|
2221 | @request.session[:user_id] = 2 | |
2203 | ActionMailer::Base.deliveries.clear |
|
2222 | ActionMailer::Base.deliveries.clear | |
2204 |
|
2223 | |||
2205 | assert_difference('Journal.count') do |
|
2224 | assert_difference('Journal.count') do | |
2206 | assert_difference('JournalDetail.count', 2) do |
|
2225 | assert_difference('JournalDetail.count', 2) do | |
2207 | put :update, :id => 1, :issue => {:project_id => '1', |
|
2226 | put :update, :id => 1, :issue => {:project_id => '1', | |
2208 | :tracker_id => '2', |
|
2227 | :tracker_id => '2', | |
2209 | :priority_id => '6' |
|
2228 | :priority_id => '6' | |
2210 | } |
|
2229 | } | |
2211 | end |
|
2230 | end | |
2212 | end |
|
2231 | end | |
2213 | assert_redirected_to :action => 'show', :id => '1' |
|
2232 | assert_redirected_to :action => 'show', :id => '1' | |
2214 | issue = Issue.find(1) |
|
2233 | issue = Issue.find(1) | |
2215 | assert_equal 1, issue.project_id |
|
2234 | assert_equal 1, issue.project_id | |
2216 | assert_equal 2, issue.tracker_id |
|
2235 | assert_equal 2, issue.tracker_id | |
2217 | assert_equal 6, issue.priority_id |
|
2236 | assert_equal 6, issue.priority_id | |
2218 | assert_equal 1, issue.category_id |
|
2237 | assert_equal 1, issue.category_id | |
2219 |
|
2238 | |||
2220 | mail = ActionMailer::Base.deliveries.last |
|
2239 | mail = ActionMailer::Base.deliveries.last | |
2221 | assert_not_nil mail |
|
2240 | assert_not_nil mail | |
2222 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") |
|
2241 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") | |
2223 | assert_mail_body_match "Tracker changed from Bug to Feature request", mail |
|
2242 | assert_mail_body_match "Tracker changed from Bug to Feature request", mail | |
2224 | end |
|
2243 | end | |
2225 |
|
2244 | |||
2226 | def test_put_update_with_custom_field_change |
|
2245 | def test_put_update_with_custom_field_change | |
2227 | @request.session[:user_id] = 2 |
|
2246 | @request.session[:user_id] = 2 | |
2228 | issue = Issue.find(1) |
|
2247 | issue = Issue.find(1) | |
2229 | assert_equal '125', issue.custom_value_for(2).value |
|
2248 | assert_equal '125', issue.custom_value_for(2).value | |
2230 |
|
2249 | |||
2231 | assert_difference('Journal.count') do |
|
2250 | assert_difference('Journal.count') do | |
2232 | assert_difference('JournalDetail.count', 3) do |
|
2251 | assert_difference('JournalDetail.count', 3) do | |
2233 | put :update, :id => 1, :issue => {:subject => 'Custom field change', |
|
2252 | put :update, :id => 1, :issue => {:subject => 'Custom field change', | |
2234 | :priority_id => '6', |
|
2253 | :priority_id => '6', | |
2235 | :category_id => '1', # no change |
|
2254 | :category_id => '1', # no change | |
2236 | :custom_field_values => { '2' => 'New custom value' } |
|
2255 | :custom_field_values => { '2' => 'New custom value' } | |
2237 | } |
|
2256 | } | |
2238 | end |
|
2257 | end | |
2239 | end |
|
2258 | end | |
2240 | assert_redirected_to :action => 'show', :id => '1' |
|
2259 | assert_redirected_to :action => 'show', :id => '1' | |
2241 | issue.reload |
|
2260 | issue.reload | |
2242 | assert_equal 'New custom value', issue.custom_value_for(2).value |
|
2261 | assert_equal 'New custom value', issue.custom_value_for(2).value | |
2243 |
|
2262 | |||
2244 | mail = ActionMailer::Base.deliveries.last |
|
2263 | mail = ActionMailer::Base.deliveries.last | |
2245 | assert_not_nil mail |
|
2264 | assert_not_nil mail | |
2246 | assert_mail_body_match "Searchable field changed from 125 to New custom value", mail |
|
2265 | assert_mail_body_match "Searchable field changed from 125 to New custom value", mail | |
2247 | end |
|
2266 | end | |
2248 |
|
2267 | |||
2249 | def test_put_update_with_multi_custom_field_change |
|
2268 | def test_put_update_with_multi_custom_field_change | |
2250 | field = CustomField.find(1) |
|
2269 | field = CustomField.find(1) | |
2251 | field.update_attribute :multiple, true |
|
2270 | field.update_attribute :multiple, true | |
2252 | issue = Issue.find(1) |
|
2271 | issue = Issue.find(1) | |
2253 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} |
|
2272 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} | |
2254 | issue.save! |
|
2273 | issue.save! | |
2255 |
|
2274 | |||
2256 | @request.session[:user_id] = 2 |
|
2275 | @request.session[:user_id] = 2 | |
2257 | assert_difference('Journal.count') do |
|
2276 | assert_difference('Journal.count') do | |
2258 | assert_difference('JournalDetail.count', 3) do |
|
2277 | assert_difference('JournalDetail.count', 3) do | |
2259 | put :update, :id => 1, |
|
2278 | put :update, :id => 1, | |
2260 | :issue => { |
|
2279 | :issue => { | |
2261 | :subject => 'Custom field change', |
|
2280 | :subject => 'Custom field change', | |
2262 | :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] } |
|
2281 | :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] } | |
2263 | } |
|
2282 | } | |
2264 | end |
|
2283 | end | |
2265 | end |
|
2284 | end | |
2266 | assert_redirected_to :action => 'show', :id => '1' |
|
2285 | assert_redirected_to :action => 'show', :id => '1' | |
2267 | assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort |
|
2286 | assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort | |
2268 | end |
|
2287 | end | |
2269 |
|
2288 | |||
2270 | def test_put_update_with_status_and_assignee_change |
|
2289 | def test_put_update_with_status_and_assignee_change | |
2271 | issue = Issue.find(1) |
|
2290 | issue = Issue.find(1) | |
2272 | assert_equal 1, issue.status_id |
|
2291 | assert_equal 1, issue.status_id | |
2273 | @request.session[:user_id] = 2 |
|
2292 | @request.session[:user_id] = 2 | |
2274 | assert_difference('TimeEntry.count', 0) do |
|
2293 | assert_difference('TimeEntry.count', 0) do | |
2275 | put :update, |
|
2294 | put :update, | |
2276 | :id => 1, |
|
2295 | :id => 1, | |
2277 | :issue => { :status_id => 2, :assigned_to_id => 3 }, |
|
2296 | :issue => { :status_id => 2, :assigned_to_id => 3 }, | |
2278 | :notes => 'Assigned to dlopper', |
|
2297 | :notes => 'Assigned to dlopper', | |
2279 | :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } |
|
2298 | :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } | |
2280 | end |
|
2299 | end | |
2281 | assert_redirected_to :action => 'show', :id => '1' |
|
2300 | assert_redirected_to :action => 'show', :id => '1' | |
2282 | issue.reload |
|
2301 | issue.reload | |
2283 | assert_equal 2, issue.status_id |
|
2302 | assert_equal 2, issue.status_id | |
2284 | j = Journal.find(:first, :order => 'id DESC') |
|
2303 | j = Journal.find(:first, :order => 'id DESC') | |
2285 | assert_equal 'Assigned to dlopper', j.notes |
|
2304 | assert_equal 'Assigned to dlopper', j.notes | |
2286 | assert_equal 2, j.details.size |
|
2305 | assert_equal 2, j.details.size | |
2287 |
|
2306 | |||
2288 | mail = ActionMailer::Base.deliveries.last |
|
2307 | mail = ActionMailer::Base.deliveries.last | |
2289 | assert_mail_body_match "Status changed from New to Assigned", mail |
|
2308 | assert_mail_body_match "Status changed from New to Assigned", mail | |
2290 | # subject should contain the new status |
|
2309 | # subject should contain the new status | |
2291 | assert mail.subject.include?("(#{ IssueStatus.find(2).name })") |
|
2310 | assert mail.subject.include?("(#{ IssueStatus.find(2).name })") | |
2292 | end |
|
2311 | end | |
2293 |
|
2312 | |||
2294 | def test_put_update_with_note_only |
|
2313 | def test_put_update_with_note_only | |
2295 | notes = 'Note added by IssuesControllerTest#test_update_with_note_only' |
|
2314 | notes = 'Note added by IssuesControllerTest#test_update_with_note_only' | |
2296 | # anonymous user |
|
2315 | # anonymous user | |
2297 | put :update, |
|
2316 | put :update, | |
2298 | :id => 1, |
|
2317 | :id => 1, | |
2299 | :notes => notes |
|
2318 | :notes => notes | |
2300 | assert_redirected_to :action => 'show', :id => '1' |
|
2319 | assert_redirected_to :action => 'show', :id => '1' | |
2301 | j = Journal.find(:first, :order => 'id DESC') |
|
2320 | j = Journal.find(:first, :order => 'id DESC') | |
2302 | assert_equal notes, j.notes |
|
2321 | assert_equal notes, j.notes | |
2303 | assert_equal 0, j.details.size |
|
2322 | assert_equal 0, j.details.size | |
2304 | assert_equal User.anonymous, j.user |
|
2323 | assert_equal User.anonymous, j.user | |
2305 |
|
2324 | |||
2306 | mail = ActionMailer::Base.deliveries.last |
|
2325 | mail = ActionMailer::Base.deliveries.last | |
2307 | assert_mail_body_match notes, mail |
|
2326 | assert_mail_body_match notes, mail | |
2308 | end |
|
2327 | end | |
2309 |
|
2328 | |||
2310 | def test_put_update_with_note_and_spent_time |
|
2329 | def test_put_update_with_note_and_spent_time | |
2311 | @request.session[:user_id] = 2 |
|
2330 | @request.session[:user_id] = 2 | |
2312 | spent_hours_before = Issue.find(1).spent_hours |
|
2331 | spent_hours_before = Issue.find(1).spent_hours | |
2313 | assert_difference('TimeEntry.count') do |
|
2332 | assert_difference('TimeEntry.count') do | |
2314 | put :update, |
|
2333 | put :update, | |
2315 | :id => 1, |
|
2334 | :id => 1, | |
2316 | :notes => '2.5 hours added', |
|
2335 | :notes => '2.5 hours added', | |
2317 | :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id } |
|
2336 | :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id } | |
2318 | end |
|
2337 | end | |
2319 | assert_redirected_to :action => 'show', :id => '1' |
|
2338 | assert_redirected_to :action => 'show', :id => '1' | |
2320 |
|
2339 | |||
2321 | issue = Issue.find(1) |
|
2340 | issue = Issue.find(1) | |
2322 |
|
2341 | |||
2323 | j = Journal.find(:first, :order => 'id DESC') |
|
2342 | j = Journal.find(:first, :order => 'id DESC') | |
2324 | assert_equal '2.5 hours added', j.notes |
|
2343 | assert_equal '2.5 hours added', j.notes | |
2325 | assert_equal 0, j.details.size |
|
2344 | assert_equal 0, j.details.size | |
2326 |
|
2345 | |||
2327 | t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time') |
|
2346 | t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time') | |
2328 | assert_not_nil t |
|
2347 | assert_not_nil t | |
2329 | assert_equal 2.5, t.hours |
|
2348 | assert_equal 2.5, t.hours | |
2330 | assert_equal spent_hours_before + 2.5, issue.spent_hours |
|
2349 | assert_equal spent_hours_before + 2.5, issue.spent_hours | |
2331 | end |
|
2350 | end | |
2332 |
|
2351 | |||
2333 | def test_put_update_with_attachment_only |
|
2352 | def test_put_update_with_attachment_only | |
2334 | set_tmp_attachments_directory |
|
2353 | set_tmp_attachments_directory | |
2335 |
|
2354 | |||
2336 | # Delete all fixtured journals, a race condition can occur causing the wrong |
|
2355 | # Delete all fixtured journals, a race condition can occur causing the wrong | |
2337 | # journal to get fetched in the next find. |
|
2356 | # journal to get fetched in the next find. | |
2338 | Journal.delete_all |
|
2357 | Journal.delete_all | |
2339 |
|
2358 | |||
2340 | # anonymous user |
|
2359 | # anonymous user | |
2341 | assert_difference 'Attachment.count' do |
|
2360 | assert_difference 'Attachment.count' do | |
2342 | put :update, :id => 1, |
|
2361 | put :update, :id => 1, | |
2343 | :notes => '', |
|
2362 | :notes => '', | |
2344 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
2363 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | |
2345 | end |
|
2364 | end | |
2346 |
|
2365 | |||
2347 | assert_redirected_to :action => 'show', :id => '1' |
|
2366 | assert_redirected_to :action => 'show', :id => '1' | |
2348 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') |
|
2367 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') | |
2349 | assert j.notes.blank? |
|
2368 | assert j.notes.blank? | |
2350 | assert_equal 1, j.details.size |
|
2369 | assert_equal 1, j.details.size | |
2351 | assert_equal 'testfile.txt', j.details.first.value |
|
2370 | assert_equal 'testfile.txt', j.details.first.value | |
2352 | assert_equal User.anonymous, j.user |
|
2371 | assert_equal User.anonymous, j.user | |
2353 |
|
2372 | |||
2354 | attachment = Attachment.first(:order => 'id DESC') |
|
2373 | attachment = Attachment.first(:order => 'id DESC') | |
2355 | assert_equal Issue.find(1), attachment.container |
|
2374 | assert_equal Issue.find(1), attachment.container | |
2356 | assert_equal User.anonymous, attachment.author |
|
2375 | assert_equal User.anonymous, attachment.author | |
2357 | assert_equal 'testfile.txt', attachment.filename |
|
2376 | assert_equal 'testfile.txt', attachment.filename | |
2358 | assert_equal 'text/plain', attachment.content_type |
|
2377 | assert_equal 'text/plain', attachment.content_type | |
2359 | assert_equal 'test file', attachment.description |
|
2378 | assert_equal 'test file', attachment.description | |
2360 | assert_equal 59, attachment.filesize |
|
2379 | assert_equal 59, attachment.filesize | |
2361 | assert File.exists?(attachment.diskfile) |
|
2380 | assert File.exists?(attachment.diskfile) | |
2362 | assert_equal 59, File.size(attachment.diskfile) |
|
2381 | assert_equal 59, File.size(attachment.diskfile) | |
2363 |
|
2382 | |||
2364 | mail = ActionMailer::Base.deliveries.last |
|
2383 | mail = ActionMailer::Base.deliveries.last | |
2365 | assert_mail_body_match 'testfile.txt', mail |
|
2384 | assert_mail_body_match 'testfile.txt', mail | |
2366 | end |
|
2385 | end | |
2367 |
|
2386 | |||
2368 | def test_put_update_with_failure_should_save_attachments |
|
2387 | def test_put_update_with_failure_should_save_attachments | |
2369 | set_tmp_attachments_directory |
|
2388 | set_tmp_attachments_directory | |
2370 | @request.session[:user_id] = 2 |
|
2389 | @request.session[:user_id] = 2 | |
2371 |
|
2390 | |||
2372 | assert_no_difference 'Journal.count' do |
|
2391 | assert_no_difference 'Journal.count' do | |
2373 | assert_difference 'Attachment.count' do |
|
2392 | assert_difference 'Attachment.count' do | |
2374 | put :update, :id => 1, |
|
2393 | put :update, :id => 1, | |
2375 | :issue => { :subject => '' }, |
|
2394 | :issue => { :subject => '' }, | |
2376 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
|
2395 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | |
2377 | assert_response :success |
|
2396 | assert_response :success | |
2378 | assert_template 'edit' |
|
2397 | assert_template 'edit' | |
2379 | end |
|
2398 | end | |
2380 | end |
|
2399 | end | |
2381 |
|
2400 | |||
2382 | attachment = Attachment.first(:order => 'id DESC') |
|
2401 | attachment = Attachment.first(:order => 'id DESC') | |
2383 | assert_equal 'testfile.txt', attachment.filename |
|
2402 | assert_equal 'testfile.txt', attachment.filename | |
2384 | assert File.exists?(attachment.diskfile) |
|
2403 | assert File.exists?(attachment.diskfile) | |
2385 | assert_nil attachment.container |
|
2404 | assert_nil attachment.container | |
2386 |
|
2405 | |||
2387 | assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} |
|
2406 | assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} | |
2388 | assert_tag 'span', :content => /testfile.txt/ |
|
2407 | assert_tag 'span', :content => /testfile.txt/ | |
2389 | end |
|
2408 | end | |
2390 |
|
2409 | |||
2391 | def test_put_update_with_failure_should_keep_saved_attachments |
|
2410 | def test_put_update_with_failure_should_keep_saved_attachments | |
2392 | set_tmp_attachments_directory |
|
2411 | set_tmp_attachments_directory | |
2393 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
|
2412 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) | |
2394 | @request.session[:user_id] = 2 |
|
2413 | @request.session[:user_id] = 2 | |
2395 |
|
2414 | |||
2396 | assert_no_difference 'Journal.count' do |
|
2415 | assert_no_difference 'Journal.count' do | |
2397 | assert_no_difference 'Attachment.count' do |
|
2416 | assert_no_difference 'Attachment.count' do | |
2398 | put :update, :id => 1, |
|
2417 | put :update, :id => 1, | |
2399 | :issue => { :subject => '' }, |
|
2418 | :issue => { :subject => '' }, | |
2400 | :attachments => {'p0' => {'token' => attachment.token}} |
|
2419 | :attachments => {'p0' => {'token' => attachment.token}} | |
2401 | assert_response :success |
|
2420 | assert_response :success | |
2402 | assert_template 'edit' |
|
2421 | assert_template 'edit' | |
2403 | end |
|
2422 | end | |
2404 | end |
|
2423 | end | |
2405 |
|
2424 | |||
2406 | assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} |
|
2425 | assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} | |
2407 | assert_tag 'span', :content => /testfile.txt/ |
|
2426 | assert_tag 'span', :content => /testfile.txt/ | |
2408 | end |
|
2427 | end | |
2409 |
|
2428 | |||
2410 | def test_put_update_should_attach_saved_attachments |
|
2429 | def test_put_update_should_attach_saved_attachments | |
2411 | set_tmp_attachments_directory |
|
2430 | set_tmp_attachments_directory | |
2412 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
|
2431 | attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) | |
2413 | @request.session[:user_id] = 2 |
|
2432 | @request.session[:user_id] = 2 | |
2414 |
|
2433 | |||
2415 | assert_difference 'Journal.count' do |
|
2434 | assert_difference 'Journal.count' do | |
2416 | assert_difference 'JournalDetail.count' do |
|
2435 | assert_difference 'JournalDetail.count' do | |
2417 | assert_no_difference 'Attachment.count' do |
|
2436 | assert_no_difference 'Attachment.count' do | |
2418 | put :update, :id => 1, |
|
2437 | put :update, :id => 1, | |
2419 | :notes => 'Attachment added', |
|
2438 | :notes => 'Attachment added', | |
2420 | :attachments => {'p0' => {'token' => attachment.token}} |
|
2439 | :attachments => {'p0' => {'token' => attachment.token}} | |
2421 | assert_redirected_to '/issues/1' |
|
2440 | assert_redirected_to '/issues/1' | |
2422 | end |
|
2441 | end | |
2423 | end |
|
2442 | end | |
2424 | end |
|
2443 | end | |
2425 |
|
2444 | |||
2426 | attachment.reload |
|
2445 | attachment.reload | |
2427 | assert_equal Issue.find(1), attachment.container |
|
2446 | assert_equal Issue.find(1), attachment.container | |
2428 |
|
2447 | |||
2429 | journal = Journal.first(:order => 'id DESC') |
|
2448 | journal = Journal.first(:order => 'id DESC') | |
2430 | assert_equal 1, journal.details.size |
|
2449 | assert_equal 1, journal.details.size | |
2431 | assert_equal 'testfile.txt', journal.details.first.value |
|
2450 | assert_equal 'testfile.txt', journal.details.first.value | |
2432 | end |
|
2451 | end | |
2433 |
|
2452 | |||
2434 | def test_put_update_with_attachment_that_fails_to_save |
|
2453 | def test_put_update_with_attachment_that_fails_to_save | |
2435 | set_tmp_attachments_directory |
|
2454 | set_tmp_attachments_directory | |
2436 |
|
2455 | |||
2437 | # Delete all fixtured journals, a race condition can occur causing the wrong |
|
2456 | # Delete all fixtured journals, a race condition can occur causing the wrong | |
2438 | # journal to get fetched in the next find. |
|
2457 | # journal to get fetched in the next find. | |
2439 | Journal.delete_all |
|
2458 | Journal.delete_all | |
2440 |
|
2459 | |||
2441 | # Mock out the unsaved attachment |
|
2460 | # Mock out the unsaved attachment | |
2442 | Attachment.any_instance.stubs(:create).returns(Attachment.new) |
|
2461 | Attachment.any_instance.stubs(:create).returns(Attachment.new) | |
2443 |
|
2462 | |||
2444 | # anonymous user |
|
2463 | # anonymous user | |
2445 | put :update, |
|
2464 | put :update, | |
2446 | :id => 1, |
|
2465 | :id => 1, | |
2447 | :notes => '', |
|
2466 | :notes => '', | |
2448 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
2467 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
2449 | assert_redirected_to :action => 'show', :id => '1' |
|
2468 | assert_redirected_to :action => 'show', :id => '1' | |
2450 | assert_equal '1 file(s) could not be saved.', flash[:warning] |
|
2469 | assert_equal '1 file(s) could not be saved.', flash[:warning] | |
2451 | end |
|
2470 | end | |
2452 |
|
2471 | |||
2453 | def test_put_update_with_no_change |
|
2472 | def test_put_update_with_no_change | |
2454 | issue = Issue.find(1) |
|
2473 | issue = Issue.find(1) | |
2455 | issue.journals.clear |
|
2474 | issue.journals.clear | |
2456 | ActionMailer::Base.deliveries.clear |
|
2475 | ActionMailer::Base.deliveries.clear | |
2457 |
|
2476 | |||
2458 | put :update, |
|
2477 | put :update, | |
2459 | :id => 1, |
|
2478 | :id => 1, | |
2460 | :notes => '' |
|
2479 | :notes => '' | |
2461 | assert_redirected_to :action => 'show', :id => '1' |
|
2480 | assert_redirected_to :action => 'show', :id => '1' | |
2462 |
|
2481 | |||
2463 | issue.reload |
|
2482 | issue.reload | |
2464 | assert issue.journals.empty? |
|
2483 | assert issue.journals.empty? | |
2465 | # No email should be sent |
|
2484 | # No email should be sent | |
2466 | assert ActionMailer::Base.deliveries.empty? |
|
2485 | assert ActionMailer::Base.deliveries.empty? | |
2467 | end |
|
2486 | end | |
2468 |
|
2487 | |||
2469 | def test_put_update_should_send_a_notification |
|
2488 | def test_put_update_should_send_a_notification | |
2470 | @request.session[:user_id] = 2 |
|
2489 | @request.session[:user_id] = 2 | |
2471 | ActionMailer::Base.deliveries.clear |
|
2490 | ActionMailer::Base.deliveries.clear | |
2472 | issue = Issue.find(1) |
|
2491 | issue = Issue.find(1) | |
2473 | old_subject = issue.subject |
|
2492 | old_subject = issue.subject | |
2474 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
|
2493 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' | |
2475 |
|
2494 | |||
2476 | put :update, :id => 1, :issue => {:subject => new_subject, |
|
2495 | put :update, :id => 1, :issue => {:subject => new_subject, | |
2477 | :priority_id => '6', |
|
2496 | :priority_id => '6', | |
2478 | :category_id => '1' # no change |
|
2497 | :category_id => '1' # no change | |
2479 | } |
|
2498 | } | |
2480 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
2499 | assert_equal 1, ActionMailer::Base.deliveries.size | |
2481 | end |
|
2500 | end | |
2482 |
|
2501 | |||
2483 | def test_put_update_with_invalid_spent_time_hours_only |
|
2502 | def test_put_update_with_invalid_spent_time_hours_only | |
2484 | @request.session[:user_id] = 2 |
|
2503 | @request.session[:user_id] = 2 | |
2485 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' |
|
2504 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' | |
2486 |
|
2505 | |||
2487 | assert_no_difference('Journal.count') do |
|
2506 | assert_no_difference('Journal.count') do | |
2488 | put :update, |
|
2507 | put :update, | |
2489 | :id => 1, |
|
2508 | :id => 1, | |
2490 | :notes => notes, |
|
2509 | :notes => notes, | |
2491 | :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} |
|
2510 | :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} | |
2492 | end |
|
2511 | end | |
2493 | assert_response :success |
|
2512 | assert_response :success | |
2494 | assert_template 'edit' |
|
2513 | assert_template 'edit' | |
2495 |
|
2514 | |||
2496 | assert_error_tag :descendant => {:content => /Activity can't be blank/} |
|
2515 | assert_error_tag :descendant => {:content => /Activity can't be blank/} | |
2497 | assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes |
|
2516 | assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes | |
2498 | assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" } |
|
2517 | assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" } | |
2499 | end |
|
2518 | end | |
2500 |
|
2519 | |||
2501 | def test_put_update_with_invalid_spent_time_comments_only |
|
2520 | def test_put_update_with_invalid_spent_time_comments_only | |
2502 | @request.session[:user_id] = 2 |
|
2521 | @request.session[:user_id] = 2 | |
2503 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' |
|
2522 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' | |
2504 |
|
2523 | |||
2505 | assert_no_difference('Journal.count') do |
|
2524 | assert_no_difference('Journal.count') do | |
2506 | put :update, |
|
2525 | put :update, | |
2507 | :id => 1, |
|
2526 | :id => 1, | |
2508 | :notes => notes, |
|
2527 | :notes => notes, | |
2509 | :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""} |
|
2528 | :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""} | |
2510 | end |
|
2529 | end | |
2511 | assert_response :success |
|
2530 | assert_response :success | |
2512 | assert_template 'edit' |
|
2531 | assert_template 'edit' | |
2513 |
|
2532 | |||
2514 | assert_error_tag :descendant => {:content => /Activity can't be blank/} |
|
2533 | assert_error_tag :descendant => {:content => /Activity can't be blank/} | |
2515 | assert_error_tag :descendant => {:content => /Hours can't be blank/} |
|
2534 | assert_error_tag :descendant => {:content => /Hours can't be blank/} | |
2516 | assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes |
|
2535 | assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes | |
2517 | assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" } |
|
2536 | assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" } | |
2518 | end |
|
2537 | end | |
2519 |
|
2538 | |||
2520 | def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject |
|
2539 | def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject | |
2521 | issue = Issue.find(2) |
|
2540 | issue = Issue.find(2) | |
2522 | @request.session[:user_id] = 2 |
|
2541 | @request.session[:user_id] = 2 | |
2523 |
|
2542 | |||
2524 | put :update, |
|
2543 | put :update, | |
2525 | :id => issue.id, |
|
2544 | :id => issue.id, | |
2526 | :issue => { |
|
2545 | :issue => { | |
2527 | :fixed_version_id => 4 |
|
2546 | :fixed_version_id => 4 | |
2528 | } |
|
2547 | } | |
2529 |
|
2548 | |||
2530 | assert_response :redirect |
|
2549 | assert_response :redirect | |
2531 | issue.reload |
|
2550 | issue.reload | |
2532 | assert_equal 4, issue.fixed_version_id |
|
2551 | assert_equal 4, issue.fixed_version_id | |
2533 | assert_not_equal issue.project_id, issue.fixed_version.project_id |
|
2552 | assert_not_equal issue.project_id, issue.fixed_version.project_id | |
2534 | end |
|
2553 | end | |
2535 |
|
2554 | |||
2536 | def test_put_update_should_redirect_back_using_the_back_url_parameter |
|
2555 | def test_put_update_should_redirect_back_using_the_back_url_parameter | |
2537 | issue = Issue.find(2) |
|
2556 | issue = Issue.find(2) | |
2538 | @request.session[:user_id] = 2 |
|
2557 | @request.session[:user_id] = 2 | |
2539 |
|
2558 | |||
2540 | put :update, |
|
2559 | put :update, | |
2541 | :id => issue.id, |
|
2560 | :id => issue.id, | |
2542 | :issue => { |
|
2561 | :issue => { | |
2543 | :fixed_version_id => 4 |
|
2562 | :fixed_version_id => 4 | |
2544 | }, |
|
2563 | }, | |
2545 | :back_url => '/issues' |
|
2564 | :back_url => '/issues' | |
2546 |
|
2565 | |||
2547 | assert_response :redirect |
|
2566 | assert_response :redirect | |
2548 | assert_redirected_to '/issues' |
|
2567 | assert_redirected_to '/issues' | |
2549 | end |
|
2568 | end | |
2550 |
|
2569 | |||
2551 | def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
2570 | def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host | |
2552 | issue = Issue.find(2) |
|
2571 | issue = Issue.find(2) | |
2553 | @request.session[:user_id] = 2 |
|
2572 | @request.session[:user_id] = 2 | |
2554 |
|
2573 | |||
2555 | put :update, |
|
2574 | put :update, | |
2556 | :id => issue.id, |
|
2575 | :id => issue.id, | |
2557 | :issue => { |
|
2576 | :issue => { | |
2558 | :fixed_version_id => 4 |
|
2577 | :fixed_version_id => 4 | |
2559 | }, |
|
2578 | }, | |
2560 | :back_url => 'http://google.com' |
|
2579 | :back_url => 'http://google.com' | |
2561 |
|
2580 | |||
2562 | assert_response :redirect |
|
2581 | assert_response :redirect | |
2563 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id |
|
2582 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id | |
2564 | end |
|
2583 | end | |
2565 |
|
2584 | |||
2566 | def test_get_bulk_edit |
|
2585 | def test_get_bulk_edit | |
2567 | @request.session[:user_id] = 2 |
|
2586 | @request.session[:user_id] = 2 | |
2568 | get :bulk_edit, :ids => [1, 2] |
|
2587 | get :bulk_edit, :ids => [1, 2] | |
2569 | assert_response :success |
|
2588 | assert_response :success | |
2570 | assert_template 'bulk_edit' |
|
2589 | assert_template 'bulk_edit' | |
2571 |
|
2590 | |||
2572 | assert_tag :select, :attributes => {:name => 'issue[project_id]'} |
|
2591 | assert_tag :select, :attributes => {:name => 'issue[project_id]'} | |
2573 | assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} |
|
2592 | assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} | |
2574 |
|
2593 | |||
2575 | # Project specific custom field, date type |
|
2594 | # Project specific custom field, date type | |
2576 | field = CustomField.find(9) |
|
2595 | field = CustomField.find(9) | |
2577 | assert !field.is_for_all? |
|
2596 | assert !field.is_for_all? | |
2578 | assert_equal 'date', field.field_format |
|
2597 | assert_equal 'date', field.field_format | |
2579 | assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} |
|
2598 | assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} | |
2580 |
|
2599 | |||
2581 | # System wide custom field |
|
2600 | # System wide custom field | |
2582 | assert CustomField.find(1).is_for_all? |
|
2601 | assert CustomField.find(1).is_for_all? | |
2583 | assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} |
|
2602 | assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} | |
2584 |
|
2603 | |||
2585 | # Be sure we don't display inactive IssuePriorities |
|
2604 | # Be sure we don't display inactive IssuePriorities | |
2586 | assert ! IssuePriority.find(15).active? |
|
2605 | assert ! IssuePriority.find(15).active? | |
2587 | assert_no_tag :option, :attributes => {:value => '15'}, |
|
2606 | assert_no_tag :option, :attributes => {:value => '15'}, | |
2588 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } |
|
2607 | :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } | |
2589 | end |
|
2608 | end | |
2590 |
|
2609 | |||
2591 | def test_get_bulk_edit_on_different_projects |
|
2610 | def test_get_bulk_edit_on_different_projects | |
2592 | @request.session[:user_id] = 2 |
|
2611 | @request.session[:user_id] = 2 | |
2593 | get :bulk_edit, :ids => [1, 2, 6] |
|
2612 | get :bulk_edit, :ids => [1, 2, 6] | |
2594 | assert_response :success |
|
2613 | assert_response :success | |
2595 | assert_template 'bulk_edit' |
|
2614 | assert_template 'bulk_edit' | |
2596 |
|
2615 | |||
2597 | # Can not set issues from different projects as children of an issue |
|
2616 | # Can not set issues from different projects as children of an issue | |
2598 | assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} |
|
2617 | assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} | |
2599 |
|
2618 | |||
2600 | # Project specific custom field, date type |
|
2619 | # Project specific custom field, date type | |
2601 | field = CustomField.find(9) |
|
2620 | field = CustomField.find(9) | |
2602 | assert !field.is_for_all? |
|
2621 | assert !field.is_for_all? | |
2603 | assert !field.project_ids.include?(Issue.find(6).project_id) |
|
2622 | assert !field.project_ids.include?(Issue.find(6).project_id) | |
2604 | assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} |
|
2623 | assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} | |
2605 | end |
|
2624 | end | |
2606 |
|
2625 | |||
2607 | def test_get_bulk_edit_with_user_custom_field |
|
2626 | def test_get_bulk_edit_with_user_custom_field | |
2608 | field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true) |
|
2627 | field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true) | |
2609 |
|
2628 | |||
2610 | @request.session[:user_id] = 2 |
|
2629 | @request.session[:user_id] = 2 | |
2611 | get :bulk_edit, :ids => [1, 2] |
|
2630 | get :bulk_edit, :ids => [1, 2] | |
2612 | assert_response :success |
|
2631 | assert_response :success | |
2613 | assert_template 'bulk_edit' |
|
2632 | assert_template 'bulk_edit' | |
2614 |
|
2633 | |||
2615 | assert_tag :select, |
|
2634 | assert_tag :select, | |
2616 | :attributes => {:name => "issue[custom_field_values][#{field.id}]"}, |
|
2635 | :attributes => {:name => "issue[custom_field_values][#{field.id}]"}, | |
2617 | :children => { |
|
2636 | :children => { | |
2618 | :only => {:tag => 'option'}, |
|
2637 | :only => {:tag => 'option'}, | |
2619 | :count => Project.find(1).users.count + 1 |
|
2638 | :count => Project.find(1).users.count + 1 | |
2620 | } |
|
2639 | } | |
2621 | end |
|
2640 | end | |
2622 |
|
2641 | |||
2623 | def test_get_bulk_edit_with_version_custom_field |
|
2642 | def test_get_bulk_edit_with_version_custom_field | |
2624 | field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true) |
|
2643 | field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true) | |
2625 |
|
2644 | |||
2626 | @request.session[:user_id] = 2 |
|
2645 | @request.session[:user_id] = 2 | |
2627 | get :bulk_edit, :ids => [1, 2] |
|
2646 | get :bulk_edit, :ids => [1, 2] | |
2628 | assert_response :success |
|
2647 | assert_response :success | |
2629 | assert_template 'bulk_edit' |
|
2648 | assert_template 'bulk_edit' | |
2630 |
|
2649 | |||
2631 | assert_tag :select, |
|
2650 | assert_tag :select, | |
2632 | :attributes => {:name => "issue[custom_field_values][#{field.id}]"}, |
|
2651 | :attributes => {:name => "issue[custom_field_values][#{field.id}]"}, | |
2633 | :children => { |
|
2652 | :children => { | |
2634 | :only => {:tag => 'option'}, |
|
2653 | :only => {:tag => 'option'}, | |
2635 | :count => Project.find(1).shared_versions.count + 1 |
|
2654 | :count => Project.find(1).shared_versions.count + 1 | |
2636 | } |
|
2655 | } | |
2637 | end |
|
2656 | end | |
2638 |
|
2657 | |||
2639 | def test_get_bulk_edit_with_multi_custom_field |
|
2658 | def test_get_bulk_edit_with_multi_custom_field | |
2640 | field = CustomField.find(1) |
|
2659 | field = CustomField.find(1) | |
2641 | field.update_attribute :multiple, true |
|
2660 | field.update_attribute :multiple, true | |
2642 |
|
2661 | |||
2643 | @request.session[:user_id] = 2 |
|
2662 | @request.session[:user_id] = 2 | |
2644 | get :bulk_edit, :ids => [1, 2] |
|
2663 | get :bulk_edit, :ids => [1, 2] | |
2645 | assert_response :success |
|
2664 | assert_response :success | |
2646 | assert_template 'bulk_edit' |
|
2665 | assert_template 'bulk_edit' | |
2647 |
|
2666 | |||
2648 | assert_tag :select, |
|
2667 | assert_tag :select, | |
2649 | :attributes => {:name => "issue[custom_field_values][1][]"}, |
|
2668 | :attributes => {:name => "issue[custom_field_values][1][]"}, | |
2650 | :children => { |
|
2669 | :children => { | |
2651 | :only => {:tag => 'option'}, |
|
2670 | :only => {:tag => 'option'}, | |
2652 | :count => 3 |
|
2671 | :count => 3 | |
2653 | } |
|
2672 | } | |
2654 | end |
|
2673 | end | |
2655 |
|
2674 | |||
2656 | def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues |
|
2675 | def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues | |
2657 | Workflow.delete_all |
|
2676 | Workflow.delete_all | |
2658 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1) |
|
2677 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1) | |
2659 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3) |
|
2678 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3) | |
2660 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4) |
|
2679 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4) | |
2661 | Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1) |
|
2680 | Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1) | |
2662 | Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3) |
|
2681 | Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3) | |
2663 | Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5) |
|
2682 | Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5) | |
2664 | @request.session[:user_id] = 2 |
|
2683 | @request.session[:user_id] = 2 | |
2665 | get :bulk_edit, :ids => [1, 2] |
|
2684 | get :bulk_edit, :ids => [1, 2] | |
2666 |
|
2685 | |||
2667 | assert_response :success |
|
2686 | assert_response :success | |
2668 | statuses = assigns(:available_statuses) |
|
2687 | statuses = assigns(:available_statuses) | |
2669 | assert_not_nil statuses |
|
2688 | assert_not_nil statuses | |
2670 | assert_equal [1, 3], statuses.map(&:id).sort |
|
2689 | assert_equal [1, 3], statuses.map(&:id).sort | |
2671 |
|
2690 | |||
2672 | assert_tag 'select', :attributes => {:name => 'issue[status_id]'}, |
|
2691 | assert_tag 'select', :attributes => {:name => 'issue[status_id]'}, | |
2673 | :children => {:count => 3} # 2 statuses + "no change" option |
|
2692 | :children => {:count => 3} # 2 statuses + "no change" option | |
2674 | end |
|
2693 | end | |
2675 |
|
2694 | |||
2676 | def test_bulk_edit_should_propose_target_project_open_shared_versions |
|
2695 | def test_bulk_edit_should_propose_target_project_open_shared_versions | |
2677 | @request.session[:user_id] = 2 |
|
2696 | @request.session[:user_id] = 2 | |
2678 | post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} |
|
2697 | post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} | |
2679 | assert_response :success |
|
2698 | assert_response :success | |
2680 | assert_template 'bulk_edit' |
|
2699 | assert_template 'bulk_edit' | |
2681 | assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort |
|
2700 | assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort | |
2682 | assert_tag 'select', |
|
2701 | assert_tag 'select', | |
2683 | :attributes => {:name => 'issue[fixed_version_id]'}, |
|
2702 | :attributes => {:name => 'issue[fixed_version_id]'}, | |
2684 | :descendant => {:tag => 'option', :content => '2.0'} |
|
2703 | :descendant => {:tag => 'option', :content => '2.0'} | |
2685 | end |
|
2704 | end | |
2686 |
|
2705 | |||
2687 | def test_bulk_edit_should_propose_target_project_categories |
|
2706 | def test_bulk_edit_should_propose_target_project_categories | |
2688 | @request.session[:user_id] = 2 |
|
2707 | @request.session[:user_id] = 2 | |
2689 | post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} |
|
2708 | post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} | |
2690 | assert_response :success |
|
2709 | assert_response :success | |
2691 | assert_template 'bulk_edit' |
|
2710 | assert_template 'bulk_edit' | |
2692 | assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort |
|
2711 | assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort | |
2693 | assert_tag 'select', |
|
2712 | assert_tag 'select', | |
2694 | :attributes => {:name => 'issue[category_id]'}, |
|
2713 | :attributes => {:name => 'issue[category_id]'}, | |
2695 | :descendant => {:tag => 'option', :content => 'Recipes'} |
|
2714 | :descendant => {:tag => 'option', :content => 'Recipes'} | |
2696 | end |
|
2715 | end | |
2697 |
|
2716 | |||
2698 | def test_bulk_update |
|
2717 | def test_bulk_update | |
2699 | @request.session[:user_id] = 2 |
|
2718 | @request.session[:user_id] = 2 | |
2700 | # update issues priority |
|
2719 | # update issues priority | |
2701 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', |
|
2720 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', | |
2702 | :issue => {:priority_id => 7, |
|
2721 | :issue => {:priority_id => 7, | |
2703 | :assigned_to_id => '', |
|
2722 | :assigned_to_id => '', | |
2704 | :custom_field_values => {'2' => ''}} |
|
2723 | :custom_field_values => {'2' => ''}} | |
2705 |
|
2724 | |||
2706 | assert_response 302 |
|
2725 | assert_response 302 | |
2707 | # check that the issues were updated |
|
2726 | # check that the issues were updated | |
2708 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} |
|
2727 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} | |
2709 |
|
2728 | |||
2710 | issue = Issue.find(1) |
|
2729 | issue = Issue.find(1) | |
2711 | journal = issue.journals.find(:first, :order => 'created_on DESC') |
|
2730 | journal = issue.journals.find(:first, :order => 'created_on DESC') | |
2712 | assert_equal '125', issue.custom_value_for(2).value |
|
2731 | assert_equal '125', issue.custom_value_for(2).value | |
2713 | assert_equal 'Bulk editing', journal.notes |
|
2732 | assert_equal 'Bulk editing', journal.notes | |
2714 | assert_equal 1, journal.details.size |
|
2733 | assert_equal 1, journal.details.size | |
2715 | end |
|
2734 | end | |
2716 |
|
2735 | |||
2717 | def test_bulk_update_with_group_assignee |
|
2736 | def test_bulk_update_with_group_assignee | |
2718 | group = Group.find(11) |
|
2737 | group = Group.find(11) | |
2719 | project = Project.find(1) |
|
2738 | project = Project.find(1) | |
2720 | project.members << Member.new(:principal => group, :roles => [Role.givable.first]) |
|
2739 | project.members << Member.new(:principal => group, :roles => [Role.givable.first]) | |
2721 |
|
2740 | |||
2722 | @request.session[:user_id] = 2 |
|
2741 | @request.session[:user_id] = 2 | |
2723 | # update issues assignee |
|
2742 | # update issues assignee | |
2724 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', |
|
2743 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', | |
2725 | :issue => {:priority_id => '', |
|
2744 | :issue => {:priority_id => '', | |
2726 | :assigned_to_id => group.id, |
|
2745 | :assigned_to_id => group.id, | |
2727 | :custom_field_values => {'2' => ''}} |
|
2746 | :custom_field_values => {'2' => ''}} | |
2728 |
|
2747 | |||
2729 | assert_response 302 |
|
2748 | assert_response 302 | |
2730 | assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to} |
|
2749 | assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to} | |
2731 | end |
|
2750 | end | |
2732 |
|
2751 | |||
2733 | def test_bulk_update_on_different_projects |
|
2752 | def test_bulk_update_on_different_projects | |
2734 | @request.session[:user_id] = 2 |
|
2753 | @request.session[:user_id] = 2 | |
2735 | # update issues priority |
|
2754 | # update issues priority | |
2736 | post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing', |
|
2755 | post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing', | |
2737 | :issue => {:priority_id => 7, |
|
2756 | :issue => {:priority_id => 7, | |
2738 | :assigned_to_id => '', |
|
2757 | :assigned_to_id => '', | |
2739 | :custom_field_values => {'2' => ''}} |
|
2758 | :custom_field_values => {'2' => ''}} | |
2740 |
|
2759 | |||
2741 | assert_response 302 |
|
2760 | assert_response 302 | |
2742 | # check that the issues were updated |
|
2761 | # check that the issues were updated | |
2743 | assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id) |
|
2762 | assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id) | |
2744 |
|
2763 | |||
2745 | issue = Issue.find(1) |
|
2764 | issue = Issue.find(1) | |
2746 | journal = issue.journals.find(:first, :order => 'created_on DESC') |
|
2765 | journal = issue.journals.find(:first, :order => 'created_on DESC') | |
2747 | assert_equal '125', issue.custom_value_for(2).value |
|
2766 | assert_equal '125', issue.custom_value_for(2).value | |
2748 | assert_equal 'Bulk editing', journal.notes |
|
2767 | assert_equal 'Bulk editing', journal.notes | |
2749 | assert_equal 1, journal.details.size |
|
2768 | assert_equal 1, journal.details.size | |
2750 | end |
|
2769 | end | |
2751 |
|
2770 | |||
2752 | def test_bulk_update_on_different_projects_without_rights |
|
2771 | def test_bulk_update_on_different_projects_without_rights | |
2753 | @request.session[:user_id] = 3 |
|
2772 | @request.session[:user_id] = 3 | |
2754 | user = User.find(3) |
|
2773 | user = User.find(3) | |
2755 | action = { :controller => "issues", :action => "bulk_update" } |
|
2774 | action = { :controller => "issues", :action => "bulk_update" } | |
2756 | assert user.allowed_to?(action, Issue.find(1).project) |
|
2775 | assert user.allowed_to?(action, Issue.find(1).project) | |
2757 | assert ! user.allowed_to?(action, Issue.find(6).project) |
|
2776 | assert ! user.allowed_to?(action, Issue.find(6).project) | |
2758 | post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail', |
|
2777 | post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail', | |
2759 | :issue => {:priority_id => 7, |
|
2778 | :issue => {:priority_id => 7, | |
2760 | :assigned_to_id => '', |
|
2779 | :assigned_to_id => '', | |
2761 | :custom_field_values => {'2' => ''}} |
|
2780 | :custom_field_values => {'2' => ''}} | |
2762 | assert_response 403 |
|
2781 | assert_response 403 | |
2763 | assert_not_equal "Bulk should fail", Journal.last.notes |
|
2782 | assert_not_equal "Bulk should fail", Journal.last.notes | |
2764 | end |
|
2783 | end | |
2765 |
|
2784 | |||
2766 | def test_bullk_update_should_send_a_notification |
|
2785 | def test_bullk_update_should_send_a_notification | |
2767 | @request.session[:user_id] = 2 |
|
2786 | @request.session[:user_id] = 2 | |
2768 | ActionMailer::Base.deliveries.clear |
|
2787 | ActionMailer::Base.deliveries.clear | |
2769 | post(:bulk_update, |
|
2788 | post(:bulk_update, | |
2770 | { |
|
2789 | { | |
2771 | :ids => [1, 2], |
|
2790 | :ids => [1, 2], | |
2772 | :notes => 'Bulk editing', |
|
2791 | :notes => 'Bulk editing', | |
2773 | :issue => { |
|
2792 | :issue => { | |
2774 | :priority_id => 7, |
|
2793 | :priority_id => 7, | |
2775 | :assigned_to_id => '', |
|
2794 | :assigned_to_id => '', | |
2776 | :custom_field_values => {'2' => ''} |
|
2795 | :custom_field_values => {'2' => ''} | |
2777 | } |
|
2796 | } | |
2778 | }) |
|
2797 | }) | |
2779 |
|
2798 | |||
2780 | assert_response 302 |
|
2799 | assert_response 302 | |
2781 | assert_equal 2, ActionMailer::Base.deliveries.size |
|
2800 | assert_equal 2, ActionMailer::Base.deliveries.size | |
2782 | end |
|
2801 | end | |
2783 |
|
2802 | |||
2784 | def test_bulk_update_project |
|
2803 | def test_bulk_update_project | |
2785 | @request.session[:user_id] = 2 |
|
2804 | @request.session[:user_id] = 2 | |
2786 | post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'} |
|
2805 | post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'} | |
2787 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
2806 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' | |
2788 | # Issues moved to project 2 |
|
2807 | # Issues moved to project 2 | |
2789 | assert_equal 2, Issue.find(1).project_id |
|
2808 | assert_equal 2, Issue.find(1).project_id | |
2790 | assert_equal 2, Issue.find(2).project_id |
|
2809 | assert_equal 2, Issue.find(2).project_id | |
2791 | # No tracker change |
|
2810 | # No tracker change | |
2792 | assert_equal 1, Issue.find(1).tracker_id |
|
2811 | assert_equal 1, Issue.find(1).tracker_id | |
2793 | assert_equal 2, Issue.find(2).tracker_id |
|
2812 | assert_equal 2, Issue.find(2).tracker_id | |
2794 | end |
|
2813 | end | |
2795 |
|
2814 | |||
2796 | def test_bulk_update_project_on_single_issue_should_follow_when_needed |
|
2815 | def test_bulk_update_project_on_single_issue_should_follow_when_needed | |
2797 | @request.session[:user_id] = 2 |
|
2816 | @request.session[:user_id] = 2 | |
2798 | post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1' |
|
2817 | post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1' | |
2799 | assert_redirected_to '/issues/1' |
|
2818 | assert_redirected_to '/issues/1' | |
2800 | end |
|
2819 | end | |
2801 |
|
2820 | |||
2802 | def test_bulk_update_project_on_multiple_issues_should_follow_when_needed |
|
2821 | def test_bulk_update_project_on_multiple_issues_should_follow_when_needed | |
2803 | @request.session[:user_id] = 2 |
|
2822 | @request.session[:user_id] = 2 | |
2804 | post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1' |
|
2823 | post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1' | |
2805 | assert_redirected_to '/projects/onlinestore/issues' |
|
2824 | assert_redirected_to '/projects/onlinestore/issues' | |
2806 | end |
|
2825 | end | |
2807 |
|
2826 | |||
2808 | def test_bulk_update_tracker |
|
2827 | def test_bulk_update_tracker | |
2809 | @request.session[:user_id] = 2 |
|
2828 | @request.session[:user_id] = 2 | |
2810 | post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'} |
|
2829 | post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'} | |
2811 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
2830 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' | |
2812 | assert_equal 2, Issue.find(1).tracker_id |
|
2831 | assert_equal 2, Issue.find(1).tracker_id | |
2813 | assert_equal 2, Issue.find(2).tracker_id |
|
2832 | assert_equal 2, Issue.find(2).tracker_id | |
2814 | end |
|
2833 | end | |
2815 |
|
2834 | |||
2816 | def test_bulk_update_status |
|
2835 | def test_bulk_update_status | |
2817 | @request.session[:user_id] = 2 |
|
2836 | @request.session[:user_id] = 2 | |
2818 | # update issues priority |
|
2837 | # update issues priority | |
2819 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status', |
|
2838 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status', | |
2820 | :issue => {:priority_id => '', |
|
2839 | :issue => {:priority_id => '', | |
2821 | :assigned_to_id => '', |
|
2840 | :assigned_to_id => '', | |
2822 | :status_id => '5'} |
|
2841 | :status_id => '5'} | |
2823 |
|
2842 | |||
2824 | assert_response 302 |
|
2843 | assert_response 302 | |
2825 | issue = Issue.find(1) |
|
2844 | issue = Issue.find(1) | |
2826 | assert issue.closed? |
|
2845 | assert issue.closed? | |
2827 | end |
|
2846 | end | |
2828 |
|
2847 | |||
2829 | def test_bulk_update_priority |
|
2848 | def test_bulk_update_priority | |
2830 | @request.session[:user_id] = 2 |
|
2849 | @request.session[:user_id] = 2 | |
2831 | post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6} |
|
2850 | post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6} | |
2832 |
|
2851 | |||
2833 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
2852 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' | |
2834 | assert_equal 6, Issue.find(1).priority_id |
|
2853 | assert_equal 6, Issue.find(1).priority_id | |
2835 | assert_equal 6, Issue.find(2).priority_id |
|
2854 | assert_equal 6, Issue.find(2).priority_id | |
2836 | end |
|
2855 | end | |
2837 |
|
2856 | |||
2838 | def test_bulk_update_with_notes |
|
2857 | def test_bulk_update_with_notes | |
2839 | @request.session[:user_id] = 2 |
|
2858 | @request.session[:user_id] = 2 | |
2840 | post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues' |
|
2859 | post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues' | |
2841 |
|
2860 | |||
2842 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' |
|
2861 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' | |
2843 | assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes |
|
2862 | assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes | |
2844 | assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes |
|
2863 | assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes | |
2845 | end |
|
2864 | end | |
2846 |
|
2865 | |||
2847 | def test_bulk_update_parent_id |
|
2866 | def test_bulk_update_parent_id | |
2848 | @request.session[:user_id] = 2 |
|
2867 | @request.session[:user_id] = 2 | |
2849 | post :bulk_update, :ids => [1, 3], |
|
2868 | post :bulk_update, :ids => [1, 3], | |
2850 | :notes => 'Bulk editing parent', |
|
2869 | :notes => 'Bulk editing parent', | |
2851 | :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'} |
|
2870 | :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'} | |
2852 |
|
2871 | |||
2853 | assert_response 302 |
|
2872 | assert_response 302 | |
2854 | parent = Issue.find(2) |
|
2873 | parent = Issue.find(2) | |
2855 | assert_equal parent.id, Issue.find(1).parent_id |
|
2874 | assert_equal parent.id, Issue.find(1).parent_id | |
2856 | assert_equal parent.id, Issue.find(3).parent_id |
|
2875 | assert_equal parent.id, Issue.find(3).parent_id | |
2857 | assert_equal [1, 3], parent.children.collect(&:id).sort |
|
2876 | assert_equal [1, 3], parent.children.collect(&:id).sort | |
2858 | end |
|
2877 | end | |
2859 |
|
2878 | |||
2860 | def test_bulk_update_custom_field |
|
2879 | def test_bulk_update_custom_field | |
2861 | @request.session[:user_id] = 2 |
|
2880 | @request.session[:user_id] = 2 | |
2862 | # update issues priority |
|
2881 | # update issues priority | |
2863 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field', |
|
2882 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field', | |
2864 | :issue => {:priority_id => '', |
|
2883 | :issue => {:priority_id => '', | |
2865 | :assigned_to_id => '', |
|
2884 | :assigned_to_id => '', | |
2866 | :custom_field_values => {'2' => '777'}} |
|
2885 | :custom_field_values => {'2' => '777'}} | |
2867 |
|
2886 | |||
2868 | assert_response 302 |
|
2887 | assert_response 302 | |
2869 |
|
2888 | |||
2870 | issue = Issue.find(1) |
|
2889 | issue = Issue.find(1) | |
2871 | journal = issue.journals.find(:first, :order => 'created_on DESC') |
|
2890 | journal = issue.journals.find(:first, :order => 'created_on DESC') | |
2872 | assert_equal '777', issue.custom_value_for(2).value |
|
2891 | assert_equal '777', issue.custom_value_for(2).value | |
2873 | assert_equal 1, journal.details.size |
|
2892 | assert_equal 1, journal.details.size | |
2874 | assert_equal '125', journal.details.first.old_value |
|
2893 | assert_equal '125', journal.details.first.old_value | |
2875 | assert_equal '777', journal.details.first.value |
|
2894 | assert_equal '777', journal.details.first.value | |
2876 | end |
|
2895 | end | |
2877 |
|
2896 | |||
2878 | def test_bulk_update_multi_custom_field |
|
2897 | def test_bulk_update_multi_custom_field | |
2879 | field = CustomField.find(1) |
|
2898 | field = CustomField.find(1) | |
2880 | field.update_attribute :multiple, true |
|
2899 | field.update_attribute :multiple, true | |
2881 |
|
2900 | |||
2882 | @request.session[:user_id] = 2 |
|
2901 | @request.session[:user_id] = 2 | |
2883 | post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field', |
|
2902 | post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field', | |
2884 | :issue => {:priority_id => '', |
|
2903 | :issue => {:priority_id => '', | |
2885 | :assigned_to_id => '', |
|
2904 | :assigned_to_id => '', | |
2886 | :custom_field_values => {'1' => ['MySQL', 'Oracle']}} |
|
2905 | :custom_field_values => {'1' => ['MySQL', 'Oracle']}} | |
2887 |
|
2906 | |||
2888 | assert_response 302 |
|
2907 | assert_response 302 | |
2889 |
|
2908 | |||
2890 | assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort |
|
2909 | assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort | |
2891 | assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort |
|
2910 | assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort | |
2892 | # the custom field is not associated with the issue tracker |
|
2911 | # the custom field is not associated with the issue tracker | |
2893 | assert_nil Issue.find(2).custom_field_value(1) |
|
2912 | assert_nil Issue.find(2).custom_field_value(1) | |
2894 | end |
|
2913 | end | |
2895 |
|
2914 | |||
2896 | def test_bulk_update_unassign |
|
2915 | def test_bulk_update_unassign | |
2897 | assert_not_nil Issue.find(2).assigned_to |
|
2916 | assert_not_nil Issue.find(2).assigned_to | |
2898 | @request.session[:user_id] = 2 |
|
2917 | @request.session[:user_id] = 2 | |
2899 | # unassign issues |
|
2918 | # unassign issues | |
2900 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'} |
|
2919 | post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'} | |
2901 | assert_response 302 |
|
2920 | assert_response 302 | |
2902 | # check that the issues were updated |
|
2921 | # check that the issues were updated | |
2903 | assert_nil Issue.find(2).assigned_to |
|
2922 | assert_nil Issue.find(2).assigned_to | |
2904 | end |
|
2923 | end | |
2905 |
|
2924 | |||
2906 | def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject |
|
2925 | def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject | |
2907 | @request.session[:user_id] = 2 |
|
2926 | @request.session[:user_id] = 2 | |
2908 |
|
2927 | |||
2909 | post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4} |
|
2928 | post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4} | |
2910 |
|
2929 | |||
2911 | assert_response :redirect |
|
2930 | assert_response :redirect | |
2912 | issues = Issue.find([1,2]) |
|
2931 | issues = Issue.find([1,2]) | |
2913 | issues.each do |issue| |
|
2932 | issues.each do |issue| | |
2914 | assert_equal 4, issue.fixed_version_id |
|
2933 | assert_equal 4, issue.fixed_version_id | |
2915 | assert_not_equal issue.project_id, issue.fixed_version.project_id |
|
2934 | assert_not_equal issue.project_id, issue.fixed_version.project_id | |
2916 | end |
|
2935 | end | |
2917 | end |
|
2936 | end | |
2918 |
|
2937 | |||
2919 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter |
|
2938 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter | |
2920 | @request.session[:user_id] = 2 |
|
2939 | @request.session[:user_id] = 2 | |
2921 | post :bulk_update, :ids => [1,2], :back_url => '/issues' |
|
2940 | post :bulk_update, :ids => [1,2], :back_url => '/issues' | |
2922 |
|
2941 | |||
2923 | assert_response :redirect |
|
2942 | assert_response :redirect | |
2924 | assert_redirected_to '/issues' |
|
2943 | assert_redirected_to '/issues' | |
2925 | end |
|
2944 | end | |
2926 |
|
2945 | |||
2927 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
2946 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host | |
2928 | @request.session[:user_id] = 2 |
|
2947 | @request.session[:user_id] = 2 | |
2929 | post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' |
|
2948 | post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' | |
2930 |
|
2949 | |||
2931 | assert_response :redirect |
|
2950 | assert_response :redirect | |
2932 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier |
|
2951 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier | |
2933 | end |
|
2952 | end | |
2934 |
|
2953 | |||
2935 | def test_bulk_copy_to_another_project |
|
2954 | def test_bulk_copy_to_another_project | |
2936 | @request.session[:user_id] = 2 |
|
2955 | @request.session[:user_id] = 2 | |
2937 | assert_difference 'Issue.count', 2 do |
|
2956 | assert_difference 'Issue.count', 2 do | |
2938 | assert_no_difference 'Project.find(1).issues.count' do |
|
2957 | assert_no_difference 'Project.find(1).issues.count' do | |
2939 | post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1' |
|
2958 | post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1' | |
2940 | end |
|
2959 | end | |
2941 | end |
|
2960 | end | |
2942 | assert_redirected_to '/projects/ecookbook/issues' |
|
2961 | assert_redirected_to '/projects/ecookbook/issues' | |
2943 | end |
|
2962 | end | |
2944 |
|
2963 | |||
2945 | def test_bulk_copy_should_allow_not_changing_the_issue_attributes |
|
2964 | def test_bulk_copy_should_allow_not_changing_the_issue_attributes | |
2946 | @request.session[:user_id] = 2 |
|
2965 | @request.session[:user_id] = 2 | |
2947 | issue_before_move = Issue.find(1) |
|
2966 | issue_before_move = Issue.find(1) | |
2948 | assert_difference 'Issue.count', 1 do |
|
2967 | assert_difference 'Issue.count', 1 do | |
2949 | assert_no_difference 'Project.find(1).issues.count' do |
|
2968 | assert_no_difference 'Project.find(1).issues.count' do | |
2950 | post :bulk_update, :ids => [1], :copy => '1', |
|
2969 | post :bulk_update, :ids => [1], :copy => '1', | |
2951 | :issue => { |
|
2970 | :issue => { | |
2952 | :project_id => '2', :tracker_id => '', :assigned_to_id => '', |
|
2971 | :project_id => '2', :tracker_id => '', :assigned_to_id => '', | |
2953 | :status_id => '', :start_date => '', :due_date => '' |
|
2972 | :status_id => '', :start_date => '', :due_date => '' | |
2954 | } |
|
2973 | } | |
2955 | end |
|
2974 | end | |
2956 | end |
|
2975 | end | |
2957 | issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2}) |
|
2976 | issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2}) | |
2958 | assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id |
|
2977 | assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id | |
2959 | assert_equal issue_before_move.status_id, issue_after_move.status_id |
|
2978 | assert_equal issue_before_move.status_id, issue_after_move.status_id | |
2960 | assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id |
|
2979 | assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id | |
2961 | end |
|
2980 | end | |
2962 |
|
2981 | |||
2963 | def test_bulk_copy_should_allow_changing_the_issue_attributes |
|
2982 | def test_bulk_copy_should_allow_changing_the_issue_attributes | |
2964 | # Fixes random test failure with Mysql |
|
2983 | # Fixes random test failure with Mysql | |
2965 | # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) |
|
2984 | # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) | |
2966 | # doesn't return the expected results |
|
2985 | # doesn't return the expected results | |
2967 | Issue.delete_all("project_id=2") |
|
2986 | Issue.delete_all("project_id=2") | |
2968 |
|
2987 | |||
2969 | @request.session[:user_id] = 2 |
|
2988 | @request.session[:user_id] = 2 | |
2970 | assert_difference 'Issue.count', 2 do |
|
2989 | assert_difference 'Issue.count', 2 do | |
2971 | assert_no_difference 'Project.find(1).issues.count' do |
|
2990 | assert_no_difference 'Project.find(1).issues.count' do | |
2972 | post :bulk_update, :ids => [1, 2], :copy => '1', |
|
2991 | post :bulk_update, :ids => [1, 2], :copy => '1', | |
2973 | :issue => { |
|
2992 | :issue => { | |
2974 | :project_id => '2', :tracker_id => '', :assigned_to_id => '4', |
|
2993 | :project_id => '2', :tracker_id => '', :assigned_to_id => '4', | |
2975 | :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31' |
|
2994 | :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31' | |
2976 | } |
|
2995 | } | |
2977 | end |
|
2996 | end | |
2978 | end |
|
2997 | end | |
2979 |
|
2998 | |||
2980 | copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) |
|
2999 | copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) | |
2981 | assert_equal 2, copied_issues.size |
|
3000 | assert_equal 2, copied_issues.size | |
2982 | copied_issues.each do |issue| |
|
3001 | copied_issues.each do |issue| | |
2983 | assert_equal 2, issue.project_id, "Project is incorrect" |
|
3002 | assert_equal 2, issue.project_id, "Project is incorrect" | |
2984 | assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" |
|
3003 | assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" | |
2985 | assert_equal 3, issue.status_id, "Status is incorrect" |
|
3004 | assert_equal 3, issue.status_id, "Status is incorrect" | |
2986 | assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect" |
|
3005 | assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect" | |
2987 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" |
|
3006 | assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect" | |
2988 | end |
|
3007 | end | |
2989 | end |
|
3008 | end | |
2990 |
|
3009 | |||
2991 | def test_bulk_copy_should_allow_adding_a_note |
|
3010 | def test_bulk_copy_should_allow_adding_a_note | |
2992 | @request.session[:user_id] = 2 |
|
3011 | @request.session[:user_id] = 2 | |
2993 | assert_difference 'Issue.count', 1 do |
|
3012 | assert_difference 'Issue.count', 1 do | |
2994 | post :bulk_update, :ids => [1], :copy => '1', |
|
3013 | post :bulk_update, :ids => [1], :copy => '1', | |
2995 | :notes => 'Copying one issue', |
|
3014 | :notes => 'Copying one issue', | |
2996 | :issue => { |
|
3015 | :issue => { | |
2997 | :project_id => '', :tracker_id => '', :assigned_to_id => '4', |
|
3016 | :project_id => '', :tracker_id => '', :assigned_to_id => '4', | |
2998 | :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31' |
|
3017 | :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31' | |
2999 | } |
|
3018 | } | |
3000 | end |
|
3019 | end | |
3001 |
|
3020 | |||
3002 | issue = Issue.first(:order => 'id DESC') |
|
3021 | issue = Issue.first(:order => 'id DESC') | |
3003 | assert_equal 1, issue.journals.size |
|
3022 | assert_equal 1, issue.journals.size | |
3004 | journal = issue.journals.first |
|
3023 | journal = issue.journals.first | |
3005 | assert_equal 0, journal.details.size |
|
3024 | assert_equal 0, journal.details.size | |
3006 | assert_equal 'Copying one issue', journal.notes |
|
3025 | assert_equal 'Copying one issue', journal.notes | |
3007 | end |
|
3026 | end | |
3008 |
|
3027 | |||
3009 | def test_bulk_copy_to_another_project_should_follow_when_needed |
|
3028 | def test_bulk_copy_to_another_project_should_follow_when_needed | |
3010 | @request.session[:user_id] = 2 |
|
3029 | @request.session[:user_id] = 2 | |
3011 | post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1' |
|
3030 | post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1' | |
3012 | issue = Issue.first(:order => 'id DESC') |
|
3031 | issue = Issue.first(:order => 'id DESC') | |
3013 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
3032 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue | |
3014 | end |
|
3033 | end | |
3015 |
|
3034 | |||
3016 | def test_destroy_issue_with_no_time_entries |
|
3035 | def test_destroy_issue_with_no_time_entries | |
3017 | assert_nil TimeEntry.find_by_issue_id(2) |
|
3036 | assert_nil TimeEntry.find_by_issue_id(2) | |
3018 | @request.session[:user_id] = 2 |
|
3037 | @request.session[:user_id] = 2 | |
3019 |
|
3038 | |||
3020 | assert_difference 'Issue.count', -1 do |
|
3039 | assert_difference 'Issue.count', -1 do | |
3021 | delete :destroy, :id => 2 |
|
3040 | delete :destroy, :id => 2 | |
3022 | end |
|
3041 | end | |
3023 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
3042 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
3024 | assert_nil Issue.find_by_id(2) |
|
3043 | assert_nil Issue.find_by_id(2) | |
3025 | end |
|
3044 | end | |
3026 |
|
3045 | |||
3027 | def test_destroy_issues_with_time_entries |
|
3046 | def test_destroy_issues_with_time_entries | |
3028 | @request.session[:user_id] = 2 |
|
3047 | @request.session[:user_id] = 2 | |
3029 |
|
3048 | |||
3030 | assert_no_difference 'Issue.count' do |
|
3049 | assert_no_difference 'Issue.count' do | |
3031 | delete :destroy, :ids => [1, 3] |
|
3050 | delete :destroy, :ids => [1, 3] | |
3032 | end |
|
3051 | end | |
3033 | assert_response :success |
|
3052 | assert_response :success | |
3034 | assert_template 'destroy' |
|
3053 | assert_template 'destroy' | |
3035 | assert_not_nil assigns(:hours) |
|
3054 | assert_not_nil assigns(:hours) | |
3036 | assert Issue.find_by_id(1) && Issue.find_by_id(3) |
|
3055 | assert Issue.find_by_id(1) && Issue.find_by_id(3) | |
3037 | assert_tag 'form', |
|
3056 | assert_tag 'form', | |
3038 | :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}} |
|
3057 | :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}} | |
3039 | end |
|
3058 | end | |
3040 |
|
3059 | |||
3041 | def test_destroy_issues_and_destroy_time_entries |
|
3060 | def test_destroy_issues_and_destroy_time_entries | |
3042 | @request.session[:user_id] = 2 |
|
3061 | @request.session[:user_id] = 2 | |
3043 |
|
3062 | |||
3044 | assert_difference 'Issue.count', -2 do |
|
3063 | assert_difference 'Issue.count', -2 do | |
3045 | assert_difference 'TimeEntry.count', -3 do |
|
3064 | assert_difference 'TimeEntry.count', -3 do | |
3046 | delete :destroy, :ids => [1, 3], :todo => 'destroy' |
|
3065 | delete :destroy, :ids => [1, 3], :todo => 'destroy' | |
3047 | end |
|
3066 | end | |
3048 | end |
|
3067 | end | |
3049 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
3068 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
3050 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
3069 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
3051 | assert_nil TimeEntry.find_by_id([1, 2]) |
|
3070 | assert_nil TimeEntry.find_by_id([1, 2]) | |
3052 | end |
|
3071 | end | |
3053 |
|
3072 | |||
3054 | def test_destroy_issues_and_assign_time_entries_to_project |
|
3073 | def test_destroy_issues_and_assign_time_entries_to_project | |
3055 | @request.session[:user_id] = 2 |
|
3074 | @request.session[:user_id] = 2 | |
3056 |
|
3075 | |||
3057 | assert_difference 'Issue.count', -2 do |
|
3076 | assert_difference 'Issue.count', -2 do | |
3058 | assert_no_difference 'TimeEntry.count' do |
|
3077 | assert_no_difference 'TimeEntry.count' do | |
3059 | delete :destroy, :ids => [1, 3], :todo => 'nullify' |
|
3078 | delete :destroy, :ids => [1, 3], :todo => 'nullify' | |
3060 | end |
|
3079 | end | |
3061 | end |
|
3080 | end | |
3062 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
3081 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
3063 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
3082 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
3064 | assert_nil TimeEntry.find(1).issue_id |
|
3083 | assert_nil TimeEntry.find(1).issue_id | |
3065 | assert_nil TimeEntry.find(2).issue_id |
|
3084 | assert_nil TimeEntry.find(2).issue_id | |
3066 | end |
|
3085 | end | |
3067 |
|
3086 | |||
3068 | def test_destroy_issues_and_reassign_time_entries_to_another_issue |
|
3087 | def test_destroy_issues_and_reassign_time_entries_to_another_issue | |
3069 | @request.session[:user_id] = 2 |
|
3088 | @request.session[:user_id] = 2 | |
3070 |
|
3089 | |||
3071 | assert_difference 'Issue.count', -2 do |
|
3090 | assert_difference 'Issue.count', -2 do | |
3072 | assert_no_difference 'TimeEntry.count' do |
|
3091 | assert_no_difference 'TimeEntry.count' do | |
3073 | delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 |
|
3092 | delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 | |
3074 | end |
|
3093 | end | |
3075 | end |
|
3094 | end | |
3076 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
3095 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
3077 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
3096 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
3078 | assert_equal 2, TimeEntry.find(1).issue_id |
|
3097 | assert_equal 2, TimeEntry.find(1).issue_id | |
3079 | assert_equal 2, TimeEntry.find(2).issue_id |
|
3098 | assert_equal 2, TimeEntry.find(2).issue_id | |
3080 | end |
|
3099 | end | |
3081 |
|
3100 | |||
3082 | def test_destroy_issues_from_different_projects |
|
3101 | def test_destroy_issues_from_different_projects | |
3083 | @request.session[:user_id] = 2 |
|
3102 | @request.session[:user_id] = 2 | |
3084 |
|
3103 | |||
3085 | assert_difference 'Issue.count', -3 do |
|
3104 | assert_difference 'Issue.count', -3 do | |
3086 | delete :destroy, :ids => [1, 2, 6], :todo => 'destroy' |
|
3105 | delete :destroy, :ids => [1, 2, 6], :todo => 'destroy' | |
3087 | end |
|
3106 | end | |
3088 | assert_redirected_to :controller => 'issues', :action => 'index' |
|
3107 | assert_redirected_to :controller => 'issues', :action => 'index' | |
3089 | assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6)) |
|
3108 | assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6)) | |
3090 | end |
|
3109 | end | |
3091 |
|
3110 | |||
3092 | def test_destroy_parent_and_child_issues |
|
3111 | def test_destroy_parent_and_child_issues | |
3093 | parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue') |
|
3112 | parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue') | |
3094 | child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id) |
|
3113 | child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id) | |
3095 | assert child.is_descendant_of?(parent.reload) |
|
3114 | assert child.is_descendant_of?(parent.reload) | |
3096 |
|
3115 | |||
3097 | @request.session[:user_id] = 2 |
|
3116 | @request.session[:user_id] = 2 | |
3098 | assert_difference 'Issue.count', -2 do |
|
3117 | assert_difference 'Issue.count', -2 do | |
3099 | delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy' |
|
3118 | delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy' | |
3100 | end |
|
3119 | end | |
3101 | assert_response 302 |
|
3120 | assert_response 302 | |
3102 | end |
|
3121 | end | |
3103 |
|
3122 | |||
3104 | def test_default_search_scope |
|
3123 | def test_default_search_scope | |
3105 | get :index |
|
3124 | get :index | |
3106 | assert_tag :div, :attributes => {:id => 'quick-search'}, |
|
3125 | assert_tag :div, :attributes => {:id => 'quick-search'}, | |
3107 | :child => {:tag => 'form', |
|
3126 | :child => {:tag => 'form', | |
3108 | :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} |
|
3127 | :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} | |
3109 | end |
|
3128 | end | |
3110 | end |
|
3129 | end |
General Comments 0
You need to be logged in to leave comments.
Login now