@@ -36,6 +36,7 module IssuesHelper | |||||
36 | # Returns a string of css classes that apply to the given issue |
|
36 | # Returns a string of css classes that apply to the given issue | |
37 | def css_issue_classes(issue) |
|
37 | def css_issue_classes(issue) | |
38 | s = "issue status-#{issue.status.position} priority-#{issue.priority.position}" |
|
38 | s = "issue status-#{issue.status.position} priority-#{issue.priority.position}" | |
|
39 | s << ' closed' if issue.closed? | |||
39 | s << ' overdue' if issue.overdue? |
|
40 | s << ' overdue' if issue.overdue? | |
40 | s |
|
41 | s | |
41 | end |
|
42 | end |
@@ -32,7 +32,7 class TimeEntry < ActiveRecord::Base | |||||
32 | :description => :comments |
|
32 | :description => :comments | |
33 |
|
33 | |||
34 | validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on |
|
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 | validates_length_of :comments, :maximum => 255, :allow_nil => true |
|
36 | validates_length_of :comments, :maximum => 255, :allow_nil => true | |
37 |
|
37 | |||
38 | def after_initialize |
|
38 | def after_initialize | |
@@ -54,7 +54,7 class TimeEntry < ActiveRecord::Base | |||||
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def hours=(h) |
|
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 | end |
|
58 | end | |
59 |
|
59 | |||
60 | # tyear, tmonth, tweek assigned where setting spent_on attributes |
|
60 | # tyear, tmonth, tweek assigned where setting spent_on attributes |
@@ -24,7 +24,9 module Redmine #:nodoc: | |||||
24 | def to_hours |
|
24 | def to_hours | |
25 | s = self.dup |
|
25 | s = self.dup | |
26 | s.strip! |
|
26 | s.strip! | |
27 |
|
|
27 | if s =~ %r{^(\d+([.,]\d+)?)h?$} | |
|
28 | s = $1 | |||
|
29 | else | |||
28 | # 2:30 => 2.5 |
|
30 | # 2:30 => 2.5 | |
29 | s.gsub!(%r{^(\d+):(\d+)$}) { $1.to_i + $2.to_i / 60.0 } |
|
31 | s.gsub!(%r{^(\d+):(\d+)$}) { $1.to_i + $2.to_i / 60.0 } | |
30 | # 2h30, 2h, 30m => 2.5, 2, 0.5 |
|
32 | # 2h30, 2h, 30m => 2.5, 2, 0.5 |
@@ -596,6 +596,24 class IssuesControllerTest < Test::Unit::TestCase | |||||
596 | # No email should be sent |
|
596 | # No email should be sent | |
597 | assert ActionMailer::Base.deliveries.empty? |
|
597 | assert ActionMailer::Base.deliveries.empty? | |
598 | end |
|
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 | def test_bulk_edit |
|
618 | def test_bulk_edit | |
601 | @request.session[:user_id] = 2 |
|
619 | @request.session[:user_id] = 2 |
@@ -24,6 +24,7 class TimeEntryTest < Test::Unit::TestCase | |||||
24 | assertions = { "2" => 2.0, |
|
24 | assertions = { "2" => 2.0, | |
25 | "21.1" => 21.1, |
|
25 | "21.1" => 21.1, | |
26 | "2,1" => 2.1, |
|
26 | "2,1" => 2.1, | |
|
27 | "1,5h" => 1.5, | |||
27 | "7:12" => 7.2, |
|
28 | "7:12" => 7.2, | |
28 | "10h" => 10.0, |
|
29 | "10h" => 10.0, | |
29 | "10 h" => 10.0, |
|
30 | "10 h" => 10.0, | |
@@ -40,7 +41,7 class TimeEntryTest < Test::Unit::TestCase | |||||
40 |
|
41 | |||
41 | assertions.each do |k, v| |
|
42 | assertions.each do |k, v| | |
42 | t = TimeEntry.new(:hours => k) |
|
43 | t = TimeEntry.new(:hours => k) | |
43 | assert_equal v, t.hours |
|
44 | assert_equal v, t.hours, "Converting #{k} failed:" | |
44 | end |
|
45 | end | |
45 | end |
|
46 | end | |
46 | end |
|
47 | end |
General Comments 0
You need to be logged in to leave comments.
Login now