diff options
-rw-r--r-- | app/models/time_entry.rb | 1 | ||||
-rw-r--r-- | test/unit/time_entry_test.rb | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index 94545cd55..76200e09f 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -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 diff --git a/test/unit/time_entry_test.rb b/test/unit/time_entry_test.rb index cb6d37d54..b14e799ce 100644 --- a/test/unit/time_entry_test.rb +++ b/test/unit/time_entry_test.rb @@ -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) |