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
introduce project representer for rendering
ulfertsb41196e87aaf
diff --git a/modules/bcf/app/controllers/bcf/api/v2_1/projects_api.rb b/modules/bcf/app/controllers/bcf/api/v2_1/projects_api.rbindex e38e3f1fcd8..29f9f6955c7 100644--- a/modules/bcf/app/controllers/bcf/api/v2_1/projects_api.rb+++ b/modules/bcf/app/controllers/bcf/api/v2_1/projects_api.rb@@ -37,10 +37,8 @@ module Bcf::API::V2_1endget do- {- project_id: @project.id,- name: @project.name- }+ Bcf::API::V2_1::Projects::SingleRepresenter+ .new(@project)endendenddiff --git a/modules/bcf/app/representers/bcf/api/v2_1/projects/single_representer.rb b/modules/bcf/app/representers/bcf/api/v2_1/projects/single_representer.rbnew file mode 100644index 00000000000..5d6c089b936--- /dev/null+++ b/modules/bcf/app/representers/bcf/api/v2_1/projects/single_representer.rb@@ -0,0 +1,40 @@+#-- 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.+#++++module Bcf::API::V2_1+ class Projects::SingleRepresenter < Roar::Decorator+ include Representable::JSON++ property :id,+ as: :project_id++ property :name+ end+enddiff --git a/modules/bcf/spec/representers/bcf/api/v2_1/projects/single_representer_rendering_spec.rb b/modules/bcf/spec/representers/bcf/api/v2_1/projects/single_representer_rendering_spec.rbnew file mode 100644index 00000000000..af65f29ed26--- /dev/null+++ b/modules/bcf/spec/representers/bcf/api/v2_1/projects/single_representer_rendering_spec.rb@@ -0,0 +1,62 @@+#-- copyright+# OpenProject is a project management system.+# Copyright (C) 2012-2019 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 'spec_helper'++describe Bcf::API::V2_1::Projects::SingleRepresenter, 'rendering' do+ let(:project) { FactoryBot.build_stubbed(:project) }+ let(:user) { FactoryBot.build_stubbed(:project) }++ let(:instance) { described_class.new(project) }++ subject { instance.to_json }++ shared_examples_for 'attribute' do+ it 'reflects the project' do+ expect(subject)+ .to be_json_eql(value.to_json)+ .at_path(path)+ end+ end++ describe 'attributes' do+ context 'project_id' do+ it_behaves_like 'attribute' do+ let(:value) { project.id }+ let(:path) { 'project_id' }+ end+ end++ context 'name' do+ it_behaves_like 'attribute' do+ let(:value) { project.name }+ let(:path) { 'name' }+ end+ end+ end+end