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

second attempt to not hardcode `customized_type` in API

Ivan Kuchina17b1eb6f663
diff --git a/lib/api/v3/utilities/custom_field_injector.rb b/lib/api/v3/utilities/custom_field_injector.rb
index 23c19b1d84b..861a37ffcea 100644
--- a/lib/api/v3/utilities/custom_field_injector.rb
+++ b/lib/api/v3/utilities/custom_field_injector.rb
@@ -312,7 +312,7 @@ module API
next unless custom_field.calculated_value?
next unless available_custom_fields.include?(custom_field)
- errors = custom_field.calculated_value_errors.where(customized_id: id, customized_type: "Project")
+ errors = calculated_value_errors.where(custom_field:)
errors.map do |err|
{ code: err.error_code,
message: CalculatedValues::ErrorsHelper.calculated_value_error_msg(err) }
diff --git a/spec/lib/api/v3/projects/project_representer_rendering_spec.rb b/spec/lib/api/v3/projects/project_representer_rendering_spec.rb
index 6d00631ebef..1e0872b8b00 100644
--- a/spec/lib/api/v3/projects/project_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/projects/project_representer_rendering_spec.rb
@@ -224,12 +224,12 @@ RSpec.describe API::V3::Projects::ProjectRepresenter, "rendering" do
end
before do
- value_errors_double = double
+ value_errors_double = instance_double(ActiveRecord::Relation)
allow(value_errors_double).to receive(:where)
- .with(customized_id: project.id, customized_type: "Project")
+ .with(custom_field: calculated_value_custom_field)
.and_return([calculated_value_error])
- allow(calculated_value_custom_field).to receive(:calculated_value_errors)
+ allow(project).to receive(:calculated_value_errors)
.and_return(value_errors_double)
end