]> source.dussan.org Git - redmine.git/commitdiff
Negative estimated hours should not be valid (#12735).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 5 Jan 2013 16:34:41 +0000 (16:34 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 5 Jan 2013 16:34:41 +0000 (16:34 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11125 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/unit/issue_test.rb

index 8a0ef7fa8148b5630df858b36d443c7f22b55d50..99803033179fe21de6f8d9daf3ca0d6108c4c602 100644 (file)
@@ -67,7 +67,7 @@ class Issue < ActiveRecord::Base
 
   validates_length_of :subject, :maximum => 255
   validates_inclusion_of :done_ratio, :in => 0..100
-  validates_numericality_of :estimated_hours, :allow_nil => true
+  validates :estimated_hours, :numericality => {:greater_than_or_equal_to => 0, :allow_nil => true, :message => :invalid}
   validates :start_date, :date => true
   validates :due_date, :date => true
   validate :validate_issue, :validate_required_fields
index 1ef94c63616f0c3984249a2b4fddd0eaca976baa..cb89d37a5cc38447e09cc5ab0c6be86e2ffc70fc 100644 (file)
@@ -79,6 +79,15 @@ class IssueTest < ActiveSupport::TestCase
     assert_include 'Due date must be greater than start date', issue.errors.full_messages
   end
 
+  def test_estimated_hours_should_be_validated
+    set_language_if_valid 'en'
+    ['-2'].each do |invalid|
+      issue = Issue.new(:estimated_hours => invalid)
+      assert !issue.valid?
+      assert_include 'Estimated time is invalid', issue.errors.full_messages
+    end
+  end
+
   def test_create_with_required_custom_field
     set_language_if_valid 'en'
     field = IssueCustomField.find_by_name('Database')