##// END OF EJS Templates
Fixes broken action url on time edit form (#2707)....
Jean-Philippe Lang -
r2373:cf5658d7fe04
parent child
Show More
@@ -1,21 +1,21
1 1 <h2><%= l(:label_spent_time) %></h2>
2 2
3 <% labelled_tabular_form_for :time_entry, @time_entry, :url => {:action => 'edit', :project_id => @time_entry.project} do |f| %>
3 <% labelled_tabular_form_for :time_entry, @time_entry, :url => {:action => 'edit', :id => @time_entry, :project_id => @time_entry.project} do |f| %>
4 4 <%= error_messages_for 'time_entry' %>
5 5 <%= back_url_hidden_field_tag %>
6 6
7 7 <div class="box">
8 8 <p><%= f.text_field :issue_id, :size => 6 %> <em><%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %></em></p>
9 9 <p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
10 10 <p><%= f.text_field :hours, :size => 6, :required => true %></p>
11 11 <p><%= f.text_field :comments, :size => 100 %></p>
12 12 <p><%= f.select :activity_id, activity_collection_for_select_options, :required => true %></p>
13 13 <% @time_entry.custom_field_values.each do |value| %>
14 14 <p><%= custom_field_tag_with_label :time_entry, value %></p>
15 15 <% end %>
16 16 <%= call_hook(:view_timelog_edit_form_bottom, { :time_entry => @time_entry, :form => f }) %>
17 17 </div>
18 18
19 19 <%= submit_tag l(:button_save) %>
20 20
21 21 <% end %>
@@ -1,385 +1,394
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'timelog_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class TimelogController; def rescue_action(e) raise e end; end
23 23
24 24 class TimelogControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :enabled_modules, :roles, :members, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values
26 26
27 27 def setup
28 28 @controller = TimelogController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 end
32 32
33 33 def test_edit_routing
34 34 assert_routing(
35 35 {:method => :get, :path => '/issues/567/time_entries/new'},
36 36 :controller => 'timelog', :action => 'edit', :issue_id => '567'
37 37 )
38 38 assert_routing(
39 39 {:method => :get, :path => '/projects/ecookbook/time_entries/new'},
40 40 :controller => 'timelog', :action => 'edit', :project_id => 'ecookbook'
41 41 )
42 42 assert_routing(
43 43 {:method => :get, :path => '/projects/ecookbook/issues/567/time_entries/new'},
44 44 :controller => 'timelog', :action => 'edit', :project_id => 'ecookbook', :issue_id => '567'
45 45 )
46 46
47 47 #TODO: change new form to POST to issue_time_entries_path instead of to edit action
48 48 #TODO: change edit form to PUT to time_entry_path
49 49 assert_routing(
50 50 {:method => :get, :path => '/time_entries/22/edit'},
51 51 :controller => 'timelog', :action => 'edit', :id => '22'
52 52 )
53 53 end
54 54
55 55 def test_get_edit
56 56 @request.session[:user_id] = 3
57 57 get :edit, :project_id => 1
58 58 assert_response :success
59 59 assert_template 'edit'
60 60 # Default activity selected
61 61 assert_tag :tag => 'option', :attributes => { :selected => 'selected' },
62 62 :content => 'Development'
63 63 end
64 64
65 def test_get_edit_existing_time
66 @request.session[:user_id] = 2
67 get :edit, :id => 2, :project_id => nil
68 assert_response :success
69 assert_template 'edit'
70 # Default activity selected
71 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/timelog/edit/2' }
72 end
73
65 74 def test_post_edit
66 75 # TODO: should POST to issues’ time log instead of project. change form
67 76 # and routing
68 77 @request.session[:user_id] = 3
69 78 post :edit, :project_id => 1,
70 79 :time_entry => {:comments => 'Some work on TimelogControllerTest',
71 80 # Not the default activity
72 81 :activity_id => '11',
73 82 :spent_on => '2008-03-14',
74 83 :issue_id => '1',
75 84 :hours => '7.3'}
76 85 assert_redirected_to :action => 'details', :project_id => 'ecookbook'
77 86
78 87 i = Issue.find(1)
79 88 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
80 89 assert_not_nil t
81 90 assert_equal 11, t.activity_id
82 91 assert_equal 7.3, t.hours
83 92 assert_equal 3, t.user_id
84 93 assert_equal i, t.issue
85 94 assert_equal i.project, t.project
86 95 end
87 96
88 97 def test_update
89 98 entry = TimeEntry.find(1)
90 99 assert_equal 1, entry.issue_id
91 100 assert_equal 2, entry.user_id
92 101
93 102 @request.session[:user_id] = 1
94 103 post :edit, :id => 1,
95 104 :time_entry => {:issue_id => '2',
96 105 :hours => '8'}
97 106 assert_redirected_to :action => 'details', :project_id => 'ecookbook'
98 107 entry.reload
99 108
100 109 assert_equal 8, entry.hours
101 110 assert_equal 2, entry.issue_id
102 111 assert_equal 2, entry.user_id
103 112 end
104 113
105 114 def test_destroy_routing
106 115 #TODO: use DELETE to time_entry_path
107 116 assert_routing(
108 117 {:method => :post, :path => '/time_entries/55/destroy'},
109 118 :controller => 'timelog', :action => 'destroy', :id => '55'
110 119 )
111 120 end
112 121
113 122 def test_destroy
114 123 @request.session[:user_id] = 2
115 124 post :destroy, :id => 1
116 125 assert_redirected_to :action => 'details', :project_id => 'ecookbook'
117 126 assert_nil TimeEntry.find_by_id(1)
118 127 end
119 128
120 129 def test_report_routing
121 130 assert_routing(
122 131 {:method => :get, :path => '/projects/567/time_entries/report'},
123 132 :controller => 'timelog', :action => 'report', :project_id => '567'
124 133 )
125 134 assert_routing(
126 135 {:method => :get, :path => '/projects/567/time_entries/report.csv'},
127 136 :controller => 'timelog', :action => 'report', :project_id => '567', :format => 'csv'
128 137 )
129 138 end
130 139
131 140 def test_report_no_criteria
132 141 get :report, :project_id => 1
133 142 assert_response :success
134 143 assert_template 'report'
135 144 end
136 145
137 146 def test_report_routing_for_all_projects
138 147 assert_routing(
139 148 {:method => :get, :path => '/time_entries/report'},
140 149 :controller => 'timelog', :action => 'report'
141 150 )
142 151 end
143 152
144 153 def test_report_all_projects
145 154 get :report
146 155 assert_response :success
147 156 assert_template 'report'
148 157 end
149 158
150 159 def test_report_all_projects_denied
151 160 r = Role.anonymous
152 161 r.permissions.delete(:view_time_entries)
153 162 r.permissions_will_change!
154 163 r.save
155 164 get :report
156 165 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport'
157 166 end
158 167
159 168 def test_report_all_projects_one_criteria
160 169 get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
161 170 assert_response :success
162 171 assert_template 'report'
163 172 assert_not_nil assigns(:total_hours)
164 173 assert_equal "8.65", "%.2f" % assigns(:total_hours)
165 174 end
166 175
167 176 def test_report_all_time
168 177 get :report, :project_id => 1, :criterias => ['project', 'issue']
169 178 assert_response :success
170 179 assert_template 'report'
171 180 assert_not_nil assigns(:total_hours)
172 181 assert_equal "162.90", "%.2f" % assigns(:total_hours)
173 182 end
174 183
175 184 def test_report_all_time_by_day
176 185 get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day'
177 186 assert_response :success
178 187 assert_template 'report'
179 188 assert_not_nil assigns(:total_hours)
180 189 assert_equal "162.90", "%.2f" % assigns(:total_hours)
181 190 assert_tag :tag => 'th', :content => '2007-03-12'
182 191 end
183 192
184 193 def test_report_one_criteria
185 194 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
186 195 assert_response :success
187 196 assert_template 'report'
188 197 assert_not_nil assigns(:total_hours)
189 198 assert_equal "8.65", "%.2f" % assigns(:total_hours)
190 199 end
191 200
192 201 def test_report_two_criterias
193 202 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"]
194 203 assert_response :success
195 204 assert_template 'report'
196 205 assert_not_nil assigns(:total_hours)
197 206 assert_equal "162.90", "%.2f" % assigns(:total_hours)
198 207 end
199 208
200 209 def test_report_custom_field_criteria
201 210 get :report, :project_id => 1, :criterias => ['project', 'cf_1']
202 211 assert_response :success
203 212 assert_template 'report'
204 213 assert_not_nil assigns(:total_hours)
205 214 assert_not_nil assigns(:criterias)
206 215 assert_equal 2, assigns(:criterias).size
207 216 assert_equal "162.90", "%.2f" % assigns(:total_hours)
208 217 # Custom field column
209 218 assert_tag :tag => 'th', :content => 'Database'
210 219 # Custom field row
211 220 assert_tag :tag => 'td', :content => 'MySQL',
212 221 :sibling => { :tag => 'td', :attributes => { :class => 'hours' },
213 222 :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' },
214 223 :content => '1' }}
215 224 end
216 225
217 226 def test_report_one_criteria_no_result
218 227 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project']
219 228 assert_response :success
220 229 assert_template 'report'
221 230 assert_not_nil assigns(:total_hours)
222 231 assert_equal "0.00", "%.2f" % assigns(:total_hours)
223 232 end
224 233
225 234 def test_report_all_projects_csv_export
226 235 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv"
227 236 assert_response :success
228 237 assert_equal 'text/csv', @response.content_type
229 238 lines = @response.body.chomp.split("\n")
230 239 # Headers
231 240 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first
232 241 # Total row
233 242 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
234 243 end
235 244
236 245 def test_report_csv_export
237 246 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv"
238 247 assert_response :success
239 248 assert_equal 'text/csv', @response.content_type
240 249 lines = @response.body.chomp.split("\n")
241 250 # Headers
242 251 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first
243 252 # Total row
244 253 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
245 254 end
246 255
247 256 def test_details_all_projects
248 257 get :details
249 258 assert_response :success
250 259 assert_template 'details'
251 260 assert_not_nil assigns(:total_hours)
252 261 assert_equal "162.90", "%.2f" % assigns(:total_hours)
253 262 end
254 263
255 264 def test_project_details_routing
256 265 assert_routing(
257 266 {:method => :get, :path => '/projects/567/time_entries'},
258 267 :controller => 'timelog', :action => 'details', :project_id => '567'
259 268 )
260 269 end
261 270
262 271 def test_details_at_project_level
263 272 get :details, :project_id => 1
264 273 assert_response :success
265 274 assert_template 'details'
266 275 assert_not_nil assigns(:entries)
267 276 assert_equal 4, assigns(:entries).size
268 277 # project and subproject
269 278 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
270 279 assert_not_nil assigns(:total_hours)
271 280 assert_equal "162.90", "%.2f" % assigns(:total_hours)
272 281 # display all time by default
273 282 assert_equal '2007-03-11'.to_date, assigns(:from)
274 283 assert_equal '2007-04-22'.to_date, assigns(:to)
275 284 end
276 285
277 286 def test_details_at_project_level_with_date_range
278 287 get :details, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30'
279 288 assert_response :success
280 289 assert_template 'details'
281 290 assert_not_nil assigns(:entries)
282 291 assert_equal 3, assigns(:entries).size
283 292 assert_not_nil assigns(:total_hours)
284 293 assert_equal "12.90", "%.2f" % assigns(:total_hours)
285 294 assert_equal '2007-03-20'.to_date, assigns(:from)
286 295 assert_equal '2007-04-30'.to_date, assigns(:to)
287 296 end
288 297
289 298 def test_details_at_project_level_with_period
290 299 get :details, :project_id => 1, :period => '7_days'
291 300 assert_response :success
292 301 assert_template 'details'
293 302 assert_not_nil assigns(:entries)
294 303 assert_not_nil assigns(:total_hours)
295 304 assert_equal Date.today - 7, assigns(:from)
296 305 assert_equal Date.today, assigns(:to)
297 306 end
298 307
299 308 def test_issue_details_routing
300 309 assert_routing(
301 310 {:method => :get, :path => 'time_entries'},
302 311 :controller => 'timelog', :action => 'details'
303 312 )
304 313 assert_routing(
305 314 {:method => :get, :path => '/issues/234/time_entries'},
306 315 :controller => 'timelog', :action => 'details', :issue_id => '234'
307 316 )
308 317 # TODO: issue detail page shouldnt link to project_issue_time_entries_path but to normal issues one
309 318 # doesnt seem to have effect on resulting page so controller can be left untouched
310 319 assert_routing(
311 320 {:method => :get, :path => '/projects/ecookbook/issues/123/time_entries'},
312 321 :controller => 'timelog', :action => 'details', :project_id => 'ecookbook', :issue_id => '123'
313 322 )
314 323 end
315 324
316 325 def test_details_at_issue_level
317 326 get :details, :issue_id => 1
318 327 assert_response :success
319 328 assert_template 'details'
320 329 assert_not_nil assigns(:entries)
321 330 assert_equal 2, assigns(:entries).size
322 331 assert_not_nil assigns(:total_hours)
323 332 assert_equal 154.25, assigns(:total_hours)
324 333 # display all time by default
325 334 assert_equal '2007-03-11'.to_date, assigns(:from)
326 335 assert_equal '2007-04-22'.to_date, assigns(:to)
327 336 end
328 337
329 338 def test_details_formatted_routing
330 339 assert_routing(
331 340 {:method => :get, :path => 'time_entries.atom'},
332 341 :controller => 'timelog', :action => 'details', :format => 'atom'
333 342 )
334 343 assert_routing(
335 344 {:method => :get, :path => 'time_entries.csv'},
336 345 :controller => 'timelog', :action => 'details', :format => 'csv'
337 346 )
338 347 end
339 348
340 349 def test_details_for_project_formatted_routing
341 350 assert_routing(
342 351 {:method => :get, :path => '/projects/567/time_entries.atom'},
343 352 :controller => 'timelog', :action => 'details', :format => 'atom', :project_id => '567'
344 353 )
345 354 assert_routing(
346 355 {:method => :get, :path => '/projects/567/time_entries.csv'},
347 356 :controller => 'timelog', :action => 'details', :format => 'csv', :project_id => '567'
348 357 )
349 358 end
350 359
351 360 def test_details_for_issue_formatted_routing
352 361 assert_routing(
353 362 {:method => :get, :path => '/projects/ecookbook/issues/123/time_entries.atom'},
354 363 :controller => 'timelog', :action => 'details', :project_id => 'ecookbook', :issue_id => '123', :format => 'atom'
355 364 )
356 365 assert_routing(
357 366 {:method => :get, :path => '/projects/ecookbook/issues/123/time_entries.csv'},
358 367 :controller => 'timelog', :action => 'details', :project_id => 'ecookbook', :issue_id => '123', :format => 'csv'
359 368 )
360 369 end
361 370
362 371 def test_details_atom_feed
363 372 get :details, :project_id => 1, :format => 'atom'
364 373 assert_response :success
365 374 assert_equal 'application/atom+xml', @response.content_type
366 375 assert_not_nil assigns(:items)
367 376 assert assigns(:items).first.is_a?(TimeEntry)
368 377 end
369 378
370 379 def test_details_all_projects_csv_export
371 380 get :details, :format => 'csv'
372 381 assert_response :success
373 382 assert_equal 'text/csv', @response.content_type
374 383 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
375 384 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n")
376 385 end
377 386
378 387 def test_details_csv_export
379 388 get :details, :project_id => 1, :format => 'csv'
380 389 assert_response :success
381 390 assert_equal 'text/csv', @response.content_type
382 391 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
383 392 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n")
384 393 end
385 394 end
General Comments 0
You need to be logged in to leave comments. Login now