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

add project status

ulferts00bd5ec0abed
diff --git a/app/models/project/status.rb b/app/models/project/status.rb
new file mode 100644
index 00000000000..cee37a771ce
--- /dev/null
+++ b/app/models/project/status.rb
@@ -0,0 +1,39 @@
+#-- 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.
+#++
+
+class Project::Status < ActiveRecord::Base
+ belongs_to :project
+
+ validates :project,
+ presence: true,
+ uniqueness: true
+
+ enum code: %i[on_track at_risk off_track]
+end
diff --git a/db/migrate/20190923111902_add_project_status_reporting.rb b/db/migrate/20190923111902_add_project_status_reporting.rb
new file mode 100644
index 00000000000..d70d1a3b846
--- /dev/null
+++ b/db/migrate/20190923111902_add_project_status_reporting.rb
@@ -0,0 +1,9 @@
+class AddProjectStatusReporting < ActiveRecord::Migration[6.0]
+ def change
+ create_table :project_statuses do |table|
+ table.references :project, foreign_key: true, index: { unique: true }
+ table.text :description
+ table.integer :code
+ end
+ end
+end
diff --git a/lib/api/v3/user_preferences/user_preferences_representer.rb b/lib/api/v3/user_preferences/user_preferences_representer.rb
index 5735d37a50c..8dcfc61bf90 100644
--- a/lib/api/v3/user_preferences/user_preferences_representer.rb
+++ b/lib/api/v3/user_preferences/user_preferences_representer.rb
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
+
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
diff --git a/spec/models/project/status_spec.rb b/spec/models/project/status_spec.rb
new file mode 100644
index 00000000000..1f9ad63eed9
--- /dev/null
+++ b/spec/models/project/status_spec.rb
@@ -0,0 +1,90 @@
+#-- 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 'spec_helper'
+
+describe Project::Status, type: :model do
+ let(:project) { FactoryBot.create(:project) }
+
+ let(:description) { 'some description' }
+ let(:code) { :on_track }
+ let(:instance) { described_class.new description: description, code: code, project: project }
+
+ describe 'description' do
+ it 'stores a description' do
+ instance.save
+
+ instance.reload
+
+ expect(instance.description)
+ .to eql description
+ end
+ end
+
+ describe 'code' do
+ it 'stores a code as an enum' do
+ instance.save
+
+ instance.reload
+
+ expect(instance.on_track?)
+ .to be_truthy
+ end
+ end
+
+ describe 'project' do
+ it 'stores a project reference' do
+ instance.save
+
+ instance.reload
+
+ expect(instance.project)
+ .to eql project
+ end
+
+ it 'requires one' do
+ instance.project = nil
+
+ expect(instance)
+ .to be_invalid
+
+ expect(instance.errors.symbols_for(:project))
+ .to eql [:blank]
+ end
+
+ it 'cannot be one already having a status' do
+ described_class.create! description: 'some other description', code: :off_track, project: project
+
+ expect(instance)
+ .to be_invalid
+
+ expect(instance.errors.symbols_for(:project))
+ .to eql [:taken]
+ end
+ end
+end