Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Remove :percent_complete_edition feature flag

Christophe Bliard4ac1b1ca7ae7
diff --git a/app/components/work_packages/progress/status_based/modal_body_component.html.erb b/app/components/work_packages/progress/status_based/modal_body_component.html.erb
index 13fd66f0006..602e7a4f149 100644
--- a/app/components/work_packages/progress/status_based/modal_body_component.html.erb
+++ b/app/components/work_packages/progress/status_based/modal_body_component.html.erb
@@ -11,20 +11,11 @@
) do |f| %>
<%= flex_layout do |modal_body| %>
<% modal_body.with_row(classes: "FormControl-horizontalGroup--sm-vertical") do |_fields| %>
- <% if OpenProject::FeatureDecisions.percent_complete_edition_active? %>
<%= render(WorkPackages::ProgressForm.new(f,
work_package:,
mode:,
focused_field:,
touched_field_map:)) %>
- <% else %>
- <%# This condition branch to be removed in 15.0 with :percent_complete_edition feature flag removal %>
- <%= render(WorkPackages::Pre144ProgressForm.new(f,
- work_package:,
- mode:,
- focused_field:,
- touched_field_map:)) %>
- <% end %>
<% end %>
<% modal_body.with_row(mt: 3) do |_tooltip| %>
diff --git a/app/components/work_packages/progress/work_based/modal_body_component.html.erb b/app/components/work_packages/progress/work_based/modal_body_component.html.erb
index 80c60dfaa45..d2b0549278a 100644
--- a/app/components/work_packages/progress/work_based/modal_body_component.html.erb
+++ b/app/components/work_packages/progress/work_based/modal_body_component.html.erb
@@ -11,38 +11,11 @@
) do |f| %>
<%= flex_layout do |modal_body| %>
<% modal_body.with_row(classes: "FormControl-horizontalGroup--sm-vertical") do |_fields| %>
- <% if OpenProject::FeatureDecisions.percent_complete_edition_active? %>
<%= render(WorkPackages::ProgressForm.new(f,
work_package:,
mode:,
focused_field:,
touched_field_map:)) %>
- <% else %>
- <%# This condition branch to be removed in 15.0 with :percent_complete_edition feature flag removal %>
- <%= render(WorkPackages::Pre144ProgressForm.new(f,
- work_package:,
- mode:,
- focused_field:,
- touched_field_map:)) %>
- <% end %>
- <% end %>
-
- <% if !OpenProject::FeatureDecisions.percent_complete_edition_active? %>
- <%# This condition branch to be removed in 15.0 with :percent_complete_edition feature flag removal %>
- <% if should_display_migration_warning? %>
- <% modal_body.with_row(mt: 3) do |_migration_warning| %>
- <%= render(Primer::Alpha::Banner.new) { t("work_package.progress.modal.migration_warning_text") } %>
- <% end %>
- <% end %>
- <% end %>
-
- <%# This condition branch to be removed in 15.0 with :percent_complete_edition feature flag removal %>
- <% unless OpenProject::FeatureDecisions.percent_complete_edition_active? %>
- <% modal_body.with_row(mt: 3) do |_tooltip| %>
- <%= render(Primer::Beta::Text.new(font_weight: :semibold)) { t("work_package.progress.label_note") } %>
- <%= render(Primer::Beta::Text.new) { t("work_package.progress.modal.work_based_help_text_pre_14_4_without_percent_complete_edition") } %>
- <%= render(Primer::Beta::Link.new(href: learn_more_href)) { t(:label_learn_more) } %>
- <% end %>
<% end %>
<% modal_body.with_row(mt: 3) do |_actions_row| %>
diff --git a/app/components/work_packages/progress/work_based/modal_body_component.rb b/app/components/work_packages/progress/work_based/modal_body_component.rb
index 668b4613d77..f2e66de74fe 100644
--- a/app/components/work_packages/progress/work_based/modal_body_component.rb
+++ b/app/components/work_packages/progress/work_based/modal_body_component.rb
@@ -40,15 +40,6 @@ module WorkPackages
@mode = :work_based
end
-
- # This method can be safely deleted once the feature flag
- # :percent_complete_edition is removed, which should happen for
- # OpenProject 15.0 release.
- def should_display_migration_warning?
- return false if OpenProject::FeatureDecisions.percent_complete_edition_active?
-
- work_package.done_ratio.present? && work_package.estimated_hours.nil? && work_package.remaining_hours.nil?
- end
end
# rubocop:enable OpenProject/AddPreviewForViewComponent
end
diff --git a/app/contracts/work_packages/base_contract.rb b/app/contracts/work_packages/base_contract.rb
index dc62c589bf4..552d27bc9c2 100644
--- a/app/contracts/work_packages/base_contract.rb
+++ b/app/contracts/work_packages/base_contract.rb
@@ -54,40 +54,27 @@ module WorkPackages
attribute :done_ratio,
writable: ->(*) {
- OpenProject::FeatureDecisions.percent_complete_edition_active? \
- && WorkPackage.work_based_mode?
+ WorkPackage.work_based_mode?
} do
- if OpenProject::FeatureDecisions.percent_complete_edition_active?
- next if invalid_work_or_remaining_work_values? # avoid too many error messages at the same time
+ next if invalid_work_or_remaining_work_values? # avoid too many error messages at the same time
- validate_percent_complete_matches_work_and_remaining_work
- validate_percent_complete_is_empty_when_work_is_zero
- validate_percent_complete_is_set_when_work_and_remaining_work_are_set
- end
+ validate_percent_complete_matches_work_and_remaining_work
+ validate_percent_complete_is_empty_when_work_is_zero
+ validate_percent_complete_is_set_when_work_and_remaining_work_are_set
end
attribute :derived_done_ratio,
writable: false
attribute :estimated_hours do
- if OpenProject::FeatureDecisions.percent_complete_edition_active?
- validate_work_is_set_when_remaining_work_and_percent_complete_are_set
- else
- # to be removed in 15.0 with :percent_complete_edition feature flag removal
- validate_work_is_set_when_remaining_work_is_set
- end
+ validate_work_is_set_when_remaining_work_and_percent_complete_are_set
end
attribute :derived_estimated_hours,
writable: false
attribute :remaining_hours do
validate_remaining_work_is_lower_than_work
- if OpenProject::FeatureDecisions.percent_complete_edition_active?
- validate_remaining_work_is_zero_or_empty_when_percent_complete_is_100p
- validate_remaining_work_is_set_when_work_and_percent_complete_are_set
- else
- # to be removed in 15.0 with :percent_complete_edition feature flag removal
- validate_remaining_work_is_set_when_work_is_set
- end
+ validate_remaining_work_is_zero_or_empty_when_percent_complete_is_100p
+ validate_remaining_work_is_set_when_work_and_percent_complete_are_set
end
attribute :derived_remaining_hours,
writable: false
@@ -350,20 +337,6 @@ module WorkPackages
end
end
- # to be removed in 15.0 with :percent_complete_edition feature flag removal
- def validate_remaining_work_is_set_when_work_is_set
- if work_set? && !remaining_work_set?
- errors.add(:remaining_hours, :must_be_set_when_work_is_set)
- end
- end
-
- # to be removed in 15.0 with :percent_complete_edition feature flag removal
- def validate_work_is_set_when_remaining_work_is_set
- if remaining_work_set? && !work_set?
- errors.add(:estimated_hours, :must_be_set_when_remaining_work_is_set)
- end
- end
-
def validate_work_is_set_when_remaining_work_and_percent_complete_are_set
if remaining_work_set_and_valid? && percent_complete_set_and_valid? && work_empty? && percent_complete != 100
errors.add(:estimated_hours, :must_be_set_when_remaining_work_and_percent_complete_are_set)
diff --git a/app/controllers/work_packages/progress_controller.rb b/app/controllers/work_packages/progress_controller.rb
index 9c5482d7046..1c77c880417 100644
--- a/app/controllers/work_packages/progress_controller.rb
+++ b/app/controllers/work_packages/progress_controller.rb
@@ -70,10 +70,6 @@ class WorkPackages::ProgressController < ApplicationController
], status: :unprocessable_entity
end
end
- # following 3 lines to be removed in 15.0 with :percent_complete_edition feature flag removal
- elsif !OpenProject::FeatureDecisions.percent_complete_edition_active?
- render json: { estimatedTime: formatted_duration(@work_package.estimated_hours),
- remainingTime: formatted_duration(@work_package.remaining_hours) }
else
render json: { estimatedTime: formatted_duration(@work_package.estimated_hours),
remainingTime: formatted_duration(@work_package.remaining_hours),
@@ -163,9 +159,6 @@ class WorkPackages::ProgressController < ApplicationController
def allowed_params
if WorkPackage.status_based_mode?
%i[estimated_hours status_id]
- # two next lines to be removed in 15.0 with :percent_complete_edition feature flag removal
- elsif !OpenProject::FeatureDecisions.percent_complete_edition_active?
- %i[estimated_hours remaining_hours]
else
%i[estimated_hours remaining_hours done_ratio]
end
diff --git a/app/forms/work_packages/pre_14_4_progress_form.rb b/app/forms/work_packages/pre_14_4_progress_form.rb
deleted file mode 100644
index 0d9ac1a2ad9..00000000000
--- a/app/forms/work_packages/pre_14_4_progress_form.rb
+++ /dev/null
@@ -1,212 +0,0 @@
-# -- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2010-2024 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-# ++
-
-# This file can be safely deleted once the feature flag :percent_complete_edition
-# is removed, which should happen for OpenProject 15.0 release.
-#
-# Copied from commit 109b135b and modified to have the [work_package][initial]
-# data needed by progress_controller
-class WorkPackages::Pre144ProgressForm < ApplicationForm
- ##
- # Primer::Forms::BaseComponent or ApplicationForm will always autofocus the
- # first input field with an error present on it. Despite this behavior being
- # a11y-friendly, it breaks the modal's UX when an invalid input field
- # is rendered.
- #
- # The reason for this is since we're implementing a "format on blur", when
- # we make a request to the server that will set an input field in an invalid
- # state and it is returned as such, any time we blur this autofocused field,
- # we'll perform another request that will still have the input in an invalid
- # state causing it to autofocus again and preventing us from leaving this
- # "limbo state".
- ##
- def before_render
- # no-op
- end
-
- attr_reader :work_package, :mode
-
- def initialize(work_package:,
- mode: :work_based,
- focused_field: :remaining_hours,
- touched_field_map: {})
- super()
-
- @work_package = work_package
- @mode = mode
- @focused_field = focused_field_by_selection(focused_field)
- @touched_field_map = touched_field_map
- ensure_only_one_error_for_remaining_work_exceeding_work
- end
-
- form do |query_form|
- query_form.group(layout: :horizontal) do |group|
- if mode == :status_based
- select_field_options = { name: :status_id, label: I18n.t(:label_percent_complete) }.tap do |options|
- options.reverse_merge!(default_field_options(:status_id))
- options.merge!(disabled: @work_package.new_record?)
- end
-
- group.select_list(**select_field_options) do |select_list|
- WorkPackages::UpdateContract.new(@work_package, User.current)
- .assignable_statuses
- .find_each do |status|
- select_list.option(
- label: "#{status.name} (#{status.default_done_ratio}%)",
- value: status.id
- )
- end
- end
-
- render_text_field(group, name: :estimated_hours, label: I18n.t(:label_work))
- render_readonly_text_field(group, name: :remaining_hours, label: I18n.t(:label_remaining_work))
-
- # Add a hidden field in create forms as the select field is disabled and is otherwise not included in the form payload
- group.hidden(name: :status_id) if @work_package.new_record?
-
- group.hidden(name: :status_id_touched,
- value: @touched_field_map["status_id_touched"] || false,
- data: { "work-packages--progress--preview-target": "touchedFieldInput",
- "referrer-field": "status_id" })
- group.hidden(name: :estimated_hours_touched,
- value: @touched_field_map["estimated_hours_touched"] || false,
- data: { "work-packages--progress--preview-target": "touchedFieldInput",
- "referrer-field": "estimated_hours" })
- else
- render_text_field(group, name: :estimated_hours, label: I18n.t(:label_work))
- render_text_field(group, name: :remaining_hours, label: I18n.t(:label_remaining_work),
- disabled: disabled_remaining_work_field?)
- render_readonly_text_field(group, name: :done_ratio, label: I18n.t(:label_percent_complete))
-
- group.hidden(name: :estimated_hours_touched,
- value: @touched_field_map["estimated_hours_touched"] || false,
- data: { "work-packages--progress--preview-target": "touchedFieldInput",
- "referrer-field": "estimated_hours" })
- group.hidden(name: :remaining_hours_touched,
- value: @touched_field_map["remaining_hours_touched"] || false,
- data: { "work-packages--progress--preview-target": "touchedFieldInput",
- "referrer-field": "remaining_hours" })
- end
- group.fields_for(:initial) do |builder|
- ::WorkPackages::ProgressForm::InitialValuesForm.new(builder, work_package:, mode:)
- end
- end
- end
-
- private
-
- def ensure_only_one_error_for_remaining_work_exceeding_work
- if work_package.errors.added?(:remaining_hours, :cant_exceed_work) &&
- work_package.errors.added?(:estimated_hours, :cant_be_inferior_to_remaining_work)
- error_to_delete =
- if @focused_field == :estimated_hours
- :remaining_hours
- else
- :estimated_hours
- end
- work_package.errors.delete(error_to_delete)
- end
- end
-
- def focused_field_by_selection(field)
- if field == :remaining_hours && disabled_remaining_work_field?
- :estimated_hours
- else
- field
- end
- end
-
- def render_text_field(group,
- name:,
- label:,
- disabled: false,
- placeholder: nil)
- text_field_options = {
- name:,
- value: field_value(name),
- label:,
- disabled:,
- placeholder:
- }
- text_field_options.reverse_merge!(default_field_options(name))
-
- group.text_field(**text_field_options)
- end
-
- def render_readonly_text_field(group,
- name:,
- label:,
- disabled: false,
- placeholder: true)
- text_field_options = {
- name:,
- value: field_value(name),
- label:,
- readonly: true,
- disabled:,
- classes: "input--readonly",
- placeholder: ("-" if placeholder)
- }
- text_field_options.reverse_merge!(default_field_options(name))
-
- group.text_field(**text_field_options)
- end
-
- def field_value(name)
- errors = @work_package.errors.where(name)
- if (user_value = errors.map { |error| error.options[:value] }.find { !_1.nil? })
- user_value
- elsif name == :done_ratio
- format_to_smallest_fractional_part(@work_package.public_send(name))
- else
- DurationConverter.output(@work_package.public_send(name))
- end
- end
-
- def format_to_smallest_fractional_part(number)
- return number if number.nil?
-
- number % 1 == 0 ? number.to_i : number
- end
-
- def default_field_options(name)
- data = { "work-packages--progress--preview-target": "progressInput",
- action: "input->work-packages--progress--preview#markFieldAsTouched" }
-
- if @focused_field == name
- data[:focus] = "true"
- end
- { data: }
- end
-
- # Remaining work field is enabled when work is set, or when there are errors
- # on fields so that they can be corrected.
- def disabled_remaining_work_field?
- @work_package.estimated_hours.nil? && @work_package.errors.empty?
- end
-end
diff --git a/app/forms/work_packages/progress_form/initial_values_form.rb b/app/forms/work_packages/progress_form/initial_values_form.rb
index 91c10a2a588..16217e53214 100644
--- a/app/forms/work_packages/progress_form/initial_values_form.rb
+++ b/app/forms/work_packages/progress_form/initial_values_form.rb
@@ -45,9 +45,6 @@ class WorkPackages::ProgressForm
else
hidden_initial_field(form, name: :estimated_hours)
hidden_initial_field(form, name: :remaining_hours)
- # next line to be removed in 15.0 with :percent_complete_edition feature flag removal
- next unless OpenProject::FeatureDecisions.percent_complete_edition_active?
-
hidden_initial_field(form, name: :done_ratio)
end
end
diff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rb
index a013034c27b..cd1118d965a 100644
--- a/app/services/work_packages/set_attributes_service.rb
+++ b/app/services/work_packages/set_attributes_service.rb
@@ -285,15 +285,17 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributes
end
def update_progress_attributes
- derive_progress_values_class =
- if OpenProject::FeatureDecisions.percent_complete_edition_active?
- WorkPackage.status_based_mode? ? DeriveProgressValuesStatusBased : DeriveProgressValuesWorkBased
- else
- Pre144DeriveProgressValues
- end
derive_progress_values_class.new(work_package).call
end
+ def derive_progress_values_class
+ if WorkPackage.status_based_mode?
+ DeriveProgressValuesStatusBased
+ else
+ DeriveProgressValuesWorkBased
+ end
+ end
+
def set_version_to_nil
if work_package.version &&
work_package.project &&
diff --git a/app/services/work_packages/set_attributes_service/pre_14_4_derive_progress_values.rb b/app/services/work_packages/set_attributes_service/pre_14_4_derive_progress_values.rb
deleted file mode 100644
index 08fe1987db5..00000000000
--- a/app/services/work_packages/set_attributes_service/pre_14_4_derive_progress_values.rb
+++ /dev/null
@@ -1,186 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-# rubocop:disable Metrics/AbcSize
-class WorkPackages::SetAttributesService
- class Pre144DeriveProgressValues
- attr_reader :work_package
-
- def initialize(work_package)
- @work_package = work_package
- end
-
- def call
- update_progress_attributes
- end
-
- # From this point, copied over from 109b135b:app/services/work_packages/set_attributes_service.rb#L287-L427
- def update_progress_attributes
- if WorkPackage.status_based_mode?
- update_done_ratio
- update_remaining_hours
- elsif only_percent_complete_initially_set?
- update_remaining_hours_from_percent_complete
- else
- update_estimated_hours
- update_remaining_hours
- update_done_ratio
- end
- round_progress_values
- end
-
- def only_percent_complete_initially_set?
- return false if work_package.done_ratio.nil?
- return false if work_package.remaining_hours.present?
-
- work_package.estimated_hours_changed? && work_package.estimated_hours.present?
- end
-
- def work_was_unset_and_remaining_work_is_set?
- work_package.estimated_hours_was.nil? && work_package.remaining_hours.present?
- end
-
- # Compute and update +done_ratio+ if its dependent attributes are being modified.
- # The dependent attributes for +done_ratio+ are
- # - +remaining_hours+
- # - +estimated_hours+
- #
- # Unless both +remaining_hours+ and +estimated_hours+ are set, +done_ratio+ will be
- # considered nil.
- def update_done_ratio
- if WorkPackage.status_based_mode?
- return unless work_package.status_id_changed?
-
- work_package.done_ratio = work_package.status.default_done_ratio
- else
- return unless work_package.remaining_hours_changed? || work_package.estimated_hours_changed?
-
- work_package.done_ratio = if done_ratio_dependent_attribute_unset?
- nil
- else
- compute_done_ratio
- end
- end
- end
-
- def round_progress_values
- rounded = work_package.estimated_hours&.round(2)
- if rounded != work_package.estimated_hours
- work_package.estimated_hours = rounded
- end
- rounded = work_package.remaining_hours&.round(2)
- if rounded != work_package.remaining_hours
- work_package.remaining_hours = rounded
- end
- end
-
- def update_remaining_hours_from_percent_complete
- return if work_package.remaining_hours_came_from_user?
- return if work_package.estimated_hours&.negative?
-
- work_package.remaining_hours = remaining_hours_from_done_ratio_and_estimated_hours
- end
-
- def done_ratio_dependent_attribute_unset?
- work_package.remaining_hours.nil? || work_package.estimated_hours.nil?
- end
-
- def compute_done_ratio
- # do not change done ratio if the values are invalid
- if invalid_progress_values?
- return work_package.done_ratio
- end
-
- completed_work = work_package.estimated_hours - work_package.remaining_hours
- completion_ratio = completed_work.to_f / work_package.estimated_hours
-
- (completion_ratio * 100).round(2)
- end
-
- def invalid_progress_values?
- work = work_package.estimated_hours
- remaining_work = work_package.remaining_hours
-
- return true if work.negative?
- return true if remaining_work.negative?
-
- work && remaining_work && remaining_work > work
- end
-
- def update_estimated_hours
- return unless WorkPackage.work_based_mode?
- return if work_package.estimated_hours_came_from_user?
- return unless work_package.remaining_hours_changed?
-
- work = work_package.estimated_hours
- remaining_work = work_package.remaining_hours
- return if work.present?
- return if remaining_work.nil? || remaining_work.negative?
-
- work_package.estimated_hours = estimated_hours_from_done_ratio_and_remaining_hours
- end
-
- # When in "Status-based" mode for % Complete, remaining hours are based
- # on the computation of it derived from the status's default done ratio
- # and the estimated hours. If the estimated hours are unset, then also
- # unset the remaining hours.
- # rubocop:disable Metrics/PerceivedComplexity
- def update_remaining_hours
- if WorkPackage.status_based_mode?
- update_remaining_hours_from_percent_complete
- elsif WorkPackage.work_based_mode? &&
- work_package.estimated_hours_changed?
- return if work_package.remaining_hours_came_from_user?
- return if work_package.estimated_hours&.negative?
- return if work_was_unset_and_remaining_work_is_set? # remaining work is kept and % complete will be set
-
- if work_package.estimated_hours.nil? || work_package.remaining_hours.nil?
- work_package.remaining_hours = work_package.estimated_hours
- else
- delta = work_package.estimated_hours - work_package.estimated_hours_was
- work_package.remaining_hours = (work_package.remaining_hours + delta).clamp(0.0, work_package.estimated_hours)
- end
- end
- end
- # rubocop:enable Metrics/PerceivedComplexity
-
- def estimated_hours_from_done_ratio_and_remaining_hours
- remaining_ratio = 1.0 - ((work_package.done_ratio || 0) / 100.0)
- work_package.remaining_hours / remaining_ratio
- end
-
- def remaining_hours_from_done_ratio_and_estimated_hours
- return nil if work_package.done_ratio.nil? || work_package.estimated_hours.nil?
-
- completed_work = work_package.estimated_hours * work_package.done_ratio / 100.0
- remaining_hours = (work_package.estimated_hours - completed_work).round(2)
- remaining_hours.clamp(0.0, work_package.estimated_hours)
- end
- end
-end
-# rubocop:enable Metrics/AbcSize
diff --git a/app/views/admin/settings/progress_tracking/show.html.erb b/app/views/admin/settings/progress_tracking/show.html.erb
index 391de8f1a50..b73fa30ba08 100644
--- a/app/views/admin/settings/progress_tracking/show.html.erb
+++ b/app/views/admin/settings/progress_tracking/show.html.erb
@@ -45,7 +45,6 @@ primer_form_with(
application_target: "dynamic",
controller: "admin--progress-tracking",
admin__progress_tracking_target: "progressCalculationModeRadioGroup",
- admin__progress_tracking_percent_complete_edition_active_value: OpenProject::FeatureDecisions.percent_complete_edition_active?,
admin__progress_tracking_initial_mode_value: Setting.work_package_done_ratio
}
) do |f|
diff --git a/app/workers/work_packages/progress/apply_statuses_change_job.rb b/app/workers/work_packages/progress/apply_statuses_change_job.rb
index 421bd104ac8..eeecc42ec4b 100644
--- a/app/workers/work_packages/progress/apply_statuses_change_job.rb
+++ b/app/workers/work_packages/progress/apply_statuses_change_job.rb
@@ -71,10 +71,8 @@ class WorkPackages::Progress::ApplyStatusesChangeJob < WorkPackages::Progress::J
clear_percent_complete_when_0h_work
elsif WorkPackage.status_based_mode?
set_percent_complete_from_status
- if OpenProject::FeatureDecisions.percent_complete_edition_active?
- fix_remaining_work_set_with_100_percent_complete
- derive_unset_work_from_remaining_work_and_percent_complete
- end
+ fix_remaining_work_set_with_100_percent_complete
+ derive_unset_work_from_remaining_work_and_percent_complete
derive_remaining_work_from_work_and_percent_complete
end
end
diff --git a/config/initializers/feature_decisions.rb b/config/initializers/feature_decisions.rb
index 77adfa592a2..d2d1d2caeb6 100644
--- a/config/initializers/feature_decisions.rb
+++ b/config/initializers/feature_decisions.rb
@@ -38,10 +38,5 @@ require_relative "../../lib_static/open_project/feature_decisions"
# initializer 'the_engine.feature_decisions' do
# OpenProject::FeatureDecisions.add :some_flag
# end
-OpenProject::FeatureDecisions.add :percent_complete_edition,
- description: "Allow edition of % Complete in work-based progress calculation mode. " \
- "Will be enabled by default in OpenProject 15.0. " \
- "See work package #52233 for more details."
-
OpenProject::FeatureDecisions.add :built_in_oauth_applications,
description: "Allows the display and use of built-in OAuth applications."
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 2194c9f433e..a7153289dd8 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -3314,9 +3314,6 @@ en:
setting_work_package_done_ratio_status_caption_html: >-
Each status has a <i>% Complete</i> value associated with it.
Changing status will change <i>% Complete</i>.
- setting_work_package_done_ratio_explanation_pre_14_4_without_percent_complete_edition_html: >
- In <b>work-based</b> mode, % Complete is calculated from how much work is done in relation to total work.
- In <b>status-based</b> mode, each status has a % Complete value associated with it. Changing status will change % Complete.
setting_work_package_done_ratio_explanation_html: >
In <b>work-based</b> mode, % Complete can be freely set to any value.
If you optionally enter a value for Work, Remaining work will automatically be derived.
@@ -3796,7 +3793,6 @@ en:
label_note: "Note:"
modal:
work_based_help_text: "Each field is automatically calculated from the two others when possible."
- work_based_help_text_pre_14_4_without_percent_complete_edition: "% Complete is automatically derived from Work and Remaining work."
status_based_help_text: "% Complete is set by work package status."
migration_warning_text: "In work-based progress calculation mode, % Complete cannot be manually set and is tied to Work. The existing value has been kept but cannot be edited. Please input Work first."
derivation_hints:
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 335a08918f1..d1ca668b9b7 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -308,12 +308,6 @@ en:
Are you sure you want to continue?
work_packages_settings:
- warning_progress_calculation_mode_change_from_status_to_field_pre_14_4_without_percent_complete_edition_html: >-
- Changing progress calculation mode from status-based to work-based will make
- <i>% Complete</i> a non-editable field whose value is derived from <i>Work</i>
- and <i>Remaining work</i>. Existing values for <i>% Complete</i> are preserved.
- If values for <i>Work</i> and <i>Remaining work</i> were not present, they
- will be required in order to change <i>% Complete</i>.
warning_progress_calculation_mode_change_from_status_to_field_html: >-
Changing progress calculation mode from status-based to work-based will make
the <i>% Complete</i> field freely editable. If you optionally enter values
diff --git a/frontend/src/stimulus/controllers/dynamic/admin/progress-tracking.controller.ts b/frontend/src/stimulus/controllers/dynamic/admin/progress-tracking.controller.ts
index c6b10b74f88..0778fb4ca23 100644
--- a/frontend/src/stimulus/controllers/dynamic/admin/progress-tracking.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/admin/progress-tracking.controller.ts
@@ -33,7 +33,6 @@ import { Controller } from '@hotwired/stimulus';
export default class ProgressTrackingController extends Controller {
static values = {
initialMode: String,
- percentCompleteEditionActive: Boolean,
};
static targets = [
@@ -44,7 +43,6 @@ export default class ProgressTrackingController extends Controller {
];
declare readonly initialModeValue:string;
- declare readonly percentCompleteEditionActiveValue:boolean;
declare readonly progressCalculationModeRadioGroupTarget:HTMLElement;
declare readonly warningTextTarget:HTMLElement;
@@ -95,13 +93,6 @@ export default class ProgressTrackingController extends Controller {
return '';
}
- // to be removed in 15.0 with :percent_complete_edition feature flag removal
- if (!this.percentCompleteEditionActiveValue && selectedMode === 'field') {
- return I18n.t(
- 'js.admin.work_packages_settings.warning_progress_calculation_mode_change_from_status_to_field_pre_14_4_without_percent_complete_edition_html',
- );
- }
-
return I18n.t(
`js.admin.work_packages_settings.warning_progress_calculation_mode_change_from_${this.initialModeValue}_to_${selectedMode}_html`,
);
diff --git a/spec/components/work_packages/progress/work_based/modal_body_component_pre_14_4_without_percent_complete_edition_spec.rb b/spec/components/work_packages/progress/work_based/modal_body_component_pre_14_4_without_percent_complete_edition_spec.rb
deleted file mode 100644
index 22719695eae..00000000000
--- a/spec/components/work_packages/progress/work_based/modal_body_component_pre_14_4_without_percent_complete_edition_spec.rb
+++ /dev/null
@@ -1,73 +0,0 @@
-# frozen_string_literal: true
-
-# -- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2010-2024 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-# ++
-require "spec_helper"
-require_relative "../shared_modal_examples"
-
-# This file can be safely deleted once the feature flag :percent_complete_edition
-# is removed, which should happen for OpenProject 15.0 release.
-RSpec.describe WorkPackages::Progress::WorkBased::ModalBodyComponent, "pre 14.4 without percent complete edition",
- type: :component,
- with_flag: { percent_complete_edition: false } do
- include OpenProject::StaticRouting::UrlHelpers
-
- describe "#should_display_migration_warning?" do
- subject(:component) { described_class.new(work_package) }
-
- context "when the work package has a percent complete value but no work or remaining work set" do
- let(:work_package) do
- create(:work_package) do |work_package|
- work_package.estimated_hours = nil
- work_package.remaining_hours = nil
- work_package.done_ratio = 10
- work_package.save!(validate: false)
- end
- end
-
- it "returns true" do
- expect(component.should_display_migration_warning?).to be true
- end
- end
-
- context "when the work package has a percent complete value and a work value but no remaining work set" do
- let(:work_package) do
- create(:work_package) do |work_package|
- work_package.estimated_hours = 55
- work_package.remaining_hours = nil
- work_package.done_ratio = 10
- work_package.save!(validate: false)
- end
- end
-
- it "returns false" do
- expect(component.should_display_migration_warning?).to be false
- end
- end
- end
-end
diff --git a/spec/contracts/work_packages/base_contract_pre_14_4_without_percent_complete_edition_spec.rb b/spec/contracts/work_packages/base_contract_pre_14_4_without_percent_complete_edition_spec.rb
deleted file mode 100644
index e66dccce328..00000000000
--- a/spec/contracts/work_packages/base_contract_pre_14_4_without_percent_complete_edition_spec.rb
+++ /dev/null
@@ -1,1250 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-require "spec_helper"
-require "contracts/shared/model_contract_shared_context"
-
-# This file can be safely deleted once the feature flag :percent_complete_edition
-# is removed, which should happen for OpenProject 15.0 release.
-# Copied from commit 109b135b with a few changes for greater_than_or_equal_to validation
-RSpec.describe WorkPackages::BaseContract, "pre 14.4 without percent complete edition",
- with_flag: { percent_complete_edition: false } do
- include_context "ModelContract shared context"
-
- let(:work_package) do
- build_stubbed(:work_package,
- type:,
- done_ratio: 50,
- estimated_hours: 6.0,
- remaining_hours: 3.0,
- project:)
- end
- let(:project) { build_stubbed(:project) }
- let(:current_user) { member }
- let(:permissions) do
- %i(
- view_work_packages
- view_work_package_watchers
- edit_work_packages
- add_work_package_watchers
- delete_work_package_watchers
- manage_work_package_relations
- add_work_package_notes
- assign_versions
- )
- end
- let(:changed_values) { [] }
- let(:type) { build_stubbed(:type, is_milestone:) }
- let(:is_milestone) { false }
-
- let(:member) { build_stubbed(:user) }
-
- before do
- mock_permissions_for(member) do |mock|
- mock.allow_in_project *permissions, project:
- end
- end
-
- subject(:contract) { described_class.new(work_package, current_user) }
-
- shared_examples_for "invalid if changed" do |attribute|
- before do
- allow(work_package).to receive(:changed).and_return(changed_values.map(&:to_s))
- end
-
- before do
- contract.validate
- end
-
- context "when has changed" do
- let(:changed_values) { [attribute] }
-
- it("is invalid") do
- expect(contract.errors.symbols_for(attribute)).to contain_exactly(:error_readonly)
- end
- end
-
- context "when not changed" do
- let(:changed_values) { [] }
-
- it("is valid") { expect(contract.errors).to be_empty }
- end
- end
-
- shared_examples "a parent unwritable property" do |attribute, schedule_sensitive: false|
- before do
- allow(work_package).to receive(:changed).and_return(changed_values.map(&:to_s))
- end
-
- context "when no parent" do
- before do
- allow(work_package)
- .to receive(:leaf?)
- .and_return(true)
-
- contract.validate
- end
-
- context "when not changed" do
- let(:changed_values) { [] }
-
- it("is valid") { expect(contract.errors).to be_empty }
- end
-
- context "when has changed" do
- let(:changed_values) { [attribute] }
-
- it("is valid") { expect(contract.errors).to be_empty }
- end
- end
-
- context "when is a parent" do
- let(:schedule_manually) { false }
-
- before do
- work_package.schedule_manually = schedule_manually
-
- allow(work_package)
- .to receive(:leaf?)
- .and_return(false)
- contract.validate
- end
-
- context "when not changed" do
- let(:changed_values) { [] }
-
- it("is valid") { expect(contract.errors).to be_empty }
- end
-
- context "when has changed" do
- let(:changed_values) { [attribute] }
-
- it("is invalid (read only)") do
- expect(contract.errors.symbols_for(attribute)).to contain_exactly(:error_readonly)
- end
- end
-
- if schedule_sensitive
- context "when is scheduled manually" do
- let(:schedule_manually) { true }
-
- context "when has changed" do
- let(:changed_values) { [attribute] }
-
- it("is valid") { expect(contract.errors).to be_empty }
- end
- end
- end
- end
- end
-
- describe "status" do
- context "for readonly status" do
- before do
- allow(work_package)
- .to receive(:readonly_status?)
- .and_return true
- end
-
- it "only sets status to allowed" do
- expect(contract.writable_attributes).to eq(%w[status status_id])
- end
- end
-
- context "when work_package has a closed version and status" do
- before do
- version = build_stubbed(:version, status: "closed")
-
- work_package.version = version
- allow(work_package.status)
- .to receive(:is_closed?)
- .and_return(true)
- end
-
- it "is not writable" do
- expect(contract).not_to be_writable(:status)
- end
-
- context "when we only switched into that status now" do
- before do
- allow(work_package)
- .to receive(:status_id_change)
- .and_return [1, 2]
- end
-
- it "is writable" do
- expect(contract).to be_writable(:status)
- end
- end
- end
-
- context "when status is inexistent" do
- before do
- work_package.status = Status::InexistentStatus.new
- end
-
- it "is invalid" do
- contract.validate
-
- expect(subject.errors.symbols_for(:status))
- .to contain_exactly(:does_not_exist)
- end
- end
-
- describe "transitions" do
- let(:roles) { [build_stubbed(:project_role)] }
- let(:valid_transition_result) { true }
- let(:new_status) { build_stubbed(:status) }
- let(:from_id) { work_package.status_id }
- let(:to_id) { new_status.id }
- let(:status_change) { work_package.status = new_status }
-
- before do
- new_statuses_scope = double("new statuses scope") # rubocop:disable RSpec/VerifiedDoubles
-
- allow(Status)
- .to receive(:find_by)
- .with(id: work_package.status_id)
- .and_return(work_package.status)
-
- # Breaking abstraction here to avoid mocking hell.
- # We might want to extract the assignable_... into separate
- # objects.
- allow(contract) # rubocop:disable RSpec/SubjectStub
- .to receive(:new_statuses_allowed_from)
- .with(work_package.status)
- .and_return(new_statuses_scope)
-
- allow(new_statuses_scope)
- .to receive(:order_by_position)
- .and_return(new_statuses_scope)
-
- allow(new_statuses_scope)
- .to receive(:exists?)
- .with(new_status.id)
- .and_return(valid_transition_result)
-
- status_change
-
- contract.validate
- end
-
- context "when valid transition" do
- it "is valid" do
- expect(subject.errors.symbols_for(:status_id))
- .to be_empty
- end
- end
-
- context "when invalid transition" do
- let(:valid_transition_result) { false }
-
- it "is invalid" do
- expect(subject.errors.symbols_for(:status_id))
- .to contain_exactly(:status_transition_invalid)
- end
- end
-
- context "when status is nil" do
- let(:status_change) { work_package.status = nil }
-
- it "is invalid" do
- expect(subject.errors.symbols_for(:status))
- .to contain_exactly(:blank)
- end
- end
-
- context "when invalid transition but the type changed as well" do
- let(:valid_transition_result) { false }
- let(:status_change) do
- work_package.status = new_status
- work_package.type = build_stubbed(:type)
- end
-
- it "is valid" do
- expect(subject.errors.symbols_for(:status_id))
- .to be_empty
- end
- end
- end
- end
-
- describe "work (estimated hours)" do
- let(:estimated_hours) { 1 }
- let(:remaining_hours) { 0 }
-
- before do
- work_package.estimated_hours = estimated_hours
- work_package.remaining_hours = remaining_hours
- work_package.clear_remaining_hours_change
- end
-
- context "when > 0" do
- let(:estimated_hours) { 1 }
-
- include_examples "contract is valid"
- end
-
- context "when 0" do
- let(:estimated_hours) { 0 }
-
- include_examples "contract is valid"
- end
-
- context "when nil while remaining work is nil" do
- let(:estimated_hours) { nil }
- let(:remaining_hours) { nil }
-
- include_examples "contract is valid"
- end
-
- context "when nil while remaining work is set" do
- let(:estimated_hours) { nil }
- let(:remaining_hours) { 2.0 }
-
- include_examples "contract is invalid", estimated_hours: :must_be_set_when_remaining_work_is_set
- end
-
- context "when < 0" do
- let(:estimated_hours) { -1 }
- let(:remaining_hours) { -2 }
-
- include_examples "contract is invalid", estimated_hours: :greater_than_or_equal_to
- end
-
- context "when inferior to remaining work" do
- let(:estimated_hours) { 5.0 }
- let(:remaining_hours) { 7.0 }
-
- include_examples "contract is invalid", estimated_hours: :cant_be_inferior_to_remaining_work
- end
- end
-
- describe "total work (derived estimated hours)" do
- let(:changed_values) { [] }
- let(:attribute) { :derived_estimated_hours }
-
- before do
- allow(work_package).to receive(:changed).and_return(changed_values.map(&:to_s))
-
- contract.validate
- end
-
- context "when has not changed" do
- let(:changed_values) { [] }
-
- it("is valid") { expect(contract.errors).to be_empty }
- end
-
- context "when has changed" do
- let(:changed_values) { [attribute] }
-
- it("is invalid (read only)") do
- expect(contract.errors.symbols_for(attribute)).to contain_exactly(:error_readonly)
- end
- end
- end
-
- describe "remaining work (remaining hours)" do
- before do
- work_package.estimated_hours = 5.0
- work_package.clear_remaining_hours_change
- work_package.remaining_hours = remaining_hours
- end
-
- context "when it's the same as work" do
- let(:remaining_hours) { 5.0 }
-
- include_examples "contract is valid"
- end
-
- context "when it's less than work" do
- let(:remaining_hours) { 4.0 }
-
- include_examples "contract is valid"
- end
-
- context "when it's greater than work" do
- let(:remaining_hours) { 6.0 }
-
- include_examples "contract is invalid", remaining_hours: :cant_exceed_work
- end
-
- context "when unset" do
- let(:remaining_hours) { nil }
-
- include_examples "contract is invalid", remaining_hours: :must_be_set_when_work_is_set
- end
- end
-
- describe "work and remaining work" do
- context "when changing both and remaining work exceeds work" do
- before do
- work_package.estimated_hours = 5.0
- work_package.remaining_hours = 6.0
- end
-
- include_examples "contract is invalid", estimated_hours: :cant_be_inferior_to_remaining_work,
- remaining_hours: :cant_exceed_work
- end
- end
-
- shared_examples_for "a date attribute" do |attribute|
- context "for a date" do
- before do
- work_package.send(:"#{attribute}=", Time.zone.today)
- contract.validate
- end
-
- it "is valid" do
- expect(subject.errors.symbols_for(attribute))
- .to be_empty
- end
- end
-
- context "for a string representing a date" do
- before do
- work_package.send(:"#{attribute}=", "01/01/17")
- contract.validate
- end
-
- it "is valid" do
- expect(subject.errors.symbols_for(attribute))
- .to be_empty
- end
- end
-
- context "for a non-date" do
- before do
- work_package.send(:"#{attribute}=", "not a date")
- contract.validate
- end
-
- it "is invalid" do
- expect(subject.errors.symbols_for(attribute))
- .to contain_exactly(:not_a_date)
- end
- end
- end
-
- describe "start date" do
- it_behaves_like "a parent unwritable property", :start_date, schedule_sensitive: true
- it_behaves_like "a date attribute", :start_date
-
- context "as before soonest start date of parent" do
- let(:schedule_manually) { false }
-
- before do
- work_package.schedule_manually = schedule_manually
- allow(work_package)
- .to receive_messages(parent: build_stubbed(:work_package),
- soonest_start: Time.zone.today + 4.days)
-
- work_package.start_date = Time.zone.today + 2.days
- end
-
- context "when scheduled automatically" do
- it "notes the error" do
- contract.validate
-
- message = I18n.t("activerecord.errors.models.work_package.attributes.start_date.violates_relationships",
- soonest_start: Time.zone.today + 4.days)
-
- expect(contract.errors[:start_date])
- .to contain_exactly(message)
- end
- end
-
- context "when scheduled manually" do
- let(:schedule_manually) { true }
-
- it_behaves_like "contract is valid"
- end
- end
-
- context "when setting due date and duration without start date" do
- before do
- work_package.duration = 1
- work_package.start_date = nil
- work_package.due_date = Time.zone.today
- end
-
- it_behaves_like "contract is invalid", start_date: :cannot_be_null
- end
- end
-
- describe "due date" do
- it_behaves_like "a parent unwritable property", :due_date, schedule_sensitive: true
- it_behaves_like "a date attribute", :due_date
-
- it "returns an error when trying to set it before the start date" do
- work_package.start_date = Time.zone.today + 2.days
- work_package.due_date = Time.zone.today
-
- contract.validate
-
- message = I18n.t("activerecord.errors.messages.greater_than_or_equal_to_start_date")
-
- expect(contract.errors[:due_date])
- .to include message
- end
-
- context "when start date is not set and due date is before soonest start date of parent" do
- let(:schedule_manually) { false }
-
- before do
- work_package.schedule_manually = schedule_manually
- allow(work_package)
- .to receive_messages(parent: build_stubbed(:work_package),
- soonest_start: Time.zone.today + 4.days)
-
- work_package.start_date = nil
- work_package.due_date = Time.zone.today + 2.days
- end
-
- context "when scheduled automatically" do
- it "notes the error" do
- contract.validate
-
- message = I18n.t("activerecord.errors.models.work_package.attributes.start_date.violates_relationships",
- soonest_start: Time.zone.today + 4.days)
-
- expect(contract.errors[:due_date])
- .to contain_exactly(message)
- end
- end
-
- context "when scheduled manually" do
- let(:schedule_manually) { true }
-
- it_behaves_like "contract is valid"
- end
- end
-
- context "when setting start date and duration without due date" do
- before do
- work_package.duration = 1
- work_package.start_date = Time.zone.today
- work_package.due_date = nil
- end
-
- it_behaves_like "contract is invalid", due_date: :cannot_be_null
- end
- end
-
- describe "duration" do
- context "when setting duration" do
- before do
- work_package.duration = 5
- end
-
- it_behaves_like "contract is valid"
- end
-
- context "when setting duration for a milestone type work package" do
- let(:is_milestone) { true }
-
- before do
- work_package.duration = 5
- end
-
- it_behaves_like "contract is invalid", duration: :not_available_for_milestones
- end
-
- context "when setting duration to nil for a milestone type work package" do
- let(:is_milestone) { true }
-
- before do
- work_package.duration = nil
- end
-
- it_behaves_like "contract is invalid"
- end
-
- context "when setting duration to 1 for a milestone type work package" do
- let(:is_milestone) { true }
-
- before do
- work_package.duration = 1
- end
-
- it_behaves_like "contract is valid"
- end
-
- context "when setting duration to 0" do
- before do
- work_package.duration = 0
- end
-
- it_behaves_like "contract is invalid", duration: :greater_than
- end
-
- context "when setting duration to a floating point" do
- before do
- work_package.duration = 4.5
- end
-
- it_behaves_like "contract is invalid", duration: :not_an_integer
- end
-
- context "when setting duration to a negative value" do
- before do
- work_package.duration = -5
- end
-
- it_behaves_like "contract is invalid", duration: :greater_than
- end
-
- context "when setting duration and dates" do
- before do
- work_package.ignore_non_working_days = true
- work_package.duration = 6
- work_package.start_date = Time.zone.today - 4.days
- work_package.due_date = Time.zone.today + 1.day
- end
-
- it_behaves_like "contract is valid"
- end
-
- context "when setting duration and dates while covering non-working days" do
- before do
- week_with_saturday_and_sunday_as_weekend
- work_package.ignore_non_working_days = false
- work_package.duration = 6
- work_package.start_date = "2022-08-22"
- work_package.due_date = "2022-08-29"
- end
-
- it_behaves_like "contract is valid"
- end
-
- context "when setting duration and dates and duration is too small" do
- before do
- work_package.ignore_non_working_days = true
- work_package.duration = 5
- work_package.start_date = Time.zone.today - 4.days
- work_package.due_date = Time.zone.today + 1.day
- end
-
- it_behaves_like "contract is invalid", duration: :smaller_than_dates
- end
-
- context "when setting duration and dates while covering non-working days and duration is too small" do
- before do
- week_with_saturday_and_sunday_as_weekend
- work_package.ignore_non_working_days = false
- work_package.duration = 1
- work_package.start_date = "2022-08-22"
- work_package.due_date = "2022-08-29"
- end
-
- it_behaves_like "contract is invalid", duration: :smaller_than_dates
- end
-
- context "when setting duration and dates and duration is too big" do
- before do
- work_package.ignore_non_working_days = true
- work_package.duration = 7
- work_package.start_date = Time.zone.today - 4.days
- work_package.due_date = Time.zone.today + 1.day
- end
-
- it_behaves_like "contract is invalid", duration: :larger_than_dates
- end
-
- context "when setting duration and dates while covering non-working days and duration is too big" do
- before do
- week_with_saturday_and_sunday_as_weekend
- work_package.ignore_non_working_days = false
- work_package.duration = 99
- work_package.start_date = "2022-08-22"
- work_package.due_date = "2022-08-29"
- end
-
- it_behaves_like "contract is invalid", duration: :larger_than_dates
- end
-
- context "when setting start date and due date without duration" do
- before do
- work_package.duration = nil
- work_package.start_date = Time.zone.today
- work_package.due_date = Time.zone.today
- end
-
- it_behaves_like "contract is invalid", duration: :cannot_be_null
- end
- end
-
- describe "ignore_non_working_days" do
- context "when setting the value to true" do
- before do
- work_package.ignore_non_working_days = true
- end
-
- it_behaves_like "contract is valid"
- end
-
- context "when setting the value to false" do
- before do
- work_package.ignore_non_working_days = false
- end
-
- it_behaves_like "contract is valid"
- end
- end
-
- describe "percentage done" do
- context "when % Complete inferred by status",
- with_settings: { work_package_done_ratio: "status" } do
- it_behaves_like "invalid if changed", :done_ratio
- end
- end
-
- describe "version" do
- subject(:contract) { described_class.new(work_package, current_user) }
-
- let(:assignable_version) { build_stubbed(:version) }
- let(:invalid_version) { build_stubbed(:version) }
-
- before do
- allow(work_package).to receive(:assignable_versions).and_return [assignable_version]
- end
-
- context "for assignable version" do
- before do
- work_package.version = assignable_version
- subject.validate
- end
-
- it "is valid" do
- expect(subject.errors).to be_empty
- end
- end
-
- context "for non assignable version" do
- before do
- work_package.version = invalid_version
- subject.validate
- end
-
- it "is invalid" do
- expect(subject.errors.symbols_for(:version_id)).to eql [:inclusion]
- end
- end
-
- context "for a closed version" do
- let(:assignable_version) { build_stubbed(:version, status: "closed") }
-
- context "when reopening a work package" do
- before do
- allow(work_package)
- .to receive(:reopened?)
- .and_return(true)
-
- work_package.version = assignable_version
- subject.validate
- end
-
- it "is invalid" do
- expect(subject.errors[:base]).to eql [I18n.t(:error_can_not_reopen_work_package_on_closed_version)]
- end
- end
-
- context "when not reopening the work package" do
- before do
- work_package.version = assignable_version
- subject.validate
- end
-
- it "is valid" do
- expect(subject.errors).to be_empty
- end
- end
- end
- end
-
- describe "parent" do
- let(:parent) { build_stubbed(:work_package) }
-
- before do
- work_package.parent = parent
- end
-
- subject do
- contract.validate
-
- # while we do validate the parent
- # the errors are still put on :base so that the messages can be reused
- contract.errors.symbols_for(:parent)
- end
-
- context "when self assigning" do
- let(:parent) { work_package }
-
- it "returns an error for the parent" do
- expect(subject)
- .to eq [:cannot_be_self_assigned]
- end
- end
-
- context "when the intended parent is not relatable" do
- before do
- scope = instance_double(ActiveRecord::Relation)
-
- allow(WorkPackage)
- .to receive(:relatable)
- .with(work_package, Relation::TYPE_PARENT)
- .and_return(scope)
-
- allow(scope)
- .to receive(:where)
- .with(id: parent.id)
- .and_return([])
- end
-
- it "is invalid" do
- expect(subject)
- .to include(:cant_link_a_work_package_with_a_descendant)
- end
- end
-
- context "when an invalid parent_id is set" do
- before do
- work_package.parent = nil
- work_package.parent_id = -1
- end
-
- it "is invalid" do
- expect(subject)
- .to include(:does_not_exist)
- end
- end
- end
-
- describe "type" do
- context "for disabled type" do
- before do
- allow(project)
- .to receive(:types)
- .and_return([])
- end
-
- describe "not changing the type" do
- it "is valid" do
- subject.validate
-
- expect(subject)
- .to be_valid
- end
- end
-
- describe "changing the type" do
- let(:other_type) { build_stubbed(:type) }
-
- it "is invalid" do
- work_package.type = other_type
-
- subject.validate
-
- expect(subject.errors.symbols_for(:type_id))
- .to contain_exactly(:inclusion)
- end
- end
-
- describe "changing the project (and that one not having the type)" do
- let(:other_project) { build_stubbed(:project) }
-
- it "is invalid" do
- work_package.project = other_project
-
- subject.validate
-
- expect(subject.errors.symbols_for(:type_id))
- .to contain_exactly(:inclusion)
- end
- end
- end
-
- context "for inexistent type" do
- before do
- work_package.type = Type::InexistentType.new
-
- contract.validate
- end
-
- it "is invalid" do
- expect(contract.errors.symbols_for(:type))
- .to contain_exactly(:does_not_exist)
- end
- end
- end
-
- describe "assigned_to" do
- context "for inexistent user" do
- before do
- work_package.assigned_to = Users::InexistentUser.new
-
- contract.validate
- end
-
- it "is invalid" do
- expect(contract.errors.symbols_for(:assigned_to))
- .to contain_exactly(:does_not_exist)
- end
- end
- end
-
- describe "category" do
- let(:category) { build_stubbed(:category) }
-
- context "for one of the project's categories" do
- before do
- allow(project)
- .to receive(:categories)
- .and_return [category]
-
- work_package.category = category
-
- contract.validate
- end
-
- it "is valid" do
- expect(contract.errors.symbols_for(:category))
- .to be_empty
- end
- end
-
- context "when empty" do
- before do
- work_package.category = nil
-
- contract.validate
- end
-
- it "is valid" do
- expect(contract.errors.symbols_for(:category))
- .to be_empty
- end
- end
-
- context "for inexistent category (e.g. removed)" do
- before do
- work_package.category_id = 5
-
- contract.validate
- end
-
- it "is invalid" do
- expect(contract.errors.symbols_for(:category))
- .to contain_exactly(:does_not_exist)
- end
- end
-
- context "when not of the project" do
- before do
- allow(project)
- .to receive(:categories)
- .and_return []
-
- work_package.category = category
-
- contract.validate
- end
-
- it "is invalid" do
- expect(contract.errors.symbols_for(:category))
- .to contain_exactly(:only_same_project_categories_allowed)
- end
- end
- end
-
- describe "priority" do
- let (:active_priority) { build_stubbed(:priority) }
- let (:inactive_priority) { build_stubbed(:priority, active: false) }
-
- context "as active priority" do
- before do
- work_package.priority = active_priority
-
- contract.validate
- end
-
- it "is valid" do
- expect(contract.errors.symbols_for(:priority_id))
- .to be_empty
- end
- end
-
- context "as inactive priority" do
- before do
- work_package.priority = inactive_priority
-
- contract.validate
- end
-
- it "is invalid" do
- expect(contract.errors.symbols_for(:priority_id))
- .to contain_exactly(:only_active_priorities_allowed)
- end
- end
-
- context "as inactive priority but priority not changed" do
- before do
- work_package.priority = inactive_priority
- work_package.clear_changes_information
-
- contract.validate
- end
-
- it "is valid" do
- expect(contract.errors.symbols_for(:priority_id))
- .to be_empty
- end
- end
-
- context "as inexistent priority" do
- before do
- work_package.priority = Priority::InexistentPriority.new
-
- contract.validate
- end
-
- it "is invalid" do
- expect(contract.errors.symbols_for(:priority))
- .to contain_exactly(:does_not_exist)
- end
- end
- end
-
- describe "#assignable_statuses" do
- let(:role) { build_stubbed(:project_role) }
- let(:type) { build_stubbed(:type) }
- let(:assignee_user) { build_stubbed(:user) }
- let(:author_user) { build_stubbed(:user) }
- let(:current_status) { build_stubbed(:status) }
- let(:version) { build_stubbed(:version) }
- let(:work_package) do
- build_stubbed(:work_package,
- assigned_to: assignee_user,
- author: author_user,
- status: current_status,
- version:,
- type:)
- end
- let!(:default_status) do
- status = build_stubbed(:status)
-
- allow(Status)
- .to receive(:default)
- .and_return(status)
-
- status
- end
-
- let(:roles) { [role] }
-
- before do
- allow(current_user)
- .to receive(:roles_for_work_package)
- .with(work_package)
- .and_return(roles)
- end
-
- shared_examples_for "new_statuses_allowed_to" do
- let(:base_scope) do
- from_workflows = Workflow
- .from_status(current_status.id, type.id, [role.id], author, assignee)
- .select(:new_status_id)
-
- Status.where(id: from_workflows)
- .or(Status.where(id: current_status.id))
- end
-
- it "returns a scope that returns current_status and those available by workflow" do
- expect(contract.assignable_statuses.to_sql)
- .to eql base_scope.order_by_position.to_sql
- end
-
- it "removes closed statuses if blocked" do
- allow(work_package)
- .to receive(:blocked?)
- .and_return(true)
-
- expected = base_scope.where(is_closed: false).order_by_position
-
- expect(contract.assignable_statuses.to_sql)
- .to eql expected.to_sql
- end
-
- context "if the current status is closed and the version is closed as well" do
- let(:version) { build_stubbed(:version, status: "closed") }
- let(:current_status) { build_stubbed(:status, is_closed: true) }
-
- it "only allows the current status" do
- expect(contract.assignable_statuses.to_sql)
- .to eql Status.where(id: current_status.id).to_sql
- end
- end
- end
-
- context "with somebody else asking" do
- it_behaves_like "new_statuses_allowed_to" do
- let(:author) { false }
- let(:assignee) { false }
- end
- end
-
- context "with the author asking" do
- let(:current_user) { author_user }
-
- it_behaves_like "new_statuses_allowed_to" do
- let(:author) { true }
- let(:assignee) { false }
- end
- end
-
- context "with the assignee asking" do
- let(:current_user) { assignee_user }
-
- it_behaves_like "new_statuses_allowed_to" do
- let(:author) { false }
- let(:assignee) { true }
- end
- end
-
- context "with the assignee changing and asking as new assignee" do
- before do
- work_package.assigned_to = current_user
- end
-
- # is using the former assignee
- it_behaves_like "new_statuses_allowed_to" do
- let(:author) { false }
- let(:assignee) { false }
- end
- end
-
- context "with the status having changed" do
- let(:new_status) { build_stubbed(:status) }
-
- before do
- allow(work_package).to receive_messages(persisted?: true,
- status_id_changed?: true)
-
- allow(Status)
- .to receive(:find_by)
- .with(id: work_package.status_id_was)
- .and_return(current_status)
-
- work_package.status = new_status
- end
-
- it_behaves_like "new_statuses_allowed_to" do
- let(:author) { false }
- let(:assignee) { false }
- end
- end
- end
-
- describe "#assignable_types" do
- let(:scope) do
- instance_double(ActiveRecord::Querying).tap do |s|
- allow(s)
- .to receive(:includes)
- .and_return(s)
- end
- end
-
- context "when project nil" do
- before do
- work_package.project = nil
- end
-
- it "is all types" do
- allow(Type)
- .to receive(:includes)
- .and_return(scope)
-
- expect(contract.assignable_types)
- .to eql(scope)
- end
- end
-
- context "when project defined" do
- it "is all types of the project" do
- allow(work_package.project)
- .to receive(:types)
- .and_return(scope)
-
- expect(contract.assignable_types)
- .to eql(scope)
- end
- end
- end
-
- describe "#assignable_versions" do
- let(:result) { double }
-
- it "calls through to the work package" do
- allow(work_package).to receive(:assignable_versions).and_return(result)
- expect(subject.assignable_values(:version, current_user)).to eql(result)
- expect(work_package).to have_received(:assignable_versions)
- end
- end
-
- describe "#assignable_priorities" do
- let(:active_priority) { build(:priority, active: true) }
- let(:inactive_priority) { build(:priority, active: false) }
-
- before do
- active_priority.save!
- inactive_priority.save!
- end
-
- it "returns only active priorities" do
- expect(subject.assignable_values(:priority, current_user).size).to be >= 1
- subject.assignable_values(:priority, current_user).each do |priority|
- expect(priority.active).to be_truthy
- end
- end
- end
-
- describe "#assignable_categories" do
- let(:category) { instance_double(Category) }
-
- before do
- allow(project).to receive(:categories).and_return([category])
- end
-
- it "returns all categories of the project" do
- expect(subject.assignable_values(:category, current_user)).to contain_exactly(category)
- end
- end
-
- include_examples "contract reuses the model errors"
-end
diff --git a/spec/contracts/work_packages/base_contract_spec.rb b/spec/contracts/work_packages/base_contract_spec.rb
index 90845e55669..8c3315ca4ef 100644
--- a/spec/contracts/work_packages/base_contract_spec.rb
+++ b/spec/contracts/work_packages/base_contract_spec.rb
@@ -29,8 +29,7 @@
require "spec_helper"
require "contracts/shared/model_contract_shared_context"
-RSpec.describe WorkPackages::BaseContract,
- with_flag: { percent_complete_edition: true } do
+RSpec.describe WorkPackages::BaseContract do
include_context "ModelContract shared context"
let(:work_package) do
diff --git a/spec/controllers/work_packages/progress_controller_pre_14_4_without_percent_complete_edition_spec.rb b/spec/controllers/work_packages/progress_controller_pre_14_4_without_percent_complete_edition_spec.rb
deleted file mode 100644
index 7af7490b168..00000000000
--- a/spec/controllers/work_packages/progress_controller_pre_14_4_without_percent_complete_edition_spec.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-# frozen_string_literal: true
-
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-require "spec_helper"
-
-# This file can be safely deleted once the feature flag :percent_complete_edition
-# is removed, which should happen for OpenProject 15.0 release.
-# Copied from commit 109b135b]
-RSpec.describe WorkPackages::ProgressController, "pre 14.4 without percent complete edition",
- with_flag: { percent_complete_edition: false } do
- shared_let(:user) { create(:admin) }
- shared_let(:work_package) { create(:work_package) }
-
- current_user { user }
-
- describe "POST /work_packages/:d/progress" do
- let(:params) do
- {
- "work_package_id" => work_package.id,
- "work_package" => {
- "estimated_hours" => "42",
- "remaining_hours" => "4h",
- "done_ratio" => "90",
- "estimated_hours_touched" => "false",
- "remaining_hours_touched" => "false"
- }
- }
- end
-
- it "updates the work package progress values with touched values (none touched)" do
- patch("update", params:, as: :turbo_stream)
- work_package.reload
-
- expect(work_package.estimated_hours).to be_nil
- expect(work_package.remaining_hours).to be_nil
- end
-
- it "updates the work package progress values with touched values (only work touched)" do
- params["work_package"]["estimated_hours_touched"] = "true"
-
- patch("update", params:, as: :turbo_stream)
- work_package.reload
-
- expect(work_package.estimated_hours).to eq(42)
- # when not supplied by the user, the remaining work is set to the same
- # value as work
- expect(work_package.remaining_hours).to eq(42)
- end
-
- it "updates the work package progress values (all values touched)" do
- params["work_package"]["estimated_hours_touched"] = "true"
- params["work_package"]["remaining_hours_touched"] = "true"
-
- patch("update", params:, as: :turbo_stream)
- work_package.reload
-
- expect(work_package.estimated_hours).to eq(42)
- expect(work_package.remaining_hours).to eq(4)
- end
- end
-end
diff --git a/spec/controllers/work_packages/progress_controller_spec.rb b/spec/controllers/work_packages/progress_controller_spec.rb
index 3be11235fc8..dbef214cb2a 100644
--- a/spec/controllers/work_packages/progress_controller_spec.rb
+++ b/spec/controllers/work_packages/progress_controller_spec.rb
@@ -30,8 +30,7 @@
require "spec_helper"
-RSpec.describe WorkPackages::ProgressController,
- with_flag: { percent_complete_edition: true } do
+RSpec.describe WorkPackages::ProgressController do
shared_let(:user) { create(:admin) }
shared_let(:work_package) { create(:work_package) }
diff --git a/spec/features/admin/progress_tracking_spec.rb b/spec/features/admin/progress_tracking_spec.rb
index c103592437f..58a6278473e 100644
--- a/spec/features/admin/progress_tracking_spec.rb
+++ b/spec/features/admin/progress_tracking_spec.rb
@@ -28,8 +28,7 @@
require "spec_helper"
-RSpec.describe "Progress tracking admin page", :cuprite, :js,
- with_flag: { percent_complete_edition: true } do
+RSpec.describe "Progress tracking admin page", :cuprite, :js do
include ActionView::Helpers::SanitizeHelper
include Toasts::Expectations
diff --git a/spec/features/work_packages/progress_modal_pre_14_4_without_percent_complete_edition_spec.rb b/spec/features/work_packages/progress_modal_pre_14_4_without_percent_complete_edition_spec.rb
deleted file mode 100644
index cf7c9755e1d..00000000000
--- a/spec/features/work_packages/progress_modal_pre_14_4_without_percent_complete_edition_spec.rb
+++ /dev/null
@@ -1,573 +0,0 @@
-# frozen_string_literal: true
-
-# -- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2024 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-# ++
-
-require "spec_helper"
-
-# This file can be safely deleted once the feature flag :percent_complete_edition
-# is removed, which should happen for OpenProject 15.0 release.
-# Copied from commit 109b135b
-RSpec.describe "Progress modal", "pre 14.4 without percent complete edition", :js, :with_cuprite, # rubocop:disable RSpec/SortMetadata
- with_flag: { percent_complete_edition: false } do
- shared_let(:user) { create(:admin) }
- shared_let(:role) { create(:project_role) }
-
- shared_let(:type_task) { create(:type_task) }
- shared_let(:project) { create(:project, types: [type_task]) }
- shared_let(:priority) { create(:default_priority, name: "Normal") }
- shared_let(:open_status_with_0p_done_ratio) do
- create(:status, name: "open", default_done_ratio: 0)
- end
- shared_let(:in_progress_status_with_50p_done_ratio) do
- create(:status, name: "in progress", default_done_ratio: 50)
- end
- shared_let(:complete_status_with_100p_done_ratio) do
- create(:status, name: "complete", default_done_ratio: 100)
- end
-
- shared_let(:estimated_hours) { 10.0 }
- shared_let(:remaining_hours) { 5.0 }
- shared_let(:work_package) do
- create(:work_package,
- project:,
- type: type_task,
- status: open_status_with_0p_done_ratio) do |wp|
- update_work_package_with(wp, estimated_hours:, remaining_hours:)
- end
- end
-
- def update_work_package_with(work_package, attributes)
- WorkPackages::UpdateService.new(model: work_package,
- user:,
- contract_class: WorkPackages::CreateContract)
- .call(**attributes)
- end
-
- let(:progress_query) do
- create(:query,
- project:,
- user:,
- display_sums: false,
- column_names: %i[id subject type status
- estimated_hours remaining_hours done_ratio]) do |query|
- create(:view_work_packages_table, query:)
- end
- end
-
- let(:work_package_table) { Pages::WorkPackagesTable.new(project) }
- let(:work_package_row) { work_package_table.work_package_container(work_package) }
- let(:work_package_create_page) { Pages::FullWorkPackageCreate.new(project:) }
-
- current_user { user }
-
- describe "clicking on a field on the work package table" do
- it "sets the cursor after the last character on the selected input field" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
- modal = work_edit_field.activate!
-
- modal.expect_cursor_at_end_of_input
- end
- end
-
- describe "work based mode" do
- shared_examples_for "opens the modal with its work field in focus" do
- it "opens the modal with its work field in focus" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
- modal = work_edit_field.activate!
-
- modal.expect_modal_field_in_focus
- end
- end
-
- describe "clicking on the work field on the work package table " \
- "with no fields set" do
- before do
- update_work_package_with(work_package, estimated_hours: nil, remaining_hours: nil)
- end
-
- include_examples "opens the modal with its work field in focus"
- end
-
- describe "clicking on the work field on the work package table" \
- "with all fields set" do
- before do
- update_work_package_with(work_package, estimated_hours: 25.0, remaining_hours: 15.0)
- end
-
- include_examples "opens the modal with its work field in focus"
- end
-
- describe "clicking on the remaining work field on the work package table " \
- "with no fields set" do
- before do
- update_work_package_with(work_package, estimated_hours: nil, remaining_hours: nil)
- end
-
- it "opens the modal with work in focus and remaining work disabled" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
- remaining_work_field = ProgressEditField.new(work_package_row, :remainingTime)
-
- remaining_work_field.activate!
-
- work_edit_field.expect_modal_field_in_focus
- remaining_work_field.expect_modal_field_disabled
- end
- end
-
- describe "clicking on the remaining work field on the work package table " \
- "with all fields set" do
- before do
- update_work_package_with(work_package, estimated_hours: 20.0, remaining_hours: 15.0)
- end
-
- it "opens the modal with remaining work in focus" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- remaining_work_field = ProgressEditField.new(work_package_row, :remainingTime)
-
- remaining_work_field.activate!
-
- remaining_work_field.expect_modal_field_in_focus
- end
- end
- end
-
- describe "status based mode", with_settings: { work_package_done_ratio: "status" } do
- describe "clicking on the work field in the work package table " \
- "with no fields set" do
- before { update_work_package_with(work_package, estimated_hours: nil, remaining_hours: nil) }
-
- it "opens the modal with work in focus" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
- modal = work_edit_field.activate!
-
- modal.expect_modal_field_in_focus
- end
- end
-
- describe "clicking on the work field in the work package table " \
- "with all fields set" do
- before { update_work_package_with(work_package, estimated_hours: 20.0, remaining_hours: 15.0) }
-
- it "opens the modal with work in focus" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
- modal = work_edit_field.activate!
-
- modal.expect_modal_field_in_focus
- end
- end
-
- describe "Remaining work field" do
- it "is readonly" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_field = ProgressEditField.new(work_package_row, :estimatedTime)
- remaining_work_field = ProgressEditField.new(work_package_row, :remainingTime)
- work_field.activate!
-
- remaining_work_field.expect_modal_field_read_only
- end
- end
-
- describe "Status field" do
- before { open_status_with_0p_done_ratio.update!(is_default: true) }
-
- it "renders only assignable statuses as options" do
- # Create a single valid transition from "open" to "in progress"
- create(:workflow,
- type_id: type_task.id,
- old_status: open_status_with_0p_done_ratio,
- new_status: in_progress_status_with_50p_done_ratio,
- role:)
-
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_field = ProgressEditField.new(work_package_row, :estimatedTime)
- modal_status_field = ProgressEditField.new(work_package_row, :statusWithinProgressModal)
-
- work_field.activate!
-
- # The only defined workflow is "open" to "in progress" so "complete" must
- # not be listed as an available option
- modal_status_field.expect_select_field_with_options("open (0%)", "in progress (50%)")
- modal_status_field.expect_select_field_with_no_options("complete (100%)")
-
- # Create another valid transition from "open" to "complete"
- create(:workflow,
- type_id: type_task.id,
- old_status: open_status_with_0p_done_ratio,
- new_status: complete_status_with_100p_done_ratio,
- role:)
-
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_field = ProgressEditField.new(work_package_row, :estimatedTime)
- modal_status_field = ProgressEditField.new(work_package_row, :statusWithinProgressModal)
-
- work_field.activate!
- modal_status_field.expect_select_field_with_options("open (0%)", "in progress (50%)", "complete (100%)")
- end
- end
-
- context "when on a new work package form" do
- specify "modal renders when no default status is set for new work packages" do
- work_package_create_page.visit!
-
- work_field = work_package_create_page.edit_field(:estimatedTime)
- work_field.activate!
- end
-
- context "with a default status set for new work packages" do
- before_all do
- open_status_with_0p_done_ratio.update!(is_default: true)
-
- create(:workflow,
- type_id: type_task.id,
- old_status: open_status_with_0p_done_ratio,
- new_status: in_progress_status_with_50p_done_ratio,
- role:)
- create(:workflow,
- type_id: type_task.id,
- old_status: open_status_with_0p_done_ratio,
- new_status: complete_status_with_100p_done_ratio,
- role:)
- end
-
- it "can create work package after setting work" do
- work_package_create_page.visit!
-
- work_package_create_page.set_attributes({ subject: "hello" })
- work_package_create_page.set_progress_attributes({ estimatedTime: "10h" })
- work_package_create_page.save!
- work_package_table.expect_and_dismiss_toaster(message: "Successful creation.", wait: 5)
- end
-
- it "renders the status selection field inside the modal as disabled " \
- "and allows setting the status solely by the top-left field" do
- work_package_create_page.visit!
- work_package_create_page.expect_fully_loaded
-
- work_field = work_package_create_page.edit_field(:estimatedTime)
- modal_status_field = work_package_create_page.edit_field(:statusWithinProgressModal)
-
- modal = work_field.activate!
-
- modal_status_field.expect_modal_field_disabled
- modal_status_field.expect_modal_field_value("open (0%)", disabled: true)
-
- modal.close!
-
- status_field = work_package_create_page.edit_field(:status)
-
- status_field.update("in progress")
-
- work_field.activate!
- modal_status_field.expect_modal_field_value("in progress (50%)", disabled: true)
- end
-
- it "can open the modal, then save without modifying anything" do
- work_package_create_page.visit!
- work_package_create_page.set_attributes({ subject: "hello" })
-
- work_field = work_package_create_page.edit_field(:estimatedTime)
- work_field.activate!
- work_field.submit_by_clicking_save
- work_package_create_page.expect_no_toaster(type: "error")
-
- work_package_create_page.save!
- work_package_table.expect_and_dismiss_toaster(message: "Successful creation.")
- end
- end
- end
- end
-
- describe "opening the progress modal" do
- before_all do
- create(:workflow,
- type_id: type_task.id,
- old_status: open_status_with_0p_done_ratio,
- new_status: in_progress_status_with_50p_done_ratio,
- role:)
- create(:workflow,
- type_id: type_task.id,
- old_status: open_status_with_0p_done_ratio,
- new_status: complete_status_with_100p_done_ratio,
- role:)
- end
-
- describe "field value format" do
- context "with all values set" do
- before { update_work_package_with(work_package, estimated_hours: 10.0, remaining_hours: 2.12345) }
-
- it "populates fields with correctly values formatted" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
- remaining_work_edit_field = ProgressEditField.new(work_package_row, :remainingTime)
- percent_complete_edit_field = ProgressEditField.new(work_package_row, :percentageDone)
-
- work_edit_field.activate!
-
- work_edit_field.expect_modal_field_value("10h")
- remaining_work_edit_field.expect_modal_field_value("2.12h") # 2h 7m
- percent_complete_edit_field.expect_modal_field_read_only
- percent_complete_edit_field.expect_modal_field_value("78")
- end
- end
-
- context "with % complete set and setting long decimal values in modal" do
- before do
- work_package.attributes = {
- estimated_hours: nil, remaining_hours: nil, done_ratio: 89
- }
- work_package.save(validate: false)
- end
-
- it "does not lose precision due to conversion from ISO duration to hours (rounded to closest minute)" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
- remaining_work_edit_field = ProgressEditField.new(work_package_row, :remainingTime)
-
- # set work to 2.5567
- work_edit_field.activate!
- work_edit_field.update("2.5567")
- work_package_table.expect_and_dismiss_toaster(message: "Successful update.")
-
- # work should have been set to 2.56 and remaining work to 0.28
- work_package.reload
- expect(work_package.estimated_hours).to eq(2.56)
- expect(work_package.remaining_hours).to eq(0.28)
-
- # work should be displayed as "2h 34m" ("2h 33m 36s" rounded to minutes),
- # and remaining work as "17m" ("16m 48s" rounded to minutes)
- work_edit_field.activate!
- work_edit_field.expect_modal_field_value("2.56h") # 2h 34m
- remaining_work_edit_field.expect_modal_field_value("0.28h") # 17m
- end
- end
-
- context "with unset values" do
- before { update_work_package_with(work_package, estimated_hours: nil, remaining_hours: nil) }
-
- it "populates fields with blank values and % Complete as '-'" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
- remaining_work_edit_field = ProgressEditField.new(work_package_row, :remainingTime)
- percent_complete_edit_field = ProgressEditField.new(work_package_row, :percentageDone)
-
- work_edit_field.activate!
-
- work_edit_field.expect_modal_field_value("")
- remaining_work_edit_field.expect_modal_field_value("", disabled: true)
- percent_complete_edit_field.expect_modal_field_read_only
- percent_complete_edit_field.expect_modal_field_value("-")
- end
- end
-
- describe "status field", with_settings: { work_package_done_ratio: "status" } do
- it "renders the status options as the << status_name (percent_complete_value %) >>" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_field = ProgressEditField.new(work_package_row, :estimatedTime)
- status_field = ProgressEditField.new(work_package_row, :statusWithinProgressModal)
-
- work_field.activate!
-
- status_field.expect_select_field_with_options("open (0%)",
- "in progress (50%)",
- "complete (100%)")
- end
- end
- end
-
- it "disables the field that triggered the modal" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
-
- work_edit_field.activate!
-
- work_edit_field.expect_trigger_field_disabled
- end
-
- it "allows clicking on a field other than the one that triggered the modal " \
- "and opens the modal with said field selected" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
- remaining_work_edit_field = ProgressEditField.new(work_package_row, :remainingTime)
-
- remaining_work_edit_field.activate!
- remaining_work_edit_field.expect_modal_field_in_focus
- remaining_work_edit_field.expect_trigger_field_disabled
-
- work_edit_field.reactivate!
- work_edit_field.expect_modal_field_in_focus
- work_edit_field.expect_trigger_field_disabled
- end
- end
-
- describe "% Complete field" do
- it "renders as readonly" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
- percent_complete_edit_field = ProgressEditField.new(work_package_row, :percentageDone)
-
- work_edit_field.activate!
-
- percent_complete_edit_field.expect_modal_field_read_only
- end
- end
-
- describe "When % Complete is set + work and remaining work are unset coming from a migration" do
- before_all do
- work_package.reload
-
- work_package.estimated_hours = nil
- work_package.remaining_hours = nil
- work_package.done_ratio = 5.0
- work_package.save!(validate: false)
- end
-
- shared_examples_for "migration warning" do |should_render: false|
- it "renders a banner with a warning message" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
- modal = work_edit_field.activate!
-
- modal.expect_migration_warning_banner(should_render:)
- end
- end
-
- context "on work based mode" do
- include_examples "migration warning", should_render: true
- end
-
- context "on status based mode", with_settings: { work_package_done_ratio: "status" } do
- include_examples "migration warning", should_render: false
- end
- end
-
- describe "Live-update edge cases" do
- context "given work = 10h, remaining work = 4h, % complete = 60%" do
- before { update_work_package_with(work_package, estimated_hours: 10.0, remaining_hours: 4.0) }
-
- specify "Case 1: When I unset work it unsets remaining work" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
- remaining_work_edit_field = ProgressEditField.new(work_package_row, :remainingTime)
-
- work_edit_field.activate!
- page.driver.wait_for_network_idle # Wait for initial loading to be ready
-
- clear_input_field_contents(work_edit_field.input_element)
- page.driver.wait_for_network_idle # Wait for live-update to finish
-
- remaining_work_edit_field.expect_modal_field_value("", disabled: true)
- end
-
- specify "Case 2: when work is set to 12h, " \
- "remaining work is automatically set to 6h " \
- "and subsequently work is set to 14h, " \
- "remaining work updates to 1d" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
- remaining_work_edit_field = ProgressEditField.new(work_package_row, :remainingTime)
-
- work_edit_field.activate!
- page.driver.wait_for_network_idle # Wait for initial loading to be ready
-
- work_edit_field.set_value("12")
- page.driver.wait_for_network_idle # Wait for live-update to finish
- remaining_work_edit_field.expect_modal_field_value("6h")
-
- work_edit_field.set_value("14")
- page.driver.wait_for_network_idle # Wait for live-update to finish
- remaining_work_edit_field.expect_modal_field_value("8h")
- end
-
- specify "Case 3: when work is set to 2h, " \
- "remaining work is automatically set to 0h, " \
- "and work is subsequently set to 12h, " \
- "remaining work is updated to 6h" do
- work_package_table.visit_query(progress_query)
- work_package_table.expect_work_package_listed(work_package)
-
- work_edit_field = ProgressEditField.new(work_package_row, :estimatedTime)
- remaining_work_edit_field = ProgressEditField.new(work_package_row, :remainingTime)
-
- work_edit_field.activate!
- page.driver.wait_for_network_idle # Wait for initial loading to be ready
-
- work_edit_field.set_value("2")
- page.driver.wait_for_network_idle # Wait for live-update to finish
- remaining_work_edit_field.expect_modal_field_value("0h")
-
- work_edit_field.set_value("12")
- page.driver.wait_for_network_idle # Wait for live-update to finish
- remaining_work_edit_field.expect_modal_field_value("6h")
- end
- end
- end
-end
diff --git a/spec/features/work_packages/progress_modal_spec.rb b/spec/features/work_packages/progress_modal_spec.rb
index 8cfdd6499d6..49780f3dfaa 100644
--- a/spec/features/work_packages/progress_modal_spec.rb
+++ b/spec/features/work_packages/progress_modal_spec.rb
@@ -30,8 +30,7 @@
require "spec_helper"
-RSpec.describe "Progress modal", :js, :with_cuprite,
- with_flag: { percent_complete_edition: true } do
+RSpec.describe "Progress modal", :js, :with_cuprite do
shared_let(:user) { create(:admin) }
shared_let(:role) { create(:project_role) }
diff --git a/spec/lib/api/v3/work_packages/schema/specific_work_package_schema_pre_14_4_without_percent_complete_edition_spec.rb b/spec/lib/api/v3/work_packages/schema/specific_work_package_schema_pre_14_4_without_percent_complete_edition_spec.rb
deleted file mode 100644
index 325b4cff41f..00000000000
--- a/spec/lib/api/v3/work_packages/schema/specific_work_package_schema_pre_14_4_without_percent_complete_edition_spec.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-require "spec_helper"
-
-# This file can be safely deleted once the feature flag :percent_complete_edition
-# is removed, which should happen for OpenProject 15.0 release.
-RSpec.describe API::V3::WorkPackages::Schema::SpecificWorkPackageSchema, "pre 14.4 without percent complete edition",
- with_flag: { percent_complete_edition: false } do
- let(:project) { build_stubbed(:project) }
- let(:type) { build_stubbed(:type) }
- let(:work_package) do
- build_stubbed(:work_package,
- project:,
- type:)
- end
- let(:current_user) { build_stubbed(:user) }
-
- before do
- mock_permissions_for(current_user, &:allow_everything)
- login_as(current_user)
- end
-
- subject { described_class.new(work_package:) }
-
- describe "#writable?" do
- describe "% Complete" do
- it "is not writable in work-based progress calculation mode",
- with_settings: { work_package_done_ratio: "field" } do
- expect(subject).not_to be_writable(:done_ratio)
- end
-
- it "is not writable in status-based progress calculation mode",
- with_settings: { work_package_done_ratio: "status" } do
- expect(subject).not_to be_writable(:done_ratio)
- end
- end
- end
-end
diff --git a/spec/lib/api/v3/work_packages/schema/specific_work_package_schema_spec.rb b/spec/lib/api/v3/work_packages/schema/specific_work_package_schema_spec.rb
index beb52f7e1ec..92c2c88a88c 100644
--- a/spec/lib/api/v3/work_packages/schema/specific_work_package_schema_spec.rb
+++ b/spec/lib/api/v3/work_packages/schema/specific_work_package_schema_spec.rb
@@ -28,8 +28,7 @@
require "spec_helper"
-RSpec.describe API::V3::WorkPackages::Schema::SpecificWorkPackageSchema,
- with_flag: { percent_complete_edition: true } do
+RSpec.describe API::V3::WorkPackages::Schema::SpecificWorkPackageSchema do
let(:project) { build_stubbed(:project) }
let(:type) { build_stubbed(:type) }
let(:work_package) do
diff --git a/spec/lib/api/v3/work_packages/schema/typed_work_package_schema_pre_14_4_without_percent_complete_edition_spec.rb b/spec/lib/api/v3/work_packages/schema/typed_work_package_schema_pre_14_4_without_percent_complete_edition_spec.rb
deleted file mode 100644
index 0384c323fe5..00000000000
--- a/spec/lib/api/v3/work_packages/schema/typed_work_package_schema_pre_14_4_without_percent_complete_edition_spec.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-require "spec_helper"
-
-# This file can be safely deleted once the feature flag :percent_complete_edition
-# is removed, which should happen for OpenProject 15.0 release.
-RSpec.describe API::V3::WorkPackages::Schema::TypedWorkPackageSchema, "pre 14.4 without percent complete edition",
- with_flag: { percent_complete_edition: false } do
- let(:project) { build(:project) }
- let(:type) { build(:type) }
-
- let(:current_user) { build_stubbed(:user) }
-
- subject { described_class.new(project:, type:) }
-
- before do
- login_as(current_user)
- mock_permissions_for(current_user, &:allow_everything)
- end
-
- describe "#writable?" do
- it "percentage done is not writable in work-based progress calculation mode",
- with_settings: { work_package_done_ratio: "field" } do
- expect(subject).not_to be_writable(:done_ratio)
- end
-
- it "percentage done is not writable in status-based progress calculation mode",
- with_settings: { work_package_done_ratio: "status" } do
- expect(subject).not_to be_writable(:done_ratio)
- end
- end
-end
diff --git a/spec/lib/api/v3/work_packages/schema/typed_work_package_schema_spec.rb b/spec/lib/api/v3/work_packages/schema/typed_work_package_schema_spec.rb
index eae7ff6605f..41affd8de2b 100644
--- a/spec/lib/api/v3/work_packages/schema/typed_work_package_schema_spec.rb
+++ b/spec/lib/api/v3/work_packages/schema/typed_work_package_schema_spec.rb
@@ -28,8 +28,7 @@
require "spec_helper"
-RSpec.describe API::V3::WorkPackages::Schema::TypedWorkPackageSchema,
- with_flag: { percent_complete_edition: true } do
+RSpec.describe API::V3::WorkPackages::Schema::TypedWorkPackageSchema do
let(:project) { build(:project) }
let(:type) { build(:type) }
diff --git a/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_pre_14_4_without_percent_complete_edition_spec.rb b/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_pre_14_4_without_percent_complete_edition_spec.rb
deleted file mode 100644
index 475ff12cd28..00000000000
--- a/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_pre_14_4_without_percent_complete_edition_spec.rb
+++ /dev/null
@@ -1,113 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-require "spec_helper"
-
-# This file can be safely deleted once the feature flag :percent_complete_edition
-# is removed, which should happen for OpenProject 15.0 release.
-RSpec.describe API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter, "pre 14.4 without percent complete edition",
- with_flag: { percent_complete_edition: false } do
- include API::V3::Utilities::PathHelper
-
- let(:project) { build_stubbed(:project_with_types) }
- let(:permissions) { [:edit_work_packages] }
- let(:attribute_query) do
- build_stubbed(:query).tap do |query|
- query.filters.clear
- query.add_filter("parent", "=", ["{id}"])
- end
- end
- let(:attribute_groups) do
- [Type::AttributeGroup.new(wp_type, "People", %w(assignee responsible)),
- Type::AttributeGroup.new(wp_type, "Estimates and time", %w(estimated_time spent_time)),
- Type::QueryGroup.new(wp_type, "Children", attribute_query)]
- end
- let(:schema) do
- API::V3::WorkPackages::Schema::SpecificWorkPackageSchema.new(work_package:).tap do |schema|
- allow(wp_type)
- .to receive(:attribute_groups)
- .and_return(attribute_groups)
- allow(schema)
- .to receive(:assignable_values)
- .and_call_original
- allow(schema)
- .to receive(:assignable_values)
- .with(:version, current_user)
- .and_return([])
- end
- end
- let(:self_link) { "/a/self/link" }
- let(:base_schema_link) { nil }
- let(:hide_self_link) { false }
- let(:embedded) { true }
- let(:representer) do
- described_class.create(schema,
- self_link:,
- form_embedded: embedded,
- base_schema_link:,
- current_user:)
- end
- let(:available_custom_fields) { [] }
- let(:wp_type) { project.types.first }
- let(:custom_field) { build_stubbed(:custom_field) }
- let(:work_package) do
- build_stubbed(:work_package, project:, type: wp_type) do |wp|
- allow(wp)
- .to receive(:available_custom_fields)
- .and_return(available_custom_fields)
- end
- end
- let(:current_user) { build_stubbed(:user) }
-
- before do
- mock_permissions_for(current_user) do |mock|
- mock.allow_in_project *permissions, project: schema.project
- end
-
- login_as(current_user)
- allow(schema.project)
- .to receive(:module_enabled?)
- .and_return(true)
-
- allow(schema).to receive(:writable?).and_call_original
- end
-
- context "for generation" do
- subject(:generated) { representer.to_json }
-
- describe "percentageDone" do
- it_behaves_like "has basic schema properties" do
- let(:path) { "percentageDone" }
- let(:type) { "Integer" }
- let(:name) { I18n.t("activerecord.attributes.work_package.done_ratio") }
- let(:required) { false }
- let(:writable) { false }
- end
- end
- end
-end
diff --git a/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb b/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb
index eef638a2c49..e1cbec9cf08 100644
--- a/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb
+++ b/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb
@@ -28,8 +28,7 @@
require "spec_helper"
-RSpec.describe API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter,
- with_flag: { percent_complete_edition: true } do
+RSpec.describe API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do
include API::V3::Utilities::PathHelper
let(:project) { build_stubbed(:project_with_types) }
diff --git a/spec/services/work_packages/set_attributes_service_pre_14_4_without_percent_complete_edition_spec.rb b/spec/services/work_packages/set_attributes_service_pre_14_4_without_percent_complete_edition_spec.rb
deleted file mode 100644
index 1444b7e4d6a..00000000000
--- a/spec/services/work_packages/set_attributes_service_pre_14_4_without_percent_complete_edition_spec.rb
+++ /dev/null
@@ -1,648 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-require "spec_helper"
-
-# This file can be safely deleted once the feature flag percent_complete_edition
-# is removed, which should happen for OpenProject 15.0 release.
-RSpec.describe WorkPackages::SetAttributesService, "pre 14.4 without percent complete edition",
- type: :model,
- with_flag: { percent_complete_edition: false } do
- shared_let(:status_0_pct_complete) { create(:status, default_done_ratio: 0, name: "0% complete") }
- shared_let(:status_50_pct_complete) { create(:status, default_done_ratio: 50, name: "50% complete") }
- shared_let(:status_70_pct_complete) { create(:status, default_done_ratio: 70, name: "70% complete") }
-
- let(:user) { build_stubbed(:user) }
- let(:project) do
- p = build_stubbed(:project)
- allow(p).to receive(:shared_versions).and_return([])
-
- p
- end
- let(:work_package) do
- build_stubbed(:work_package, project:, status: status_0_pct_complete)
- end
- let(:statuses) { [] }
- let(:contract_class) { WorkPackages::UpdateContract }
- let(:mock_contract) do
- class_double(contract_class,
- new: mock_contract_instance)
- end
- let(:mock_contract_instance) do
- instance_double(contract_class,
- assignable_statuses: statuses,
- errors: contract_errors,
- validate: contract_valid)
- end
- let(:contract_valid) { true }
- let(:contract_errors) do
- instance_double(ActiveModel::Errors)
- end
- let(:instance) do
- described_class.new(user:,
- model: work_package,
- contract_class: mock_contract)
- end
-
- shared_examples_for "service call" do |description: nil|
- subject do
- allow(work_package)
- .to receive(:save)
-
- instance.call(call_attributes)
- end
-
- it description || "sets the value" do
- all_expected_attributes = {}
- all_expected_attributes.merge!(expected_attributes) if defined?(expected_attributes)
- if defined?(expected_kept_attributes)
- kept = work_package.attributes.slice(*expected_kept_attributes)
- if kept.size != expected_kept_attributes.size
- raise ArgumentError, "expected_kept_attributes contains attributes that are not present in the work_package: " \
- "#{expected_kept_attributes - kept.keys} not present in #{work_package.attributes}"
- end
- all_expected_attributes.merge!(kept)
- end
- next if all_expected_attributes.blank?
-
- subject
-
- aggregate_failures do
- expect(subject).to be_success
- expect(work_package).to have_attributes(all_expected_attributes)
- # work package is not saved and no errors are created by the service
- # (that's contract's responsibility and it is mocked in this test)
- expect(work_package).not_to have_received(:save)
- expect(subject.errors).to be_empty
- end
- end
-
- context "when the contract does not validate" do
- let(:contract_valid) { false }
-
- it "is unsuccessful, does not persist the changes and exposes the contract's errors", :aggregate_failures do
- expect(subject).not_to be_success
- expect(work_package).not_to have_received(:save)
- expect(subject.errors).to eql mock_contract_instance.errors
- end
- end
- end
-
- # Scenarios specified in https://community.openproject.org/wp/40749
- describe "deriving remaining work attribute (remaining_hours)" do
- context "in status-based mode",
- with_settings: { work_package_done_ratio: "status" } do
- context "given a work package with work, remaining work, and status with % complete being set" do
- before do
- work_package.status = status_50_pct_complete
- work_package.done_ratio = work_package.status.default_done_ratio
- work_package.estimated_hours = 10.0
- work_package.remaining_hours = 5.0
- work_package.clear_changes_information
- end
-
- context "when work is unset" do
- let(:call_attributes) { { estimated_hours: nil } }
- let(:expected_attributes) { { remaining_hours: nil } }
-
- it_behaves_like "service call", description: "unsets remaining work"
- end
-
- context "when work is changed" do
- let(:call_attributes) { { estimated_hours: 5.0 } }
- let(:expected_attributes) { { remaining_hours: 2.5 } }
-
- it_behaves_like "service call", description: "recomputes remaining work accordingly"
- end
-
- context "when work is changed to a negative value" do
- let(:call_attributes) { { estimated_hours: -1.0 } }
- let(:expected_kept_attributes) { %w[remaining_hours] }
-
- it_behaves_like "service call",
- description: "is an error state (to be detected by contract), and remaining work is kept"
- end
-
- context "when another status is set" do
- let(:call_attributes) { { status: status_70_pct_complete } }
- let(:expected_attributes) { { remaining_hours: 3.0 } }
-
- it_behaves_like "service call",
- description: "recomputes remaining work according to the % complete value of the new status"
- end
-
- context "when floating point operations are inaccurate (2.4000000000000004h)" do
- let(:call_attributes) { { estimated_hours: 8.0, status: status_70_pct_complete } }
- let(:expected_attributes) { { remaining_hours: 2.4 } } # would be 2.4000000000000004 without rounding
-
- it_behaves_like "service call", description: "remaining work is computed and rounded (2.4)"
- end
- end
-
- context "given a work package with work and remaining work unset, and a status with 0% complete" do
- before do
- work_package.status = status_0_pct_complete
- work_package.done_ratio = work_package.status.default_done_ratio
- work_package.estimated_hours = nil
- work_package.remaining_hours = nil
- work_package.clear_changes_information
- end
-
- context "when another status with another % complete value is set" do
- let(:call_attributes) { { status: status_70_pct_complete } }
- let(:expected_attributes) { { remaining_hours: nil } }
-
- it_behaves_like "service call",
- description: "remaining work remains unset"
- end
-
- context "when work is set" do
- let(:call_attributes) { { estimated_hours: 10.0 } }
- let(:expected_attributes) { { remaining_hours: 10.0 } }
-
- it_behaves_like "service call",
- description: "remaining work is updated accordingly from work and % complete value of the status"
- end
-
- context "when work is set to a negative value" do
- let(:call_attributes) { { estimated_hours: -1.0 } }
- let(:expected_kept_attributes) { %w[remaining_hours] }
-
- it_behaves_like "service call",
- description: "is an error state (to be detected by contract), and remaining work is kept"
- end
-
- context "when work is set with 2nd decimal rounding up" do
- let(:call_attributes) { { estimated_hours: 3.567 } }
- let(:expected_attributes) { { estimated_hours: 3.57, remaining_hours: 3.57 } }
-
- it_behaves_like "service call",
- description: "values are rounded up to 2 decimals and set to the same value"
- end
- end
- end
- end
-
- # Scenarios specified in https://community.openproject.org/wp/40749
- describe "deriving % complete attribute (done_ratio)" do
- context "in status-based mode",
- with_settings: { work_package_done_ratio: "status" } do
- context "given a work package with a status with 50% complete" do
- before do
- work_package.status = status_50_pct_complete
- work_package.done_ratio = work_package.status.default_done_ratio
- work_package.clear_changes_information
- end
-
- context "when another status with another % complete value is set" do
- let(:call_attributes) { { status: status_70_pct_complete } }
- let(:expected_attributes) { { done_ratio: 70 } }
-
- it_behaves_like "service call", description: "sets the % complete value to the status default % complete value"
- end
- end
- end
-
- context "in work-based mode",
- with_settings: { work_package_done_ratio: "field" } do
- context "given a work package with work, remaining work, and % complete being set" do
- before do
- work_package.estimated_hours = 10.0
- work_package.remaining_hours = 3.0
- work_package.done_ratio = 70
- work_package.clear_changes_information
- end
-
- context "when work is unset" do
- let(:call_attributes) { { estimated_hours: nil } }
- let(:expected_attributes) { { remaining_hours: nil, done_ratio: nil } }
-
- it_behaves_like "service call", description: "unsets remaining work and % complete"
- end
-
- context "when remaining work is unset" do
- let(:call_attributes) { { remaining_hours: nil } }
- let(:expected_attributes) { { estimated_hours: 10.0, done_ratio: nil } }
-
- it_behaves_like "service call", description: "keeps work, and unsets % complete"
- end
-
- context "when both work and remaining work are unset" do
- let(:call_attributes) { { estimated_hours: nil, remaining_hours: nil } }
- let(:expected_attributes) { { done_ratio: nil } }
-
- it_behaves_like "service call", description: "unsets % complete"
- end
-
- context "when work is increased" do
- # work changed by +10h
- let(:call_attributes) { { estimated_hours: 10.0 + 10.0 } }
- let(:expected_attributes) do
- { remaining_hours: 3.0 + 10.0, done_ratio: 35 }
- end
-
- it_behaves_like "service call",
- description: "remaining work is increased by the same amount, and % complete is updated accordingly"
- end
-
- context "when work is set to 0h" do
- let(:call_attributes) { { estimated_hours: 0 } }
- let(:expected_attributes) do
- { remaining_hours: 0, done_ratio: nil }
- end
-
- it_behaves_like "service call",
- description: "remaining work is set to 0h and % Complete is unset"
- end
-
- context "when work is decreased" do
- # work changed by -2h
- let(:call_attributes) { { estimated_hours: 10.0 - 2.0 } }
- let(:expected_attributes) do
- { remaining_hours: 3.0 - 2.0, done_ratio: 87 }
- end
-
- it_behaves_like "service call",
- description: "remaining work is decreased by the same amount, and % complete is updated accordingly"
- end
-
- context "when work is decreased below remaining work value" do
- # work changed by -8h
- let(:call_attributes) { { estimated_hours: 10.0 - 8.0 } }
- let(:expected_attributes) do
- { remaining_hours: 0, done_ratio: 100 }
- end
-
- it_behaves_like "service call",
- description: "remaining work becomes 0h, and % complete becomes 100%"
- end
-
- context "when work is changed to a negative value" do
- let(:call_attributes) { { estimated_hours: -1.0 } }
- let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }
-
- it_behaves_like "service call",
- description: "is an error state (to be detected by contract), " \
- "and % complete and remaining work are kept"
- end
-
- context "when remaining work is changed" do
- let(:call_attributes) { { remaining_hours: 2 } }
- let(:expected_attributes) { { done_ratio: 80 } }
- let(:expected_kept_attributes) { %w[estimated_hours] }
-
- it_behaves_like "service call", description: "updates % complete accordingly"
- end
-
- context "when work and remaining work are both changed to negative values" do
- let(:call_attributes) { { estimated_hours: -10, remaining_hours: -5 } }
- let(:expected_kept_attributes) { %w[done_ratio] }
-
- it_behaves_like "service call", description: "is an error state (to be detected by contract), and % Complete is kept"
- end
-
- context "when work and remaining work are both changed to values with more than 2 decimals" do
- let(:call_attributes) { { estimated_hours: 10.123456, remaining_hours: 5.6789 } }
- let(:expected_attributes) { { estimated_hours: 10.12, remaining_hours: 5.68, done_ratio: 43 } }
-
- it_behaves_like "service call", description: "rounds work and remaining work to 2 decimals " \
- "and updates % complete accordingly"
- end
-
- context "when remaining work is changed to a value greater than work" do
- let(:call_attributes) { { remaining_hours: 200.0 } }
- let(:expected_kept_attributes) { %w[done_ratio] }
-
- it_behaves_like "service call", description: "is an error state (to be detected by contract), and % Complete is kept"
- end
-
- context "when remaining work is changed to a negative value" do
- let(:call_attributes) { { remaining_hours: -1.0 } }
- let(:expected_kept_attributes) { %w[done_ratio] }
-
- it_behaves_like "service call", description: "is an error state (to be detected by contract), and % Complete is kept"
- end
-
- context "when both work and remaining work are changed" do
- let(:call_attributes) { { estimated_hours: 20, remaining_hours: 2 } }
- let(:expected_attributes) { call_attributes.merge(done_ratio: 90) }
-
- it_behaves_like "service call", description: "updates % complete accordingly"
- end
-
- context "when work is changed and remaining work is unset" do
- let(:call_attributes) { { estimated_hours: 8.0, remaining_hours: nil } }
- let(:expected_attributes) { call_attributes.dup }
- let(:expected_kept_attributes) { %w[done_ratio] }
-
- it_behaves_like "service call",
- description: "% complete is kept and remaining work is kept unset and not recomputed" \
- "(error state to be detected by contract)"
- end
-
- context "when work is increased and remaining work is set to its current value (to prevent it from being increased)" do
- # work changed by +10h
- let(:call_attributes) { { estimated_hours: 10.0 + 10.0, remaining_hours: 3 } }
- let(:expected_attributes) { { remaining_hours: 3.0, done_ratio: 85 } }
-
- it_behaves_like "service call",
- description: "remaining work is kept (not increased), and % complete is updated accordingly"
- end
- end
-
- context "given a work package with work and % complete being set, and remaining work being unset" do
- before do
- work_package.estimated_hours = 10
- work_package.remaining_hours = nil
- work_package.done_ratio = 30
- work_package.clear_changes_information
- end
-
- context "when work is changed" do
- let(:call_attributes) { { estimated_hours: 20.0 } }
- let(:expected_attributes) { { remaining_hours: 14.0 } }
- let(:expected_kept_attributes) { %w[done_ratio] }
-
- it_behaves_like "service call", description: "% complete is kept and remaining work is updated accordingly"
- end
-
- context "when work is changed to a negative value" do
- let(:call_attributes) { { estimated_hours: -1.0 } }
- let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }
-
- it_behaves_like "service call",
- description: "is an error state (to be detected by contract), " \
- "and % complete and remaining work are kept"
- end
-
- context "when remaining work is set" do
- let(:call_attributes) { { remaining_hours: 1.0 } }
- let(:expected_attributes) { call_attributes.merge(done_ratio: 90.0) }
- let(:expected_kept_attributes) { %w[estimated_hours] }
-
- it_behaves_like "service call", description: "work is kept and % complete is updated accordingly"
- end
- end
-
- context "given a work package with remaining work and % complete being set, and work being unset" do
- before do
- work_package.estimated_hours = nil
- work_package.remaining_hours = 2.0
- work_package.done_ratio = 50
- work_package.clear_changes_information
- end
-
- context "when remaining work is changed" do
- let(:call_attributes) { { remaining_hours: 10.0 } }
- let(:expected_attributes) { call_attributes.merge(estimated_hours: 20.0) }
- let(:expected_kept_attributes) { %w[done_ratio] }
-
- it_behaves_like "service call", description: "% complete is kept and work is updated accordingly"
- end
-
- context "when % complete is 0% and remaining work is changed to a decimal rounded up" do
- let(:call_attributes) { { remaining_hours: 5.679 } }
- let(:expected_attributes) { { estimated_hours: 5.68, remaining_hours: 5.68 } }
- let(:expected_kept_attributes) { %w[done_ratio] }
-
- before do
- work_package.done_ratio = 0
- work_package.clear_changes_information
- end
-
- it_behaves_like "service call",
- description: "% complete is kept, values are rounded, and work is updated accordingly"
- end
-
- context "when work is set" do
- let(:call_attributes) { { estimated_hours: 10.0 } }
- let(:expected_attributes) { call_attributes.merge(done_ratio: 80.0) }
- let(:expected_kept_attributes) { %w[remaining_hours] }
-
- it_behaves_like "service call", description: "remaining work is kept and % complete is updated accordingly"
- end
- end
-
- context "given a work package with work being set, and remaining work and % complete being unset" do
- before do
- work_package.estimated_hours = 10
- work_package.remaining_hours = nil
- work_package.done_ratio = nil
- work_package.clear_changes_information
- end
-
- context "when work is changed" do
- let(:call_attributes) { { estimated_hours: 20.0 } }
- let(:expected_attributes) { { remaining_hours: 20.0, done_ratio: 0 } }
-
- it_behaves_like "service call", description: "remaining work is set to the same value and % complete is set to 0%"
- end
-
- context "when work is changed and remaining work is unset" do
- let(:call_attributes) { { estimated_hours: 10.0, remaining_hours: nil } }
- let(:expected_attributes) { call_attributes.dup }
- let(:expected_kept_attributes) { %w[done_ratio] }
-
- it_behaves_like "service call",
- description: "% complete is kept and remaining work is kept unset and not recomputed" \
- "(error state to be detected by contract)"
- end
-
- context "when work is changed to a negative value" do
- let(:call_attributes) { { estimated_hours: -1.0 } }
- let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }
-
- it_behaves_like "service call",
- description: "is an error state (to be detected by contract), " \
- "and % complete and remaining work are kept"
- end
- end
-
- context "given a work package with remaining work being set, and work and % complete being unset" do
- before do
- work_package.estimated_hours = nil
- work_package.remaining_hours = 6.0
- work_package.done_ratio = nil
- work_package.clear_changes_information
- end
-
- context "when work is set" do
- let(:call_attributes) { { estimated_hours: 10.0 } }
- let(:expected_attributes) { { done_ratio: 40 } }
- let(:expected_kept_attributes) { %w[remaining_hours] }
-
- it_behaves_like "service call",
- description: "remaining work is kept to the same value and % complete is updated accordingly"
- end
-
- context "when work is changed to a negative value" do
- let(:call_attributes) { { estimated_hours: -1.0 } }
- let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }
-
- it_behaves_like "service call",
- description: "is an error state (to be detected by contract), " \
- "and % complete and remaining work are kept"
- end
-
- context "when remaining work is changed" do
- let(:call_attributes) { { remaining_hours: 12.0 } }
- let(:expected_attributes) { { estimated_hours: 12.0, done_ratio: 0 } }
-
- it_behaves_like "service call",
- description: "work is set to the same value and % complete is set to 0%"
- end
-
- context "when remaining work is changed to a negative value" do
- let(:call_attributes) { { remaining_hours: -1.0 } }
- let(:expected_kept_attributes) { %w[estimated_hours done_ratio] }
-
- it_behaves_like "service call",
- description: "is an error state (to be detected by contract), " \
- "and % complete and work are kept"
- end
- end
-
- context "given a work package with work and remaining work unset, and % complete being set" do
- before do
- work_package.estimated_hours = nil
- work_package.remaining_hours = nil
- work_package.done_ratio = 60
- work_package.clear_changes_information
- end
-
- context "when work is set" do
- let(:call_attributes) { { estimated_hours: 10.0 } }
- let(:expected_attributes) { { remaining_hours: 4.0 } }
- let(:expected_kept_attributes) { %w[done_ratio] }
-
- it_behaves_like "service call", description: "% complete is kept and remaining work is updated accordingly"
- end
-
- context "when work is set to a number with with 4 decimals" do
- let(:call_attributes) { { estimated_hours: 2.5678 } }
- let(:expected_attributes) { { estimated_hours: 2.57, remaining_hours: 1.03 } }
- let(:expected_kept_attributes) { %w[done_ratio] }
-
- it_behaves_like "service call",
- description: "% complete is kept, work is rounded to 2 decimals, " \
- "and remaining work is updated and rounded to 2 decimals"
- end
-
- context "when work is set to a string" do
- let(:call_attributes) { { estimated_hours: "I am a string" } }
- let(:expected_attributes) { { estimated_hours: 0.0, remaining_hours: 0.0 } }
-
- it "keeps the original string value in the _before_type_cast method " \
- "so that validation can detect it is invalid" do
- allow(work_package).to receive(:save)
- instance.call(call_attributes)
-
- expect(work_package.estimated_hours_before_type_cast).to eq("I am a string")
- end
- end
-
- context "when work and remaining work are set" do
- let(:call_attributes) { { estimated_hours: 10.0, remaining_hours: 0 } }
- let(:expected_attributes) { call_attributes.merge(done_ratio: 100) }
-
- it_behaves_like "service call", description: "% complete is updated accordingly"
- end
-
- context "when work is set and remaining work is unset" do
- let(:call_attributes) { { estimated_hours: 10.0, remaining_hours: nil } }
- let(:expected_attributes) { call_attributes.dup }
- let(:expected_kept_attributes) { %w[done_ratio] }
-
- it_behaves_like "service call",
- description: "% complete is kept and remaining work is kept unset and not recomputed" \
- "(error state to be detected by contract)"
- end
-
- context "when work and remaining work are both set to negative values" do
- let(:call_attributes) { { estimated_hours: -10, remaining_hours: -5 } }
- let(:expected_kept_attributes) { %w[done_ratio] }
-
- it_behaves_like "service call", description: "is an error state (to be detected by contract), and % Complete is kept"
- end
- end
-
- context "given a work package with work, remaining work, and % complete being unset" do
- before do
- work_package.estimated_hours = nil
- work_package.remaining_hours = nil
- work_package.done_ratio = nil
- work_package.clear_changes_information
- end
-
- context "when work is set" do
- let(:call_attributes) { { estimated_hours: 10.0 } }
- let(:expected_attributes) do
- { remaining_hours: 10.0, done_ratio: 0 }
- end
-
- it_behaves_like "service call", description: "remaining work is set to the same value and % complete is set to 0%"
- end
-
- context "when work is set to a negative value" do
- let(:call_attributes) { { estimated_hours: -1.0 } }
- let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }
-
- it_behaves_like "service call",
- description: "is an error state (to be detected by contract), " \
- "and % complete and remaining work are kept"
- end
-
- context "when remaining work is set" do
- let(:call_attributes) { { remaining_hours: 10.0 } }
- let(:expected_attributes) { { estimated_hours: 10.0, done_ratio: 0 } }
-
- it_behaves_like "service call", description: "work is set to the same value and % complete is set to 0%"
- end
-
- context "when remaining work is set to a negative value" do
- let(:call_attributes) { { remaining_hours: -1.0 } }
- let(:expected_kept_attributes) { %w[estimated_hours done_ratio] }
-
- it_behaves_like "service call",
- description: "is an error state (to be detected by contract), " \
- "and % complete and work are kept"
- end
-
- context "when remaining work is set and work is unset" do
- let(:call_attributes) { { estimated_hours: nil, remaining_hours: 6.7 } }
- let(:expected_attributes) { call_attributes.dup }
- let(:expected_kept_attributes) { %w[done_ratio] }
-
- it_behaves_like "service call",
- description: "% complete is kept and work is kept unset and not recomputed" \
- "(error state to be detected by contract)"
- end
- end
- end
- end
-end
diff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rb
index 6ef48368d89..0915781acf4 100644
--- a/spec/services/work_packages/set_attributes_service_spec.rb
+++ b/spec/services/work_packages/set_attributes_service_spec.rb
@@ -29,8 +29,7 @@
require "spec_helper"
RSpec.describe WorkPackages::SetAttributesService,
- type: :model,
- with_flag: { percent_complete_edition: true } do
+ type: :model do
shared_let(:status_0_pct_complete) { create(:status, default_done_ratio: 0, name: "0% complete") }
shared_let(:status_50_pct_complete) { create(:status, default_done_ratio: 50, name: "50% complete") }
shared_let(:status_70_pct_complete) { create(:status, default_done_ratio: 70, name: "70% complete") }
diff --git a/spec/support/edit_fields/progress_edit_field.rb b/spec/support/edit_fields/progress_edit_field.rb
index be72681ed16..7ce954d4c84 100644
--- a/spec/support/edit_fields/progress_edit_field.rb
+++ b/spec/support/edit_fields/progress_edit_field.rb
@@ -268,19 +268,6 @@ class ProgressEditField < EditField
end
end
- # to be removed in 15.0 with :percent_complete_edition feature flag removal
- def expect_migration_warning_banner(should_render: true)
- within modal_element do
- if should_render
- expect(page)
- .to have_text(I18n.t("work_package.progress.modal.migration_warning_text"))
- else
- expect(page)
- .to have_no_text(I18n.t("work_package.progress.modal.migration_warning_text"))
- end
- end
- end
-
private
attr_reader :field_name
diff --git a/spec/workers/work_packages/progress/apply_statuses_change_job_pre_14_4_without_percent_complete_edition_spec.rb b/spec/workers/work_packages/progress/apply_statuses_change_job_pre_14_4_without_percent_complete_edition_spec.rb
deleted file mode 100644
index aa0607eb1ab..00000000000
--- a/spec/workers/work_packages/progress/apply_statuses_change_job_pre_14_4_without_percent_complete_edition_spec.rb
+++ /dev/null
@@ -1,428 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-require "rails_helper"
-
-# This file can be safely deleted once the feature flag :percent_complete_edition
-# is removed, which should happen for OpenProject 15.0 release.
-RSpec.describe WorkPackages::Progress::ApplyStatusesChangeJob, "pre 14.4 without percent complete edition",
- with_flag: { percent_complete_edition: false } do
- shared_let(:author) { create(:user) }
- shared_let(:priority) { create(:priority, name: "Normal") }
- shared_let(:project) { create(:project, name: "Main project") }
-
- # statuses for work-based mode
- shared_let(:status_new) { create(:status, name: "New") }
- shared_let(:status_wip) { create(:status, name: "In progress") }
- shared_let(:status_closed) { create(:status, name: "Closed") }
-
- # statuses for status-based mode
- shared_let(:status_0p_todo) { create(:status, name: "To do (0%)", default_done_ratio: 0) }
- shared_let(:status_40p_doing) { create(:status, name: "Doing (40%)", default_done_ratio: 40) }
- shared_let(:status_100p_done) { create(:status, name: "Done (100%)", default_done_ratio: 100) }
-
- # statuses for both work-based and status-based modes
- shared_let(:status_excluded) { create(:status, :excluded_from_totals, name: "Excluded") }
-
- before_all do
- set_factory_default(:user, author)
- set_factory_default(:priority, priority)
- set_factory_default(:project, project)
- set_factory_default(:project_with_types, project)
- set_factory_default(:status, status_new)
- end
-
- subject(:job) { described_class }
-
- def expect_performing_job_changes(from:, to:,
- cause_type: "status_changed",
- status_name: "Some status name",
- status_id: 99,
- changes: { "default_done_ratio" => [33, 66] })
- table = create_table(from)
-
- job.perform_now(cause_type:, status_name:, status_id:, changes:)
-
- table.work_packages.map(&:reload)
- expect_work_packages(table.work_packages, to)
-
- table.work_packages
- end
-
- context "when in work-based mode",
- with_settings: { work_package_done_ratio: "field" } do
- context "when some work packages have % complete value different from their status" do
- it "does not change any of their progress values" do
- expect_performing_job_changes(
- from: <<~TABLE,
- subject | status | % complete
- wp | Doing (40%) |
- wp 0% | To do (0%) | 55%
- wp 40% | Doing (40%) | 55%
- wp 100% | Done (100%) | 55%
- TABLE
- to: <<~TABLE
- subject | status | % complete
- wp | Doing (40%) |
- wp 0% | To do (0%) | 55%
- wp 40% | Doing (40%) | 55%
- wp 100% | Done (100%) | 55%
- TABLE
- )
- end
- end
-
- context "when some work packages have work set to 0h and a % complete value being set" do
- it "clears the % complete valuedoes not change any of their progress values" do
- expect_performing_job_changes(
- from: <<~TABLE,
- hierarchy | status | work | remaining work | % complete
- wp 10h 40% | To do (0%) | 10h | 6h | 40%
- wp 0h 0% | To do (0%) | 0h | 0h | 0%
- wp 0h 40% | Doing (40%) | 0h | 0h | 40%
- wp 0h 100% | Done (100%) | 0h | 0h | 100%
- TABLE
- to: <<~TABLE
- subject | status | work | remaining work | % complete
- wp 10h 40% | To do (0%) | 10h | 6h | 40%
- wp 0h 0% | To do (0%) | 0h | 0h |
- wp 0h 40% | Doing (40%) | 0h | 0h |
- wp 0h 100% | Done (100%) | 0h | 0h |
- TABLE
- )
- end
- end
-
- context "when a status is being excluded from progress calculation" do
- it "computes totals of the parent having work when all children are excluded" do
- expect_performing_job_changes(
- from: <<~TABLE,
- hierarchy | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
- parent | In progress | 10h | 3h | 70% | 20h | 5h | 75%
- child | Excluded | 10h | 2h | 50% | | |
- TABLE
- to: <<~TABLE
- subject | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
- parent | In progress | 10h | 3h | 70% | 10h | 3h | 70%
- child | Excluded | 10h | 2h | 50% | | |
- TABLE
- )
- end
-
- it "keeps the totals unset if work, remaining work, and % complete are all nil" do
- expect_performing_job_changes(
- from: <<~TABLE,
- hierarchy | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
- parent | In progress | | | | | |
- child | Excluded | | | | | |
- TABLE
- to: <<~TABLE
- subject | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
- parent | In progress | | | | | |
- child | Excluded | | | | | |
- TABLE
- )
- end
-
- describe "general case" do
- # The work packages are created like if the status is not excluded yet
- shared_let_work_packages(<<~TABLE)
- hierarchy | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
- grandparent | New | 1h | 0.6h | 40% | 24h | 11.3h | 53%
- parent | Excluded | 4h | 1h | 75% | 23h | 10.7h | 53%
- child 1 | Excluded | 9h | 7.2h | 20% | | |
- child 2 | In progress | 5h | 2.5h | 50% | | |
- child 3 | Closed | 5h | 0h | 100% | | |
- TABLE
-
- before do
- job.perform_now(
- cause_type: "status_changed",
- status_name: status_excluded.name,
- status_id: status_excluded.id,
- changes: { "excluded_from_totals" => [false, true] }
- )
- table_work_packages.map(&:reload)
- end
-
- it "recomputes totals without the values from work packages having the excluded status" do
- expect_work_packages(table_work_packages, <<~TABLE)
- subject | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
- grandparent | New | 1h | 0.6h | 40% | 11h | 3.1h | 72%
- parent | Excluded | 4h | 1h | 75% | 10H | 2.5h | 75%
- child 1 | Excluded | 9h | 7.2h | 20% | | |
- child 2 | In progress | 5h | 2.5h | 50% | | |
- child 3 | Closed | 5h | 0h | 100% | | |
- TABLE
- end
-
- it "adds a relevant journal entry for the parent with recomputed total" do
- changed_worked_packages = [grandparent, parent]
- changed_worked_packages.each do |work_package|
- expect(work_package.journals.count).to eq(2), "expected #{work_package} to have a new journal"
- last_journal = work_package.last_journal
- expect(last_journal.user).to eq(User.system)
- expect(last_journal.cause_type).to eq("status_changed")
- expect(last_journal.cause_status_name).to eq("Excluded")
- expect(last_journal.cause_status_id).to eq(status_excluded.id)
- expect(last_journal.cause_status_changes).to eq({ "excluded_from_totals" => [false, true] })
- end
-
- unchanged_work_packages = table_work_packages - changed_worked_packages
- unchanged_work_packages.each do |work_package|
- expect(work_package.journals.count).to eq(1), "expected #{work_package} not to have new journals"
- end
- end
- end
- end
- end
-
- context "when in status-based mode",
- with_settings: { work_package_done_ratio: "status" } do
- context "when work packages have % complete value different from their status" do
- it "updates the work packages % complete value from the status" do
- expect_performing_job_changes(
- from: <<~TABLE,
- subject | status | % complete
- wp | Doing (40%) |
- wp 0% | To do (0%) | 50%
- wp 40% | Doing (40%) | 50%
- wp 100% | Done (100%) | 50%
- TABLE
- to: <<~TABLE
- subject | status | % complete
- wp | Doing (40%) | 40%
- wp 0% | To do (0%) | 0%
- wp 40% | Doing (40%) | 40%
- wp 100% | Done (100%) | 100%
- TABLE
- )
- end
- end
-
- context "when work packages have work and remaining work values" do
- it "updates the work packages remaining work along with the % complete value from the status" do
- expect_performing_job_changes(
- from: <<~TABLE,
- subject | status | work | remaining work | % complete
- wp | Doing (40%) | 10h | |
- wp 0% | To do (0%) | 10h | 5h | 50%
- wp 40% | Doing (40%) | 10h | 5h | 50%
- wp 100% | Done (100%) | 10h | 5h | 50%
- TABLE
- to: <<~TABLE
- subject | status | work | remaining work | % complete
- wp | Doing (40%) | 10h | 6h | 40%
- wp 0% | To do (0%) | 10h | 10h | 0%
- wp 40% | Doing (40%) | 10h | 6h | 40%
- wp 100% | Done (100%) | 10h | 0h | 100%
- TABLE
- )
- end
- end
-
- context "when in hierarchy" do
- it "the total remaining work and total % complete values are recomputed" do
- # Simulating changing "Doing" status default % progress from 20% to 40%
- expect_performing_job_changes(
- from: <<~TABLE,
- hierarchy | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
- grandparent | Doing (40%) | 1h | 0.8h | 20% | 20h | 9.8h | 51%
- parent | Doing (40%) | | | 20% | 19h | 9h | 53%
- child 1 | Done (100%) | 9h | 0h | 100% | | |
- child 2 | Doing (40%) | 5h | 4h | 20% | | |
- child 3 | To do (0%) | 5h | 5h | 0% | | |
- TABLE
- to: <<~TABLE
- subject | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
- grandparent | Doing (40%) | 1h | 0.6h | 40% | 20h | 8.6h | 57%
- parent | Doing (40%) | | | 40% | 19h | 8h | 58%
- child 1 | Done (100%) | 9h | 0h | 100% | | |
- child 2 | Doing (40%) | 5h | 3h | 40% | | |
- child 3 | To do (0%) | 5h | 5h | 0% | | |
- TABLE
- )
- end
- end
-
- context "when a status is being excluded from progress calculation" do
- # The work packages are created like if the status is not excluded yet
- shared_let_work_packages(<<~TABLE)
- hierarchy | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
- grandparent | Doing (40%) | 1h | 0.6h | 40% | 24h | 16.6h | 31%
- parent | Excluded | 4h | 4h | 0% | 23h | 16h | 30%
- child 1 | Excluded | 9h | 9h | 0% | | |
- child 2 | Doing (40%) | 5h | 3h | 40% | | |
- child 3 | Done (100%) | 5h | 0h | 100% | | |
- TABLE
-
- before do
- job.perform_now(
- cause_type: "status_changed",
- status_name: status_excluded.name,
- status_id: status_excluded.id,
- changes: { "excluded_from_totals" => [false, true] }
- )
- table_work_packages.map(&:reload)
- end
-
- it "recomputes totals without the values from work packages having the excluded status" do
- expect_work_packages(table_work_packages, <<~TABLE)
- subject | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
- grandparent | Doing (40%) | 1h | 0.6h | 40% | 11h | 3.6h | 67%
- parent | Excluded | 4h | 4h | 0% | 10h | 3h | 70%
- child 1 | Excluded | 9h | 9h | 0% | | |
- child 2 | Doing (40%) | 5h | 3h | 40% | | |
- child 3 | Done (100%) | 5h | 0h | 100% | | |
- TABLE
- end
-
- it "adds a relevant journal entry for the parent with recomputed total" do
- changed_worked_packages = [grandparent, parent]
- changed_worked_packages.each do |work_package|
- expect(work_package.journals.count).to eq(2), "expected #{work_package} to have a new journal"
- last_journal = work_package.last_journal
- expect(last_journal.user).to eq(User.system)
- expect(last_journal.cause_type).to eq("status_changed")
- expect(last_journal.cause_status_name).to eq("Excluded")
- expect(last_journal.cause_status_id).to eq(status_excluded.id)
- expect(last_journal.cause_status_changes).to eq({ "excluded_from_totals" => [false, true] })
- end
-
- unchanged_work_packages = table_work_packages - changed_worked_packages
- unchanged_work_packages.each do |work_package|
- expect(work_package.journals.count).to eq(1), "expected #{work_package} not to have new journals"
- end
- end
- end
-
- describe "journals" do
- # rubocop:disable RSpec/ExampleLength
- it "creates journal entries for modified work packages on status % complete change" do
- parent, child1, child2 = expect_performing_job_changes(
- from: <<~TABLE,
- hierarchy | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
- parent | To do (0%) | | | 0% | 20h | 8h | 60%
- child 1 | Doing (40%) | 10h | 8h | 20% | | |
- child 2 | Done (100%) | 10h | 0h | 100% | | |
- TABLE
- to: <<~TABLE,
- subject | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
- parent | To do (0%) | | | 0% | 20h | 6h | 70%
- child 1 | Doing (40%) | 10h | 6h | 40% | | |
- child 2 | Done (100%) | 10h | 0h | 100% | | |
- TABLE
- cause_type: "status_changed",
- status_name: status_40p_doing.name,
- status_id: status_40p_doing.id,
- changes: { "default_done_ratio" => [20, 40] }
- )
- [parent, child1].each do |work_package|
- expect(work_package.journals.count).to eq 2
- last_journal = work_package.last_journal
- expect(last_journal.user).to eq(User.system)
- expect(last_journal.cause_type).to eq("status_changed")
- expect(last_journal.cause_status_name).to eq("Doing (40%)")
- expect(last_journal.cause_status_id).to eq(status_40p_doing.id)
- expect(last_journal.cause_status_changes).to eq({ "default_done_ratio" => [20, 40] })
- end
-
- # unchanged => no new journals
- expect(child2.journals.count).to eq 1
- end
- # rubocop:enable RSpec/ExampleLength
-
- it "creates journal entries for modified work packages on progress calculation mode set to status-based" do
- parent, child1, child2 = expect_performing_job_changes(
- from: <<~TABLE,
- hierarchy | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
- parent | To do (0%) | | | 0% | 20h | 8h | 60%
- child 1 | Doing (40%) | 10h | 8h | 20% | | |
- child 2 | Done (100%) | 10h | 0h | 100% | | |
- TABLE
- to: <<~TABLE,
- subject | status | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
- parent | To do (0%) | | | 0% | 20h | 6h | 70%
- child 1 | Doing (40%) | 10h | 6h | 40% | | |
- child 2 | Done (100%) | 10h | 0h | 100% | | |
- TABLE
- cause_type: "progress_mode_changed_to_status_based"
- )
- [parent, child1].each do |work_package|
- expect(work_package.journals.count).to eq 2
- last_journal = work_package.last_journal
- expect(last_journal.user).to eq(User.system)
- expect(last_journal.cause_type).to eq("progress_mode_changed_to_status_based")
- end
-
- # unchanged => no new journals
- expect(child2.journals.count).to eq 1
- end
- end
- end
-
- context "with errors during job execution",
- with_settings: { work_package_done_ratio: "status" } do
- let_work_packages(<<~TABLE)
- subject | status | % complete
- wp | Doing (40%) |
- wp 0% | To do (0%) | 50%
- wp 40% | Doing (40%) | 50%
- wp 100% | Done (100%) | 50%
- TABLE
-
- before do
- allow(Journals::CreateService)
- .to receive(:new)
- .and_call_original
-
- allow(Journals::CreateService)
- .to receive(:new)
- .with(WorkPackage.last, User.system)
- .and_return(nil)
-
- begin
- job.perform_now(cause_type: "status_changed",
- status_name: "New",
- status_id: 99,
- changes: { "default_done_ratio" => [33, 66] })
- rescue StandardError
- end
- end
-
- it "does not update any work package" do
- expect_work_packages(WorkPackage.all, <<~TABLE)
- subject | status | % complete
- wp | Doing (40%) |
- wp 0% | To do (0%) | 50%
- wp 40% | Doing (40%) | 50%
- wp 100% | Done (100%) | 50%
- TABLE
- end
- end
-end
diff --git a/spec/workers/work_packages/progress/apply_statuses_change_job_spec.rb b/spec/workers/work_packages/progress/apply_statuses_change_job_spec.rb
index dbcf01d1403..fb09a63a4c1 100644
--- a/spec/workers/work_packages/progress/apply_statuses_change_job_spec.rb
+++ b/spec/workers/work_packages/progress/apply_statuses_change_job_spec.rb
@@ -28,8 +28,7 @@
require "rails_helper"
-RSpec.describe WorkPackages::Progress::ApplyStatusesChangeJob,
- with_flag: { percent_complete_edition: true } do
+RSpec.describe WorkPackages::Progress::ApplyStatusesChangeJob do
shared_let(:author) { create(:user) }
shared_let(:priority) { create(:priority, name: "Normal") }
shared_let(:project) { create(:project, name: "Main project") }