1. Unofficial Redmine Clones
  2. Untitled project
  3. redmine

Commits

jplang  committed 3825aa3

Time entry with 2 digits year should not validate (#3107).

  • Participants
  • Parent commits 7af983c
  • Branches default

Comments (0)

Files changed (2)

File app/models/time_entry.rb

View file
   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
 

File test/unit/time_entry_test.rb

View file
     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)