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

Adapt backend tests for separated attributes

Oliver Günthera2ede60dd3ef
diff --git a/lib/api/v3/projects/schemas/project_schema_representer.rb b/lib/api/v3/projects/schemas/project_schema_representer.rb
index dbd27ad77ca..d90cdbafa2b 100644
--- a/lib/api/v3/projects/schemas/project_schema_representer.rb
+++ b/lib/api/v3/projects/schemas/project_schema_representer.rb
@@ -67,12 +67,14 @@ module API
schema :status_code,
type: 'ProjectStatus',
+ name_source: ->(*) { I18n.t('activerecord.attributes.project/status.code') },
visibility: false,
required: false,
writable: ->(*) { represented.writable?(:status) }
schema :status_explanation,
type: 'Formattable',
+ name_source: ->(*) { I18n.t('activerecord.attributes.project/status.explanation') },
visibility: false,
required: false,
writable: ->(*) { represented.writable?(:status) }
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 d6e1bbf688f..71d927698b0 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
@@ -179,13 +179,24 @@ describe ::API::V3::Projects::Schemas::ProjectSchemaRepresenter do
it_behaves_like 'has no visibility property'
end
- describe 'status' do
+ describe 'statusExplanation' do
+ let(:path) { 'statusExplanation' }
+
+ it_behaves_like 'has basic schema properties' do
+ let(:type) { 'Formattible' }
+ let(:name) { I18n.t('activerecord.attributes.project/status.explanation') }
+ let(:required) { false }
+ let(:writable) { true }
+ end
+ end
+
+ describe 'statusCode' do
let(:path) { 'status' }
it_behaves_like 'has basic schema properties' do
let(:type) { 'ProjectStatus' }
- let(:name) { I18n.t('attributes.status') }
- let(:required) { true }
+ let(:name) { I18n.t('activerecord.attributes.project/status.code') }
+ let(:required) { false }
let(:writable) { true }
end
diff --git a/spec/requests/api/v3/project_resource_spec.rb b/spec/requests/api/v3/project_resource_spec.rb
index 954e50deca6..c1daf9fc741 100644
--- a/spec/requests/api/v3/project_resource_spec.rb
+++ b/spec/requests/api/v3/project_resource_spec.rb
@@ -107,11 +107,11 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
it 'includes the project status' do
expect(subject.body)
.to be_json_eql(project_status.explanation.to_json)
- .at_path("status/explanation/raw")
+ .at_path("statusExplanation/raw")
expect(subject.body)
.to be_json_eql(project_status.code.tr('_', ' ').to_json)
- .at_path("status/code")
+ .at_path("statusCode")
end
context 'requesting nonexistent project' do
@@ -299,26 +299,25 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
{
identifier: 'new_project_identifier',
name: 'Project name',
- status: {
- "code": "off track",
- "explanation": "Some explanation."
- }
+ statusCode: 'off track',
+ statusExplanation: { raw: "Some explanation." }
}.to_json
end
it 'sets the status' do
+ expect(last_response.body)
+ .to be_json_eql('off track'.to_json)
+ .at_path('statusCode')
+
expect(last_response.body)
.to be_json_eql(
{
- "code": "off track",
- "explanation": {
- "format": "markdown",
- "html": "<p>Some explanation.</p>",
- "raw": "Some explanation."
- }
+ "format": "markdown",
+ "html": "<p>Some explanation.</p>",
+ "raw": "Some explanation."
}.to_json
)
- .at_path("status")
+ .at_path("statusExplanation")
end
it 'creates a project and a status' do
@@ -393,10 +392,8 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
{
identifier: 'new_project_identifier',
name: 'Project name',
- status: {
- "code": "faulty",
- "explanation": "Some explanation."
- }
+ statusCode: 'faulty',
+ statusExplanation: "Some explanation."
}.to_json
end
@@ -502,26 +499,27 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
context 'with a status' do
let(:body) do
{
- status: {
- "code": "off track",
- "explanation": "Some explanation."
+ statusCode: 'off track',
+ statusExplanation: {
+ raw: "Some explanation."
}
}
end
it 'alters the status' do
+ expect(last_response.body)
+ .to be_json_eql('off track'.to_json)
+ .at_path('statusCode')
+
expect(last_response.body)
.to be_json_eql(
{
- "code": "off track",
- "explanation": {
- "format": "markdown",
- "html": "<p>Some explanation.</p>",
- "raw": "Some explanation."
- }
+ "format": "markdown",
+ "html": "<p>Some explanation.</p>",
+ "raw": "Some explanation."
}.to_json
)
- .at_path("status")
+ .at_path("statusExplanation")
end
it 'persists the altered status' do
@@ -567,9 +565,7 @@ describe 'API v3 Project resource', type: :request, content_type: :json do
context 'with a faulty status' do
let(:body) do
{
- status: {
- "code": "bogus"
- }
+ statusCode: "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 5bc4bdcea9e..683c429eb68 100644
--- a/spec/requests/api/v3/projects/update_form_resource_spec.rb
+++ b/spec/requests/api/v3/projects/update_form_resource_spec.rb
@@ -167,10 +167,8 @@ describe ::API::V3::Projects::UpdateFormAPI, content_type: :json do
"customField#{text_custom_field.id}": {
"raw": "new CF text"
},
- status: {
- code: "off track",
- explanation: "Something goes awry."
- },
+ statusCode: 'off track',
+ statusExplanation: 'Something goes awry.',
"_links": {
"customField#{list_custom_field.id}": {
"href": api_v3_paths.custom_option(list_custom_field.custom_options.last.id)
@@ -204,11 +202,11 @@ describe ::API::V3::Projects::UpdateFormAPI, content_type: :json do
expect(body)
.to be_json_eql('off track'.to_json)
- .at_path("_embedded/payload/status/code")
+ .at_path("_embedded/payload/statusCcode")
expect(body)
.to be_json_eql('Something goes awry.'.to_json)
- .at_path("_embedded/payload/status/explanation/raw")
+ .at_path("_embedded/payload/statusExplanation/raw")
end
it 'has a commit link' do
@@ -240,16 +238,14 @@ describe ::API::V3::Projects::UpdateFormAPI, content_type: :json do
context 'with faulty status parameters' do
let(:params) do
{
- status: {
- code: "bogus"
- }
+ statusCode: "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/status/code')
+ .at_path('_embedded/payload/statuCcode')
end
it 'has 1 validation errors' do
@@ -257,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/status')
+ expect(subject.body).to have_json_path('_embedded/validationErrors/statusCode')
end
it 'has no commit link' do