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

Fix tests after status / explanation breakup

Oliver Günthere1e9edd66817
diff --git a/frontend/src/app/modules/grids/widgets/project-status/project-status.component.html b/frontend/src/app/modules/grids/widgets/project-status/project-status.component.html
index e339d32ef3e..e52fd24706d 100644
--- a/frontend/src/app/modules/grids/widgets/project-status/project-status.component.html
+++ b/frontend/src/app/modules/grids/widgets/project-status/project-status.component.html
@@ -11,7 +11,7 @@
<div class="grid--widget-content">
<edit-form *ngIf="(project$ | async) as project" [resource]="project">
<editable-attribute-field [resource]="project"
- fieldName="statusCode">
+ fieldName="status">
</editable-attribute-field>
<editable-attribute-field [resource]="project"
fieldName="statusExplanation">
diff --git a/lib/api/v3/projects/project_representer.rb b/lib/api/v3/projects/project_representer.rb
index 6c59442d138..2e91d888559 100644
--- a/lib/api/v3/projects/project_representer.rb
+++ b/lib/api/v3/projects/project_representer.rb
@@ -162,32 +162,33 @@ module API
date_time_property :updated_at
- formattable_property :status_explanation,
- getter: ->(*) {
- status = represented.status || Project::Status.new
- ::API::Decorators::Formattable.new(status.explanation,
- object: represented,
- plain: false)
- },
- setter: ->(fragment:, **) {
- represented.status ||= {}
- represented.status[:explanation] = fragment["raw"]
- }
-
- property :status_code,
+ property :status_explanation,
+ getter: ->(*) {
+ status_obj = status || Project::Status.new
+ ::API::Decorators::Formattable.new(status_obj.explanation,
+ object: self,
+ plain: false)
+ },
+ setter: ->(fragment:, **) {
+ self.status ||= {}
+ status[:explanation] = fragment["raw"]
+ }
+
+ property :status,
render_nil: true,
- getter: ->(represented:, **) {
- next unless represented.status&.code
+ getter: ->(*) {
+ next unless status&.code
- represented.status.code.to_s.tr('_', ' ')
+ status.code.to_s.tr('_', ' ')
},
- setter: ->(fragment:,represented:, **) {
- represented.status ||= {}
- represented.status[:code] = if fragment.nil?
- nil
- else
- fragment.strip.tr(' ', '_').underscore.to_sym
- end
+ setter: ->(fragment:, **) {
+ self.status ||= {}
+ status[:code] =
+ if fragment.nil?
+ nil
+ else
+ fragment.strip.tr(' ', '_').underscore.to_sym
+ end
}
def _type
diff --git a/lib/api/v3/projects/schemas/project_schema_representer.rb b/lib/api/v3/projects/schemas/project_schema_representer.rb
index d90cdbafa2b..8ecde8b072a 100644
--- a/lib/api/v3/projects/schemas/project_schema_representer.rb
+++ b/lib/api/v3/projects/schemas/project_schema_representer.rb
@@ -65,7 +65,7 @@ module API
type: 'Boolean',
visibility: false
- schema :status_code,
+ schema :status,
type: 'ProjectStatus',
name_source: ->(*) { I18n.t('activerecord.attributes.project/status.code') },
visibility: false,
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 71d927698b0..12928d33bbf 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
@@ -183,14 +183,14 @@ describe ::API::V3::Projects::Schemas::ProjectSchemaRepresenter do
let(:path) { 'statusExplanation' }
it_behaves_like 'has basic schema properties' do
- let(:type) { 'Formattible' }
+ let(:type) { 'Formattable' }
let(:name) { I18n.t('activerecord.attributes.project/status.explanation') }
let(:required) { false }
let(:writable) { true }
end
end
- describe 'statusCode' do
+ describe 'status' do
let(:path) { 'status' }
it_behaves_like 'has basic schema properties' do
diff --git a/spec/requests/api/v3/project_resource_spec.rb b/spec/requests/api/v3/project_resource_spec.rb
index c1daf9fc741..2ed09096a2f 100644
--- a/spec/requests/api/v3/project_resource_spec.rb
+++ b/spec/requests/api/v3/project_resource_spec.rb
@@ -111,7 +111,7 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
expect(subject.body)
.to be_json_eql(project_status.code.tr('_', ' ').to_json)
- .at_path("statusCode")
+ .at_path("status")
end
context 'requesting nonexistent project' do
@@ -299,7 +299,7 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
{
identifier: 'new_project_identifier',
name: 'Project name',
- statusCode: 'off track',
+ status: 'off track',
statusExplanation: { raw: "Some explanation." }
}.to_json
end
@@ -307,7 +307,7 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
it 'sets the status' do
expect(last_response.body)
.to be_json_eql('off track'.to_json)
- .at_path('statusCode')
+ .at_path('status')
expect(last_response.body)
.to be_json_eql(
@@ -392,7 +392,7 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
{
identifier: 'new_project_identifier',
name: 'Project name',
- statusCode: 'faulty',
+ status: 'faulty',
statusExplanation: "Some explanation."
}.to_json
end
@@ -499,7 +499,7 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
context 'with a status' do
let(:body) do
{
- statusCode: 'off track',
+ status: 'off track',
statusExplanation: {
raw: "Some explanation."
}
@@ -509,7 +509,7 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
it 'alters the status' do
expect(last_response.body)
.to be_json_eql('off track'.to_json)
- .at_path('statusCode')
+ .at_path('status')
expect(last_response.body)
.to be_json_eql(
@@ -565,7 +565,7 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
context 'with a faulty status' do
let(:body) do
{
- statusCode: "bogus"
+ status: "bogus"
}
end
diff --git a/spec/requests/api/v3/projects/create_form_resource_spec.rb b/spec/requests/api/v3/projects/create_form_resource_spec.rb
index 0a61fc27cd4..b023ce4655b 100644
--- a/spec/requests/api/v3/projects/create_form_resource_spec.rb
+++ b/spec/requests/api/v3/projects/create_form_resource_spec.rb
@@ -106,10 +106,8 @@ describe ::API::V3::Projects::CreateFormAPI, content_type: :json do
"customField#{text_custom_field.id}": {
"raw": "CF text"
},
- status: {
- code: "on track",
- explanation: "A magic dwells in each beginning."
- },
+ status: 'on track',
+ statusExplanation: "A magic dwells in each beginning.",
"_links": {
"customField#{list_custom_field.id}": {
"href": api_v3_paths.custom_option(list_custom_field.custom_options.first.id)
@@ -141,17 +139,18 @@ describe ::API::V3::Projects::CreateFormAPI, content_type: :json do
.to be_json_eql(api_v3_paths.custom_option(list_custom_field.custom_options.first.id).to_json)
.at_path("_embedded/payload/_links/customField#{list_custom_field.id}/href")
+ expect(body)
+ .to be_json_eql('on track'.to_json)
+ .at_path('_embedded/payload/status')
+
expect(body)
.to be_json_eql(
{
- code: "on track",
- explanation: {
- "format": "markdown",
- "html": "<p>A magic dwells in each beginning.</p>",
- "raw": "A magic dwells in each beginning."
- }
+ "format": "markdown",
+ "html": "<p>A magic dwells in each beginning.</p>",
+ "raw": "A magic dwells in each beginning."
}.to_json
- ).at_path("_embedded/payload/status")
+ ).at_path("_embedded/payload/statusExplanation")
end
it 'has a commit link' do
@@ -166,9 +165,7 @@ describe ::API::V3::Projects::CreateFormAPI, content_type: :json do
{
identifier: 'new_project_identifier',
name: 'Project name',
- status: {
- code: "bogus"
- }
+ status: "bogus"
}
end
diff --git a/spec/requests/api/v3/projects/update_form_resource_spec.rb b/spec/requests/api/v3/projects/update_form_resource_spec.rb
index 683c429eb68..39b931d75fd 100644
--- a/spec/requests/api/v3/projects/update_form_resource_spec.rb
+++ b/spec/requests/api/v3/projects/update_form_resource_spec.rb
@@ -167,8 +167,8 @@ describe ::API::V3::Projects::UpdateFormAPI, content_type: :json do
"customField#{text_custom_field.id}": {
"raw": "new CF text"
},
- statusCode: 'off track',
- statusExplanation: 'Something goes awry.',
+ status: 'off track',
+ statusExplanation: { raw: 'Something goes awry.' },
"_links": {
"customField#{list_custom_field.id}": {
"href": api_v3_paths.custom_option(list_custom_field.custom_options.last.id)
@@ -202,7 +202,7 @@ describe ::API::V3::Projects::UpdateFormAPI, content_type: :json do
expect(body)
.to be_json_eql('off track'.to_json)
- .at_path("_embedded/payload/statusCcode")
+ .at_path("_embedded/payload/status")
expect(body)
.to be_json_eql('Something goes awry.'.to_json)
@@ -238,14 +238,14 @@ describe ::API::V3::Projects::UpdateFormAPI, content_type: :json do
context 'with faulty status parameters' do
let(:params) do
{
- statusCode: "bogus"
+ status: "bogus"
}
end
it 'displays the faulty status in the payload' do
expect(subject.body)
.to be_json_eql('bogus'.to_json)
- .at_path('_embedded/payload/statuCcode')
+ .at_path('_embedded/payload/status')
end
it 'has 1 validation errors' do
@@ -253,7 +253,7 @@ describe ::API::V3::Projects::UpdateFormAPI, content_type: :json do
end
it 'has a validation error on status' do
- expect(subject.body).to have_json_path('_embedded/validationErrors/statusCode')
+ expect(subject.body).to have_json_path('_embedded/validationErrors/status')
end
it 'has no commit link' do
diff --git a/spec/services/projects/set_attributes_service_spec.rb b/spec/services/projects/set_attributes_service_spec.rb
index 6d1d4a8a718..d25b9f97030 100644
--- a/spec/services/projects/set_attributes_service_spec.rb
+++ b/spec/services/projects/set_attributes_service_spec.rb
@@ -259,10 +259,8 @@ describe Projects::SetAttributesService, type: :model do
context 'with a value provided' do
let(:call_attributes) do
{
- status: {
- code: 'on_track',
- explanation: 'A magic dwells in each beginning.'
- }
+ status: 'on track',
+ statusExplanation: 'A magic dwells in each beginning.'
}
end
@@ -290,10 +288,8 @@ describe Projects::SetAttributesService, type: :model do
context 'with a value provided' do
let(:call_attributes) do
{
- status: {
- code: 'on_track',
- explanation: 'A magic dwells in each beginning.'
- }
+ status: 'on_track',
+ statusExplanation: 'A magic dwells in each beginning.'
}
end
@@ -316,10 +312,8 @@ describe Projects::SetAttributesService, type: :model do
context 'with an invalid code' do
let(:call_attributes) do
{
- status: {
- code: 'bogus',
- explanation: 'A magic dwells in each beginning.'
- }
+ status: 'bogus',
+ statusExplanation: 'A magic dwells in each beginning.'
}
end
@@ -351,10 +345,8 @@ describe Projects::SetAttributesService, type: :model do
context 'with a value provided' do
let(:call_attributes) do
{
- status: {
- code: 'at_risk',
- explanation: 'Still some magic there.'
- }
+ status: 'at_risk',
+ statusExplanation: 'Still some magic there.'
}
end