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
project status explanation now formattable property
ulferts16ee49bf8a3a
diff --git a/lib/api/v3/projects/project_representer.rb b/lib/api/v3/projects/project_representer.rbindex 01c6983f9a5..d888123211a 100644--- a/lib/api/v3/projects/project_representer.rb+++ b/lib/api/v3/projects/project_representer.rb@@ -1,4 +1,5 @@#-- encoding: UTF-8+#-- copyright# OpenProject is a project management system.# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)@@ -40,6 +41,8 @@ module APIinclude API::Decorators::FormattablePropertyextend ::API::V3::Utilities::CustomFieldInjector::RepresenterClass+ cached_representer key_parts: %i(status)+self_linklink :createWorkPackage,@@ -152,10 +155,13 @@ module APIdate_time_property :updated_at- property :status do- property :explanation- property :code- end+ property :status,+ render_nil: true,+ exec_context: :decorator,+ getter: ->(*) {+ ::API::V3::Projects::Status::ProjectStatusRepresenter.create(represented.status || Project::Status.new,+ current_user: current_user)+ }def _type'Project'diff --git a/lib/api/v3/projects/status/project_status_representer.rb b/lib/api/v3/projects/status/project_status_representer.rbnew file mode 100644index 00000000000..34121f7897b--- /dev/null+++ b/lib/api/v3/projects/status/project_status_representer.rb@@ -0,0 +1,48 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is a project management system.+# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2017 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++require 'roar/decorator'+require 'roar/json/hal'++module API+ module V3+ module Projects+ module Status+ class ProjectStatusRepresenter < ::API::Decorators::Single+ include API::Decorators::FormattableProperty++ formattable_property :explanation+ property :code,+ render_nil: true+ end+ end+ end+ end+enddiff --git a/spec/lib/api/v3/projects/project_representer_spec.rb b/spec/lib/api/v3/projects/project_representer_spec.rbindex 3d99222942d..0c02d1a3082 100644--- a/spec/lib/api/v3/projects/project_representer_spec.rb+++ b/spec/lib/api/v3/projects/project_representer_spec.rb@@ -120,10 +120,8 @@ describe ::API::V3::Projects::ProjectRepresenter doendcontext 'status' do- it 'includes the project status explanation' do- expect(subject)- .to be_json_eql(status.explanation.to_json)- .at_path('status/explanation')+ it_behaves_like 'formattable property', :'status/explanation' do+ let(:value) { status.explanation }endit 'includes the project status code' do@@ -131,6 +129,20 @@ describe ::API::V3::Projects::ProjectRepresenter do.to be_json_eql(status.code.to_json).at_path('status/code')end++ context 'if the status is nil' do+ let(:status) { nil }++ it_behaves_like 'formattable property', :'status/explanation' do+ let(:value) { nil }+ end++ it 'includes the project status code' do+ expect(subject)+ .to be_json_eql(nil.to_json)+ .at_path('status/code')+ end+ endendit_behaves_like 'has UTC ISO 8601 date and time' do@@ -446,6 +458,13 @@ describe ::API::V3::Projects::ProjectRepresenter doexpect(representer.json_cache_key).not_to eql former_cache_keyend++ it 'changes when the project status is updated' do+ project.status.updated_at = Time.now + 20.seconds++ expect(representer.json_cache_key)+ .not_to eql former_cache_key+ endendendenddiff --git a/spec/requests/api/v3/project_resource_spec.rb b/spec/requests/api/v3/project_resource_spec.rbindex f0e16c2b791..9cd1c7d0eb1 100644--- a/spec/requests/api/v3/project_resource_spec.rb+++ b/spec/requests/api/v3/project_resource_spec.rb@@ -107,7 +107,7 @@ describe 'API v3 Project resource', type: :request, content_type: :json doit 'includes the project status' doexpect(subject.body).to be_json_eql(project_status.explanation.to_json)- .at_path("status/explanation")+ .at_path("status/explanation/raw")expect(subject.body).to be_json_eql(project_status.code.to_json)