@@ -40,6 +40,7 class TimeEntry < ActiveRecord::Base | |||||
40 | validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on |
|
40 | validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on | |
41 | validates_numericality_of :hours, :allow_nil => true, :message => :invalid |
|
41 | validates_numericality_of :hours, :allow_nil => true, :message => :invalid | |
42 | validates_length_of :comments, :maximum => 255, :allow_nil => true |
|
42 | validates_length_of :comments, :maximum => 255, :allow_nil => true | |
|
43 | validates :spent_on, :date => true | |||
43 | before_validation :set_project_if_nil |
|
44 | before_validation :set_project_if_nil | |
44 | validate :validate_time_entry |
|
45 | validate :validate_time_entry | |
45 |
|
46 |
@@ -110,6 +110,13 class TimeEntryTest < ActiveSupport::TestCase | |||||
110 | assert_equal 1, te.errors.count |
|
110 | assert_equal 1, te.errors.count | |
111 | end |
|
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 | def test_set_project_if_nil |
|
120 | def test_set_project_if_nil | |
114 | anon = User.anonymous |
|
121 | anon = User.anonymous | |
115 | project = Project.find(1) |
|
122 | project = Project.find(1) |
General Comments 0
You need to be logged in to leave comments.
Login now