Chris@0
|
1 # -*- coding: utf-8 -*-
|
Chris@909
|
2 # Redmine - project management software
|
Chris@1494
|
3 # Copyright (C) 2006-2014 Jean-Philippe Lang
|
Chris@0
|
4 #
|
Chris@0
|
5 # This program is free software; you can redistribute it and/or
|
Chris@0
|
6 # modify it under the terms of the GNU General Public License
|
Chris@0
|
7 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
8 # of the License, or (at your option) any later version.
|
Chris@909
|
9 #
|
Chris@0
|
10 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
13 # GNU General Public License for more details.
|
Chris@909
|
14 #
|
Chris@0
|
15 # You should have received a copy of the GNU General Public License
|
Chris@0
|
16 # along with this program; if not, write to the Free Software
|
Chris@0
|
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
18
|
Chris@119
|
19 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
20
|
Chris@0
|
21 class TimelogControllerTest < ActionController::TestCase
|
Chris@909
|
22 fixtures :projects, :enabled_modules, :roles, :members,
|
Chris@909
|
23 :member_roles, :issues, :time_entries, :users,
|
Chris@909
|
24 :trackers, :enumerations, :issue_statuses,
|
Chris@1464
|
25 :custom_fields, :custom_values,
|
Chris@1464
|
26 :projects_trackers, :custom_fields_trackers,
|
Chris@1464
|
27 :custom_fields_projects
|
Chris@909
|
28
|
Chris@909
|
29 include Redmine::I18n
|
Chris@0
|
30
|
Chris@1115
|
31 def test_new_with_project_id
|
Chris@0
|
32 @request.session[:user_id] = 3
|
chris@37
|
33 get :new, :project_id => 1
|
Chris@0
|
34 assert_response :success
|
Chris@1115
|
35 assert_template 'new'
|
Chris@1115
|
36 assert_select 'select[name=?]', 'time_entry[project_id]', 0
|
Chris@1115
|
37 assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]'
|
Chris@0
|
38 end
|
Chris@909
|
39
|
Chris@1115
|
40 def test_new_with_issue_id
|
Chris@1115
|
41 @request.session[:user_id] = 3
|
Chris@1115
|
42 get :new, :issue_id => 2
|
Chris@1115
|
43 assert_response :success
|
Chris@1115
|
44 assert_template 'new'
|
Chris@1115
|
45 assert_select 'select[name=?]', 'time_entry[project_id]', 0
|
Chris@1115
|
46 assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]'
|
Chris@1115
|
47 end
|
Chris@1115
|
48
|
Chris@1115
|
49 def test_new_without_project
|
Chris@1115
|
50 @request.session[:user_id] = 3
|
Chris@1115
|
51 get :new
|
Chris@1115
|
52 assert_response :success
|
Chris@1115
|
53 assert_template 'new'
|
Chris@1115
|
54 assert_select 'select[name=?]', 'time_entry[project_id]'
|
Chris@1115
|
55 assert_select 'input[name=?]', 'time_entry[project_id]', 0
|
Chris@1115
|
56 end
|
Chris@1115
|
57
|
Chris@1115
|
58 def test_new_without_project_should_prefill_the_form
|
Chris@1115
|
59 @request.session[:user_id] = 3
|
Chris@1115
|
60 get :new, :time_entry => {:project_id => '1'}
|
Chris@1115
|
61 assert_response :success
|
Chris@1115
|
62 assert_template 'new'
|
Chris@1115
|
63 assert_select 'select[name=?]', 'time_entry[project_id]' do
|
Chris@1115
|
64 assert_select 'option[value=1][selected=selected]'
|
Chris@1115
|
65 end
|
Chris@1115
|
66 assert_select 'input[name=?]', 'time_entry[project_id]', 0
|
Chris@1115
|
67 end
|
Chris@1115
|
68
|
Chris@1115
|
69 def test_new_without_project_should_deny_without_permission
|
Chris@1115
|
70 Role.all.each {|role| role.remove_permission! :log_time}
|
Chris@1115
|
71 @request.session[:user_id] = 3
|
Chris@1115
|
72
|
Chris@1115
|
73 get :new
|
Chris@1115
|
74 assert_response 403
|
Chris@1115
|
75 end
|
Chris@1115
|
76
|
Chris@1115
|
77 def test_new_should_select_default_activity
|
chris@37
|
78 @request.session[:user_id] = 3
|
chris@37
|
79 get :new, :project_id => 1
|
chris@37
|
80 assert_response :success
|
Chris@1115
|
81 assert_select 'select[name=?]', 'time_entry[activity_id]' do
|
Chris@1115
|
82 assert_select 'option[selected=selected]', :text => 'Development'
|
Chris@1115
|
83 end
|
Chris@1115
|
84 end
|
Chris@1115
|
85
|
Chris@1115
|
86 def test_new_should_only_show_active_time_entry_activities
|
Chris@1115
|
87 @request.session[:user_id] = 3
|
Chris@1115
|
88 get :new, :project_id => 1
|
Chris@1115
|
89 assert_response :success
|
Chris@1115
|
90 assert_no_tag 'option', :content => 'Inactive Activity'
|
chris@37
|
91 end
|
chris@37
|
92
|
Chris@0
|
93 def test_get_edit_existing_time
|
Chris@0
|
94 @request.session[:user_id] = 2
|
Chris@0
|
95 get :edit, :id => 2, :project_id => nil
|
Chris@0
|
96 assert_response :success
|
Chris@0
|
97 assert_template 'edit'
|
Chris@0
|
98 # Default activity selected
|
chris@37
|
99 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' }
|
Chris@0
|
100 end
|
Chris@909
|
101
|
Chris@0
|
102 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
|
Chris@0
|
103 te = TimeEntry.find(1)
|
Chris@0
|
104 te.activity = TimeEntryActivity.find_by_name("Inactive Activity")
|
Chris@0
|
105 te.save!
|
Chris@0
|
106
|
Chris@0
|
107 @request.session[:user_id] = 1
|
Chris@0
|
108 get :edit, :project_id => 1, :id => 1
|
Chris@0
|
109 assert_response :success
|
Chris@0
|
110 assert_template 'edit'
|
Chris@0
|
111 # Blank option since nothing is pre-selected
|
Chris@0
|
112 assert_tag :tag => 'option', :content => '--- Please select ---'
|
Chris@0
|
113 end
|
Chris@909
|
114
|
chris@37
|
115 def test_post_create
|
Chris@0
|
116 # TODO: should POST to issues’ time log instead of project. change form
|
Chris@0
|
117 # and routing
|
Chris@0
|
118 @request.session[:user_id] = 3
|
chris@37
|
119 post :create, :project_id => 1,
|
Chris@0
|
120 :time_entry => {:comments => 'Some work on TimelogControllerTest',
|
Chris@0
|
121 # Not the default activity
|
Chris@0
|
122 :activity_id => '11',
|
Chris@0
|
123 :spent_on => '2008-03-14',
|
Chris@0
|
124 :issue_id => '1',
|
Chris@0
|
125 :hours => '7.3'}
|
chris@37
|
126 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
|
Chris@909
|
127
|
Chris@0
|
128 i = Issue.find(1)
|
Chris@0
|
129 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
|
Chris@0
|
130 assert_not_nil t
|
Chris@0
|
131 assert_equal 11, t.activity_id
|
Chris@0
|
132 assert_equal 7.3, t.hours
|
Chris@0
|
133 assert_equal 3, t.user_id
|
Chris@0
|
134 assert_equal i, t.issue
|
Chris@0
|
135 assert_equal i.project, t.project
|
Chris@0
|
136 end
|
Chris@119
|
137
|
Chris@119
|
138 def test_post_create_with_blank_issue
|
Chris@119
|
139 # TODO: should POST to issues’ time log instead of project. change form
|
Chris@119
|
140 # and routing
|
Chris@119
|
141 @request.session[:user_id] = 3
|
Chris@119
|
142 post :create, :project_id => 1,
|
Chris@119
|
143 :time_entry => {:comments => 'Some work on TimelogControllerTest',
|
Chris@119
|
144 # Not the default activity
|
Chris@119
|
145 :activity_id => '11',
|
Chris@119
|
146 :issue_id => '',
|
Chris@119
|
147 :spent_on => '2008-03-14',
|
Chris@119
|
148 :hours => '7.3'}
|
Chris@119
|
149 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
|
Chris@909
|
150
|
Chris@119
|
151 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
|
Chris@119
|
152 assert_not_nil t
|
Chris@119
|
153 assert_equal 11, t.activity_id
|
Chris@119
|
154 assert_equal 7.3, t.hours
|
Chris@119
|
155 assert_equal 3, t.user_id
|
Chris@119
|
156 end
|
Chris@909
|
157
|
Chris@1115
|
158 def test_create_and_continue
|
Chris@1115
|
159 @request.session[:user_id] = 2
|
Chris@1115
|
160 post :create, :project_id => 1,
|
Chris@1115
|
161 :time_entry => {:activity_id => '11',
|
Chris@1115
|
162 :issue_id => '',
|
Chris@1115
|
163 :spent_on => '2008-03-14',
|
Chris@1115
|
164 :hours => '7.3'},
|
Chris@1115
|
165 :continue => '1'
|
Chris@1115
|
166 assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D='
|
Chris@1115
|
167 end
|
Chris@1115
|
168
|
Chris@1115
|
169 def test_create_and_continue_with_issue_id
|
Chris@1115
|
170 @request.session[:user_id] = 2
|
Chris@1115
|
171 post :create, :project_id => 1,
|
Chris@1115
|
172 :time_entry => {:activity_id => '11',
|
Chris@1115
|
173 :issue_id => '1',
|
Chris@1115
|
174 :spent_on => '2008-03-14',
|
Chris@1115
|
175 :hours => '7.3'},
|
Chris@1115
|
176 :continue => '1'
|
Chris@1115
|
177 assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1'
|
Chris@1115
|
178 end
|
Chris@1115
|
179
|
Chris@1115
|
180 def test_create_and_continue_without_project
|
Chris@1115
|
181 @request.session[:user_id] = 2
|
Chris@1115
|
182 post :create, :time_entry => {:project_id => '1',
|
Chris@1115
|
183 :activity_id => '11',
|
Chris@1115
|
184 :issue_id => '',
|
Chris@1115
|
185 :spent_on => '2008-03-14',
|
Chris@1115
|
186 :hours => '7.3'},
|
Chris@1115
|
187 :continue => '1'
|
Chris@1115
|
188
|
Chris@1115
|
189 assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1'
|
Chris@1115
|
190 end
|
Chris@1115
|
191
|
Chris@909
|
192 def test_create_without_log_time_permission_should_be_denied
|
Chris@909
|
193 @request.session[:user_id] = 2
|
Chris@909
|
194 Role.find_by_name('Manager').remove_permission! :log_time
|
Chris@909
|
195 post :create, :project_id => 1,
|
Chris@909
|
196 :time_entry => {:activity_id => '11',
|
Chris@909
|
197 :issue_id => '',
|
Chris@909
|
198 :spent_on => '2008-03-14',
|
Chris@909
|
199 :hours => '7.3'}
|
Chris@909
|
200
|
Chris@909
|
201 assert_response 403
|
Chris@909
|
202 end
|
Chris@909
|
203
|
Chris@1115
|
204 def test_create_with_failure
|
Chris@1115
|
205 @request.session[:user_id] = 2
|
Chris@1115
|
206 post :create, :project_id => 1,
|
Chris@1115
|
207 :time_entry => {:activity_id => '',
|
Chris@1115
|
208 :issue_id => '',
|
Chris@1115
|
209 :spent_on => '2008-03-14',
|
Chris@1115
|
210 :hours => '7.3'}
|
Chris@1115
|
211
|
Chris@1115
|
212 assert_response :success
|
Chris@1115
|
213 assert_template 'new'
|
Chris@1115
|
214 end
|
Chris@1115
|
215
|
Chris@1115
|
216 def test_create_without_project
|
Chris@1115
|
217 @request.session[:user_id] = 2
|
Chris@1115
|
218 assert_difference 'TimeEntry.count' do
|
Chris@1115
|
219 post :create, :time_entry => {:project_id => '1',
|
Chris@1115
|
220 :activity_id => '11',
|
Chris@1115
|
221 :issue_id => '',
|
Chris@1115
|
222 :spent_on => '2008-03-14',
|
Chris@1115
|
223 :hours => '7.3'}
|
Chris@1115
|
224 end
|
Chris@1115
|
225
|
Chris@1115
|
226 assert_redirected_to '/projects/ecookbook/time_entries'
|
Chris@1517
|
227 time_entry = TimeEntry.order('id DESC').first
|
Chris@1115
|
228 assert_equal 1, time_entry.project_id
|
Chris@1115
|
229 end
|
Chris@1115
|
230
|
Chris@1115
|
231 def test_create_without_project_should_fail_with_issue_not_inside_project
|
Chris@1115
|
232 @request.session[:user_id] = 2
|
Chris@1115
|
233 assert_no_difference 'TimeEntry.count' do
|
Chris@1115
|
234 post :create, :time_entry => {:project_id => '1',
|
Chris@1115
|
235 :activity_id => '11',
|
Chris@1115
|
236 :issue_id => '5',
|
Chris@1115
|
237 :spent_on => '2008-03-14',
|
Chris@1115
|
238 :hours => '7.3'}
|
Chris@1115
|
239 end
|
Chris@1115
|
240
|
Chris@1115
|
241 assert_response :success
|
Chris@1115
|
242 assert assigns(:time_entry).errors[:issue_id].present?
|
Chris@1115
|
243 end
|
Chris@1115
|
244
|
Chris@1115
|
245 def test_create_without_project_should_deny_without_permission
|
Chris@1115
|
246 @request.session[:user_id] = 2
|
Chris@1115
|
247 Project.find(3).disable_module!(:time_tracking)
|
Chris@1115
|
248
|
Chris@1115
|
249 assert_no_difference 'TimeEntry.count' do
|
Chris@1115
|
250 post :create, :time_entry => {:project_id => '3',
|
Chris@1115
|
251 :activity_id => '11',
|
Chris@1115
|
252 :issue_id => '',
|
Chris@1115
|
253 :spent_on => '2008-03-14',
|
Chris@1115
|
254 :hours => '7.3'}
|
Chris@1115
|
255 end
|
Chris@1115
|
256
|
Chris@1115
|
257 assert_response 403
|
Chris@1115
|
258 end
|
Chris@1115
|
259
|
Chris@1115
|
260 def test_create_without_project_with_failure
|
Chris@1115
|
261 @request.session[:user_id] = 2
|
Chris@1115
|
262 assert_no_difference 'TimeEntry.count' do
|
Chris@1115
|
263 post :create, :time_entry => {:project_id => '1',
|
Chris@1115
|
264 :activity_id => '11',
|
Chris@1115
|
265 :issue_id => '',
|
Chris@1115
|
266 :spent_on => '2008-03-14',
|
Chris@1115
|
267 :hours => ''}
|
Chris@1115
|
268 end
|
Chris@1115
|
269
|
Chris@1115
|
270 assert_response :success
|
Chris@1115
|
271 assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'},
|
Chris@1115
|
272 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
|
Chris@1115
|
273 end
|
Chris@1115
|
274
|
Chris@0
|
275 def test_update
|
Chris@0
|
276 entry = TimeEntry.find(1)
|
Chris@0
|
277 assert_equal 1, entry.issue_id
|
Chris@0
|
278 assert_equal 2, entry.user_id
|
Chris@909
|
279
|
Chris@0
|
280 @request.session[:user_id] = 1
|
chris@37
|
281 put :update, :id => 1,
|
Chris@0
|
282 :time_entry => {:issue_id => '2',
|
Chris@0
|
283 :hours => '8'}
|
chris@37
|
284 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
|
Chris@0
|
285 entry.reload
|
Chris@909
|
286
|
Chris@0
|
287 assert_equal 8, entry.hours
|
Chris@0
|
288 assert_equal 2, entry.issue_id
|
Chris@0
|
289 assert_equal 2, entry.user_id
|
Chris@0
|
290 end
|
Chris@441
|
291
|
Chris@1517
|
292 def test_update_should_allow_to_change_issue_to_another_project
|
Chris@1517
|
293 entry = TimeEntry.generate!(:issue_id => 1)
|
Chris@1517
|
294
|
Chris@1517
|
295 @request.session[:user_id] = 1
|
Chris@1517
|
296 put :update, :id => entry.id, :time_entry => {:issue_id => '5'}
|
Chris@1517
|
297 assert_response 302
|
Chris@1517
|
298 entry.reload
|
Chris@1517
|
299
|
Chris@1517
|
300 assert_equal 5, entry.issue_id
|
Chris@1517
|
301 assert_equal 3, entry.project_id
|
Chris@1517
|
302 end
|
Chris@1517
|
303
|
Chris@1517
|
304 def test_update_should_not_allow_to_change_issue_to_an_invalid_project
|
Chris@1517
|
305 entry = TimeEntry.generate!(:issue_id => 1)
|
Chris@1517
|
306 Project.find(3).disable_module!(:time_tracking)
|
Chris@1517
|
307
|
Chris@1517
|
308 @request.session[:user_id] = 1
|
Chris@1517
|
309 put :update, :id => entry.id, :time_entry => {:issue_id => '5'}
|
Chris@1517
|
310 assert_response 200
|
Chris@1517
|
311 assert_include "Issue is invalid", assigns(:time_entry).errors.full_messages
|
Chris@1517
|
312 end
|
Chris@1517
|
313
|
Chris@441
|
314 def test_get_bulk_edit
|
Chris@441
|
315 @request.session[:user_id] = 2
|
Chris@441
|
316 get :bulk_edit, :ids => [1, 2]
|
Chris@441
|
317 assert_response :success
|
Chris@441
|
318 assert_template 'bulk_edit'
|
Chris@909
|
319
|
Chris@1464
|
320 assert_select 'ul#bulk-selection' do
|
Chris@1464
|
321 assert_select 'li', 2
|
Chris@1464
|
322 assert_select 'li a', :text => '03/23/2007 - eCookbook: 4.25 hours'
|
Chris@1464
|
323 end
|
Chris@1115
|
324
|
Chris@1464
|
325 assert_select 'form#bulk_edit_form[action=?]', '/time_entries/bulk_update' do
|
Chris@1464
|
326 # System wide custom field
|
Chris@1464
|
327 assert_select 'select[name=?]', 'time_entry[custom_field_values][10]'
|
Chris@1464
|
328
|
Chris@1464
|
329 # Activities
|
Chris@1464
|
330 assert_select 'select[name=?]', 'time_entry[activity_id]' do
|
Chris@1464
|
331 assert_select 'option[value=]', :text => '(No change)'
|
Chris@1464
|
332 assert_select 'option[value=9]', :text => 'Design'
|
Chris@1464
|
333 end
|
Chris@1115
|
334 end
|
Chris@441
|
335 end
|
Chris@441
|
336
|
Chris@441
|
337 def test_get_bulk_edit_on_different_projects
|
Chris@441
|
338 @request.session[:user_id] = 2
|
Chris@441
|
339 get :bulk_edit, :ids => [1, 2, 6]
|
Chris@441
|
340 assert_response :success
|
Chris@441
|
341 assert_template 'bulk_edit'
|
Chris@441
|
342 end
|
Chris@441
|
343
|
Chris@441
|
344 def test_bulk_update
|
Chris@441
|
345 @request.session[:user_id] = 2
|
Chris@441
|
346 # update time entry activity
|
Chris@441
|
347 post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9}
|
Chris@909
|
348
|
Chris@441
|
349 assert_response 302
|
Chris@441
|
350 # check that the issues were updated
|
Chris@1517
|
351 assert_equal [9, 9], TimeEntry.where(:id => [1, 2]).collect {|i| i.activity_id}
|
Chris@441
|
352 end
|
Chris@441
|
353
|
Chris@1115
|
354 def test_bulk_update_with_failure
|
Chris@1115
|
355 @request.session[:user_id] = 2
|
Chris@1115
|
356 post :bulk_update, :ids => [1, 2], :time_entry => { :hours => 'A'}
|
Chris@1115
|
357
|
Chris@1115
|
358 assert_response 302
|
Chris@1115
|
359 assert_match /Failed to save 2 time entrie/, flash[:error]
|
Chris@1115
|
360 end
|
Chris@1115
|
361
|
Chris@441
|
362 def test_bulk_update_on_different_projects
|
Chris@441
|
363 @request.session[:user_id] = 2
|
Chris@909
|
364 # makes user a manager on the other project
|
Chris@909
|
365 Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1])
|
Chris@909
|
366
|
Chris@441
|
367 # update time entry activity
|
Chris@441
|
368 post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 }
|
Chris@909
|
369
|
Chris@441
|
370 assert_response 302
|
Chris@441
|
371 # check that the issues were updated
|
Chris@1517
|
372 assert_equal [9, 9, 9], TimeEntry.where(:id => [1, 2, 4]).collect {|i| i.activity_id}
|
Chris@441
|
373 end
|
Chris@441
|
374
|
Chris@441
|
375 def test_bulk_update_on_different_projects_without_rights
|
Chris@441
|
376 @request.session[:user_id] = 3
|
Chris@441
|
377 user = User.find(3)
|
Chris@441
|
378 action = { :controller => "timelog", :action => "bulk_update" }
|
Chris@441
|
379 assert user.allowed_to?(action, TimeEntry.find(1).project)
|
Chris@441
|
380 assert ! user.allowed_to?(action, TimeEntry.find(5).project)
|
Chris@441
|
381 post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 }
|
Chris@441
|
382 assert_response 403
|
Chris@441
|
383 end
|
Chris@441
|
384
|
Chris@441
|
385 def test_bulk_update_custom_field
|
Chris@441
|
386 @request.session[:user_id] = 2
|
Chris@441
|
387 post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} }
|
Chris@909
|
388
|
Chris@441
|
389 assert_response 302
|
Chris@1517
|
390 assert_equal ["0", "0"], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(10).value}
|
Chris@441
|
391 end
|
Chris@441
|
392
|
Chris@441
|
393 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
|
Chris@441
|
394 @request.session[:user_id] = 2
|
Chris@441
|
395 post :bulk_update, :ids => [1,2], :back_url => '/time_entries'
|
Chris@441
|
396
|
Chris@441
|
397 assert_response :redirect
|
Chris@441
|
398 assert_redirected_to '/time_entries'
|
Chris@441
|
399 end
|
Chris@441
|
400
|
Chris@441
|
401 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
|
Chris@441
|
402 @request.session[:user_id] = 2
|
Chris@441
|
403 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
|
Chris@441
|
404
|
Chris@441
|
405 assert_response :redirect
|
Chris@441
|
406 assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier
|
Chris@441
|
407 end
|
Chris@909
|
408
|
Chris@909
|
409 def test_post_bulk_update_without_edit_permission_should_be_denied
|
Chris@909
|
410 @request.session[:user_id] = 2
|
Chris@909
|
411 Role.find_by_name('Manager').remove_permission! :edit_time_entries
|
Chris@909
|
412 post :bulk_update, :ids => [1,2]
|
Chris@909
|
413
|
Chris@909
|
414 assert_response 403
|
Chris@909
|
415 end
|
Chris@909
|
416
|
Chris@0
|
417 def test_destroy
|
Chris@0
|
418 @request.session[:user_id] = 2
|
chris@37
|
419 delete :destroy, :id => 1
|
chris@37
|
420 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
|
Chris@0
|
421 assert_equal I18n.t(:notice_successful_delete), flash[:notice]
|
Chris@0
|
422 assert_nil TimeEntry.find_by_id(1)
|
Chris@0
|
423 end
|
Chris@909
|
424
|
Chris@0
|
425 def test_destroy_should_fail
|
Chris@0
|
426 # simulate that this fails (e.g. due to a plugin), see #5700
|
Chris@441
|
427 TimeEntry.any_instance.expects(:destroy).returns(false)
|
Chris@0
|
428
|
Chris@0
|
429 @request.session[:user_id] = 2
|
chris@37
|
430 delete :destroy, :id => 1
|
chris@37
|
431 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
|
Chris@0
|
432 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
|
Chris@0
|
433 assert_not_nil TimeEntry.find_by_id(1)
|
Chris@0
|
434 end
|
Chris@909
|
435
|
chris@37
|
436 def test_index_all_projects
|
chris@37
|
437 get :index
|
Chris@0
|
438 assert_response :success
|
chris@37
|
439 assert_template 'index'
|
Chris@0
|
440 assert_not_nil assigns(:total_hours)
|
Chris@0
|
441 assert_equal "162.90", "%.2f" % assigns(:total_hours)
|
Chris@441
|
442 assert_tag :form,
|
Chris@441
|
443 :attributes => {:action => "/time_entries", :id => 'query_form'}
|
Chris@0
|
444 end
|
Chris@909
|
445
|
Chris@1115
|
446 def test_index_all_projects_should_show_log_time_link
|
Chris@1115
|
447 @request.session[:user_id] = 2
|
Chris@1115
|
448 get :index
|
Chris@1115
|
449 assert_response :success
|
Chris@1115
|
450 assert_template 'index'
|
Chris@1115
|
451 assert_tag 'a', :attributes => {:href => '/time_entries/new'}, :content => /Log time/
|
Chris@1115
|
452 end
|
Chris@1115
|
453
|
Chris@1464
|
454 def test_index_my_spent_time
|
Chris@1464
|
455 @request.session[:user_id] = 2
|
Chris@1464
|
456 get :index, :user_id => 'me'
|
Chris@1464
|
457 assert_response :success
|
Chris@1464
|
458 assert_template 'index'
|
Chris@1464
|
459 assert assigns(:entries).all? {|entry| entry.user_id == 2}
|
Chris@1464
|
460 end
|
Chris@1464
|
461
|
chris@37
|
462 def test_index_at_project_level
|
Chris@441
|
463 get :index, :project_id => 'ecookbook'
|
Chris@0
|
464 assert_response :success
|
chris@37
|
465 assert_template 'index'
|
Chris@0
|
466 assert_not_nil assigns(:entries)
|
Chris@0
|
467 assert_equal 4, assigns(:entries).size
|
Chris@0
|
468 # project and subproject
|
Chris@0
|
469 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
|
Chris@0
|
470 assert_not_nil assigns(:total_hours)
|
Chris@0
|
471 assert_equal "162.90", "%.2f" % assigns(:total_hours)
|
Chris@441
|
472 assert_tag :form,
|
Chris@441
|
473 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
|
Chris@0
|
474 end
|
Chris@909
|
475
|
Chris@1464
|
476 def test_index_with_display_subprojects_issues_to_false_should_not_include_subproject_entries
|
Chris@1464
|
477 entry = TimeEntry.generate!(:project => Project.find(3))
|
Chris@1464
|
478
|
Chris@1464
|
479 with_settings :display_subprojects_issues => '0' do
|
Chris@1464
|
480 get :index, :project_id => 'ecookbook'
|
Chris@1464
|
481 assert_response :success
|
Chris@1464
|
482 assert_template 'index'
|
Chris@1464
|
483 assert_not_include entry, assigns(:entries)
|
Chris@1464
|
484 end
|
Chris@1464
|
485 end
|
Chris@1464
|
486
|
Chris@1464
|
487 def test_index_with_display_subprojects_issues_to_false_and_subproject_filter_should_include_subproject_entries
|
Chris@1464
|
488 entry = TimeEntry.generate!(:project => Project.find(3))
|
Chris@1464
|
489
|
Chris@1464
|
490 with_settings :display_subprojects_issues => '0' do
|
Chris@1464
|
491 get :index, :project_id => 'ecookbook', :subproject_id => 3
|
Chris@1464
|
492 assert_response :success
|
Chris@1464
|
493 assert_template 'index'
|
Chris@1464
|
494 assert_include entry, assigns(:entries)
|
Chris@1464
|
495 end
|
Chris@1464
|
496 end
|
Chris@1464
|
497
|
chris@37
|
498 def test_index_at_project_level_with_date_range
|
Chris@1464
|
499 get :index, :project_id => 'ecookbook',
|
Chris@1464
|
500 :f => ['spent_on'],
|
Chris@1464
|
501 :op => {'spent_on' => '><'},
|
Chris@1464
|
502 :v => {'spent_on' => ['2007-03-20', '2007-04-30']}
|
Chris@1464
|
503 assert_response :success
|
Chris@1464
|
504 assert_template 'index'
|
Chris@1464
|
505 assert_not_nil assigns(:entries)
|
Chris@1464
|
506 assert_equal 3, assigns(:entries).size
|
Chris@1464
|
507 assert_not_nil assigns(:total_hours)
|
Chris@1464
|
508 assert_equal "12.90", "%.2f" % assigns(:total_hours)
|
Chris@1464
|
509 assert_tag :form,
|
Chris@1464
|
510 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
|
Chris@1464
|
511 end
|
Chris@1464
|
512
|
Chris@1464
|
513 def test_index_at_project_level_with_date_range_using_from_and_to_params
|
Chris@441
|
514 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30'
|
Chris@0
|
515 assert_response :success
|
chris@37
|
516 assert_template 'index'
|
Chris@0
|
517 assert_not_nil assigns(:entries)
|
Chris@0
|
518 assert_equal 3, assigns(:entries).size
|
Chris@0
|
519 assert_not_nil assigns(:total_hours)
|
Chris@0
|
520 assert_equal "12.90", "%.2f" % assigns(:total_hours)
|
Chris@441
|
521 assert_tag :form,
|
Chris@441
|
522 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
|
Chris@0
|
523 end
|
Chris@0
|
524
|
chris@37
|
525 def test_index_at_project_level_with_period
|
Chris@1464
|
526 get :index, :project_id => 'ecookbook',
|
Chris@1464
|
527 :f => ['spent_on'],
|
Chris@1464
|
528 :op => {'spent_on' => '>t-'},
|
Chris@1464
|
529 :v => {'spent_on' => ['7']}
|
Chris@0
|
530 assert_response :success
|
chris@37
|
531 assert_template 'index'
|
Chris@0
|
532 assert_not_nil assigns(:entries)
|
Chris@0
|
533 assert_not_nil assigns(:total_hours)
|
Chris@441
|
534 assert_tag :form,
|
Chris@441
|
535 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
|
Chris@0
|
536 end
|
Chris@0
|
537
|
chris@37
|
538 def test_index_at_issue_level
|
chris@37
|
539 get :index, :issue_id => 1
|
Chris@0
|
540 assert_response :success
|
chris@37
|
541 assert_template 'index'
|
Chris@0
|
542 assert_not_nil assigns(:entries)
|
Chris@0
|
543 assert_equal 2, assigns(:entries).size
|
Chris@0
|
544 assert_not_nil assigns(:total_hours)
|
Chris@0
|
545 assert_equal 154.25, assigns(:total_hours)
|
Chris@1115
|
546 # display all time
|
Chris@1115
|
547 assert_nil assigns(:from)
|
Chris@1115
|
548 assert_nil assigns(:to)
|
Chris@441
|
549 # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes
|
Chris@441
|
550 # to use /issues/:issue_id/time_entries
|
Chris@441
|
551 assert_tag :form,
|
Chris@441
|
552 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'}
|
Chris@0
|
553 end
|
Chris@909
|
554
|
Chris@1115
|
555 def test_index_should_sort_by_spent_on_and_created_on
|
Chris@1115
|
556 t1 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:00:00', :activity_id => 10)
|
Chris@1115
|
557 t2 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:05:00', :activity_id => 10)
|
Chris@1115
|
558 t3 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-15', :created_on => '2012-06-16 20:10:00', :activity_id => 10)
|
Chris@1115
|
559
|
Chris@1464
|
560 get :index, :project_id => 1,
|
Chris@1464
|
561 :f => ['spent_on'],
|
Chris@1464
|
562 :op => {'spent_on' => '><'},
|
Chris@1464
|
563 :v => {'spent_on' => ['2012-06-15', '2012-06-16']}
|
Chris@1115
|
564 assert_response :success
|
Chris@1115
|
565 assert_equal [t2, t1, t3], assigns(:entries)
|
Chris@1115
|
566
|
Chris@1464
|
567 get :index, :project_id => 1,
|
Chris@1464
|
568 :f => ['spent_on'],
|
Chris@1464
|
569 :op => {'spent_on' => '><'},
|
Chris@1464
|
570 :v => {'spent_on' => ['2012-06-15', '2012-06-16']},
|
Chris@1464
|
571 :sort => 'spent_on'
|
Chris@1115
|
572 assert_response :success
|
Chris@1115
|
573 assert_equal [t3, t1, t2], assigns(:entries)
|
Chris@1115
|
574 end
|
Chris@1115
|
575
|
Chris@1464
|
576 def test_index_with_filter_on_issue_custom_field
|
Chris@1464
|
577 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'})
|
Chris@1464
|
578 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5)
|
Chris@1464
|
579
|
Chris@1464
|
580 get :index, :f => ['issue.cf_2'], :op => {'issue.cf_2' => '='}, :v => {'issue.cf_2' => ['filter_on_issue_custom_field']}
|
Chris@1464
|
581 assert_response :success
|
Chris@1464
|
582 assert_equal [entry], assigns(:entries)
|
Chris@1464
|
583 end
|
Chris@1464
|
584
|
Chris@1464
|
585 def test_index_with_issue_custom_field_column
|
Chris@1464
|
586 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'})
|
Chris@1464
|
587 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5)
|
Chris@1464
|
588
|
Chris@1464
|
589 get :index, :c => %w(project spent_on issue comments hours issue.cf_2)
|
Chris@1464
|
590 assert_response :success
|
Chris@1464
|
591 assert_include :'issue.cf_2', assigns(:query).column_names
|
Chris@1464
|
592 assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field'
|
Chris@1464
|
593 end
|
Chris@1464
|
594
|
Chris@1464
|
595 def test_index_with_time_entry_custom_field_column
|
Chris@1464
|
596 field = TimeEntryCustomField.generate!(:field_format => 'string')
|
Chris@1464
|
597 entry = TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value'})
|
Chris@1464
|
598 field_name = "cf_#{field.id}"
|
Chris@1464
|
599
|
Chris@1464
|
600 get :index, :c => ["hours", field_name]
|
Chris@1464
|
601 assert_response :success
|
Chris@1464
|
602 assert_include field_name.to_sym, assigns(:query).column_names
|
Chris@1464
|
603 assert_select "td.#{field_name}", :text => 'CF Value'
|
Chris@1464
|
604 end
|
Chris@1464
|
605
|
Chris@1464
|
606 def test_index_with_time_entry_custom_field_sorting
|
Chris@1464
|
607 field = TimeEntryCustomField.generate!(:field_format => 'string', :name => 'String Field')
|
Chris@1464
|
608 TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 1'})
|
Chris@1464
|
609 TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 3'})
|
Chris@1464
|
610 TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 2'})
|
Chris@1464
|
611 field_name = "cf_#{field.id}"
|
Chris@1464
|
612
|
Chris@1464
|
613 get :index, :c => ["hours", field_name], :sort => field_name
|
Chris@1464
|
614 assert_response :success
|
Chris@1464
|
615 assert_include field_name.to_sym, assigns(:query).column_names
|
Chris@1464
|
616 assert_select "th a.sort", :text => 'String Field'
|
Chris@1464
|
617
|
Chris@1464
|
618 # Make sure that values are properly sorted
|
Chris@1464
|
619 values = assigns(:entries).map {|e| e.custom_field_value(field)}.compact
|
Chris@1464
|
620 assert_equal 3, values.size
|
Chris@1464
|
621 assert_equal values.sort, values
|
Chris@1464
|
622 end
|
Chris@1464
|
623
|
chris@37
|
624 def test_index_atom_feed
|
chris@37
|
625 get :index, :project_id => 1, :format => 'atom'
|
Chris@0
|
626 assert_response :success
|
Chris@0
|
627 assert_equal 'application/atom+xml', @response.content_type
|
Chris@0
|
628 assert_not_nil assigns(:items)
|
Chris@0
|
629 assert assigns(:items).first.is_a?(TimeEntry)
|
Chris@0
|
630 end
|
Chris@909
|
631
|
Chris@1464
|
632 def test_index_at_project_level_should_include_csv_export_dialog
|
Chris@1464
|
633 get :index, :project_id => 'ecookbook',
|
Chris@1464
|
634 :f => ['spent_on'],
|
Chris@1464
|
635 :op => {'spent_on' => '>='},
|
Chris@1464
|
636 :v => {'spent_on' => ['2007-04-01']},
|
Chris@1464
|
637 :c => ['spent_on', 'user']
|
Chris@1464
|
638 assert_response :success
|
Chris@1464
|
639
|
Chris@1464
|
640 assert_select '#csv-export-options' do
|
Chris@1464
|
641 assert_select 'form[action=?][method=get]', '/projects/ecookbook/time_entries.csv' do
|
Chris@1464
|
642 # filter
|
Chris@1464
|
643 assert_select 'input[name=?][value=?]', 'f[]', 'spent_on'
|
Chris@1464
|
644 assert_select 'input[name=?][value=?]', 'op[spent_on]', '>='
|
Chris@1464
|
645 assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01'
|
Chris@1464
|
646 # columns
|
Chris@1464
|
647 assert_select 'input[name=?][value=?]', 'c[]', 'spent_on'
|
Chris@1464
|
648 assert_select 'input[name=?][value=?]', 'c[]', 'user'
|
Chris@1464
|
649 assert_select 'input[name=?]', 'c[]', 2
|
Chris@1464
|
650 end
|
Chris@1464
|
651 end
|
Chris@1464
|
652 end
|
Chris@1464
|
653
|
Chris@1464
|
654 def test_index_cross_project_should_include_csv_export_dialog
|
Chris@1464
|
655 get :index
|
Chris@1464
|
656 assert_response :success
|
Chris@1464
|
657
|
Chris@1464
|
658 assert_select '#csv-export-options' do
|
Chris@1464
|
659 assert_select 'form[action=?][method=get]', '/time_entries.csv'
|
Chris@1464
|
660 end
|
Chris@1464
|
661 end
|
Chris@1464
|
662
|
Chris@1464
|
663 def test_index_at_issue_level_should_include_csv_export_dialog
|
Chris@1464
|
664 get :index, :project_id => 'ecookbook', :issue_id => 3
|
Chris@1464
|
665 assert_response :success
|
Chris@1464
|
666
|
Chris@1464
|
667 assert_select '#csv-export-options' do
|
Chris@1464
|
668 assert_select 'form[action=?][method=get]', '/projects/ecookbook/issues/3/time_entries.csv'
|
Chris@1464
|
669 end
|
Chris@1464
|
670 end
|
Chris@1464
|
671
|
Chris@1464
|
672 def test_index_csv_all_projects
|
Chris@0
|
673 Setting.date_format = '%m/%d/%Y'
|
chris@37
|
674 get :index, :format => 'csv'
|
Chris@0
|
675 assert_response :success
|
Chris@1464
|
676 assert_equal 'text/csv; header=present', response.content_type
|
Chris@0
|
677 end
|
Chris@909
|
678
|
Chris@1464
|
679 def test_index_csv
|
Chris@0
|
680 Setting.date_format = '%m/%d/%Y'
|
chris@37
|
681 get :index, :project_id => 1, :format => 'csv'
|
Chris@0
|
682 assert_response :success
|
Chris@1464
|
683 assert_equal 'text/csv; header=present', response.content_type
|
Chris@909
|
684 end
|
Chris@0
|
685 end
|