##// END OF EJS Templates
Random test failure....
Jean-Philippe Lang -
r15527:06d66df16e7c
parent child
Show More
@@ -1,1018 +1,1018
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 # Redmine - project management software
2 # Redmine - project management software
3 # Copyright (C) 2006-2016 Jean-Philippe Lang
3 # Copyright (C) 2006-2016 Jean-Philippe Lang
4 #
4 #
5 # This program is free software; you can redistribute it and/or
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
8 # of the License, or (at your option) any later version.
9 #
9 #
10 # This program is distributed in the hope that it will be useful,
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
13 # GNU General Public License for more details.
14 #
14 #
15 # You should have received a copy of the GNU General Public License
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
18
19 require File.expand_path('../../test_helper', __FILE__)
19 require File.expand_path('../../test_helper', __FILE__)
20
20
21 class TimelogControllerTest < Redmine::ControllerTest
21 class TimelogControllerTest < Redmine::ControllerTest
22 fixtures :projects, :enabled_modules, :roles, :members,
22 fixtures :projects, :enabled_modules, :roles, :members,
23 :member_roles, :issues, :time_entries, :users,
23 :member_roles, :issues, :time_entries, :users,
24 :trackers, :enumerations, :issue_statuses,
24 :trackers, :enumerations, :issue_statuses,
25 :custom_fields, :custom_values,
25 :custom_fields, :custom_values,
26 :projects_trackers, :custom_fields_trackers,
26 :projects_trackers, :custom_fields_trackers,
27 :custom_fields_projects
27 :custom_fields_projects
28
28
29 include Redmine::I18n
29 include Redmine::I18n
30
30
31 def test_new
31 def test_new
32 @request.session[:user_id] = 3
32 @request.session[:user_id] = 3
33 get :new
33 get :new
34 assert_response :success
34 assert_response :success
35
35
36 assert_select 'input[name=?][type=hidden]', 'project_id', 0
36 assert_select 'input[name=?][type=hidden]', 'project_id', 0
37 assert_select 'input[name=?][type=hidden]', 'issue_id', 0
37 assert_select 'input[name=?][type=hidden]', 'issue_id', 0
38 assert_select 'select[name=?]', 'time_entry[project_id]' do
38 assert_select 'select[name=?]', 'time_entry[project_id]' do
39 # blank option for project
39 # blank option for project
40 assert_select 'option[value=""]'
40 assert_select 'option[value=""]'
41 end
41 end
42 end
42 end
43
43
44 def test_new_with_project_id
44 def test_new_with_project_id
45 @request.session[:user_id] = 3
45 @request.session[:user_id] = 3
46 get :new, :params => {:project_id => 1}
46 get :new, :params => {:project_id => 1}
47 assert_response :success
47 assert_response :success
48
48
49 assert_select 'input[name=?][type=hidden]', 'project_id'
49 assert_select 'input[name=?][type=hidden]', 'project_id'
50 assert_select 'input[name=?][type=hidden]', 'issue_id', 0
50 assert_select 'input[name=?][type=hidden]', 'issue_id', 0
51 assert_select 'select[name=?]', 'time_entry[project_id]', 0
51 assert_select 'select[name=?]', 'time_entry[project_id]', 0
52 end
52 end
53
53
54 def test_new_with_issue_id
54 def test_new_with_issue_id
55 @request.session[:user_id] = 3
55 @request.session[:user_id] = 3
56 get :new, :params => {:issue_id => 2}
56 get :new, :params => {:issue_id => 2}
57 assert_response :success
57 assert_response :success
58
58
59 assert_select 'input[name=?][type=hidden]', 'project_id', 0
59 assert_select 'input[name=?][type=hidden]', 'project_id', 0
60 assert_select 'input[name=?][type=hidden]', 'issue_id'
60 assert_select 'input[name=?][type=hidden]', 'issue_id'
61 assert_select 'select[name=?]', 'time_entry[project_id]', 0
61 assert_select 'select[name=?]', 'time_entry[project_id]', 0
62 end
62 end
63
63
64 def test_new_without_project_should_prefill_the_form
64 def test_new_without_project_should_prefill_the_form
65 @request.session[:user_id] = 3
65 @request.session[:user_id] = 3
66 get :new, :params => {:time_entry => {:project_id => '1'}}
66 get :new, :params => {:time_entry => {:project_id => '1'}}
67 assert_response :success
67 assert_response :success
68
68
69 assert_select 'select[name=?]', 'time_entry[project_id]' do
69 assert_select 'select[name=?]', 'time_entry[project_id]' do
70 assert_select 'option[value="1"][selected=selected]'
70 assert_select 'option[value="1"][selected=selected]'
71 end
71 end
72 end
72 end
73
73
74 def test_new_without_project_should_deny_without_permission
74 def test_new_without_project_should_deny_without_permission
75 Role.all.each {|role| role.remove_permission! :log_time}
75 Role.all.each {|role| role.remove_permission! :log_time}
76 @request.session[:user_id] = 3
76 @request.session[:user_id] = 3
77
77
78 get :new
78 get :new
79 assert_response 403
79 assert_response 403
80 end
80 end
81
81
82 def test_new_should_select_default_activity
82 def test_new_should_select_default_activity
83 @request.session[:user_id] = 3
83 @request.session[:user_id] = 3
84 get :new, :params => {:project_id => 1}
84 get :new, :params => {:project_id => 1}
85 assert_response :success
85 assert_response :success
86 assert_select 'select[name=?]', 'time_entry[activity_id]' do
86 assert_select 'select[name=?]', 'time_entry[activity_id]' do
87 assert_select 'option[selected=selected]', :text => 'Development'
87 assert_select 'option[selected=selected]', :text => 'Development'
88 end
88 end
89 end
89 end
90
90
91 def test_new_should_only_show_active_time_entry_activities
91 def test_new_should_only_show_active_time_entry_activities
92 @request.session[:user_id] = 3
92 @request.session[:user_id] = 3
93 get :new, :params => {:project_id => 1}
93 get :new, :params => {:project_id => 1}
94 assert_response :success
94 assert_response :success
95 assert_select 'option', :text => 'Inactive Activity', :count => 0
95 assert_select 'option', :text => 'Inactive Activity', :count => 0
96 end
96 end
97
97
98 def test_post_new_as_js_should_update_activity_options
98 def test_post_new_as_js_should_update_activity_options
99 @request.session[:user_id] = 3
99 @request.session[:user_id] = 3
100 post :new, :params => {:time_entry => {:project_id => 1}, :format => 'js'}
100 post :new, :params => {:time_entry => {:project_id => 1}, :format => 'js'}
101 assert_response :success
101 assert_response :success
102 assert_include '#time_entry_activity_id', response.body
102 assert_include '#time_entry_activity_id', response.body
103 end
103 end
104
104
105 def test_get_edit_existing_time
105 def test_get_edit_existing_time
106 @request.session[:user_id] = 2
106 @request.session[:user_id] = 2
107 get :edit, :params => {:id => 2, :project_id => nil}
107 get :edit, :params => {:id => 2, :project_id => nil}
108 assert_response :success
108 assert_response :success
109
109
110 assert_select 'form[action=?]', '/time_entries/2'
110 assert_select 'form[action=?]', '/time_entries/2'
111 end
111 end
112
112
113 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
113 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
114 te = TimeEntry.find(1)
114 te = TimeEntry.find(1)
115 te.activity = TimeEntryActivity.find_by_name("Inactive Activity")
115 te.activity = TimeEntryActivity.find_by_name("Inactive Activity")
116 te.save!(:validate => false)
116 te.save!(:validate => false)
117
117
118 @request.session[:user_id] = 1
118 @request.session[:user_id] = 1
119 get :edit, :params => {:project_id => 1, :id => 1}
119 get :edit, :params => {:project_id => 1, :id => 1}
120 assert_response :success
120 assert_response :success
121
121
122 # Blank option since nothing is pre-selected
122 # Blank option since nothing is pre-selected
123 assert_select 'option', :text => '--- Please select ---'
123 assert_select 'option', :text => '--- Please select ---'
124 end
124 end
125
125
126 def test_post_create
126 def test_post_create
127 @request.session[:user_id] = 3
127 @request.session[:user_id] = 3
128 assert_difference 'TimeEntry.count' do
128 assert_difference 'TimeEntry.count' do
129 post :create, :params => {
129 post :create, :params => {
130 :project_id => 1,
130 :project_id => 1,
131 :time_entry => {:comments => 'Some work on TimelogControllerTest',
131 :time_entry => {:comments => 'Some work on TimelogControllerTest',
132 # Not the default activity
132 # Not the default activity
133 :activity_id => '11',
133 :activity_id => '11',
134 :spent_on => '2008-03-14',
134 :spent_on => '2008-03-14',
135 :issue_id => '1',
135 :issue_id => '1',
136 :hours => '7.3'
136 :hours => '7.3'
137 }
137 }
138 }
138 }
139 assert_redirected_to '/projects/ecookbook/time_entries'
139 assert_redirected_to '/projects/ecookbook/time_entries'
140 end
140 end
141
141
142 t = TimeEntry.order('id DESC').first
142 t = TimeEntry.order('id DESC').first
143 assert_not_nil t
143 assert_not_nil t
144 assert_equal 'Some work on TimelogControllerTest', t.comments
144 assert_equal 'Some work on TimelogControllerTest', t.comments
145 assert_equal 1, t.project_id
145 assert_equal 1, t.project_id
146 assert_equal 1, t.issue_id
146 assert_equal 1, t.issue_id
147 assert_equal 11, t.activity_id
147 assert_equal 11, t.activity_id
148 assert_equal 7.3, t.hours
148 assert_equal 7.3, t.hours
149 assert_equal 3, t.user_id
149 assert_equal 3, t.user_id
150 end
150 end
151
151
152 def test_post_create_with_blank_issue
152 def test_post_create_with_blank_issue
153 @request.session[:user_id] = 3
153 @request.session[:user_id] = 3
154 assert_difference 'TimeEntry.count' do
154 assert_difference 'TimeEntry.count' do
155 post :create, :params => {
155 post :create, :params => {
156 :project_id => 1,
156 :project_id => 1,
157 :time_entry => {
157 :time_entry => {
158 :comments => 'Some work on TimelogControllerTest',
158 :comments => 'Some work on TimelogControllerTest',
159 # Not the default activity
159 # Not the default activity
160 :activity_id => '11',
160 :activity_id => '11',
161 :issue_id => '',
161 :issue_id => '',
162 :spent_on => '2008-03-14',
162 :spent_on => '2008-03-14',
163 :hours => '7.3'
163 :hours => '7.3'
164 }
164 }
165 }
165 }
166 assert_redirected_to '/projects/ecookbook/time_entries'
166 assert_redirected_to '/projects/ecookbook/time_entries'
167 end
167 end
168
168
169 t = TimeEntry.order('id DESC').first
169 t = TimeEntry.order('id DESC').first
170 assert_not_nil t
170 assert_not_nil t
171 assert_equal 'Some work on TimelogControllerTest', t.comments
171 assert_equal 'Some work on TimelogControllerTest', t.comments
172 assert_equal 1, t.project_id
172 assert_equal 1, t.project_id
173 assert_nil t.issue_id
173 assert_nil t.issue_id
174 assert_equal 11, t.activity_id
174 assert_equal 11, t.activity_id
175 assert_equal 7.3, t.hours
175 assert_equal 7.3, t.hours
176 assert_equal 3, t.user_id
176 assert_equal 3, t.user_id
177 end
177 end
178
178
179 def test_create_on_project_with_time_tracking_disabled_should_fail
179 def test_create_on_project_with_time_tracking_disabled_should_fail
180 Project.find(1).disable_module! :time_tracking
180 Project.find(1).disable_module! :time_tracking
181
181
182 @request.session[:user_id] = 2
182 @request.session[:user_id] = 2
183 assert_no_difference 'TimeEntry.count' do
183 assert_no_difference 'TimeEntry.count' do
184 post :create, :params => {
184 post :create, :params => {
185 :time_entry => {
185 :time_entry => {
186 :project_id => '1', :issue_id => '',
186 :project_id => '1', :issue_id => '',
187 :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
187 :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
188 }
188 }
189 }
189 }
190 end
190 end
191 end
191 end
192
192
193 def test_create_on_project_without_permission_should_fail
193 def test_create_on_project_without_permission_should_fail
194 Role.find(1).remove_permission! :log_time
194 Role.find(1).remove_permission! :log_time
195
195
196 @request.session[:user_id] = 2
196 @request.session[:user_id] = 2
197 assert_no_difference 'TimeEntry.count' do
197 assert_no_difference 'TimeEntry.count' do
198 post :create, :params => {
198 post :create, :params => {
199 :time_entry => {
199 :time_entry => {
200 :project_id => '1', :issue_id => '',
200 :project_id => '1', :issue_id => '',
201 :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
201 :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
202 }
202 }
203 }
203 }
204 end
204 end
205 end
205 end
206
206
207 def test_create_on_issue_in_project_with_time_tracking_disabled_should_fail
207 def test_create_on_issue_in_project_with_time_tracking_disabled_should_fail
208 Project.find(1).disable_module! :time_tracking
208 Project.find(1).disable_module! :time_tracking
209
209
210 @request.session[:user_id] = 2
210 @request.session[:user_id] = 2
211 assert_no_difference 'TimeEntry.count' do
211 assert_no_difference 'TimeEntry.count' do
212 post :create, :params => {
212 post :create, :params => {
213 :time_entry => {
213 :time_entry => {
214 :project_id => '', :issue_id => '1',
214 :project_id => '', :issue_id => '1',
215 :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
215 :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
216 }
216 }
217 }
217 }
218 assert_select_error /Issue is invalid/
218 assert_select_error /Issue is invalid/
219 end
219 end
220 end
220 end
221
221
222 def test_create_on_issue_in_project_without_permission_should_fail
222 def test_create_on_issue_in_project_without_permission_should_fail
223 Role.find(1).remove_permission! :log_time
223 Role.find(1).remove_permission! :log_time
224
224
225 @request.session[:user_id] = 2
225 @request.session[:user_id] = 2
226 assert_no_difference 'TimeEntry.count' do
226 assert_no_difference 'TimeEntry.count' do
227 post :create, :params => {
227 post :create, :params => {
228 :time_entry => {
228 :time_entry => {
229 :project_id => '', :issue_id => '1',
229 :project_id => '', :issue_id => '1',
230 :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
230 :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
231 }
231 }
232 }
232 }
233 assert_select_error /Issue is invalid/
233 assert_select_error /Issue is invalid/
234 end
234 end
235 end
235 end
236
236
237 def test_create_on_issue_that_is_not_visible_should_not_disclose_subject
237 def test_create_on_issue_that_is_not_visible_should_not_disclose_subject
238 issue = Issue.generate!(:subject => "issue_that_is_not_visible", :is_private => true)
238 issue = Issue.generate!(:subject => "issue_that_is_not_visible", :is_private => true)
239 assert !issue.visible?(User.find(3))
239 assert !issue.visible?(User.find(3))
240
240
241 @request.session[:user_id] = 3
241 @request.session[:user_id] = 3
242 assert_no_difference 'TimeEntry.count' do
242 assert_no_difference 'TimeEntry.count' do
243 post :create, :params => {
243 post :create, :params => {
244 :time_entry => {
244 :time_entry => {
245 :project_id => '', :issue_id => issue.id.to_s,
245 :project_id => '', :issue_id => issue.id.to_s,
246 :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
246 :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3'
247 }
247 }
248 }
248 }
249 end
249 end
250 assert_select_error /Issue is invalid/
250 assert_select_error /Issue is invalid/
251 assert_select "input[name=?][value=?]", "time_entry[issue_id]", issue.id.to_s
251 assert_select "input[name=?][value=?]", "time_entry[issue_id]", issue.id.to_s
252 assert_select "#time_entry_issue", 0
252 assert_select "#time_entry_issue", 0
253 assert !response.body.include?('issue_that_is_not_visible')
253 assert !response.body.include?('issue_that_is_not_visible')
254 end
254 end
255
255
256 def test_create_and_continue_at_project_level
256 def test_create_and_continue_at_project_level
257 @request.session[:user_id] = 2
257 @request.session[:user_id] = 2
258 assert_difference 'TimeEntry.count' do
258 assert_difference 'TimeEntry.count' do
259 post :create, :params => {
259 post :create, :params => {
260 :time_entry => {
260 :time_entry => {
261 :project_id => '1',
261 :project_id => '1',
262 :activity_id => '11',
262 :activity_id => '11',
263 :issue_id => '',
263 :issue_id => '',
264 :spent_on => '2008-03-14',
264 :spent_on => '2008-03-14',
265 :hours => '7.3'
265 :hours => '7.3'
266 },
266 },
267 :continue => '1'
267 :continue => '1'
268 }
268 }
269 assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1'
269 assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1'
270 end
270 end
271 end
271 end
272
272
273 def test_create_and_continue_at_issue_level
273 def test_create_and_continue_at_issue_level
274 @request.session[:user_id] = 2
274 @request.session[:user_id] = 2
275 assert_difference 'TimeEntry.count' do
275 assert_difference 'TimeEntry.count' do
276 post :create, :params => {
276 post :create, :params => {
277 :time_entry => {
277 :time_entry => {
278 :project_id => '',
278 :project_id => '',
279 :activity_id => '11',
279 :activity_id => '11',
280 :issue_id => '1',
280 :issue_id => '1',
281 :spent_on => '2008-03-14',
281 :spent_on => '2008-03-14',
282 :hours => '7.3'
282 :hours => '7.3'
283 },
283 },
284 :continue => '1'
284 :continue => '1'
285 }
285 }
286 assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1&time_entry%5Bproject_id%5D='
286 assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1&time_entry%5Bproject_id%5D='
287 end
287 end
288 end
288 end
289
289
290 def test_create_and_continue_with_project_id
290 def test_create_and_continue_with_project_id
291 @request.session[:user_id] = 2
291 @request.session[:user_id] = 2
292 assert_difference 'TimeEntry.count' do
292 assert_difference 'TimeEntry.count' do
293 post :create, :params => {
293 post :create, :params => {
294 :project_id => 1,
294 :project_id => 1,
295 :time_entry => {
295 :time_entry => {
296 :activity_id => '11',
296 :activity_id => '11',
297 :issue_id => '',
297 :issue_id => '',
298 :spent_on => '2008-03-14',
298 :spent_on => '2008-03-14',
299 :hours => '7.3'
299 :hours => '7.3'
300 },
300 },
301 :continue => '1'
301 :continue => '1'
302 }
302 }
303 assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D='
303 assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D='
304 end
304 end
305 end
305 end
306
306
307 def test_create_and_continue_with_issue_id
307 def test_create_and_continue_with_issue_id
308 @request.session[:user_id] = 2
308 @request.session[:user_id] = 2
309 assert_difference 'TimeEntry.count' do
309 assert_difference 'TimeEntry.count' do
310 post :create, :params => {
310 post :create, :params => {
311 :issue_id => 1,
311 :issue_id => 1,
312 :time_entry => {
312 :time_entry => {
313 :activity_id => '11',
313 :activity_id => '11',
314 :issue_id => '1',
314 :issue_id => '1',
315 :spent_on => '2008-03-14',
315 :spent_on => '2008-03-14',
316 :hours => '7.3'
316 :hours => '7.3'
317 },
317 },
318 :continue => '1'
318 :continue => '1'
319 }
319 }
320 assert_redirected_to '/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1&time_entry%5Bproject_id%5D='
320 assert_redirected_to '/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1&time_entry%5Bproject_id%5D='
321 end
321 end
322 end
322 end
323
323
324 def test_create_without_log_time_permission_should_be_denied
324 def test_create_without_log_time_permission_should_be_denied
325 @request.session[:user_id] = 2
325 @request.session[:user_id] = 2
326 Role.find_by_name('Manager').remove_permission! :log_time
326 Role.find_by_name('Manager').remove_permission! :log_time
327 post :create, :params => {
327 post :create, :params => {
328 :project_id => 1,
328 :project_id => 1,
329 :time_entry => {
329 :time_entry => {
330 :activity_id => '11',
330 :activity_id => '11',
331 :issue_id => '',
331 :issue_id => '',
332 :spent_on => '2008-03-14',
332 :spent_on => '2008-03-14',
333 :hours => '7.3'
333 :hours => '7.3'
334 }
334 }
335 }
335 }
336 assert_response 403
336 assert_response 403
337 end
337 end
338
338
339 def test_create_without_project_and_issue_should_fail
339 def test_create_without_project_and_issue_should_fail
340 @request.session[:user_id] = 2
340 @request.session[:user_id] = 2
341 post :create, :params => {:time_entry => {:issue_id => ''}}
341 post :create, :params => {:time_entry => {:issue_id => ''}}
342
342
343 assert_response :success
343 assert_response :success
344 assert_select_error /Project cannot be blank/
344 assert_select_error /Project cannot be blank/
345 end
345 end
346
346
347 def test_create_with_failure
347 def test_create_with_failure
348 @request.session[:user_id] = 2
348 @request.session[:user_id] = 2
349 post :create, :params => {
349 post :create, :params => {
350 :project_id => 1,
350 :project_id => 1,
351 :time_entry => {
351 :time_entry => {
352 :activity_id => '',
352 :activity_id => '',
353 :issue_id => '',
353 :issue_id => '',
354 :spent_on => '2008-03-14',
354 :spent_on => '2008-03-14',
355 :hours => '7.3'
355 :hours => '7.3'
356 }
356 }
357 }
357 }
358 assert_response :success
358 assert_response :success
359 end
359 end
360
360
361 def test_create_without_project
361 def test_create_without_project
362 @request.session[:user_id] = 2
362 @request.session[:user_id] = 2
363 assert_difference 'TimeEntry.count' do
363 assert_difference 'TimeEntry.count' do
364 post :create, :params => {
364 post :create, :params => {
365 :time_entry => {
365 :time_entry => {
366 :project_id => '1',
366 :project_id => '1',
367 :activity_id => '11',
367 :activity_id => '11',
368 :issue_id => '',
368 :issue_id => '',
369 :spent_on => '2008-03-14',
369 :spent_on => '2008-03-14',
370 :hours => '7.3'
370 :hours => '7.3'
371 }
371 }
372 }
372 }
373 end
373 end
374
374
375 assert_redirected_to '/projects/ecookbook/time_entries'
375 assert_redirected_to '/projects/ecookbook/time_entries'
376 time_entry = TimeEntry.order('id DESC').first
376 time_entry = TimeEntry.order('id DESC').first
377 assert_equal 1, time_entry.project_id
377 assert_equal 1, time_entry.project_id
378 end
378 end
379
379
380 def test_create_without_project_should_fail_with_issue_not_inside_project
380 def test_create_without_project_should_fail_with_issue_not_inside_project
381 @request.session[:user_id] = 2
381 @request.session[:user_id] = 2
382 assert_no_difference 'TimeEntry.count' do
382 assert_no_difference 'TimeEntry.count' do
383 post :create, :params => {
383 post :create, :params => {
384 :time_entry => {
384 :time_entry => {
385 :project_id => '1',
385 :project_id => '1',
386 :activity_id => '11',
386 :activity_id => '11',
387 :issue_id => '5',
387 :issue_id => '5',
388 :spent_on => '2008-03-14',
388 :spent_on => '2008-03-14',
389 :hours => '7.3'
389 :hours => '7.3'
390 }
390 }
391 }
391 }
392 end
392 end
393
393
394 assert_response :success
394 assert_response :success
395 assert_select_error /Issue is invalid/
395 assert_select_error /Issue is invalid/
396 end
396 end
397
397
398 def test_create_without_project_should_deny_without_permission
398 def test_create_without_project_should_deny_without_permission
399 @request.session[:user_id] = 2
399 @request.session[:user_id] = 2
400 Project.find(3).disable_module!(:time_tracking)
400 Project.find(3).disable_module!(:time_tracking)
401
401
402 assert_no_difference 'TimeEntry.count' do
402 assert_no_difference 'TimeEntry.count' do
403 post :create, :params => {
403 post :create, :params => {
404 :time_entry => {
404 :time_entry => {
405 :project_id => '3',
405 :project_id => '3',
406 :activity_id => '11',
406 :activity_id => '11',
407 :issue_id => '',
407 :issue_id => '',
408 :spent_on => '2008-03-14',
408 :spent_on => '2008-03-14',
409 :hours => '7.3'
409 :hours => '7.3'
410 }
410 }
411 }
411 }
412 end
412 end
413
413
414 assert_response 403
414 assert_response 403
415 end
415 end
416
416
417 def test_create_without_project_with_failure
417 def test_create_without_project_with_failure
418 @request.session[:user_id] = 2
418 @request.session[:user_id] = 2
419 assert_no_difference 'TimeEntry.count' do
419 assert_no_difference 'TimeEntry.count' do
420 post :create, :params => {
420 post :create, :params => {
421 :time_entry => {
421 :time_entry => {
422 :project_id => '1',
422 :project_id => '1',
423 :activity_id => '11',
423 :activity_id => '11',
424 :issue_id => '',
424 :issue_id => '',
425 :spent_on => '2008-03-14',
425 :spent_on => '2008-03-14',
426 :hours => ''
426 :hours => ''
427 }
427 }
428 }
428 }
429 end
429 end
430
430
431 assert_response :success
431 assert_response :success
432 assert_select 'select[name=?]', 'time_entry[project_id]' do
432 assert_select 'select[name=?]', 'time_entry[project_id]' do
433 assert_select 'option[value="1"][selected=selected]'
433 assert_select 'option[value="1"][selected=selected]'
434 end
434 end
435 end
435 end
436
436
437 def test_update
437 def test_update
438 entry = TimeEntry.find(1)
438 entry = TimeEntry.find(1)
439 assert_equal 1, entry.issue_id
439 assert_equal 1, entry.issue_id
440 assert_equal 2, entry.user_id
440 assert_equal 2, entry.user_id
441
441
442 @request.session[:user_id] = 1
442 @request.session[:user_id] = 1
443 put :update, :params => {
443 put :update, :params => {
444 :id => 1,
444 :id => 1,
445 :time_entry => {
445 :time_entry => {
446 :issue_id => '2',
446 :issue_id => '2',
447 :hours => '8'
447 :hours => '8'
448 }
448 }
449 }
449 }
450 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
450 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
451 entry.reload
451 entry.reload
452
452
453 assert_equal 8, entry.hours
453 assert_equal 8, entry.hours
454 assert_equal 2, entry.issue_id
454 assert_equal 2, entry.issue_id
455 assert_equal 2, entry.user_id
455 assert_equal 2, entry.user_id
456 end
456 end
457
457
458 def test_update_should_allow_to_change_issue_to_another_project
458 def test_update_should_allow_to_change_issue_to_another_project
459 entry = TimeEntry.generate!(:issue_id => 1)
459 entry = TimeEntry.generate!(:issue_id => 1)
460
460
461 @request.session[:user_id] = 1
461 @request.session[:user_id] = 1
462 put :update, :params => {
462 put :update, :params => {
463 :id => entry.id,
463 :id => entry.id,
464 :time_entry => {
464 :time_entry => {
465 :issue_id => '5'
465 :issue_id => '5'
466 }
466 }
467 }
467 }
468 assert_response 302
468 assert_response 302
469 entry.reload
469 entry.reload
470
470
471 assert_equal 5, entry.issue_id
471 assert_equal 5, entry.issue_id
472 assert_equal 3, entry.project_id
472 assert_equal 3, entry.project_id
473 end
473 end
474
474
475 def test_update_should_not_allow_to_change_issue_to_an_invalid_project
475 def test_update_should_not_allow_to_change_issue_to_an_invalid_project
476 entry = TimeEntry.generate!(:issue_id => 1)
476 entry = TimeEntry.generate!(:issue_id => 1)
477 Project.find(3).disable_module!(:time_tracking)
477 Project.find(3).disable_module!(:time_tracking)
478
478
479 @request.session[:user_id] = 1
479 @request.session[:user_id] = 1
480 put :update, :params => {
480 put :update, :params => {
481 :id => entry.id,
481 :id => entry.id,
482 :time_entry => {
482 :time_entry => {
483 :issue_id => '5'
483 :issue_id => '5'
484 }
484 }
485 }
485 }
486 assert_response :success
486 assert_response :success
487 assert_select_error /Issue is invalid/
487 assert_select_error /Issue is invalid/
488 end
488 end
489
489
490 def test_get_bulk_edit
490 def test_get_bulk_edit
491 @request.session[:user_id] = 2
491 @request.session[:user_id] = 2
492
492
493 get :bulk_edit, :params => {:ids => [1, 2]}
493 get :bulk_edit, :params => {:ids => [1, 2]}
494 assert_response :success
494 assert_response :success
495
495
496 assert_select 'ul#bulk-selection' do
496 assert_select 'ul#bulk-selection' do
497 assert_select 'li', 2
497 assert_select 'li', 2
498 assert_select 'li a', :text => '03/23/2007 - eCookbook: 4.25 hours'
498 assert_select 'li a', :text => '03/23/2007 - eCookbook: 4.25 hours'
499 end
499 end
500
500
501 assert_select 'form#bulk_edit_form[action=?]', '/time_entries/bulk_update' do
501 assert_select 'form#bulk_edit_form[action=?]', '/time_entries/bulk_update' do
502 # System wide custom field
502 # System wide custom field
503 assert_select 'select[name=?]', 'time_entry[custom_field_values][10]'
503 assert_select 'select[name=?]', 'time_entry[custom_field_values][10]'
504
504
505 # Activities
505 # Activities
506 assert_select 'select[name=?]', 'time_entry[activity_id]' do
506 assert_select 'select[name=?]', 'time_entry[activity_id]' do
507 assert_select 'option[value=""]', :text => '(No change)'
507 assert_select 'option[value=""]', :text => '(No change)'
508 assert_select 'option[value="9"]', :text => 'Design'
508 assert_select 'option[value="9"]', :text => 'Design'
509 end
509 end
510 end
510 end
511 end
511 end
512
512
513 def test_get_bulk_edit_on_different_projects
513 def test_get_bulk_edit_on_different_projects
514 @request.session[:user_id] = 2
514 @request.session[:user_id] = 2
515
515
516 get :bulk_edit, :params => {:ids => [1, 2, 6]}
516 get :bulk_edit, :params => {:ids => [1, 2, 6]}
517 assert_response :success
517 assert_response :success
518 end
518 end
519
519
520 def test_bulk_edit_with_edit_own_time_entries_permission
520 def test_bulk_edit_with_edit_own_time_entries_permission
521 @request.session[:user_id] = 2
521 @request.session[:user_id] = 2
522 Role.find_by_name('Manager').remove_permission! :edit_time_entries
522 Role.find_by_name('Manager').remove_permission! :edit_time_entries
523 Role.find_by_name('Manager').add_permission! :edit_own_time_entries
523 Role.find_by_name('Manager').add_permission! :edit_own_time_entries
524 ids = (0..1).map {TimeEntry.generate!(:user => User.find(2)).id}
524 ids = (0..1).map {TimeEntry.generate!(:user => User.find(2)).id}
525
525
526 get :bulk_edit, :params => {:ids => ids}
526 get :bulk_edit, :params => {:ids => ids}
527 assert_response :success
527 assert_response :success
528 end
528 end
529
529
530 def test_bulk_update
530 def test_bulk_update
531 @request.session[:user_id] = 2
531 @request.session[:user_id] = 2
532 # update time entry activity
532 # update time entry activity
533 post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :activity_id => 9}}
533 post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :activity_id => 9}}
534
534
535 assert_response 302
535 assert_response 302
536 # check that the issues were updated
536 # check that the issues were updated
537 assert_equal [9, 9], TimeEntry.where(:id => [1, 2]).collect {|i| i.activity_id}
537 assert_equal [9, 9], TimeEntry.where(:id => [1, 2]).collect {|i| i.activity_id}
538 end
538 end
539
539
540 def test_bulk_update_with_failure
540 def test_bulk_update_with_failure
541 @request.session[:user_id] = 2
541 @request.session[:user_id] = 2
542 post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :hours => 'A'}}
542 post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :hours => 'A'}}
543
543
544 assert_response 302
544 assert_response 302
545 assert_match /Failed to save 2 time entrie/, flash[:error]
545 assert_match /Failed to save 2 time entrie/, flash[:error]
546 end
546 end
547
547
548 def test_bulk_update_on_different_projects
548 def test_bulk_update_on_different_projects
549 @request.session[:user_id] = 2
549 @request.session[:user_id] = 2
550 # makes user a manager on the other project
550 # makes user a manager on the other project
551 Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1])
551 Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1])
552
552
553 # update time entry activity
553 # update time entry activity
554 post :bulk_update, :params => {:ids => [1, 2, 4], :time_entry => { :activity_id => 9 }}
554 post :bulk_update, :params => {:ids => [1, 2, 4], :time_entry => { :activity_id => 9 }}
555
555
556 assert_response 302
556 assert_response 302
557 # check that the issues were updated
557 # check that the issues were updated
558 assert_equal [9, 9, 9], TimeEntry.where(:id => [1, 2, 4]).collect {|i| i.activity_id}
558 assert_equal [9, 9, 9], TimeEntry.where(:id => [1, 2, 4]).collect {|i| i.activity_id}
559 end
559 end
560
560
561 def test_bulk_update_on_different_projects_without_rights
561 def test_bulk_update_on_different_projects_without_rights
562 @request.session[:user_id] = 3
562 @request.session[:user_id] = 3
563 user = User.find(3)
563 user = User.find(3)
564 action = { :controller => "timelog", :action => "bulk_update" }
564 action = { :controller => "timelog", :action => "bulk_update" }
565 assert user.allowed_to?(action, TimeEntry.find(1).project)
565 assert user.allowed_to?(action, TimeEntry.find(1).project)
566 assert ! user.allowed_to?(action, TimeEntry.find(5).project)
566 assert ! user.allowed_to?(action, TimeEntry.find(5).project)
567
567
568 post :bulk_update, :params => {:ids => [1, 5], :time_entry => { :activity_id => 9 }}
568 post :bulk_update, :params => {:ids => [1, 5], :time_entry => { :activity_id => 9 }}
569 assert_response 403
569 assert_response 403
570 end
570 end
571
571
572 def test_bulk_update_with_edit_own_time_entries_permission
572 def test_bulk_update_with_edit_own_time_entries_permission
573 @request.session[:user_id] = 2
573 @request.session[:user_id] = 2
574 Role.find_by_name('Manager').remove_permission! :edit_time_entries
574 Role.find_by_name('Manager').remove_permission! :edit_time_entries
575 Role.find_by_name('Manager').add_permission! :edit_own_time_entries
575 Role.find_by_name('Manager').add_permission! :edit_own_time_entries
576 ids = (0..1).map {TimeEntry.generate!(:user => User.find(2)).id}
576 ids = (0..1).map {TimeEntry.generate!(:user => User.find(2)).id}
577
577
578 post :bulk_update, :params => {:ids => ids, :time_entry => { :activity_id => 9 }}
578 post :bulk_update, :params => {:ids => ids, :time_entry => { :activity_id => 9 }}
579 assert_response 302
579 assert_response 302
580 end
580 end
581
581
582 def test_bulk_update_with_edit_own_time_entries_permissions_should_be_denied_for_time_entries_of_other_user
582 def test_bulk_update_with_edit_own_time_entries_permissions_should_be_denied_for_time_entries_of_other_user
583 @request.session[:user_id] = 2
583 @request.session[:user_id] = 2
584 Role.find_by_name('Manager').remove_permission! :edit_time_entries
584 Role.find_by_name('Manager').remove_permission! :edit_time_entries
585 Role.find_by_name('Manager').add_permission! :edit_own_time_entries
585 Role.find_by_name('Manager').add_permission! :edit_own_time_entries
586
586
587 post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :activity_id => 9 }}
587 post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :activity_id => 9 }}
588 assert_response 403
588 assert_response 403
589 end
589 end
590
590
591 def test_bulk_update_custom_field
591 def test_bulk_update_custom_field
592 @request.session[:user_id] = 2
592 @request.session[:user_id] = 2
593 post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} }}
593 post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} }}
594
594
595 assert_response 302
595 assert_response 302
596 assert_equal ["0", "0"], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(10).value}
596 assert_equal ["0", "0"], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(10).value}
597 end
597 end
598
598
599 def test_bulk_update_clear_custom_field
599 def test_bulk_update_clear_custom_field
600 field = TimeEntryCustomField.generate!(:field_format => 'string')
600 field = TimeEntryCustomField.generate!(:field_format => 'string')
601 @request.session[:user_id] = 2
601 @request.session[:user_id] = 2
602 post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :custom_field_values => {field.id.to_s => '__none__'} }}
602 post :bulk_update, :params => {:ids => [1, 2], :time_entry => { :custom_field_values => {field.id.to_s => '__none__'} }}
603
603
604 assert_response 302
604 assert_response 302
605 assert_equal ["", ""], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(field).value}
605 assert_equal ["", ""], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(field).value}
606 end
606 end
607
607
608 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
608 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
609 @request.session[:user_id] = 2
609 @request.session[:user_id] = 2
610 post :bulk_update, :params => {:ids => [1,2], :back_url => '/time_entries'}
610 post :bulk_update, :params => {:ids => [1,2], :back_url => '/time_entries'}
611
611
612 assert_response :redirect
612 assert_response :redirect
613 assert_redirected_to '/time_entries'
613 assert_redirected_to '/time_entries'
614 end
614 end
615
615
616 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
616 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
617 @request.session[:user_id] = 2
617 @request.session[:user_id] = 2
618 post :bulk_update, :params => {:ids => [1,2], :back_url => 'http://google.com'}
618 post :bulk_update, :params => {:ids => [1,2], :back_url => 'http://google.com'}
619
619
620 assert_response :redirect
620 assert_response :redirect
621 assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier
621 assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier
622 end
622 end
623
623
624 def test_post_bulk_update_without_edit_permission_should_be_denied
624 def test_post_bulk_update_without_edit_permission_should_be_denied
625 @request.session[:user_id] = 2
625 @request.session[:user_id] = 2
626 Role.find_by_name('Manager').remove_permission! :edit_time_entries
626 Role.find_by_name('Manager').remove_permission! :edit_time_entries
627
627
628 post :bulk_update, :params => {:ids => [1,2]}
628 post :bulk_update, :params => {:ids => [1,2]}
629 assert_response 403
629 assert_response 403
630 end
630 end
631
631
632 def test_destroy
632 def test_destroy
633 @request.session[:user_id] = 2
633 @request.session[:user_id] = 2
634
634
635 delete :destroy, :params => {:id => 1}
635 delete :destroy, :params => {:id => 1}
636 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
636 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
637 assert_equal I18n.t(:notice_successful_delete), flash[:notice]
637 assert_equal I18n.t(:notice_successful_delete), flash[:notice]
638 assert_nil TimeEntry.find_by_id(1)
638 assert_nil TimeEntry.find_by_id(1)
639 end
639 end
640
640
641 def test_destroy_should_fail
641 def test_destroy_should_fail
642 # simulate that this fails (e.g. due to a plugin), see #5700
642 # simulate that this fails (e.g. due to a plugin), see #5700
643 TimeEntry.any_instance.expects(:destroy).returns(false)
643 TimeEntry.any_instance.expects(:destroy).returns(false)
644 @request.session[:user_id] = 2
644 @request.session[:user_id] = 2
645
645
646 delete :destroy, :params => {:id => 1}
646 delete :destroy, :params => {:id => 1}
647 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
647 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
648 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
648 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
649 assert_not_nil TimeEntry.find_by_id(1)
649 assert_not_nil TimeEntry.find_by_id(1)
650 end
650 end
651
651
652 def test_index_all_projects
652 def test_index_all_projects
653 get :index
653 get :index
654 assert_response :success
654 assert_response :success
655
655
656 assert_select '.total-for-hours', :text => 'Hours: 162.90'
656 assert_select '.total-for-hours', :text => 'Hours: 162.90'
657 assert_select 'form#query_form[action=?]', '/time_entries'
657 assert_select 'form#query_form[action=?]', '/time_entries'
658 end
658 end
659
659
660 def test_index_all_projects_should_show_log_time_link
660 def test_index_all_projects_should_show_log_time_link
661 @request.session[:user_id] = 2
661 @request.session[:user_id] = 2
662 get :index
662 get :index
663 assert_response :success
663 assert_response :success
664
664
665 assert_select 'a[href=?]', '/time_entries/new', :text => /Log time/
665 assert_select 'a[href=?]', '/time_entries/new', :text => /Log time/
666 end
666 end
667
667
668 def test_index_my_spent_time
668 def test_index_my_spent_time
669 @request.session[:user_id] = 2
669 @request.session[:user_id] = 2
670 get :index, :params => {:user_id => 'me', :c => ['user']}
670 get :index, :params => {:user_id => 'me', :c => ['user']}
671 assert_response :success
671 assert_response :success
672
672
673 users = css_select('table.time-entries tbody td.user').map(&:text).uniq
673 users = css_select('table.time-entries tbody td.user').map(&:text).uniq
674 assert_equal ["John Smith"], users
674 assert_equal ["John Smith"], users
675 end
675 end
676
676
677 def test_index_at_project_level
677 def test_index_at_project_level
678 get :index, :params => {:project_id => 'ecookbook', :c => ['project']}
678 get :index, :params => {:project_id => 'ecookbook', :c => ['project']}
679 assert_response :success
679 assert_response :success
680
680
681 assert_select 'tr.time-entry', 4
681 assert_select 'tr.time-entry', 4
682
682
683 # project and subproject
683 # project and subproject
684 projects = css_select('table.time-entries tbody td.project').map(&:text).uniq.sort
684 projects = css_select('table.time-entries tbody td.project').map(&:text).uniq.sort
685 assert_equal ["eCookbook", "eCookbook Subproject 1"], projects
685 assert_equal ["eCookbook", "eCookbook Subproject 1"], projects
686
686
687 assert_select '.total-for-hours', :text => 'Hours: 162.90'
687 assert_select '.total-for-hours', :text => 'Hours: 162.90'
688 assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries'
688 assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries'
689 end
689 end
690
690
691 def test_index_with_display_subprojects_issues_to_false_should_not_include_subproject_entries
691 def test_index_with_display_subprojects_issues_to_false_should_not_include_subproject_entries
692 entry = TimeEntry.generate!(:project => Project.find(3))
692 entry = TimeEntry.generate!(:project => Project.find(3))
693
693
694 with_settings :display_subprojects_issues => '0' do
694 with_settings :display_subprojects_issues => '0' do
695 get :index, :params => {:project_id => 'ecookbook', :c => ['project']}
695 get :index, :params => {:project_id => 'ecookbook', :c => ['project']}
696 assert_response :success
696 assert_response :success
697
697
698 projects = css_select('table.time-entries tbody td.project').map(&:text).uniq.sort
698 projects = css_select('table.time-entries tbody td.project').map(&:text).uniq.sort
699 assert_equal ["eCookbook"], projects
699 assert_equal ["eCookbook"], projects
700 end
700 end
701 end
701 end
702
702
703 def test_index_with_display_subprojects_issues_to_false_and_subproject_filter_should_include_subproject_entries
703 def test_index_with_display_subprojects_issues_to_false_and_subproject_filter_should_include_subproject_entries
704 entry = TimeEntry.generate!(:project => Project.find(3))
704 entry = TimeEntry.generate!(:project => Project.find(3))
705
705
706 with_settings :display_subprojects_issues => '0' do
706 with_settings :display_subprojects_issues => '0' do
707 get :index, :params => {:project_id => 'ecookbook', :c => ['project'], :subproject_id => 3}
707 get :index, :params => {:project_id => 'ecookbook', :c => ['project'], :subproject_id => 3}
708 assert_response :success
708 assert_response :success
709
709
710 projects = css_select('table.time-entries tbody td.project').map(&:text).uniq.sort
710 projects = css_select('table.time-entries tbody td.project').map(&:text).uniq.sort
711 assert_equal ["eCookbook", "eCookbook Subproject 1"], projects
711 assert_equal ["eCookbook", "eCookbook Subproject 1"], projects
712 end
712 end
713 end
713 end
714
714
715 def test_index_at_project_level_with_issue_id_short_filter
715 def test_index_at_project_level_with_issue_id_short_filter
716 issue = Issue.generate!(:project_id => 1)
716 issue = Issue.generate!(:project_id => 1)
717 TimeEntry.generate!(:issue => issue, :hours => 4)
717 TimeEntry.generate!(:issue => issue, :hours => 4)
718 TimeEntry.generate!(:issue => issue, :hours => 3)
718 TimeEntry.generate!(:issue => issue, :hours => 3)
719 @request.session[:user_id] = 2
719 @request.session[:user_id] = 2
720
720
721 get :index, :params => {:project_id => 'ecookbook', :issue_id => issue.id.to_s, :set_filter => 1}
721 get :index, :params => {:project_id => 'ecookbook', :issue_id => issue.id.to_s, :set_filter => 1}
722 assert_select '.total-for-hours', :text => 'Hours: 7.00'
722 assert_select '.total-for-hours', :text => 'Hours: 7.00'
723 end
723 end
724
724
725 def test_index_at_project_level_with_issue_fixed_version_id_short_filter
725 def test_index_at_project_level_with_issue_fixed_version_id_short_filter
726 version = Version.generate!(:project_id => 1)
726 version = Version.generate!(:project_id => 1)
727 issue = Issue.generate!(:project_id => 1, :fixed_version => version)
727 issue = Issue.generate!(:project_id => 1, :fixed_version => version)
728 TimeEntry.generate!(:issue => issue, :hours => 2)
728 TimeEntry.generate!(:issue => issue, :hours => 2)
729 TimeEntry.generate!(:issue => issue, :hours => 3)
729 TimeEntry.generate!(:issue => issue, :hours => 3)
730 @request.session[:user_id] = 2
730 @request.session[:user_id] = 2
731
731
732 get :index, :params => {:project_id => 'ecookbook', :"issue.fixed_version_id" => version.id.to_s, :set_filter => 1}
732 get :index, :params => {:project_id => 'ecookbook', :"issue.fixed_version_id" => version.id.to_s, :set_filter => 1}
733 assert_select '.total-for-hours', :text => 'Hours: 5.00'
733 assert_select '.total-for-hours', :text => 'Hours: 5.00'
734 end
734 end
735
735
736 def test_index_at_project_level_with_date_range
736 def test_index_at_project_level_with_date_range
737 get :index, :params => {
737 get :index, :params => {
738 :project_id => 'ecookbook',
738 :project_id => 'ecookbook',
739 :f => ['spent_on'],
739 :f => ['spent_on'],
740 :op => {'spent_on' => '><'},
740 :op => {'spent_on' => '><'},
741 :v => {'spent_on' => ['2007-03-20', '2007-04-30']}
741 :v => {'spent_on' => ['2007-03-20', '2007-04-30']}
742 }
742 }
743 assert_response :success
743 assert_response :success
744
744
745 assert_select 'tr.time-entry', 3
745 assert_select 'tr.time-entry', 3
746 assert_select '.total-for-hours', :text => 'Hours: 12.90'
746 assert_select '.total-for-hours', :text => 'Hours: 12.90'
747 assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries'
747 assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries'
748 end
748 end
749
749
750 def test_index_at_project_level_with_date_range_using_from_and_to_params
750 def test_index_at_project_level_with_date_range_using_from_and_to_params
751 get :index, :params => {
751 get :index, :params => {
752 :project_id => 'ecookbook',
752 :project_id => 'ecookbook',
753 :from => '2007-03-20',
753 :from => '2007-03-20',
754 :to => '2007-04-30'
754 :to => '2007-04-30'
755 }
755 }
756 assert_response :success
756 assert_response :success
757
757
758 assert_select 'tr.time-entry', 3
758 assert_select 'tr.time-entry', 3
759 assert_select '.total-for-hours', :text => 'Hours: 12.90'
759 assert_select '.total-for-hours', :text => 'Hours: 12.90'
760 assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries'
760 assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries'
761 end
761 end
762
762
763 def test_index_at_project_level_with_period
763 def test_index_at_project_level_with_period
764 get :index, :params => {
764 get :index, :params => {
765 :project_id => 'ecookbook',
765 :project_id => 'ecookbook',
766 :f => ['spent_on'],
766 :f => ['spent_on'],
767 :op => {'spent_on' => '>t-'},
767 :op => {'spent_on' => '>t-'},
768 :v => {'spent_on' => ['7']}
768 :v => {'spent_on' => ['7']}
769 }
769 }
770 assert_response :success
770 assert_response :success
771
771
772 assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries'
772 assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries'
773 end
773 end
774
774
775 def test_index_should_sort_by_spent_on_and_created_on
775 def test_index_should_sort_by_spent_on_and_created_on
776 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)
776 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)
777 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)
777 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)
778 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)
778 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)
779
779
780 get :index, :params => {
780 get :index, :params => {
781 :project_id => 1,
781 :project_id => 1,
782 :f => ['spent_on'],
782 :f => ['spent_on'],
783 :op => {'spent_on' => '><'},
783 :op => {'spent_on' => '><'},
784 :v => {'spent_on' => ['2012-06-15', '2012-06-16']}
784 :v => {'spent_on' => ['2012-06-15', '2012-06-16']}
785 }
785 }
786 assert_response :success
786 assert_response :success
787 assert_equal [t2, t1, t3].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
787 assert_equal [t2, t1, t3].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
788
788
789 get :index, :params => {
789 get :index, :params => {
790 :project_id => 1,
790 :project_id => 1,
791 :f => ['spent_on'],
791 :f => ['spent_on'],
792 :op => {'spent_on' => '><'},
792 :op => {'spent_on' => '><'},
793 :v => {'spent_on' => ['2012-06-15', '2012-06-16']},
793 :v => {'spent_on' => ['2012-06-15', '2012-06-16']},
794 :sort => 'spent_on'
794 :sort => 'spent_on'
795 }
795 }
796 assert_response :success
796 assert_response :success
797 assert_equal [t3, t1, t2].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
797 assert_equal [t3, t1, t2].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
798 end
798 end
799
799
800 def test_index_with_issue_status_filter
800 def test_index_with_issue_status_filter
801 Issue.where(:status_id => 4).update_all(:status_id => 2)
801 Issue.where(:status_id => 4).update_all(:status_id => 2)
802 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 4)
802 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 4)
803 entry = TimeEntry.generate!(:issue => issue, :hours => 4.5)
803 entry = TimeEntry.generate!(:issue => issue, :hours => 4.5)
804
804
805 get :index, :params => {
805 get :index, :params => {
806 :f => ['issue.status_id'],
806 :f => ['issue.status_id'],
807 :op => {'issue.status_id' => '='},
807 :op => {'issue.status_id' => '='},
808 :v => {'issue.status_id' => ['4']}
808 :v => {'issue.status_id' => ['4']}
809 }
809 }
810 assert_response :success
810 assert_response :success
811 assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
811 assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
812 end
812 end
813
813
814 def test_index_with_issue_status_column
814 def test_index_with_issue_status_column
815 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 4)
815 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 4)
816 entry = TimeEntry.generate!(:issue => issue)
816 entry = TimeEntry.generate!(:issue => issue)
817
817
818 get :index, :params => {
818 get :index, :params => {
819 :c => %w(project spent_on issue comments hours issue.status)
819 :c => %w(project spent_on issue comments hours issue.status)
820 }
820 }
821 assert_response :success
821 assert_response :success
822 assert_select 'td.issue-status', :text => issue.status.name
822 assert_select 'td.issue-status', :text => issue.status.name
823 end
823 end
824
824
825 def test_index_with_issue_status_sort
825 def test_index_with_issue_status_sort
826 TimeEntry.delete_all
826 TimeEntry.delete_all
827 TimeEntry.generate!(:issue => Issue.generate!(:status_id => 1))
827 TimeEntry.generate!(:issue => Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 1))
828 TimeEntry.generate!(:issue => Issue.generate!(:status_id => 5))
828 TimeEntry.generate!(:issue => Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 5))
829 TimeEntry.generate!(:issue => Issue.generate!(:status_id => 3))
829 TimeEntry.generate!(:issue => Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 3))
830 TimeEntry.generate!(:project_id => 1)
830 TimeEntry.generate!(:project_id => 1)
831
831
832 get :index, :params => {
832 get :index, :params => {
833 :c => ["hours", 'issue.status'],
833 :c => ["hours", 'issue.status'],
834 :sort => 'issue.status'
834 :sort => 'issue.status'
835 }
835 }
836 assert_response :success
836 assert_response :success
837
837
838 # Make sure that values are properly sorted
838 # Make sure that values are properly sorted
839 values = css_select("td.issue-status").map(&:text).reject(&:blank?)
839 values = css_select("td.issue-status").map(&:text).reject(&:blank?)
840 assert_equal IssueStatus.where(:id => [1, 5, 3]).sorted.pluck(:name), values
840 assert_equal IssueStatus.where(:id => [1, 5, 3]).sorted.pluck(:name), values
841 end
841 end
842
842
843 def test_index_with_issue_tracker_filter
843 def test_index_with_issue_tracker_filter
844 Issue.where(:tracker_id => 2).update_all(:tracker_id => 1)
844 Issue.where(:tracker_id => 2).update_all(:tracker_id => 1)
845 issue = Issue.generate!(:project_id => 1, :tracker_id => 2)
845 issue = Issue.generate!(:project_id => 1, :tracker_id => 2)
846 entry = TimeEntry.generate!(:issue => issue, :hours => 4.5)
846 entry = TimeEntry.generate!(:issue => issue, :hours => 4.5)
847
847
848 get :index, :params => {
848 get :index, :params => {
849 :f => ['issue.tracker_id'],
849 :f => ['issue.tracker_id'],
850 :op => {'issue.tracker_id' => '='},
850 :op => {'issue.tracker_id' => '='},
851 :v => {'issue.tracker_id' => ['2']}
851 :v => {'issue.tracker_id' => ['2']}
852 }
852 }
853 assert_response :success
853 assert_response :success
854 assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
854 assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
855 end
855 end
856
856
857 def test_index_with_issue_tracker_column
857 def test_index_with_issue_tracker_column
858 issue = Issue.generate!(:project_id => 1, :tracker_id => 2)
858 issue = Issue.generate!(:project_id => 1, :tracker_id => 2)
859 entry = TimeEntry.generate!(:issue => issue)
859 entry = TimeEntry.generate!(:issue => issue)
860
860
861 get :index, :params => {
861 get :index, :params => {
862 :c => %w(project spent_on issue comments hours issue.tracker)
862 :c => %w(project spent_on issue comments hours issue.tracker)
863 }
863 }
864 assert_response :success
864 assert_response :success
865 assert_select 'td.issue-tracker', :text => issue.tracker.name
865 assert_select 'td.issue-tracker', :text => issue.tracker.name
866 end
866 end
867
867
868 def test_index_with_issue_tracker_sort
868 def test_index_with_issue_tracker_sort
869 TimeEntry.delete_all
869 TimeEntry.delete_all
870 TimeEntry.generate!(:issue => Issue.generate!(:tracker_id => 1))
870 TimeEntry.generate!(:issue => Issue.generate!(:tracker_id => 1))
871 TimeEntry.generate!(:issue => Issue.generate!(:tracker_id => 3))
871 TimeEntry.generate!(:issue => Issue.generate!(:tracker_id => 3))
872 TimeEntry.generate!(:issue => Issue.generate!(:tracker_id => 2))
872 TimeEntry.generate!(:issue => Issue.generate!(:tracker_id => 2))
873 TimeEntry.generate!(:project_id => 1)
873 TimeEntry.generate!(:project_id => 1)
874
874
875 get :index, :params => {
875 get :index, :params => {
876 :c => ["hours", 'issue.tracker'],
876 :c => ["hours", 'issue.tracker'],
877 :sort => 'issue.tracker'
877 :sort => 'issue.tracker'
878 }
878 }
879 assert_response :success
879 assert_response :success
880
880
881 # Make sure that values are properly sorted
881 # Make sure that values are properly sorted
882 values = css_select("td.issue-tracker").map(&:text).reject(&:blank?)
882 values = css_select("td.issue-tracker").map(&:text).reject(&:blank?)
883 assert_equal Tracker.where(:id => [1, 2, 3]).sorted.pluck(:name), values
883 assert_equal Tracker.where(:id => [1, 2, 3]).sorted.pluck(:name), values
884 end
884 end
885
885
886 def test_index_with_filter_on_issue_custom_field
886 def test_index_with_filter_on_issue_custom_field
887 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'})
887 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'})
888 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5)
888 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5)
889
889
890 get :index, :params => {
890 get :index, :params => {
891 :f => ['issue.cf_2'],
891 :f => ['issue.cf_2'],
892 :op => {'issue.cf_2' => '='},
892 :op => {'issue.cf_2' => '='},
893 :v => {'issue.cf_2' => ['filter_on_issue_custom_field']}
893 :v => {'issue.cf_2' => ['filter_on_issue_custom_field']}
894 }
894 }
895 assert_response :success
895 assert_response :success
896 assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
896 assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
897 end
897 end
898
898
899 def test_index_with_issue_custom_field_column
899 def test_index_with_issue_custom_field_column
900 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'})
900 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'})
901 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5)
901 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5)
902
902
903 get :index, :params => {
903 get :index, :params => {
904 :c => %w(project spent_on issue comments hours issue.cf_2)
904 :c => %w(project spent_on issue comments hours issue.cf_2)
905 }
905 }
906 assert_response :success
906 assert_response :success
907 assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field'
907 assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field'
908 end
908 end
909
909
910 def test_index_with_time_entry_custom_field_column
910 def test_index_with_time_entry_custom_field_column
911 field = TimeEntryCustomField.generate!(:field_format => 'string')
911 field = TimeEntryCustomField.generate!(:field_format => 'string')
912 entry = TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value'})
912 entry = TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value'})
913 field_name = "cf_#{field.id}"
913 field_name = "cf_#{field.id}"
914
914
915 get :index, :params => {
915 get :index, :params => {
916 :c => ["hours", field_name]
916 :c => ["hours", field_name]
917 }
917 }
918 assert_response :success
918 assert_response :success
919 assert_select "td.#{field_name}", :text => 'CF Value'
919 assert_select "td.#{field_name}", :text => 'CF Value'
920 end
920 end
921
921
922 def test_index_with_time_entry_custom_field_sorting
922 def test_index_with_time_entry_custom_field_sorting
923 field = TimeEntryCustomField.generate!(:field_format => 'string', :name => 'String Field')
923 field = TimeEntryCustomField.generate!(:field_format => 'string', :name => 'String Field')
924 TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 1'})
924 TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 1'})
925 TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 3'})
925 TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 3'})
926 TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 2'})
926 TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 2'})
927 field_name = "cf_#{field.id}"
927 field_name = "cf_#{field.id}"
928
928
929 get :index, :params => {
929 get :index, :params => {
930 :c => ["hours", field_name],
930 :c => ["hours", field_name],
931 :sort => field_name
931 :sort => field_name
932 }
932 }
933 assert_response :success
933 assert_response :success
934 assert_select "th a.sort", :text => 'String Field'
934 assert_select "th a.sort", :text => 'String Field'
935
935
936 # Make sure that values are properly sorted
936 # Make sure that values are properly sorted
937 values = css_select("td.#{field_name}").map(&:text).reject(&:blank?)
937 values = css_select("td.#{field_name}").map(&:text).reject(&:blank?)
938 assert_equal values.sort, values
938 assert_equal values.sort, values
939 assert_equal 3, values.size
939 assert_equal 3, values.size
940 end
940 end
941
941
942 def test_index_with_query
942 def test_index_with_query
943 query = TimeEntryQuery.new(:project_id => 1, :name => 'Time Entry Query', :visibility => 2)
943 query = TimeEntryQuery.new(:project_id => 1, :name => 'Time Entry Query', :visibility => 2)
944 query.save!
944 query.save!
945 @request.session[:user_id] = 2
945 @request.session[:user_id] = 2
946
946
947 get :index, :params => {:project_id => 'ecookbook', :query_id => query.id}
947 get :index, :params => {:project_id => 'ecookbook', :query_id => query.id}
948 assert_response :success
948 assert_response :success
949 assert_select 'h2', :text => query.name
949 assert_select 'h2', :text => query.name
950 assert_select '#sidebar a.selected', :text => query.name
950 assert_select '#sidebar a.selected', :text => query.name
951 end
951 end
952
952
953 def test_index_atom_feed
953 def test_index_atom_feed
954 get :index, :params => {:project_id => 1, :format => 'atom'}
954 get :index, :params => {:project_id => 1, :format => 'atom'}
955 assert_response :success
955 assert_response :success
956 assert_equal 'application/atom+xml', @response.content_type
956 assert_equal 'application/atom+xml', @response.content_type
957 assert_select 'entry > title', :text => /7\.65 hours/
957 assert_select 'entry > title', :text => /7\.65 hours/
958 end
958 end
959
959
960 def test_index_at_project_level_should_include_csv_export_dialog
960 def test_index_at_project_level_should_include_csv_export_dialog
961 get :index, :params => {
961 get :index, :params => {
962 :project_id => 'ecookbook',
962 :project_id => 'ecookbook',
963 :f => ['spent_on'],
963 :f => ['spent_on'],
964 :op => {'spent_on' => '>='},
964 :op => {'spent_on' => '>='},
965 :v => {'spent_on' => ['2007-04-01']},
965 :v => {'spent_on' => ['2007-04-01']},
966 :c => ['spent_on', 'user']
966 :c => ['spent_on', 'user']
967 }
967 }
968 assert_response :success
968 assert_response :success
969
969
970 assert_select '#csv-export-options' do
970 assert_select '#csv-export-options' do
971 assert_select 'form[action=?][method=get]', '/projects/ecookbook/time_entries.csv' do
971 assert_select 'form[action=?][method=get]', '/projects/ecookbook/time_entries.csv' do
972 # filter
972 # filter
973 assert_select 'input[name=?][value=?]', 'f[]', 'spent_on'
973 assert_select 'input[name=?][value=?]', 'f[]', 'spent_on'
974 assert_select 'input[name=?][value=?]', 'op[spent_on]', '>='
974 assert_select 'input[name=?][value=?]', 'op[spent_on]', '>='
975 assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01'
975 assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01'
976 # columns
976 # columns
977 assert_select 'input[name=?][value=?]', 'c[]', 'spent_on'
977 assert_select 'input[name=?][value=?]', 'c[]', 'spent_on'
978 assert_select 'input[name=?][value=?]', 'c[]', 'user'
978 assert_select 'input[name=?][value=?]', 'c[]', 'user'
979 assert_select 'input[name=?]', 'c[]', 2
979 assert_select 'input[name=?]', 'c[]', 2
980 end
980 end
981 end
981 end
982 end
982 end
983
983
984 def test_index_cross_project_should_include_csv_export_dialog
984 def test_index_cross_project_should_include_csv_export_dialog
985 get :index
985 get :index
986 assert_response :success
986 assert_response :success
987
987
988 assert_select '#csv-export-options' do
988 assert_select '#csv-export-options' do
989 assert_select 'form[action=?][method=get]', '/time_entries.csv'
989 assert_select 'form[action=?][method=get]', '/time_entries.csv'
990 end
990 end
991 end
991 end
992
992
993 def test_index_csv_all_projects
993 def test_index_csv_all_projects
994 with_settings :date_format => '%m/%d/%Y' do
994 with_settings :date_format => '%m/%d/%Y' do
995 get :index, :params => {:format => 'csv'}
995 get :index, :params => {:format => 'csv'}
996 assert_response :success
996 assert_response :success
997 assert_equal 'text/csv; header=present', response.content_type
997 assert_equal 'text/csv; header=present', response.content_type
998 end
998 end
999 end
999 end
1000
1000
1001 def test_index_csv
1001 def test_index_csv
1002 with_settings :date_format => '%m/%d/%Y' do
1002 with_settings :date_format => '%m/%d/%Y' do
1003 get :index, :params => {:project_id => 1, :format => 'csv'}
1003 get :index, :params => {:project_id => 1, :format => 'csv'}
1004 assert_response :success
1004 assert_response :success
1005 assert_equal 'text/csv; header=present', response.content_type
1005 assert_equal 'text/csv; header=present', response.content_type
1006 end
1006 end
1007 end
1007 end
1008
1008
1009 def test_index_csv_should_fill_issue_column_with_tracker_id_and_subject
1009 def test_index_csv_should_fill_issue_column_with_tracker_id_and_subject
1010 issue = Issue.find(1)
1010 issue = Issue.find(1)
1011 entry = TimeEntry.generate!(:issue => issue, :comments => "Issue column content test")
1011 entry = TimeEntry.generate!(:issue => issue, :comments => "Issue column content test")
1012
1012
1013 get :index, :params => {:format => 'csv'}
1013 get :index, :params => {:format => 'csv'}
1014 line = response.body.split("\n").detect {|l| l.include?(entry.comments)}
1014 line = response.body.split("\n").detect {|l| l.include?(entry.comments)}
1015 assert_not_nil line
1015 assert_not_nil line
1016 assert_include "#{issue.tracker} #1: #{issue.subject}", line
1016 assert_include "#{issue.tracker} #1: #{issue.subject}", line
1017 end
1017 end
1018 end
1018 end
General Comments 0
You need to be logged in to leave comments. Login now