diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /app/models/concerns/time_trackable.rb | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'app/models/concerns/time_trackable.rb')
-rw-r--r-- | app/models/concerns/time_trackable.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/app/models/concerns/time_trackable.rb b/app/models/concerns/time_trackable.rb index 54fe9eac2bc..2b7447dc700 100644 --- a/app/models/concerns/time_trackable.rb +++ b/app/models/concerns/time_trackable.rb @@ -15,12 +15,13 @@ module TimeTrackable alias_method :time_spent?, :time_spent - default_value_for :time_estimate, value: 0, allows_nil: false + attribute :time_estimate, default: 0 validates :time_estimate, numericality: { message: 'has an invalid format' }, allow_nil: false validate :check_negative_time_spent has_many :timelogs, dependent: :destroy, autosave: true # rubocop:disable Cop/ActiveRecordDependent + after_initialize :set_time_estimate_default_value end # rubocop:disable Gitlab/ModuleWithInstanceVariables @@ -67,6 +68,13 @@ module TimeTrackable val.is_a?(Integer) ? super([val, Gitlab::Database::MAX_INT_VALUE].min) : super(val) end + def set_time_estimate_default_value + return if new_record? + return unless has_attribute?(:time_estimate) + + self.time_estimate ||= self.class.column_defaults['time_estimate'] + end + private def reset_spent_time |