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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Ensure human_attribute_name is present on ServiceResult
Oliver Günther7c37cb7bf0b7
diff --git a/app/services/service_result.rb b/app/services/service_result.rbindex 950a140f5d4..f22a576ef74 100644--- a/app/services/service_result.rb+++ b/app/services/service_result.rb@@ -223,6 +223,13 @@ class ServiceResult@state ||= ::Shared::ServiceState.buildend+ ##+ # Required as we create an errors object bound to this ServiceResult.+ # calling `errors#full_messages` will call `human_attribute_name` here.+ def self.human_attribute_name(*)+ ApplicationRecord.human_attribute_name(*)+ end+privatedef initialize_errors(errors)diff --git a/spec/services/service_result_spec.rb b/spec/services/service_result_spec.rbindex e851f22b66f..f51f66e3a17 100644--- a/spec/services/service_result_spec.rb+++ b/spec/services/service_result_spec.rb@@ -151,6 +151,16 @@ RSpec.describe ServiceResult, type: :model doexpect(instance.errors).not_to eq result.errorsendend++ context "when using default errors" do+ it "uses the default human_attribute_name from ServiceResult (Regression #61483)" do+ instance = described_class.new+ instance.errors.add(:base, "some error")+ instance.errors.add(:foo, "an error for foo")++ expect { instance.errors.full_messages }.not_to raise_error+ end+ endenddescribe "result" do