@@ -40,6 +40,7 class TimeEntry < ActiveRecord::Base | |||
|
40 | 40 | validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on |
|
41 | 41 | validates_numericality_of :hours, :allow_nil => true, :message => :invalid |
|
42 | 42 | validates_length_of :comments, :maximum => 255, :allow_nil => true |
|
43 | validates :spent_on, :date => true | |
|
43 | 44 | before_validation :set_project_if_nil |
|
44 | 45 | validate :validate_time_entry |
|
45 | 46 |
@@ -110,6 +110,13 class TimeEntryTest < ActiveSupport::TestCase | |||
|
110 | 110 | assert_equal 1, te.errors.count |
|
111 | 111 | end |
|
112 | 112 | |
|
113 | def test_spent_on_with_2_digits_year_should_not_be_valid | |
|
114 | entry = TimeEntry.new(:project => Project.find(1), :user => User.find(1), :activity => TimeEntryActivity.first, :hours => 1) | |
|
115 | entry.spent_on = "09-02-04" | |
|
116 | assert !entry.valid? | |
|
117 | assert_include I18n.translate('activerecord.errors.messages.not_a_date'), entry.errors[:spent_on] | |
|
118 | end | |
|
119 | ||
|
113 | 120 | def test_set_project_if_nil |
|
114 | 121 | anon = User.anonymous |
|
115 | 122 | project = Project.find(1) |
General Comments 0
You need to be logged in to leave comments.
Login now