@@ -38,6 +38,7 class TimeEntry < ActiveRecord::Base | |||||
38 | validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on |
|
38 | validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on | |
39 | validates_numericality_of :hours, :allow_nil => true, :message => :invalid |
|
39 | validates_numericality_of :hours, :allow_nil => true, :message => :invalid | |
40 | validates_length_of :comments, :maximum => 255, :allow_nil => true |
|
40 | validates_length_of :comments, :maximum => 255, :allow_nil => true | |
|
41 | validate :validate_time_entry | |||
41 |
|
42 | |||
42 | named_scope :visible, lambda {|*args| { |
|
43 | named_scope :visible, lambda {|*args| { | |
43 | :include => :project, |
|
44 | :include => :project, | |
@@ -57,7 +58,7 class TimeEntry < ActiveRecord::Base | |||||
57 | self.project = issue.project if issue && project.nil? |
|
58 | self.project = issue.project if issue && project.nil? | |
58 | end |
|
59 | end | |
59 |
|
60 | |||
60 | def validate |
|
61 | def validate_time_entry | |
61 | errors.add :hours, :invalid if hours && (hours < 0 || hours >= 1000) |
|
62 | errors.add :hours, :invalid if hours && (hours < 0 || hours >= 1000) | |
62 | errors.add :project_id, :invalid if project.nil? |
|
63 | errors.add :project_id, :invalid if project.nil? | |
63 | errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) |
|
64 | errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) |
General Comments 0
You need to be logged in to leave comments.
Login now