##// END OF EJS Templates
Merged r2250 and r2251 from trunk....
Jean-Philippe Lang -
r2250:764393aa6ac2
parent child
Show More
@@ -36,6 +36,7 module IssuesHelper
36 36 # Returns a string of css classes that apply to the given issue
37 37 def css_issue_classes(issue)
38 38 s = "issue status-#{issue.status.position} priority-#{issue.priority.position}"
39 s << ' closed' if issue.closed?
39 40 s << ' overdue' if issue.overdue?
40 41 s
41 42 end
@@ -32,7 +32,7 class TimeEntry < ActiveRecord::Base
32 32 :description => :comments
33 33
34 34 validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
35 validates_numericality_of :hours, :allow_nil => true
35 validates_numericality_of :hours, :allow_nil => true, :message => :activerecord_error_invalid
36 36 validates_length_of :comments, :maximum => 255, :allow_nil => true
37 37
38 38 def after_initialize
@@ -54,7 +54,7 class TimeEntry < ActiveRecord::Base
54 54 end
55 55
56 56 def hours=(h)
57 write_attribute :hours, (h.is_a?(String) ? h.to_hours : h)
57 write_attribute :hours, (h.is_a?(String) ? (h.to_hours || h) : h)
58 58 end
59 59
60 60 # tyear, tmonth, tweek assigned where setting spent_on attributes
@@ -24,7 +24,9 module Redmine #:nodoc:
24 24 def to_hours
25 25 s = self.dup
26 26 s.strip!
27 unless s =~ %r{^[\d\.,]+$}
27 if s =~ %r{^(\d+([.,]\d+)?)h?$}
28 s = $1
29 else
28 30 # 2:30 => 2.5
29 31 s.gsub!(%r{^(\d+):(\d+)$}) { $1.to_i + $2.to_i / 60.0 }
30 32 # 2h30, 2h, 30m => 2.5, 2, 0.5
@@ -596,6 +596,24 class IssuesControllerTest < Test::Unit::TestCase
596 596 # No email should be sent
597 597 assert ActionMailer::Base.deliveries.empty?
598 598 end
599
600 def test_post_edit_with_invalid_spent_time
601 @request.session[:user_id] = 2
602 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
603
604 assert_no_difference('Journal.count') do
605 post :edit,
606 :id => 1,
607 :notes => notes,
608 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
609 end
610 assert_response :success
611 assert_template 'edit'
612
613 assert_tag :textarea, :attributes => { :name => 'notes' },
614 :content => notes
615 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
616 end
599 617
600 618 def test_bulk_edit
601 619 @request.session[:user_id] = 2
@@ -24,6 +24,7 class TimeEntryTest < Test::Unit::TestCase
24 24 assertions = { "2" => 2.0,
25 25 "21.1" => 21.1,
26 26 "2,1" => 2.1,
27 "1,5h" => 1.5,
27 28 "7:12" => 7.2,
28 29 "10h" => 10.0,
29 30 "10 h" => 10.0,
@@ -40,7 +41,7 class TimeEntryTest < Test::Unit::TestCase
40 41
41 42 assertions.each do |k, v|
42 43 t = TimeEntry.new(:hours => k)
43 assert_equal v, t.hours
44 assert_equal v, t.hours, "Converting #{k} failed:"
44 45 end
45 46 end
46 47 end
General Comments 0
You need to be logged in to leave comments. Login now