@@ -1,7 +1,8 | |||
|
1 | 1 | <h2><%= l(:label_spent_time) %></h2> |
|
2 | 2 | |
|
3 | 3 | <%= labelled_form_for @time_entry, :url => time_entries_path do |f| %> |
|
4 | <%= hidden_field_tag 'project_id', params[:project_id] if params[:project_id] %> | |
|
4 | 5 | <%= render :partial => 'form', :locals => {:f => f} %> |
|
5 | 6 | <%= submit_tag l(:button_create) %> |
|
6 | 7 | <%= submit_tag l(:button_create_and_continue), :name => 'continue' %> |
|
7 | 8 | <% end %> |
@@ -1,748 +1,750 | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | # Redmine - project management software |
|
3 | 3 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
4 | 4 | # |
|
5 | 5 | # This program is free software; you can redistribute it and/or |
|
6 | 6 | # modify it under the terms of the GNU General Public License |
|
7 | 7 | # as published by the Free Software Foundation; either version 2 |
|
8 | 8 | # of the License, or (at your option) any later version. |
|
9 | 9 | # |
|
10 | 10 | # This program is distributed in the hope that it will be useful, |
|
11 | 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | # GNU General Public License for more details. |
|
14 | 14 | # |
|
15 | 15 | # You should have received a copy of the GNU General Public License |
|
16 | 16 | # along with this program; if not, write to the Free Software |
|
17 | 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18 | 18 | |
|
19 | 19 | require File.expand_path('../../test_helper', __FILE__) |
|
20 | 20 | require 'timelog_controller' |
|
21 | 21 | |
|
22 | 22 | # Re-raise errors caught by the controller. |
|
23 | 23 | class TimelogController; def rescue_action(e) raise e end; end |
|
24 | 24 | |
|
25 | 25 | class TimelogControllerTest < ActionController::TestCase |
|
26 | 26 | fixtures :projects, :enabled_modules, :roles, :members, |
|
27 | 27 | :member_roles, :issues, :time_entries, :users, |
|
28 | 28 | :trackers, :enumerations, :issue_statuses, |
|
29 | 29 | :custom_fields, :custom_values |
|
30 | 30 | |
|
31 | 31 | include Redmine::I18n |
|
32 | 32 | |
|
33 | 33 | def setup |
|
34 | 34 | @controller = TimelogController.new |
|
35 | 35 | @request = ActionController::TestRequest.new |
|
36 | 36 | @response = ActionController::TestResponse.new |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | def test_get_new |
|
40 | 40 | @request.session[:user_id] = 3 |
|
41 | 41 | get :new, :project_id => 1 |
|
42 | 42 | assert_response :success |
|
43 | 43 | assert_template 'new' |
|
44 | 44 | # Default activity selected |
|
45 | 45 | assert_tag :tag => 'option', :attributes => { :selected => 'selected' }, |
|
46 | 46 | :content => 'Development' |
|
47 | assert_select 'input[name=project_id][value=1]' | |
|
47 | 48 | end |
|
48 | 49 | |
|
49 | 50 | def test_get_new_should_only_show_active_time_entry_activities |
|
50 | 51 | @request.session[:user_id] = 3 |
|
51 | 52 | get :new, :project_id => 1 |
|
52 | 53 | assert_response :success |
|
53 | 54 | assert_template 'new' |
|
54 | 55 | assert_no_tag 'select', :attributes => {:name => 'time_entry[project_id]'} |
|
55 | 56 | assert_no_tag 'option', :content => 'Inactive Activity' |
|
56 | 57 | end |
|
57 | 58 | |
|
58 | 59 | def test_new_without_project |
|
59 | 60 | @request.session[:user_id] = 3 |
|
60 | 61 | get :new |
|
61 | 62 | assert_response :success |
|
62 | 63 | assert_template 'new' |
|
63 | 64 | assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'} |
|
65 | assert_select 'input[name=project_id]', 0 | |
|
64 | 66 | end |
|
65 | 67 | |
|
66 | 68 | def test_new_without_project_should_deny_without_permission |
|
67 | 69 | Role.all.each {|role| role.remove_permission! :log_time} |
|
68 | 70 | @request.session[:user_id] = 3 |
|
69 | 71 | |
|
70 | 72 | get :new |
|
71 | 73 | assert_response 403 |
|
72 | 74 | end |
|
73 | 75 | |
|
74 | 76 | def test_get_edit_existing_time |
|
75 | 77 | @request.session[:user_id] = 2 |
|
76 | 78 | get :edit, :id => 2, :project_id => nil |
|
77 | 79 | assert_response :success |
|
78 | 80 | assert_template 'edit' |
|
79 | 81 | # Default activity selected |
|
80 | 82 | assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' } |
|
81 | 83 | end |
|
82 | 84 | |
|
83 | 85 | def test_get_edit_with_an_existing_time_entry_with_inactive_activity |
|
84 | 86 | te = TimeEntry.find(1) |
|
85 | 87 | te.activity = TimeEntryActivity.find_by_name("Inactive Activity") |
|
86 | 88 | te.save! |
|
87 | 89 | |
|
88 | 90 | @request.session[:user_id] = 1 |
|
89 | 91 | get :edit, :project_id => 1, :id => 1 |
|
90 | 92 | assert_response :success |
|
91 | 93 | assert_template 'edit' |
|
92 | 94 | # Blank option since nothing is pre-selected |
|
93 | 95 | assert_tag :tag => 'option', :content => '--- Please select ---' |
|
94 | 96 | end |
|
95 | 97 | |
|
96 | 98 | def test_post_create |
|
97 | 99 | # TODO: should POST to issuesβ time log instead of project. change form |
|
98 | 100 | # and routing |
|
99 | 101 | @request.session[:user_id] = 3 |
|
100 | 102 | post :create, :project_id => 1, |
|
101 | 103 | :time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
102 | 104 | # Not the default activity |
|
103 | 105 | :activity_id => '11', |
|
104 | 106 | :spent_on => '2008-03-14', |
|
105 | 107 | :issue_id => '1', |
|
106 | 108 | :hours => '7.3'} |
|
107 | 109 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
108 | 110 | |
|
109 | 111 | i = Issue.find(1) |
|
110 | 112 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') |
|
111 | 113 | assert_not_nil t |
|
112 | 114 | assert_equal 11, t.activity_id |
|
113 | 115 | assert_equal 7.3, t.hours |
|
114 | 116 | assert_equal 3, t.user_id |
|
115 | 117 | assert_equal i, t.issue |
|
116 | 118 | assert_equal i.project, t.project |
|
117 | 119 | end |
|
118 | 120 | |
|
119 | 121 | def test_post_create_with_blank_issue |
|
120 | 122 | # TODO: should POST to issuesβ time log instead of project. change form |
|
121 | 123 | # and routing |
|
122 | 124 | @request.session[:user_id] = 3 |
|
123 | 125 | post :create, :project_id => 1, |
|
124 | 126 | :time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
125 | 127 | # Not the default activity |
|
126 | 128 | :activity_id => '11', |
|
127 | 129 | :issue_id => '', |
|
128 | 130 | :spent_on => '2008-03-14', |
|
129 | 131 | :hours => '7.3'} |
|
130 | 132 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
131 | 133 | |
|
132 | 134 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') |
|
133 | 135 | assert_not_nil t |
|
134 | 136 | assert_equal 11, t.activity_id |
|
135 | 137 | assert_equal 7.3, t.hours |
|
136 | 138 | assert_equal 3, t.user_id |
|
137 | 139 | end |
|
138 | 140 | |
|
139 | 141 | def test_create_and_continue |
|
140 | 142 | @request.session[:user_id] = 2 |
|
141 | 143 | post :create, :project_id => 1, |
|
142 | 144 | :time_entry => {:activity_id => '11', |
|
143 | 145 | :issue_id => '', |
|
144 | 146 | :spent_on => '2008-03-14', |
|
145 | 147 | :hours => '7.3'}, |
|
146 | 148 | :continue => '1' |
|
147 | 149 | assert_redirected_to '/projects/ecookbook/time_entries/new' |
|
148 | 150 | end |
|
149 | 151 | |
|
150 | 152 | def test_create_and_continue_with_issue_id |
|
151 | 153 | @request.session[:user_id] = 2 |
|
152 | 154 | post :create, :project_id => 1, |
|
153 | 155 | :time_entry => {:activity_id => '11', |
|
154 | 156 | :issue_id => '1', |
|
155 | 157 | :spent_on => '2008-03-14', |
|
156 | 158 | :hours => '7.3'}, |
|
157 | 159 | :continue => '1' |
|
158 | 160 | assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new' |
|
159 | 161 | end |
|
160 | 162 | |
|
161 | 163 | def test_create_and_continue_without_project |
|
162 | 164 | @request.session[:user_id] = 2 |
|
163 | 165 | post :create, :time_entry => {:project_id => '1', |
|
164 | 166 | :activity_id => '11', |
|
165 | 167 | :issue_id => '', |
|
166 | 168 | :spent_on => '2008-03-14', |
|
167 | 169 | :hours => '7.3'}, |
|
168 | 170 | :continue => '1' |
|
169 | 171 | |
|
170 | 172 | assert_redirected_to '/time_entries/new' |
|
171 | 173 | end |
|
172 | 174 | |
|
173 | 175 | def test_create_without_log_time_permission_should_be_denied |
|
174 | 176 | @request.session[:user_id] = 2 |
|
175 | 177 | Role.find_by_name('Manager').remove_permission! :log_time |
|
176 | 178 | post :create, :project_id => 1, |
|
177 | 179 | :time_entry => {:activity_id => '11', |
|
178 | 180 | :issue_id => '', |
|
179 | 181 | :spent_on => '2008-03-14', |
|
180 | 182 | :hours => '7.3'} |
|
181 | 183 | |
|
182 | 184 | assert_response 403 |
|
183 | 185 | end |
|
184 | 186 | |
|
185 | 187 | def test_create_with_failure |
|
186 | 188 | @request.session[:user_id] = 2 |
|
187 | 189 | post :create, :project_id => 1, |
|
188 | 190 | :time_entry => {:activity_id => '', |
|
189 | 191 | :issue_id => '', |
|
190 | 192 | :spent_on => '2008-03-14', |
|
191 | 193 | :hours => '7.3'} |
|
192 | 194 | |
|
193 | 195 | assert_response :success |
|
194 | 196 | assert_template 'new' |
|
195 | 197 | end |
|
196 | 198 | |
|
197 | 199 | def test_create_without_project |
|
198 | 200 | @request.session[:user_id] = 2 |
|
199 | 201 | assert_difference 'TimeEntry.count' do |
|
200 | 202 | post :create, :time_entry => {:project_id => '1', |
|
201 | 203 | :activity_id => '11', |
|
202 | 204 | :issue_id => '', |
|
203 | 205 | :spent_on => '2008-03-14', |
|
204 | 206 | :hours => '7.3'} |
|
205 | 207 | end |
|
206 | 208 | |
|
207 | 209 | assert_redirected_to '/projects/ecookbook/time_entries' |
|
208 | 210 | time_entry = TimeEntry.first(:order => 'id DESC') |
|
209 | 211 | assert_equal 1, time_entry.project_id |
|
210 | 212 | end |
|
211 | 213 | |
|
212 | 214 | def test_create_without_project_should_fail_with_issue_not_inside_project |
|
213 | 215 | @request.session[:user_id] = 2 |
|
214 | 216 | assert_no_difference 'TimeEntry.count' do |
|
215 | 217 | post :create, :time_entry => {:project_id => '1', |
|
216 | 218 | :activity_id => '11', |
|
217 | 219 | :issue_id => '5', |
|
218 | 220 | :spent_on => '2008-03-14', |
|
219 | 221 | :hours => '7.3'} |
|
220 | 222 | end |
|
221 | 223 | |
|
222 | 224 | assert_response :success |
|
223 | 225 | assert assigns(:time_entry).errors[:issue_id].present? |
|
224 | 226 | end |
|
225 | 227 | |
|
226 | 228 | def test_create_without_project_should_deny_without_permission |
|
227 | 229 | @request.session[:user_id] = 2 |
|
228 | 230 | Project.find(3).disable_module!(:time_tracking) |
|
229 | 231 | |
|
230 | 232 | assert_no_difference 'TimeEntry.count' do |
|
231 | 233 | post :create, :time_entry => {:project_id => '3', |
|
232 | 234 | :activity_id => '11', |
|
233 | 235 | :issue_id => '', |
|
234 | 236 | :spent_on => '2008-03-14', |
|
235 | 237 | :hours => '7.3'} |
|
236 | 238 | end |
|
237 | 239 | |
|
238 | 240 | assert_response 403 |
|
239 | 241 | end |
|
240 | 242 | |
|
241 | 243 | def test_create_without_project_with_failure |
|
242 | 244 | @request.session[:user_id] = 2 |
|
243 | 245 | assert_no_difference 'TimeEntry.count' do |
|
244 | 246 | post :create, :time_entry => {:project_id => '1', |
|
245 | 247 | :activity_id => '11', |
|
246 | 248 | :issue_id => '', |
|
247 | 249 | :spent_on => '2008-03-14', |
|
248 | 250 | :hours => ''} |
|
249 | 251 | end |
|
250 | 252 | |
|
251 | 253 | assert_response :success |
|
252 | 254 | assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'}, |
|
253 | 255 | :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}} |
|
254 | 256 | end |
|
255 | 257 | |
|
256 | 258 | def test_update |
|
257 | 259 | entry = TimeEntry.find(1) |
|
258 | 260 | assert_equal 1, entry.issue_id |
|
259 | 261 | assert_equal 2, entry.user_id |
|
260 | 262 | |
|
261 | 263 | @request.session[:user_id] = 1 |
|
262 | 264 | put :update, :id => 1, |
|
263 | 265 | :time_entry => {:issue_id => '2', |
|
264 | 266 | :hours => '8'} |
|
265 | 267 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
266 | 268 | entry.reload |
|
267 | 269 | |
|
268 | 270 | assert_equal 8, entry.hours |
|
269 | 271 | assert_equal 2, entry.issue_id |
|
270 | 272 | assert_equal 2, entry.user_id |
|
271 | 273 | end |
|
272 | 274 | |
|
273 | 275 | def test_get_bulk_edit |
|
274 | 276 | @request.session[:user_id] = 2 |
|
275 | 277 | get :bulk_edit, :ids => [1, 2] |
|
276 | 278 | assert_response :success |
|
277 | 279 | assert_template 'bulk_edit' |
|
278 | 280 | |
|
279 | 281 | # System wide custom field |
|
280 | 282 | assert_tag :select, :attributes => {:name => 'time_entry[custom_field_values][10]'} |
|
281 | 283 | |
|
282 | 284 | # Activities |
|
283 | 285 | assert_select 'select[name=?]', 'time_entry[activity_id]' do |
|
284 | 286 | assert_select 'option[value=]', :text => '(No change)' |
|
285 | 287 | assert_select 'option[value=9]', :text => 'Design' |
|
286 | 288 | end |
|
287 | 289 | end |
|
288 | 290 | |
|
289 | 291 | def test_get_bulk_edit_on_different_projects |
|
290 | 292 | @request.session[:user_id] = 2 |
|
291 | 293 | get :bulk_edit, :ids => [1, 2, 6] |
|
292 | 294 | assert_response :success |
|
293 | 295 | assert_template 'bulk_edit' |
|
294 | 296 | end |
|
295 | 297 | |
|
296 | 298 | def test_bulk_update |
|
297 | 299 | @request.session[:user_id] = 2 |
|
298 | 300 | # update time entry activity |
|
299 | 301 | post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9} |
|
300 | 302 | |
|
301 | 303 | assert_response 302 |
|
302 | 304 | # check that the issues were updated |
|
303 | 305 | assert_equal [9, 9], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.activity_id} |
|
304 | 306 | end |
|
305 | 307 | |
|
306 | 308 | def test_bulk_update_with_failure |
|
307 | 309 | @request.session[:user_id] = 2 |
|
308 | 310 | post :bulk_update, :ids => [1, 2], :time_entry => { :hours => 'A'} |
|
309 | 311 | |
|
310 | 312 | assert_response 302 |
|
311 | 313 | assert_match /Failed to save 2 time entrie/, flash[:error] |
|
312 | 314 | end |
|
313 | 315 | |
|
314 | 316 | def test_bulk_update_on_different_projects |
|
315 | 317 | @request.session[:user_id] = 2 |
|
316 | 318 | # makes user a manager on the other project |
|
317 | 319 | Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1]) |
|
318 | 320 | |
|
319 | 321 | # update time entry activity |
|
320 | 322 | post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 } |
|
321 | 323 | |
|
322 | 324 | assert_response 302 |
|
323 | 325 | # check that the issues were updated |
|
324 | 326 | assert_equal [9, 9, 9], TimeEntry.find_all_by_id([1, 2, 4]).collect {|i| i.activity_id} |
|
325 | 327 | end |
|
326 | 328 | |
|
327 | 329 | def test_bulk_update_on_different_projects_without_rights |
|
328 | 330 | @request.session[:user_id] = 3 |
|
329 | 331 | user = User.find(3) |
|
330 | 332 | action = { :controller => "timelog", :action => "bulk_update" } |
|
331 | 333 | assert user.allowed_to?(action, TimeEntry.find(1).project) |
|
332 | 334 | assert ! user.allowed_to?(action, TimeEntry.find(5).project) |
|
333 | 335 | post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 } |
|
334 | 336 | assert_response 403 |
|
335 | 337 | end |
|
336 | 338 | |
|
337 | 339 | def test_bulk_update_custom_field |
|
338 | 340 | @request.session[:user_id] = 2 |
|
339 | 341 | post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} } |
|
340 | 342 | |
|
341 | 343 | assert_response 302 |
|
342 | 344 | assert_equal ["0", "0"], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.custom_value_for(10).value} |
|
343 | 345 | end |
|
344 | 346 | |
|
345 | 347 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter |
|
346 | 348 | @request.session[:user_id] = 2 |
|
347 | 349 | post :bulk_update, :ids => [1,2], :back_url => '/time_entries' |
|
348 | 350 | |
|
349 | 351 | assert_response :redirect |
|
350 | 352 | assert_redirected_to '/time_entries' |
|
351 | 353 | end |
|
352 | 354 | |
|
353 | 355 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
354 | 356 | @request.session[:user_id] = 2 |
|
355 | 357 | post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' |
|
356 | 358 | |
|
357 | 359 | assert_response :redirect |
|
358 | 360 | assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier |
|
359 | 361 | end |
|
360 | 362 | |
|
361 | 363 | def test_post_bulk_update_without_edit_permission_should_be_denied |
|
362 | 364 | @request.session[:user_id] = 2 |
|
363 | 365 | Role.find_by_name('Manager').remove_permission! :edit_time_entries |
|
364 | 366 | post :bulk_update, :ids => [1,2] |
|
365 | 367 | |
|
366 | 368 | assert_response 403 |
|
367 | 369 | end |
|
368 | 370 | |
|
369 | 371 | def test_destroy |
|
370 | 372 | @request.session[:user_id] = 2 |
|
371 | 373 | delete :destroy, :id => 1 |
|
372 | 374 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
373 | 375 | assert_equal I18n.t(:notice_successful_delete), flash[:notice] |
|
374 | 376 | assert_nil TimeEntry.find_by_id(1) |
|
375 | 377 | end |
|
376 | 378 | |
|
377 | 379 | def test_destroy_should_fail |
|
378 | 380 | # simulate that this fails (e.g. due to a plugin), see #5700 |
|
379 | 381 | TimeEntry.any_instance.expects(:destroy).returns(false) |
|
380 | 382 | |
|
381 | 383 | @request.session[:user_id] = 2 |
|
382 | 384 | delete :destroy, :id => 1 |
|
383 | 385 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
384 | 386 | assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error] |
|
385 | 387 | assert_not_nil TimeEntry.find_by_id(1) |
|
386 | 388 | end |
|
387 | 389 | |
|
388 | 390 | def test_index_all_projects |
|
389 | 391 | get :index |
|
390 | 392 | assert_response :success |
|
391 | 393 | assert_template 'index' |
|
392 | 394 | assert_not_nil assigns(:total_hours) |
|
393 | 395 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
394 | 396 | assert_tag :form, |
|
395 | 397 | :attributes => {:action => "/time_entries", :id => 'query_form'} |
|
396 | 398 | end |
|
397 | 399 | |
|
398 | 400 | def test_index_all_projects_should_show_log_time_link |
|
399 | 401 | @request.session[:user_id] = 2 |
|
400 | 402 | get :index |
|
401 | 403 | assert_response :success |
|
402 | 404 | assert_template 'index' |
|
403 | 405 | assert_tag 'a', :attributes => {:href => '/time_entries/new'}, :content => /Log time/ |
|
404 | 406 | end |
|
405 | 407 | |
|
406 | 408 | def test_index_at_project_level |
|
407 | 409 | get :index, :project_id => 'ecookbook' |
|
408 | 410 | assert_response :success |
|
409 | 411 | assert_template 'index' |
|
410 | 412 | assert_not_nil assigns(:entries) |
|
411 | 413 | assert_equal 4, assigns(:entries).size |
|
412 | 414 | # project and subproject |
|
413 | 415 | assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort |
|
414 | 416 | assert_not_nil assigns(:total_hours) |
|
415 | 417 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
416 | 418 | # display all time by default |
|
417 | 419 | assert_nil assigns(:from) |
|
418 | 420 | assert_nil assigns(:to) |
|
419 | 421 | assert_tag :form, |
|
420 | 422 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
421 | 423 | end |
|
422 | 424 | |
|
423 | 425 | def test_index_at_project_level_with_date_range |
|
424 | 426 | get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30' |
|
425 | 427 | assert_response :success |
|
426 | 428 | assert_template 'index' |
|
427 | 429 | assert_not_nil assigns(:entries) |
|
428 | 430 | assert_equal 3, assigns(:entries).size |
|
429 | 431 | assert_not_nil assigns(:total_hours) |
|
430 | 432 | assert_equal "12.90", "%.2f" % assigns(:total_hours) |
|
431 | 433 | assert_equal '2007-03-20'.to_date, assigns(:from) |
|
432 | 434 | assert_equal '2007-04-30'.to_date, assigns(:to) |
|
433 | 435 | assert_tag :form, |
|
434 | 436 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
435 | 437 | end |
|
436 | 438 | |
|
437 | 439 | def test_index_at_project_level_with_period |
|
438 | 440 | get :index, :project_id => 'ecookbook', :period => '7_days' |
|
439 | 441 | assert_response :success |
|
440 | 442 | assert_template 'index' |
|
441 | 443 | assert_not_nil assigns(:entries) |
|
442 | 444 | assert_not_nil assigns(:total_hours) |
|
443 | 445 | assert_equal Date.today - 7, assigns(:from) |
|
444 | 446 | assert_equal Date.today, assigns(:to) |
|
445 | 447 | assert_tag :form, |
|
446 | 448 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
447 | 449 | end |
|
448 | 450 | |
|
449 | 451 | def test_index_one_day |
|
450 | 452 | get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => "2007-03-23" |
|
451 | 453 | assert_response :success |
|
452 | 454 | assert_template 'index' |
|
453 | 455 | assert_not_nil assigns(:total_hours) |
|
454 | 456 | assert_equal "4.25", "%.2f" % assigns(:total_hours) |
|
455 | 457 | assert_tag :form, |
|
456 | 458 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
457 | 459 | end |
|
458 | 460 | |
|
459 | 461 | def test_index_from_a_date |
|
460 | 462 | get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => "" |
|
461 | 463 | assert_equal '2007-03-23'.to_date, assigns(:from) |
|
462 | 464 | assert_nil assigns(:to) |
|
463 | 465 | end |
|
464 | 466 | |
|
465 | 467 | def test_index_to_a_date |
|
466 | 468 | get :index, :project_id => 'ecookbook', :from => "", :to => "2007-03-23" |
|
467 | 469 | assert_nil assigns(:from) |
|
468 | 470 | assert_equal '2007-03-23'.to_date, assigns(:to) |
|
469 | 471 | end |
|
470 | 472 | |
|
471 | 473 | def test_index_today |
|
472 | 474 | Date.stubs(:today).returns('2011-12-15'.to_date) |
|
473 | 475 | get :index, :period => 'today' |
|
474 | 476 | assert_equal '2011-12-15'.to_date, assigns(:from) |
|
475 | 477 | assert_equal '2011-12-15'.to_date, assigns(:to) |
|
476 | 478 | end |
|
477 | 479 | |
|
478 | 480 | def test_index_yesterday |
|
479 | 481 | Date.stubs(:today).returns('2011-12-15'.to_date) |
|
480 | 482 | get :index, :period => 'yesterday' |
|
481 | 483 | assert_equal '2011-12-14'.to_date, assigns(:from) |
|
482 | 484 | assert_equal '2011-12-14'.to_date, assigns(:to) |
|
483 | 485 | end |
|
484 | 486 | |
|
485 | 487 | def test_index_current_week |
|
486 | 488 | Date.stubs(:today).returns('2011-12-15'.to_date) |
|
487 | 489 | get :index, :period => 'current_week' |
|
488 | 490 | assert_equal '2011-12-12'.to_date, assigns(:from) |
|
489 | 491 | assert_equal '2011-12-18'.to_date, assigns(:to) |
|
490 | 492 | end |
|
491 | 493 | |
|
492 | 494 | def test_index_last_week |
|
493 | 495 | Date.stubs(:today).returns('2011-12-15'.to_date) |
|
494 | 496 | get :index, :period => 'current_week' |
|
495 | 497 | assert_equal '2011-12-05'.to_date, assigns(:from) |
|
496 | 498 | assert_equal '2011-12-11'.to_date, assigns(:to) |
|
497 | 499 | end |
|
498 | 500 | |
|
499 | 501 | def test_index_last_week |
|
500 | 502 | Date.stubs(:today).returns('2011-12-15'.to_date) |
|
501 | 503 | get :index, :period => 'last_week' |
|
502 | 504 | assert_equal '2011-12-05'.to_date, assigns(:from) |
|
503 | 505 | assert_equal '2011-12-11'.to_date, assigns(:to) |
|
504 | 506 | end |
|
505 | 507 | |
|
506 | 508 | def test_index_7_days |
|
507 | 509 | Date.stubs(:today).returns('2011-12-15'.to_date) |
|
508 | 510 | get :index, :period => '7_days' |
|
509 | 511 | assert_equal '2011-12-08'.to_date, assigns(:from) |
|
510 | 512 | assert_equal '2011-12-15'.to_date, assigns(:to) |
|
511 | 513 | end |
|
512 | 514 | |
|
513 | 515 | def test_index_current_month |
|
514 | 516 | Date.stubs(:today).returns('2011-12-15'.to_date) |
|
515 | 517 | get :index, :period => 'current_month' |
|
516 | 518 | assert_equal '2011-12-01'.to_date, assigns(:from) |
|
517 | 519 | assert_equal '2011-12-31'.to_date, assigns(:to) |
|
518 | 520 | end |
|
519 | 521 | |
|
520 | 522 | def test_index_last_month |
|
521 | 523 | Date.stubs(:today).returns('2011-12-15'.to_date) |
|
522 | 524 | get :index, :period => 'last_month' |
|
523 | 525 | assert_equal '2011-11-01'.to_date, assigns(:from) |
|
524 | 526 | assert_equal '2011-11-30'.to_date, assigns(:to) |
|
525 | 527 | end |
|
526 | 528 | |
|
527 | 529 | def test_index_30_days |
|
528 | 530 | Date.stubs(:today).returns('2011-12-15'.to_date) |
|
529 | 531 | get :index, :period => '30_days' |
|
530 | 532 | assert_equal '2011-11-15'.to_date, assigns(:from) |
|
531 | 533 | assert_equal '2011-12-15'.to_date, assigns(:to) |
|
532 | 534 | end |
|
533 | 535 | |
|
534 | 536 | def test_index_current_year |
|
535 | 537 | Date.stubs(:today).returns('2011-12-15'.to_date) |
|
536 | 538 | get :index, :period => 'current_year' |
|
537 | 539 | assert_equal '2011-01-01'.to_date, assigns(:from) |
|
538 | 540 | assert_equal '2011-12-31'.to_date, assigns(:to) |
|
539 | 541 | end |
|
540 | 542 | |
|
541 | 543 | def test_index_at_issue_level |
|
542 | 544 | get :index, :issue_id => 1 |
|
543 | 545 | assert_response :success |
|
544 | 546 | assert_template 'index' |
|
545 | 547 | assert_not_nil assigns(:entries) |
|
546 | 548 | assert_equal 2, assigns(:entries).size |
|
547 | 549 | assert_not_nil assigns(:total_hours) |
|
548 | 550 | assert_equal 154.25, assigns(:total_hours) |
|
549 | 551 | # display all time |
|
550 | 552 | assert_nil assigns(:from) |
|
551 | 553 | assert_nil assigns(:to) |
|
552 | 554 | # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes |
|
553 | 555 | # to use /issues/:issue_id/time_entries |
|
554 | 556 | assert_tag :form, |
|
555 | 557 | :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'} |
|
556 | 558 | end |
|
557 | 559 | |
|
558 | 560 | def test_index_atom_feed |
|
559 | 561 | get :index, :project_id => 1, :format => 'atom' |
|
560 | 562 | assert_response :success |
|
561 | 563 | assert_equal 'application/atom+xml', @response.content_type |
|
562 | 564 | assert_not_nil assigns(:items) |
|
563 | 565 | assert assigns(:items).first.is_a?(TimeEntry) |
|
564 | 566 | end |
|
565 | 567 | |
|
566 | 568 | def test_index_all_projects_csv_export |
|
567 | 569 | Setting.date_format = '%m/%d/%Y' |
|
568 | 570 | get :index, :format => 'csv' |
|
569 | 571 | assert_response :success |
|
570 | 572 | assert_equal 'text/csv; header=present', @response.content_type |
|
571 | 573 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n") |
|
572 | 574 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n") |
|
573 | 575 | end |
|
574 | 576 | |
|
575 | 577 | def test_index_csv_export |
|
576 | 578 | Setting.date_format = '%m/%d/%Y' |
|
577 | 579 | get :index, :project_id => 1, :format => 'csv' |
|
578 | 580 | assert_response :success |
|
579 | 581 | assert_equal 'text/csv; header=present', @response.content_type |
|
580 | 582 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n") |
|
581 | 583 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n") |
|
582 | 584 | end |
|
583 | 585 | |
|
584 | 586 | def test_index_csv_export_with_multi_custom_field |
|
585 | 587 | field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'list', |
|
586 | 588 | :multiple => true, :possible_values => ['value1', 'value2']) |
|
587 | 589 | entry = TimeEntry.find(1) |
|
588 | 590 | entry.custom_field_values = {field.id => ['value1', 'value2']} |
|
589 | 591 | entry.save! |
|
590 | 592 | |
|
591 | 593 | get :index, :project_id => 1, :format => 'csv' |
|
592 | 594 | assert_response :success |
|
593 | 595 | assert_include '"value1, value2"', @response.body |
|
594 | 596 | end |
|
595 | 597 | |
|
596 | 598 | def test_csv_big_5 |
|
597 | 599 | user = User.find_by_id(3) |
|
598 | 600 | user.language = "zh-TW" |
|
599 | 601 | assert user.save |
|
600 | 602 | str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" |
|
601 | 603 | str_big5 = "\xa4@\xa4\xeb" |
|
602 | 604 | if str_utf8.respond_to?(:force_encoding) |
|
603 | 605 | str_utf8.force_encoding('UTF-8') |
|
604 | 606 | str_big5.force_encoding('Big5') |
|
605 | 607 | end |
|
606 | 608 | @request.session[:user_id] = 3 |
|
607 | 609 | post :create, :project_id => 1, |
|
608 | 610 | :time_entry => {:comments => str_utf8, |
|
609 | 611 | # Not the default activity |
|
610 | 612 | :activity_id => '11', |
|
611 | 613 | :issue_id => '', |
|
612 | 614 | :spent_on => '2011-11-10', |
|
613 | 615 | :hours => '7.3'} |
|
614 | 616 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
615 | 617 | |
|
616 | 618 | t = TimeEntry.find_by_comments(str_utf8) |
|
617 | 619 | assert_not_nil t |
|
618 | 620 | assert_equal 11, t.activity_id |
|
619 | 621 | assert_equal 7.3, t.hours |
|
620 | 622 | assert_equal 3, t.user_id |
|
621 | 623 | |
|
622 | 624 | get :index, :project_id => 1, :format => 'csv', |
|
623 | 625 | :from => '2011-11-10', :to => '2011-11-10' |
|
624 | 626 | assert_response :success |
|
625 | 627 | assert_equal 'text/csv; header=present', @response.content_type |
|
626 | 628 | ar = @response.body.chomp.split("\n") |
|
627 | 629 | s1 = "\xa4\xe9\xb4\xc1" |
|
628 | 630 | if str_utf8.respond_to?(:force_encoding) |
|
629 | 631 | s1.force_encoding('Big5') |
|
630 | 632 | end |
|
631 | 633 | assert ar[0].include?(s1) |
|
632 | 634 | assert ar[1].include?(str_big5) |
|
633 | 635 | end |
|
634 | 636 | |
|
635 | 637 | def test_csv_cannot_convert_should_be_replaced_big_5 |
|
636 | 638 | user = User.find_by_id(3) |
|
637 | 639 | user.language = "zh-TW" |
|
638 | 640 | assert user.save |
|
639 | 641 | str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85" |
|
640 | 642 | if str_utf8.respond_to?(:force_encoding) |
|
641 | 643 | str_utf8.force_encoding('UTF-8') |
|
642 | 644 | end |
|
643 | 645 | @request.session[:user_id] = 3 |
|
644 | 646 | post :create, :project_id => 1, |
|
645 | 647 | :time_entry => {:comments => str_utf8, |
|
646 | 648 | # Not the default activity |
|
647 | 649 | :activity_id => '11', |
|
648 | 650 | :issue_id => '', |
|
649 | 651 | :spent_on => '2011-11-10', |
|
650 | 652 | :hours => '7.3'} |
|
651 | 653 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
652 | 654 | |
|
653 | 655 | t = TimeEntry.find_by_comments(str_utf8) |
|
654 | 656 | assert_not_nil t |
|
655 | 657 | assert_equal 11, t.activity_id |
|
656 | 658 | assert_equal 7.3, t.hours |
|
657 | 659 | assert_equal 3, t.user_id |
|
658 | 660 | |
|
659 | 661 | get :index, :project_id => 1, :format => 'csv', |
|
660 | 662 | :from => '2011-11-10', :to => '2011-11-10' |
|
661 | 663 | assert_response :success |
|
662 | 664 | assert_equal 'text/csv; header=present', @response.content_type |
|
663 | 665 | ar = @response.body.chomp.split("\n") |
|
664 | 666 | s1 = "\xa4\xe9\xb4\xc1" |
|
665 | 667 | if str_utf8.respond_to?(:force_encoding) |
|
666 | 668 | s1.force_encoding('Big5') |
|
667 | 669 | end |
|
668 | 670 | assert ar[0].include?(s1) |
|
669 | 671 | s2 = ar[1].split(",")[8] |
|
670 | 672 | if s2.respond_to?(:force_encoding) |
|
671 | 673 | s3 = "\xa5H?" |
|
672 | 674 | s3.force_encoding('Big5') |
|
673 | 675 | assert_equal s3, s2 |
|
674 | 676 | elsif RUBY_PLATFORM == 'java' |
|
675 | 677 | assert_equal "??", s2 |
|
676 | 678 | else |
|
677 | 679 | assert_equal "\xa5H???", s2 |
|
678 | 680 | end |
|
679 | 681 | end |
|
680 | 682 | |
|
681 | 683 | def test_csv_tw |
|
682 | 684 | with_settings :default_language => "zh-TW" do |
|
683 | 685 | str1 = "test_csv_tw" |
|
684 | 686 | user = User.find_by_id(3) |
|
685 | 687 | te1 = TimeEntry.create(:spent_on => '2011-11-10', |
|
686 | 688 | :hours => 999.9, |
|
687 | 689 | :project => Project.find(1), |
|
688 | 690 | :user => user, |
|
689 | 691 | :activity => TimeEntryActivity.find_by_name('Design'), |
|
690 | 692 | :comments => str1) |
|
691 | 693 | te2 = TimeEntry.find_by_comments(str1) |
|
692 | 694 | assert_not_nil te2 |
|
693 | 695 | assert_equal 999.9, te2.hours |
|
694 | 696 | assert_equal 3, te2.user_id |
|
695 | 697 | |
|
696 | 698 | get :index, :project_id => 1, :format => 'csv', |
|
697 | 699 | :from => '2011-11-10', :to => '2011-11-10' |
|
698 | 700 | assert_response :success |
|
699 | 701 | assert_equal 'text/csv; header=present', @response.content_type |
|
700 | 702 | |
|
701 | 703 | ar = @response.body.chomp.split("\n") |
|
702 | 704 | s2 = ar[1].split(",")[7] |
|
703 | 705 | assert_equal '999.9', s2 |
|
704 | 706 | |
|
705 | 707 | str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)" |
|
706 | 708 | if str_tw.respond_to?(:force_encoding) |
|
707 | 709 | str_tw.force_encoding('UTF-8') |
|
708 | 710 | end |
|
709 | 711 | assert_equal str_tw, l(:general_lang_name) |
|
710 | 712 | assert_equal ',', l(:general_csv_separator) |
|
711 | 713 | assert_equal '.', l(:general_csv_decimal_separator) |
|
712 | 714 | end |
|
713 | 715 | end |
|
714 | 716 | |
|
715 | 717 | def test_csv_fr |
|
716 | 718 | with_settings :default_language => "fr" do |
|
717 | 719 | str1 = "test_csv_fr" |
|
718 | 720 | user = User.find_by_id(3) |
|
719 | 721 | te1 = TimeEntry.create(:spent_on => '2011-11-10', |
|
720 | 722 | :hours => 999.9, |
|
721 | 723 | :project => Project.find(1), |
|
722 | 724 | :user => user, |
|
723 | 725 | :activity => TimeEntryActivity.find_by_name('Design'), |
|
724 | 726 | :comments => str1) |
|
725 | 727 | te2 = TimeEntry.find_by_comments(str1) |
|
726 | 728 | assert_not_nil te2 |
|
727 | 729 | assert_equal 999.9, te2.hours |
|
728 | 730 | assert_equal 3, te2.user_id |
|
729 | 731 | |
|
730 | 732 | get :index, :project_id => 1, :format => 'csv', |
|
731 | 733 | :from => '2011-11-10', :to => '2011-11-10' |
|
732 | 734 | assert_response :success |
|
733 | 735 | assert_equal 'text/csv; header=present', @response.content_type |
|
734 | 736 | |
|
735 | 737 | ar = @response.body.chomp.split("\n") |
|
736 | 738 | s2 = ar[1].split(";")[7] |
|
737 | 739 | assert_equal '999,9', s2 |
|
738 | 740 | |
|
739 | 741 | str_fr = "Fran\xc3\xa7ais" |
|
740 | 742 | if str_fr.respond_to?(:force_encoding) |
|
741 | 743 | str_fr.force_encoding('UTF-8') |
|
742 | 744 | end |
|
743 | 745 | assert_equal str_fr, l(:general_lang_name) |
|
744 | 746 | assert_equal ';', l(:general_csv_separator) |
|
745 | 747 | assert_equal ',', l(:general_csv_decimal_separator) |
|
746 | 748 | end |
|
747 | 749 | end |
|
748 | 750 | end |
General Comments 0
You need to be logged in to leave comments.
Login now