Defect #9090 » do_not_allow_spent_time_with_0_hours.patch
| app/models/time_entry.rb | ||
|---|---|---|
|
validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
|
||
|
validates_presence_of :issue_id, :if => lambda { Setting.timelog_required_fields.include?('issue_id') }
|
||
|
validates_presence_of :comments, :if => lambda { Setting.timelog_required_fields.include?('comments') }
|
||
|
validates_numericality_of :hours, :allow_nil => true, :message => :invalid
|
||
|
validates_numericality_of :hours, :allow_nil => true, :greater_than => 0, :less_than_or_equal_to => 1000
|
||
|
validates_length_of :comments, :maximum => 1024, :allow_nil => true
|
||
|
validates :spent_on, :date => true
|
||
|
before_validation :set_project_if_nil
|
||
| ... | ... | |
|
end
|
||
|
def validate_time_entry
|
||
|
errors.add :hours, :invalid if hours && (hours < 0 || hours >= 1000)
|
||
|
errors.add :project_id, :invalid if project.nil?
|
||
|
errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) || @invalid_issue_id
|
||
|
errors.add :activity_id, :inclusion if activity_id_changed? && project && !project.activities.include?(activity)
|
||
| test/unit/time_entry_test.rb | ||
|---|---|---|
|
assert_equal ["Comment cannot be blank", "Issue cannot be blank"], entry.errors.full_messages.sort
|
||
|
end
|
||
|
end
|
||
|
def test_create_should_not_allow_spent_time_with_0_hours
|
||
|
entry = TimeEntry.new(:project_id => 1, :spent_on => '2010-01-01', :hours => 0, :user => User.find(1), :activity => TimeEntryActivity.first)
|
||
|
assert !entry.save
|
||
|
assert_equal 1, entry.errors.count
|
||
|
end
|
||
|
end
|
||