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

add project status to representer

ulfertsb9f83d7d7a34
diff --git a/lib/api/v3/projects/project_representer.rb b/lib/api/v3/projects/project_representer.rb
index 1597a6277ba..01c6983f9a5 100644
--- a/lib/api/v3/projects/project_representer.rb
+++ b/lib/api/v3/projects/project_representer.rb
@@ -152,6 +152,11 @@ module API
date_time_property :updated_at
+ property :status do
+ property :explanation
+ property :code
+ end
+
def _type
'Project'
end
diff --git a/spec/factories/project_status.rb b/spec/factories/project_status.rb
index 280996cff88..69d10107646 100644
--- a/spec/factories/project_status.rb
+++ b/spec/factories/project_status.rb
@@ -31,5 +31,6 @@ FactoryBot.define do
factory :project_status, class: Project::Status do
project
sequence(:explanation) { |n| "Status explanation #{n}" }
+ code { Project::Status.codes[:on_track] }
end
end
diff --git a/spec/lib/api/v3/projects/project_representer_spec.rb b/spec/lib/api/v3/projects/project_representer_spec.rb
index 2f94d39c5e0..3d99222942d 100644
--- a/spec/lib/api/v3/projects/project_representer_spec.rb
+++ b/spec/lib/api/v3/projects/project_representer_spec.rb
@@ -120,6 +120,17 @@ describe ::API::V3::Projects::ProjectRepresenter do
end
context 'status' do
+ it 'includes the project status explanation' do
+ expect(subject)
+ .to be_json_eql(status.explanation.to_json)
+ .at_path('status/explanation')
+ end
+
+ it 'includes the project status code' do
+ expect(subject)
+ .to be_json_eql(status.code.to_json)
+ .at_path('status/code')
+ end
end
it_behaves_like 'has UTC ISO 8601 date and time' do
diff --git a/spec/requests/api/v3/project_resource_spec.rb b/spec/requests/api/v3/project_resource_spec.rb
index 9403ae5ce15..f0e16c2b791 100644
--- a/spec/requests/api/v3/project_resource_spec.rb
+++ b/spec/requests/api/v3/project_resource_spec.rb
@@ -37,7 +37,10 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
FactoryBot.create(:user, member_in_project: project, member_through_role: role)
end
let(:project) do
- FactoryBot.create(:project, public: false)
+ FactoryBot.create(:project, public: false, status: project_status)
+ end
+ let(:project_status) do
+ FactoryBot.create(:project_status)
end
let(:other_project) do
FactoryBot.create(:project, public: false)
@@ -101,6 +104,16 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
.at_path("customField#{custom_field.id}/raw")
end
+ it 'includes the project status' do
+ expect(subject.body)
+ .to be_json_eql(project_status.explanation.to_json)
+ .at_path("status/explanation")
+
+ expect(subject.body)
+ .to be_json_eql(project_status.code.to_json)
+ .at_path("status/code")
+ end
+
context 'requesting nonexistent project' do
let(:get_path) { api_v3_paths.project 9999 }