Project

General

Profile

Patch #24005 » time_entries_day.diff

Helder Manuel Torres Vieira, 2016-10-05 20:09

View differences:

app/models/time_entry.rb
113 113
  end
114 114

  
115 115
  def validate_time_entry
116
    errors.add :hours, :invalid if hours && (hours < 0 || hours >= 1000)
116
    errors.add :hours, :invalid if hours && (hours < 0 || hours > 24) || hours == 0
117 117
    errors.add :project_id, :invalid if project.nil?
118 118
    errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) || @invalid_issue_id
119 119
    errors.add :activity_id, :inclusion if activity_id_changed? && project && !project.activities.include?(activity)
test/unit/time_entry_test.rb
133 133
                         :description => 'IssueTest#test_create', :estimated_hours => '1:30')
134 134
    assert issue.save
135 135
    activity = TimeEntryActivity.find_by_name('Design')
136
    
137
    te = TimeEntry.create(:spent_on => '2010-01-01',
138
                          :hours    => 1,
139
                          :issue    => issue,
140
                          :project  => project,
141
                          :user     => anon,
142
                          :activity => activity)
143
    assert_equal 0, te.errors.count
144

  
145
    te = TimeEntry.create(:spent_on => '2010-01-01',
146
                          :hours    => 24,
147
                          :issue    => issue,
148
                          :project  => project,
149
                          :user     => anon,
150
                          :activity => activity)
151
    assert_equal 0, te.errors.count
152
    
136 153
    te = TimeEntry.create(:spent_on => '2010-01-01',
137 154
                          :hours    => 100000,
138 155
                          :issue    => issue,
......
140 157
                          :user     => anon,
141 158
                          :activity => activity)
142 159
    assert_equal 1, te.errors.count
160

  
161
    te = TimeEntry.create(:spent_on => '2010-01-01',
162
                          :hours    => 0,
163
                          :issue    => issue,
164
                          :project  => project,
165
                          :user     => anon,
166
                          :activity => activity)
167
    assert_equal 1, te.errors.count
168

  
169
    te = TimeEntry.create(:spent_on => '2010-01-01',
170
                          :hours    => 25,
171
                          :issue    => issue,
172
                          :project  => project,
173
                          :user     => anon,
174
                          :activity => activity)
175
    assert_equal 1, te.errors.count
143 176
  end
144 177

  
145 178
  def test_acitivity_should_belong_to_project_activities
(1-1/7)