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

Correctly format unsetting done_ratio in activity

Christophe Bliarda135c1f2f2ef
diff --git a/app/models/work_package/journalized.rb b/app/models/work_package/journalized.rb
index 879fa89fd00..2f5c5fc0669 100644
--- a/app/models/work_package/journalized.rb
+++ b/app/models/work_package/journalized.rb
@@ -81,7 +81,7 @@ module WorkPackage::Journalized
register_journal_formatted_fields(:fraction,
"estimated_hours", "derived_estimated_hours",
"remaining_hours", "derived_remaining_hours")
- register_journal_formatted_fields(:decimal, "done_ratio")
+ register_journal_formatted_fields(:percentage, "done_ratio")
register_journal_formatted_fields(:diff, "description")
register_journal_formatted_fields(:schedule_manually, "schedule_manually")
register_journal_formatted_fields(:attachment, /attachments_?\d+/)
diff --git a/lib_static/plugins/acts_as_journalized/lib/journal_formatter.rb b/lib_static/plugins/acts_as_journalized/lib/journal_formatter.rb
index 1eb2e6d81ff..75088197814 100644
--- a/lib_static/plugins/acts_as_journalized/lib/journal_formatter.rb
+++ b/lib_static/plugins/acts_as_journalized/lib/journal_formatter.rb
@@ -58,6 +58,7 @@ require_relative "journal_formatter/decimal"
require_relative "journal_formatter/fraction"
require_relative "journal_formatter/id"
require_relative "journal_formatter/named_association"
+require_relative "journal_formatter/percentage"
require_relative "journal_formatter/plaintext"
module JournalFormatter
@@ -80,6 +81,7 @@ module JournalFormatter
fraction: JournalFormatter::Fraction,
id: JournalFormatter::Id,
named_association: JournalFormatter::NamedAssociation,
+ percentage: JournalFormatter::Percentage,
plaintext: JournalFormatter::Plaintext }
end
diff --git a/lib_static/plugins/acts_as_journalized/lib/journal_formatter/percentage.rb b/lib_static/plugins/acts_as_journalized/lib/journal_formatter/percentage.rb
new file mode 100644
index 00000000000..7e27a8a161e
--- /dev/null
+++ b/lib_static/plugins/acts_as_journalized/lib/journal_formatter/percentage.rb
@@ -0,0 +1,35 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-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.
+#++
+
+module JournalFormatter
+ class Percentage < Attribute
+ def format_values(values)
+ values.map { |v| v ? "#{v}%" : nil }
+ end
+ end
+end
diff --git a/spec/lib/journal_formatter/percentage_spec.rb b/spec/lib/journal_formatter/percentage_spec.rb
new file mode 100644
index 00000000000..9d0dc61566f
--- /dev/null
+++ b/spec/lib/journal_formatter/percentage_spec.rb
@@ -0,0 +1,93 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-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"
+
+RSpec.describe JournalFormatter::Percentage do
+ describe ".render" do
+ let(:journal) { build_stubbed(:work_package_journal) }
+ let(:instance) { described_class.new(journal) }
+
+ context "when setting new value" do
+ let(:old_value) { nil }
+ let(:new_value) { 33 }
+
+ it "renders the new value" do
+ expect(instance.render("done_ratio", [old_value, new_value]))
+ .to eq(I18n.t(:text_journal_set_to,
+ label: "<strong>% Complete</strong>",
+ value: "<i>#{new_value}%</i>"))
+
+ expect(instance.render("done_ratio", [old_value, new_value], html: false))
+ .to eq(I18n.t(:text_journal_set_to,
+ label: "% Complete",
+ value: "#{new_value}%"))
+ end
+ end
+
+ context "when changing value" do
+ let(:old_value) { 98 }
+ let(:new_value) { 33 }
+
+ it "renders the change from old to new value" do
+ expect(instance.render("done_ratio", [old_value, new_value]))
+ .to eq(I18n.t(:text_journal_changed_plain,
+ label: "<strong>% Complete</strong>",
+ linebreak: nil,
+ old: "<i>#{old_value}%</i>",
+ new: "<i>#{new_value}%</i>"))
+
+ expect(instance.render("done_ratio", [old_value, new_value], html: false))
+ .to eq(I18n.t(:text_journal_changed_plain,
+ label: "% Complete",
+ linebreak: nil,
+ old: "#{old_value}%",
+ new: "#{new_value}%"))
+ end
+ end
+
+ context "when removing the value" do
+ let(:old_value) { 98 }
+ let(:new_value) { nil }
+
+ it "renders as removed instead of displaying 'changed to 0'" do
+ expect(instance.render("done_ratio", [old_value, new_value]))
+ .to eq(I18n.t(:text_journal_deleted,
+ label: "<strong>% Complete</strong>",
+ old: "<strike><i>#{old_value}%</i></strike>"))
+
+ expect(instance.render("done_ratio", [old_value, new_value], html: false))
+ .to eq(I18n.t(:text_journal_deleted,
+ label: "% Complete",
+ old: "#{old_value}%"))
+ end
+ end
+ end
+end