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] ProjectSchemaRepresenter spec

Tobias Dillmann47df7d61abfb
diff --git a/spec/lib/api/v3/projects/schemas/project_schema_representer_spec.rb b/spec/lib/api/v3/projects/schemas/project_schema_representer_spec.rb
index 16d36b0dbc2..13f00709b22 100644
--- a/spec/lib/api/v3/projects/schemas/project_schema_representer_spec.rb
+++ b/spec/lib/api/v3/projects/schemas/project_schema_representer_spec.rb
@@ -41,6 +41,9 @@ RSpec.describe API::V3::Projects::Schemas::ProjectSchemaRepresenter do
let(:custom_field) do
build_stubbed(:integer_project_custom_field)
end
+ let(:calculated_value_cf) do
+ build_stubbed(:calculated_value_project_custom_field, formula: "23 + {{cf_#{custom_field.id}}}")
+ end
let(:allowed_status) { ["some status"] }
let(:contract) do
contract = double("contract")
@@ -60,8 +63,7 @@ RSpec.describe API::V3::Projects::Schemas::ProjectSchemaRepresenter do
.and_return(allowed_status)
allow(contract)
- .to receive_messages(available_custom_fields: [custom_field], model: model)
-
+ .to receive_messages(available_custom_fields: [custom_field, calculated_value_cf], model: model)
allow(model)
.to receive_messages(new_record?: new_record, id: model_id)
@@ -84,7 +86,7 @@ RSpec.describe API::V3::Projects::Schemas::ProjectSchemaRepresenter do
end
end
- context "generation" do
+ describe "generation" do
subject(:generated) { representer.to_json }
describe "_type" do
@@ -299,6 +301,18 @@ RSpec.describe API::V3::Projects::Schemas::ProjectSchemaRepresenter do
end
end
+ describe "calculated value custom field" do
+ let(:path) { "customField#{calculated_value_cf.id}" }
+
+ it_behaves_like "has basic schema properties" do
+ let(:type) { "CalculatedValue" }
+ let(:name) { calculated_value_cf.name }
+ let(:formula) { "23 + {{cf_#{custom_field.id}}}" }
+ let(:required) { false }
+ let(:writable) { false }
+ end
+ end
+
describe "parent" do
let(:path) { "parent" }
diff --git a/spec/lib/api/v3/support/schema_examples.rb b/spec/lib/api/v3/support/schema_examples.rb
index 690f1337c47..a1c8ad45d1a 100644
--- a/spec/lib/api/v3/support/schema_examples.rb
+++ b/spec/lib/api/v3/support/schema_examples.rb
@@ -82,6 +82,16 @@ RSpec.shared_examples_for "has basic schema properties" do
expect(subject).not_to have_json_path("#{path}/description")
end
end
+
+ it "indicates if it has a formula" do
+ if defined?(formula)
+ expect(subject)
+ .to be_json_eql(formula.to_json)
+ .at_path("#{path}/formula")
+ else
+ expect(subject).not_to have_json_path("#{path}/formula")
+ end
+ end
end
RSpec.shared_examples_for "indicates length requirements" do