Chris@0
|
1 # -*- coding: utf-8 -*-
|
Chris@909
|
2 # Redmine - project management software
|
Chris@1295
|
3 # Copyright (C) 2006-2013 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@1295
|
25 :custom_fields, :custom_values,
|
Chris@1295
|
26 :projects_trackers, :custom_fields_trackers,
|
Chris@1295
|
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@1115
|
227 time_entry = TimeEntry.first(:order => 'id DESC')
|
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@441
|
292 def test_get_bulk_edit
|
Chris@441
|
293 @request.session[:user_id] = 2
|
Chris@441
|
294 get :bulk_edit, :ids => [1, 2]
|
Chris@441
|
295 assert_response :success
|
Chris@441
|
296 assert_template 'bulk_edit'
|
Chris@909
|
297
|
Chris@1295
|
298 assert_select 'ul#bulk-selection' do
|
Chris@1295
|
299 assert_select 'li', 2
|
Chris@1295
|
300 assert_select 'li a', :text => '03/23/2007 - eCookbook: 4.25 hours'
|
Chris@1295
|
301 end
|
Chris@1115
|
302
|
Chris@1295
|
303 assert_select 'form#bulk_edit_form[action=?]', '/time_entries/bulk_update' do
|
Chris@1295
|
304 # System wide custom field
|
Chris@1295
|
305 assert_select 'select[name=?]', 'time_entry[custom_field_values][10]'
|
Chris@1295
|
306
|
Chris@1295
|
307 # Activities
|
Chris@1295
|
308 assert_select 'select[name=?]', 'time_entry[activity_id]' do
|
Chris@1295
|
309 assert_select 'option[value=]', :text => '(No change)'
|
Chris@1295
|
310 assert_select 'option[value=9]', :text => 'Design'
|
Chris@1295
|
311 end
|
Chris@1115
|
312 end
|
Chris@441
|
313 end
|
Chris@441
|
314
|
Chris@441
|
315 def test_get_bulk_edit_on_different_projects
|
Chris@441
|
316 @request.session[:user_id] = 2
|
Chris@441
|
317 get :bulk_edit, :ids => [1, 2, 6]
|
Chris@441
|
318 assert_response :success
|
Chris@441
|
319 assert_template 'bulk_edit'
|
Chris@441
|
320 end
|
Chris@441
|
321
|
Chris@441
|
322 def test_bulk_update
|
Chris@441
|
323 @request.session[:user_id] = 2
|
Chris@441
|
324 # update time entry activity
|
Chris@441
|
325 post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9}
|
Chris@909
|
326
|
Chris@441
|
327 assert_response 302
|
Chris@441
|
328 # check that the issues were updated
|
Chris@441
|
329 assert_equal [9, 9], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.activity_id}
|
Chris@441
|
330 end
|
Chris@441
|
331
|
Chris@1115
|
332 def test_bulk_update_with_failure
|
Chris@1115
|
333 @request.session[:user_id] = 2
|
Chris@1115
|
334 post :bulk_update, :ids => [1, 2], :time_entry => { :hours => 'A'}
|
Chris@1115
|
335
|
Chris@1115
|
336 assert_response 302
|
Chris@1115
|
337 assert_match /Failed to save 2 time entrie/, flash[:error]
|
Chris@1115
|
338 end
|
Chris@1115
|
339
|
Chris@441
|
340 def test_bulk_update_on_different_projects
|
Chris@441
|
341 @request.session[:user_id] = 2
|
Chris@909
|
342 # makes user a manager on the other project
|
Chris@909
|
343 Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1])
|
Chris@909
|
344
|
Chris@441
|
345 # update time entry activity
|
Chris@441
|
346 post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 }
|
Chris@909
|
347
|
Chris@441
|
348 assert_response 302
|
Chris@441
|
349 # check that the issues were updated
|
Chris@441
|
350 assert_equal [9, 9, 9], TimeEntry.find_all_by_id([1, 2, 4]).collect {|i| i.activity_id}
|
Chris@441
|
351 end
|
Chris@441
|
352
|
Chris@441
|
353 def test_bulk_update_on_different_projects_without_rights
|
Chris@441
|
354 @request.session[:user_id] = 3
|
Chris@441
|
355 user = User.find(3)
|
Chris@441
|
356 action = { :controller => "timelog", :action => "bulk_update" }
|
Chris@441
|
357 assert user.allowed_to?(action, TimeEntry.find(1).project)
|
Chris@441
|
358 assert ! user.allowed_to?(action, TimeEntry.find(5).project)
|
Chris@441
|
359 post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 }
|
Chris@441
|
360 assert_response 403
|
Chris@441
|
361 end
|
Chris@441
|
362
|
Chris@441
|
363 def test_bulk_update_custom_field
|
Chris@441
|
364 @request.session[:user_id] = 2
|
Chris@441
|
365 post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} }
|
Chris@909
|
366
|
Chris@441
|
367 assert_response 302
|
Chris@441
|
368 assert_equal ["0", "0"], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.custom_value_for(10).value}
|
Chris@441
|
369 end
|
Chris@441
|
370
|
Chris@441
|
371 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
|
Chris@441
|
372 @request.session[:user_id] = 2
|
Chris@441
|
373 post :bulk_update, :ids => [1,2], :back_url => '/time_entries'
|
Chris@441
|
374
|
Chris@441
|
375 assert_response :redirect
|
Chris@441
|
376 assert_redirected_to '/time_entries'
|
Chris@441
|
377 end
|
Chris@441
|
378
|
Chris@441
|
379 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
|
Chris@441
|
380 @request.session[:user_id] = 2
|
Chris@441
|
381 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
|
Chris@441
|
382
|
Chris@441
|
383 assert_response :redirect
|
Chris@441
|
384 assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier
|
Chris@441
|
385 end
|
Chris@909
|
386
|
Chris@909
|
387 def test_post_bulk_update_without_edit_permission_should_be_denied
|
Chris@909
|
388 @request.session[:user_id] = 2
|
Chris@909
|
389 Role.find_by_name('Manager').remove_permission! :edit_time_entries
|
Chris@909
|
390 post :bulk_update, :ids => [1,2]
|
Chris@909
|
391
|
Chris@909
|
392 assert_response 403
|
Chris@909
|
393 end
|
Chris@909
|
394
|
Chris@0
|
395 def test_destroy
|
Chris@0
|
396 @request.session[:user_id] = 2
|
chris@37
|
397 delete :destroy, :id => 1
|
chris@37
|
398 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
|
Chris@0
|
399 assert_equal I18n.t(:notice_successful_delete), flash[:notice]
|
Chris@0
|
400 assert_nil TimeEntry.find_by_id(1)
|
Chris@0
|
401 end
|
Chris@909
|
402
|
Chris@0
|
403 def test_destroy_should_fail
|
Chris@0
|
404 # simulate that this fails (e.g. due to a plugin), see #5700
|
Chris@441
|
405 TimeEntry.any_instance.expects(:destroy).returns(false)
|
Chris@0
|
406
|
Chris@0
|
407 @request.session[:user_id] = 2
|
chris@37
|
408 delete :destroy, :id => 1
|
chris@37
|
409 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
|
Chris@0
|
410 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
|
Chris@0
|
411 assert_not_nil TimeEntry.find_by_id(1)
|
Chris@0
|
412 end
|
Chris@909
|
413
|
chris@37
|
414 def test_index_all_projects
|
chris@37
|
415 get :index
|
Chris@0
|
416 assert_response :success
|
chris@37
|
417 assert_template 'index'
|
Chris@0
|
418 assert_not_nil assigns(:total_hours)
|
Chris@0
|
419 assert_equal "162.90", "%.2f" % assigns(:total_hours)
|
Chris@441
|
420 assert_tag :form,
|
Chris@441
|
421 :attributes => {:action => "/time_entries", :id => 'query_form'}
|
Chris@0
|
422 end
|
Chris@909
|
423
|
Chris@1115
|
424 def test_index_all_projects_should_show_log_time_link
|
Chris@1115
|
425 @request.session[:user_id] = 2
|
Chris@1115
|
426 get :index
|
Chris@1115
|
427 assert_response :success
|
Chris@1115
|
428 assert_template 'index'
|
Chris@1115
|
429 assert_tag 'a', :attributes => {:href => '/time_entries/new'}, :content => /Log time/
|
Chris@1115
|
430 end
|
Chris@1115
|
431
|
chris@37
|
432 def test_index_at_project_level
|
Chris@441
|
433 get :index, :project_id => 'ecookbook'
|
Chris@0
|
434 assert_response :success
|
chris@37
|
435 assert_template 'index'
|
Chris@0
|
436 assert_not_nil assigns(:entries)
|
Chris@0
|
437 assert_equal 4, assigns(:entries).size
|
Chris@0
|
438 # project and subproject
|
Chris@0
|
439 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
|
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 => "/projects/ecookbook/time_entries", :id => 'query_form'}
|
Chris@0
|
444 end
|
Chris@909
|
445
|
chris@37
|
446 def test_index_at_project_level_with_date_range
|
Chris@1295
|
447 get :index, :project_id => 'ecookbook',
|
Chris@1295
|
448 :f => ['spent_on'],
|
Chris@1295
|
449 :op => {'spent_on' => '><'},
|
Chris@1295
|
450 :v => {'spent_on' => ['2007-03-20', '2007-04-30']}
|
Chris@1295
|
451 assert_response :success
|
Chris@1295
|
452 assert_template 'index'
|
Chris@1295
|
453 assert_not_nil assigns(:entries)
|
Chris@1295
|
454 assert_equal 3, assigns(:entries).size
|
Chris@1295
|
455 assert_not_nil assigns(:total_hours)
|
Chris@1295
|
456 assert_equal "12.90", "%.2f" % assigns(:total_hours)
|
Chris@1295
|
457 assert_tag :form,
|
Chris@1295
|
458 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
|
Chris@1295
|
459 end
|
Chris@1295
|
460
|
Chris@1295
|
461 def test_index_at_project_level_with_date_range_using_from_and_to_params
|
Chris@441
|
462 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30'
|
Chris@0
|
463 assert_response :success
|
chris@37
|
464 assert_template 'index'
|
Chris@0
|
465 assert_not_nil assigns(:entries)
|
Chris@0
|
466 assert_equal 3, assigns(:entries).size
|
Chris@0
|
467 assert_not_nil assigns(:total_hours)
|
Chris@0
|
468 assert_equal "12.90", "%.2f" % assigns(:total_hours)
|
Chris@441
|
469 assert_tag :form,
|
Chris@441
|
470 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
|
Chris@0
|
471 end
|
Chris@0
|
472
|
chris@37
|
473 def test_index_at_project_level_with_period
|
Chris@1295
|
474 get :index, :project_id => 'ecookbook',
|
Chris@1295
|
475 :f => ['spent_on'],
|
Chris@1295
|
476 :op => {'spent_on' => '>t-'},
|
Chris@1295
|
477 :v => {'spent_on' => ['7']}
|
Chris@0
|
478 assert_response :success
|
chris@37
|
479 assert_template 'index'
|
Chris@0
|
480 assert_not_nil assigns(:entries)
|
Chris@0
|
481 assert_not_nil assigns(:total_hours)
|
Chris@441
|
482 assert_tag :form,
|
Chris@441
|
483 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
|
Chris@0
|
484 end
|
Chris@0
|
485
|
chris@37
|
486 def test_index_at_issue_level
|
chris@37
|
487 get :index, :issue_id => 1
|
Chris@0
|
488 assert_response :success
|
chris@37
|
489 assert_template 'index'
|
Chris@0
|
490 assert_not_nil assigns(:entries)
|
Chris@0
|
491 assert_equal 2, assigns(:entries).size
|
Chris@0
|
492 assert_not_nil assigns(:total_hours)
|
Chris@0
|
493 assert_equal 154.25, assigns(:total_hours)
|
Chris@1115
|
494 # display all time
|
Chris@1115
|
495 assert_nil assigns(:from)
|
Chris@1115
|
496 assert_nil assigns(:to)
|
Chris@441
|
497 # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes
|
Chris@441
|
498 # to use /issues/:issue_id/time_entries
|
Chris@441
|
499 assert_tag :form,
|
Chris@441
|
500 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'}
|
Chris@0
|
501 end
|
Chris@909
|
502
|
Chris@1115
|
503 def test_index_should_sort_by_spent_on_and_created_on
|
Chris@1115
|
504 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
|
505 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
|
506 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
|
507
|
Chris@1295
|
508 get :index, :project_id => 1,
|
Chris@1295
|
509 :f => ['spent_on'],
|
Chris@1295
|
510 :op => {'spent_on' => '><'},
|
Chris@1295
|
511 :v => {'spent_on' => ['2012-06-15', '2012-06-16']}
|
Chris@1115
|
512 assert_response :success
|
Chris@1115
|
513 assert_equal [t2, t1, t3], assigns(:entries)
|
Chris@1115
|
514
|
Chris@1295
|
515 get :index, :project_id => 1,
|
Chris@1295
|
516 :f => ['spent_on'],
|
Chris@1295
|
517 :op => {'spent_on' => '><'},
|
Chris@1295
|
518 :v => {'spent_on' => ['2012-06-15', '2012-06-16']},
|
Chris@1295
|
519 :sort => 'spent_on'
|
Chris@1115
|
520 assert_response :success
|
Chris@1115
|
521 assert_equal [t3, t1, t2], assigns(:entries)
|
Chris@1115
|
522 end
|
Chris@1115
|
523
|
Chris@1295
|
524 def test_index_with_filter_on_issue_custom_field
|
Chris@1295
|
525 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'})
|
Chris@1295
|
526 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5)
|
Chris@1295
|
527
|
Chris@1295
|
528 get :index, :f => ['issue.cf_2'], :op => {'issue.cf_2' => '='}, :v => {'issue.cf_2' => ['filter_on_issue_custom_field']}
|
Chris@1295
|
529 assert_response :success
|
Chris@1295
|
530 assert_equal [entry], assigns(:entries)
|
Chris@1295
|
531 end
|
Chris@1295
|
532
|
Chris@1295
|
533 def test_index_with_issue_custom_field_column
|
Chris@1295
|
534 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'})
|
Chris@1295
|
535 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5)
|
Chris@1295
|
536
|
Chris@1295
|
537 get :index, :c => %w(project spent_on issue comments hours issue.cf_2)
|
Chris@1295
|
538 assert_response :success
|
Chris@1295
|
539 assert_include :'issue.cf_2', assigns(:query).column_names
|
Chris@1295
|
540 assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field'
|
Chris@1295
|
541 end
|
Chris@1295
|
542
|
chris@37
|
543 def test_index_atom_feed
|
chris@37
|
544 get :index, :project_id => 1, :format => 'atom'
|
Chris@0
|
545 assert_response :success
|
Chris@0
|
546 assert_equal 'application/atom+xml', @response.content_type
|
Chris@0
|
547 assert_not_nil assigns(:items)
|
Chris@0
|
548 assert assigns(:items).first.is_a?(TimeEntry)
|
Chris@0
|
549 end
|
Chris@909
|
550
|
Chris@1295
|
551 def test_index_at_project_level_should_include_csv_export_dialog
|
Chris@1295
|
552 get :index, :project_id => 'ecookbook',
|
Chris@1295
|
553 :f => ['spent_on'],
|
Chris@1295
|
554 :op => {'spent_on' => '>='},
|
Chris@1295
|
555 :v => {'spent_on' => ['2007-04-01']},
|
Chris@1295
|
556 :c => ['spent_on', 'user']
|
Chris@1295
|
557 assert_response :success
|
Chris@1295
|
558
|
Chris@1295
|
559 assert_select '#csv-export-options' do
|
Chris@1295
|
560 assert_select 'form[action=?][method=get]', '/projects/ecookbook/time_entries.csv' do
|
Chris@1295
|
561 # filter
|
Chris@1295
|
562 assert_select 'input[name=?][value=?]', 'f[]', 'spent_on'
|
Chris@1295
|
563 assert_select 'input[name=?][value=?]', 'op[spent_on]', '>='
|
Chris@1295
|
564 assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01'
|
Chris@1295
|
565 # columns
|
Chris@1295
|
566 assert_select 'input[name=?][value=?]', 'c[]', 'spent_on'
|
Chris@1295
|
567 assert_select 'input[name=?][value=?]', 'c[]', 'user'
|
Chris@1295
|
568 assert_select 'input[name=?]', 'c[]', 2
|
Chris@1295
|
569 end
|
Chris@1295
|
570 end
|
Chris@1295
|
571 end
|
Chris@1295
|
572
|
Chris@1295
|
573 def test_index_cross_project_should_include_csv_export_dialog
|
Chris@1295
|
574 get :index
|
Chris@1295
|
575 assert_response :success
|
Chris@1295
|
576
|
Chris@1295
|
577 assert_select '#csv-export-options' do
|
Chris@1295
|
578 assert_select 'form[action=?][method=get]', '/time_entries.csv'
|
Chris@1295
|
579 end
|
Chris@1295
|
580 end
|
Chris@1295
|
581
|
Chris@1295
|
582 def test_index_at_issue_level_should_include_csv_export_dialog
|
Chris@1295
|
583 get :index, :project_id => 'ecookbook', :issue_id => 3
|
Chris@1295
|
584 assert_response :success
|
Chris@1295
|
585
|
Chris@1295
|
586 assert_select '#csv-export-options' do
|
Chris@1295
|
587 assert_select 'form[action=?][method=get]', '/projects/ecookbook/issues/3/time_entries.csv'
|
Chris@1295
|
588 end
|
Chris@1295
|
589 end
|
Chris@1295
|
590
|
Chris@1295
|
591 def test_index_csv_all_projects
|
Chris@0
|
592 Setting.date_format = '%m/%d/%Y'
|
chris@37
|
593 get :index, :format => 'csv'
|
Chris@0
|
594 assert_response :success
|
Chris@1295
|
595 assert_equal 'text/csv; header=present', response.content_type
|
Chris@0
|
596 end
|
Chris@909
|
597
|
Chris@1295
|
598 def test_index_csv
|
Chris@0
|
599 Setting.date_format = '%m/%d/%Y'
|
chris@37
|
600 get :index, :project_id => 1, :format => 'csv'
|
Chris@0
|
601 assert_response :success
|
Chris@1295
|
602 assert_equal 'text/csv; header=present', response.content_type
|
Chris@909
|
603 end
|
Chris@0
|
604 end
|