Skip to content

Commit

Permalink
Merge pull request #14958 from opf/feature/40749--make_done_ratio_nil…
Browse files Browse the repository at this point in the history
…_by_default

Make done_ratio nil by default
  • Loading branch information
cbliard authored Mar 22, 2024
2 parents 03d9ff7 + 188bae7 commit 8c4a540
Show file tree
Hide file tree
Showing 9 changed files with 360 additions and 233 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,10 @@ RSpec/ContextWording:
- as
- even
- for
- given
- having
- if
- in
- 'on'
- to
- unless
Expand Down
2 changes: 1 addition & 1 deletion app/models/work_package/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module WorkPackage::Validations
validates :subject, :priority, :project, :type, :author, :status, presence: true

validates :subject, length: { maximum: 255 }
validates :done_ratio, inclusion: { in: 0..100 }
validates :done_ratio, inclusion: { in: 0..100 }, allow_nil: true
validates :estimated_hours, numericality: { allow_nil: true }
validates :remaining_hours, numericality: { allow_nil: true, greater_than_or_equal_to: 0 }
validates :derived_remaining_hours, numericality: { allow_nil: true, greater_than_or_equal_to: 0 }
Expand Down
8 changes: 6 additions & 2 deletions app/services/work_packages/set_attributes_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def update_duration
# - +estimated_hours+
#
# Unless both +remaining_hours+ and +estimated_hours+ are set, +done_ratio+ will be
# considered 0.
# considered nil.
def update_done_ratio
if WorkPackage.use_status_for_done_ratio?
return unless model.status_id_changed?
Expand All @@ -302,7 +302,7 @@ def update_done_ratio
return unless work_package.remaining_hours_changed? || work_package.estimated_hours_changed?

work_package.done_ratio = if done_ratio_dependent_attribute_unset?
0
nil
else
compute_done_ratio
end
Expand Down Expand Up @@ -331,6 +331,10 @@ def update_remaining_hours
model.remaining_hours = if model.estimated_hours
remaining_hours_from_done_ratio_and_estimated_hours
end
elsif WorkPackage.use_field_for_done_ratio? &&
model.estimated_hours_changed? &&
model.estimated_hours.nil?
model.remaining_hours = nil
end
end

Expand Down
2 changes: 1 addition & 1 deletion config/initializers/new_framework_defaults_7_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
# This default means that all columns will be referenced in INSERT queries
# regardless of whether they have a default or not.
# Previous versions had true. Rails 7.0+ default is false.
# Rails.application.config.active_record.partial_inserts = false
Rails.application.config.active_record.partial_inserts = false

# https://guides.rubyonrails.org/configuring.html#config-action-controller-raise-on-open-redirects
# Protect from open redirect attacks in `redirect_back_or_to` and `redirect_to`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class ChangeDoneRatioDefaultValueToNull < ActiveRecord::Migration[7.1]
def change
change_column_null :work_packages, :done_ratio, true
change_column_default :work_packages, :done_ratio, from: 0, to: nil
change_column_null :work_package_journals, :done_ratio, true
change_column_default :work_package_journals, :done_ratio, from: 0, to: nil
end
end
2 changes: 1 addition & 1 deletion spec/models/mail_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@
.to be_nil

expect(subject.done_ratio)
.to be 0
.to be_nil

expect(subject.priority)
.to eql priority_low
Expand Down
Loading

0 comments on commit 8c4a540

Please sign in to comment.