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

[#66093] Use `module_function`

Tobias Dillmann71af416c053d
diff --git a/app/helpers/calculated_values/errors_helper.rb b/app/helpers/calculated_values/errors_helper.rb
index e9c7d6b3a06..746561f624e 100644
--- a/app/helpers/calculated_values/errors_helper.rb
+++ b/app/helpers/calculated_values/errors_helper.rb
@@ -28,20 +28,24 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# Provides translated error messages for CalculatedValueError instances.
module CalculatedValues::ErrorsHelper
+ DEFAULT_TRANSLATION = "calculated_values.errors.unknown"
+
ERROR_TRANSLATIONS = {
+ "ERROR_UNKNOWN" => DEFAULT_TRANSLATION,
"ERROR_MATHEMATICAL" => "calculated_values.errors.mathematical",
"ERROR_MISSING_VALUE" => "calculated_values.errors.missing_value",
"ERROR_DISABLED_VALUE" => "calculated_values.errors.disabled_value"
}.freeze
- def self.calculated_value_error_msg(calculated_value_error)
+ def calculated_value_error_msg(calculated_value_error)
return unless calculated_value_error.is_a?(CalculatedValueError)
error_code = calculated_value_error.error_code
missing_custom_field_ids = calculated_value_error.missing_custom_field_ids
- translation_key = ERROR_TRANSLATIONS.fetch(error_code, "calculated_values.errors.unknown")
+ translation_key = ERROR_TRANSLATIONS.fetch(error_code, DEFAULT_TRANSLATION)
translation_options = {}
if %w[ERROR_MISSING_VALUE ERROR_DISABLED_VALUE].include?(error_code)
@@ -51,12 +55,12 @@ module CalculatedValues::ErrorsHelper
if cf
translation_options[:custom_field_name] = cf.name
else
- translation_key = "calculated_values.errors.unknown"
+ translation_key = DEFAULT_TRANSLATION
end
end
I18n.t(translation_key, **translation_options)
end
- delegate :calculated_value_error_msg, to: :"CalculatedValues::ErrorsHelper"
+ module_function :calculated_value_error_msg
end
diff --git a/spec/helpers/calculated_values/errors_helper_spec.rb b/spec/helpers/calculated_values/errors_helper_spec.rb
index df153f15378..fae5b6dede4 100644
--- a/spec/helpers/calculated_values/errors_helper_spec.rb
+++ b/spec/helpers/calculated_values/errors_helper_spec.rb
@@ -89,15 +89,4 @@ RSpec.describe CalculatedValues::ErrorsHelper do
end
end
end
-
- describe "#calculated_value_error_msg" do
- let(:instance) do
- Object.new.extend(described_class)
- end
-
- it "delegates to the class method" do
- error.error_code = "ERROR_MATHEMATICAL"
- expect(instance.calculated_value_error_msg(error)).to eq(I18n.t("calculated_values.errors.mathematical"))
- end
- end
end