Project

General

Profile

Defect #39079 ยป 0001-Avoid-exception-during-validation-if-the-spent_on-da.patch

Holger Just, 2023-09-19 15:28

View differences:

app/models/time_entry.rb
179 179
    end
180 180
    errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) || @invalid_issue_id
181 181
    errors.add :activity_id, :inclusion if activity_id_changed? && project && !project.activities.include?(activity)
182
    if spent_on_changed? && user
182
    if spent_on && spent_on_changed? && user
183 183
      errors.add :base, I18n.t(:error_spent_on_future_date) if !Setting.timelog_accept_future_dates? && (spent_on > user.today)
184 184
    end
185 185
  end
test/unit/time_entry_test.rb
171 171
    end
172 172
  end
173 173

  
174
  def test_should_require_spent_on
175
    with_settings :timelog_accept_future_dates => '0' do
176
      entry = TimeEntry.find(1)
177
      entry.spent_on = ''
178

  
179
      assert !entry.save
180
      assert entry.errors[:spent_on].present?
181
    end
182
  end
183

  
174 184
  def test_spent_on_with_blank
175 185
    c = TimeEntry.new
176 186
    c.spent_on = ''
    (1-1/1)