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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
implement project status updating
ulfertsfbb6c9dc8f06
diff --git a/app/services/projects/set_attributes_service.rb b/app/services/projects/set_attributes_service.rbindex 1d3ab77f052..f462098a567 100644--- a/app/services/projects/set_attributes_service.rb+++ b/app/services/projects/set_attributes_service.rb@@ -99,7 +99,7 @@ module Projectsenddef faulty_code?(attributes)- attributes && attributes[:code] && !Project::Status.codes.keys.include?(attributes[:code])+ attributes && attributes[:code] && !Project::Status.codes.keys.include?(attributes[:code].to_s)enddef first_not_set_codediff --git a/app/services/projects/update_service.rb b/app/services/projects/update_service.rbindex ac4afbd4574..b2e942ab381 100644--- a/app/services/projects/update_service.rb+++ b/app/services/projects/update_service.rb@@ -49,6 +49,7 @@ module Projectsnotify_on_identifier_renamedsend_update_notificationupdate_wp_versions_on_parent_change+ persist_statusservice_callend@@ -76,5 +77,9 @@ module ProjectsWorkPackage.update_versions_from_hierarchy_change(model)end++ def persist_status+ model.status.save if model.status.changed?+ endendenddiff --git a/spec/requests/api/v3/project_resource_spec.rb b/spec/requests/api/v3/project_resource_spec.rbindex 65df801d30a..954e50deca6 100644--- a/spec/requests/api/v3/project_resource_spec.rb+++ b/spec/requests/api/v3/project_resource_spec.rb@@ -484,7 +484,7 @@ describe 'API v3 Project resource', type: :request, content_type: :json doendend- context 'without permission to create projects' do+ context 'without permission to patch projects' dolet(:permissions) { [] }it 'responds with 403' do@@ -499,7 +499,43 @@ describe 'API v3 Project resource', type: :request, content_type: :json doendend- context 'with faulty params' do+ context 'with a status' do+ let(:body) do+ {+ status: {+ "code": "off track",+ "explanation": "Some explanation."+ }+ }+ end++ it 'alters the status' do+ expect(last_response.body)+ .to be_json_eql(+ {+ "code": "off track",+ "explanation": {+ "format": "markdown",+ "html": "<p>Some explanation.</p>",+ "raw": "Some explanation."+ }+ }.to_json+ )+ .at_path("status")+ end++ it 'persists the altered status' do+ project_status.reload++ expect(project_status.code)+ .to eql('off_track')++ expect(project_status.explanation)+ .to eql('Some explanation.')+ end+ end++ context 'with faulty name' dolet(:body) do{name: nil@@ -527,6 +563,37 @@ describe 'API v3 Project resource', type: :request, content_type: :json do.at_path('message')endend++ context 'with a faulty status' do+ let(:body) do+ {+ status: {+ "code": "bogus"+ }+ }+ end++ it 'responds with 422' do+ expect(last_response.status).to eq(422)+ end++ it 'does not change the project status' do+ code_before = project_status.code++ expect(project_status.reload.code)+ .to eql(code_before)+ end++ it 'denotes the error' do+ expect(last_response.body)+ .to be_json_eql('Error'.to_json)+ .at_path('_type')++ expect(last_response.body)+ .to be_json_eql("Status is not set to one of the allowed values.".to_json)+ .at_path('message')+ end+ endenddescribe '#delete /api/v3/projects/:id' dodiff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rbindex c5e97a89a97..29a130b8c45 100644--- a/spec/services/projects/update_service_spec.rb+++ b/spec/services/projects/update_service_spec.rb@@ -54,12 +54,17 @@ describe Projects::UpdateService, type: :model doerrors: set_attributes_errorsendlet!(:project) do- FactoryBot.build_stubbed(:project).tap do |p|+ FactoryBot.build_stubbed(:project, status: project_status).tap do |p|allow(p).to receive(:save).and_return(project_valid)++ project_status.clear_changes_informationendend+ let(:project_status) do+ FactoryBot.build_stubbed(:project_status)+ endlet!(:set_attributes_service) doservice = double('set_attributes_service_instance')@@ -145,6 +150,21 @@ describe Projects::UpdateService, type: :model doendend+ context 'if the project status is altered' do+ before do+ allow(project_status)+ .to receive(:changed?)+ .and_return(true)+ end++ it 'persists the changes' do+ expect(project_status)+ .to receive(:save)++ subject+ end+ end+context 'if the SetAttributeService is unsuccessful' dolet(:set_attributes_success) { false }