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