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

[#64530] ProjectRepresenter spec

Tobias Dillmannf352b25a654b
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 1d015b41138..46dfad47aa7 100644
--- a/spec/lib/api/v3/projects/project_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/projects/project_representer_rendering_spec.rb
@@ -35,23 +35,35 @@ RSpec.describe API::V3::Projects::ProjectRepresenter, "rendering" do
subject(:generated) { representer.to_json }
+ let(:available_custom_fields) { [int_custom_field, version_custom_field] }
+ let(:all_available_custom_fields) { [int_custom_field, version_custom_field] }
let(:project) do
build_stubbed(:project,
:with_status,
parent: parent_project,
description: "some description").tap do |p|
- allow(p).to receive_messages(available_custom_fields: [int_custom_field, version_custom_field],
- all_available_custom_fields: [int_custom_field, version_custom_field],
+ allow(p).to receive_messages(available_custom_fields:,
+ all_available_custom_fields:,
ancestors_from_root: ancestors)
- allow(p)
- .to receive(int_custom_field.attribute_getter)
- .and_return(int_custom_value.value)
+ if available_custom_fields.include?(int_custom_field)
+ allow(p)
+ .to receive(int_custom_field.attribute_getter)
+ .and_return(int_custom_value.value)
+ end
+
+ if available_custom_fields.include?(version_custom_field)
+ allow(p)
+ .to receive(:custom_value_for)
+ .with(version_custom_field)
+ .and_return(version_custom_value)
+ end
- allow(p)
- .to receive(:custom_value_for)
- .with(version_custom_field)
- .and_return(version_custom_value)
+ if available_custom_fields.include?(calculated_value_custom_field)
+ allow(p)
+ .to receive(calculated_value_custom_field.attribute_getter)
+ .and_return(calculated_custom_value.value)
+ end
end
end
@@ -72,6 +84,14 @@ RSpec.describe API::V3::Projects::ProjectRepresenter, "rendering" do
.and_return(version)
end
end
+ let(:calculated_value_custom_field) do
+ build_stubbed(:calculated_value_project_custom_field, :skip_validations, admin_only: false, formula: "21 + 3")
+ end
+ let(:calculated_custom_value) do
+ CustomValue.new(custom_field: calculated_value_custom_field,
+ value: "24.0",
+ customized: nil)
+ end
let(:permissions) { %i[view_project add_work_packages view_members] }
let(:parent_project) do
build_stubbed(:project).tap do |parent|
@@ -187,6 +207,17 @@ RSpec.describe API::V3::Projects::ProjectRepresenter, "rendering" do
end
end
end
+
+ describe "calculated value custom field" do
+ let(:available_custom_fields) { [calculated_value_custom_field] }
+ let(:all_available_custom_fields) { [calculated_value_custom_field] }
+ let(:cf_path) { "customField#{calculated_value_custom_field.id}" }
+
+ it "has a property for the calculated value custom field" do
+ expect(subject).to be_json_eql(calculated_custom_value.value.to_json)
+ .at_path(cf_path)
+ end
+ end
end
describe "_links" do