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