]> source.dussan.org Git - redmine.git/commitdiff
Time entry with 2 digits year should not validate (#3107).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 24 Feb 2013 12:28:44 +0000 (12:28 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 24 Feb 2013 12:28:44 +0000 (12:28 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11472 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/time_entry.rb
test/unit/time_entry_test.rb

index 94545cd555ad914ee0dac67275c4e52ffd115fc6..76200e09f713a72ead6e628085c1a19497e28a33 100644 (file)
@@ -40,6 +40,7 @@ class TimeEntry < ActiveRecord::Base
   validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
   validates_numericality_of :hours, :allow_nil => true, :message => :invalid
   validates_length_of :comments, :maximum => 255, :allow_nil => true
+  validates :spent_on, :date => true
   before_validation :set_project_if_nil
   validate :validate_time_entry
 
index cb6d37d542335e905e3b72590f880fc98d0e9413..b14e799ce55a5f4e5db0cf82323855e5f3c51722 100644 (file)
@@ -110,6 +110,13 @@ class TimeEntryTest < ActiveSupport::TestCase
     assert_equal 1, te.errors.count
   end
 
+  def test_spent_on_with_2_digits_year_should_not_be_valid
+    entry = TimeEntry.new(:project => Project.find(1), :user => User.find(1), :activity => TimeEntryActivity.first, :hours => 1)
+    entry.spent_on = "09-02-04"
+    assert !entry.valid?
+    assert_include I18n.translate('activerecord.errors.messages.not_a_date'), entry.errors[:spent_on]
+  end
+
   def test_set_project_if_nil
     anon     = User.anonymous
     project  = Project.find(1)