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

Use ::Project namespace for LifeCycle, Stage and Gate

Dombi Attila7f458c71f6ac
diff --git a/app/models/life_cycle.rb b/app/models/life_cycle.rb
index 5744a30b914..ec88b5ff43c 100644
--- a/app/models/life_cycle.rb
+++ b/app/models/life_cycle.rb
@@ -27,7 +27,7 @@
#++
class LifeCycle < ApplicationRecord
- has_many :project_life_cycles, dependent: :destroy
+ has_many :project_life_cycles, class_name: "Project::LifeCycle", dependent: :destroy
has_many :projects, through: :project_life_cycles
belongs_to :color, optional: false
diff --git a/app/models/project.rb b/app/models/project.rb
index 0ce2162dcdd..0893018a0ba 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -86,7 +86,7 @@ class Project < ApplicationRecord
has_many :notification_settings, dependent: :destroy
has_many :project_storages, dependent: :destroy, class_name: "Storages::ProjectStorage"
has_many :storages, through: :project_storages
- has_many :project_life_cycles, dependent: :destroy
+ has_many :project_life_cycles, class_name: "Project::LifeCycle", dependent: :destroy
has_many :life_cycles, through: :project_life_cycles
store_attribute :settings, :deactivate_work_package_attachments, :boolean
diff --git a/app/models/projects/gate.rb b/app/models/project/gate.rb
similarity index 97%
rename from app/models/projects/gate.rb
rename to app/models/project/gate.rb
index 9559b4c115c..1aef0ec5464 100644
--- a/app/models/projects/gate.rb
+++ b/app/models/project/gate.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Projects::Gate < ProjectLifeCycle
+class Project::Gate < Project::LifeCycle
validates :date, presence: true
validate :validate_restricted_attributes
diff --git a/app/models/project_life_cycle.rb b/app/models/project/life_cycle.rb
similarity index 78%
rename from app/models/project_life_cycle.rb
rename to app/models/project/life_cycle.rb
index 74fa6df3f00..377dbe00e09 100644
--- a/app/models/project_life_cycle.rb
+++ b/app/models/project/life_cycle.rb
@@ -26,18 +26,18 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class ProjectLifeCycle < ApplicationRecord
+class Project::LifeCycle < ApplicationRecord
belongs_to :project, optional: false
belongs_to :life_cycle, optional: false
- has_many :work_packages, dependent: :nullify
+ has_many :work_packages, foreign_key: :project_life_cycle_id, dependent: :nullify
- validates :type, inclusion: { in: %w[Projects::Stage Projects::Gate], message: :must_be_a_stage_or_gate }
+ validates :type, inclusion: { in: %w[Project::Stage Project::Gate], message: :must_be_a_stage_or_gate }
def initialize(*args)
- if instance_of? ProjectLifeCycle
+ if instance_of? Project::LifeCycle
# Do not allow directly instantiating this class
- raise NotImplementedError, "Cannot instantiate the base ProjectLifeCycle class directly. " \
- "Use Projects::Stage or Projects::Gate instead."
+ raise NotImplementedError, "Cannot instantiate the base Project::LifeCycle class directly. " \
+ "Use Project::Stage or Project::Gate instead."
end
super
diff --git a/app/models/projects/stage.rb b/app/models/project/stage.rb
similarity index 97%
rename from app/models/projects/stage.rb
rename to app/models/project/stage.rb
index 0532653795c..31a82be13ff 100644
--- a/app/models/projects/stage.rb
+++ b/app/models/project/stage.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Projects::Stage < ProjectLifeCycle
+class Project::Stage < Project::LifeCycle
validates :start_date, :end_date, presence: true
validate :validate_restricted_attributes
diff --git a/app/models/work_package.rb b/app/models/work_package.rb
index 9f5c2f2c046..c8a2e7a98e7 100644
--- a/app/models/work_package.rb
+++ b/app/models/work_package.rb
@@ -54,7 +54,7 @@ class WorkPackage < ApplicationRecord
belongs_to :assigned_to, class_name: "Principal", optional: true
belongs_to :responsible, class_name: "Principal", optional: true
belongs_to :version, optional: true
- belongs_to :project_life_cycle, optional: true
+ belongs_to :project_life_cycle, class_name: "Project::LifeCycle", optional: true
belongs_to :priority, class_name: "IssuePriority"
belongs_to :category, class_name: "Category", optional: true
diff --git a/config/locales/en.yml b/config/locales/en.yml
index c02f52111cd..2644d868e04 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1110,15 +1110,15 @@ en:
attributes:
project_ids:
blank: "Please select a project."
- project_life_cycle:
+ project/life_cycle:
attributes:
type:
must_be_a_stage_or_gate: "must be either Stage or Gate"
- projects/gate:
+ project/gate:
attributes:
base:
date_range_not_allowed: "Cannot assign `start_date` or `end_date` to a Gate"
- projects/stage:
+ project/stage:
attributes:
base:
date_not_allowed: "Cannot assign `date` to a Stage"
diff --git a/spec/factories/project_life_cycle_factory.rb b/spec/factories/project_life_cycle_factory.rb
index abe1ce59cf6..f96a7c160ac 100644
--- a/spec/factories/project_life_cycle_factory.rb
+++ b/spec/factories/project_life_cycle_factory.rb
@@ -27,16 +27,16 @@
#++
FactoryBot.define do
- factory :project_life_cycle do
+ factory :project_life_cycle, class: "Project::LifeCycle" do
project
life_cycle
- factory :project_stage, class: "::Projects::Stage" do
+ factory :project_stage, class: "Project::Stage" do
start_date { Date.current - 2.days }
end_date { Date.current + 2.days }
end
- factory :project_gate, class: "::Projects::Gate" do
+ factory :project_gate, class: "Project::Gate" do
date { Date.current + 2.days }
end
end
diff --git a/spec/models/projects/life_cycle_spec.rb b/spec/models/life_cycle_spec.rb
similarity index 100%
rename from spec/models/projects/life_cycle_spec.rb
rename to spec/models/life_cycle_spec.rb
diff --git a/spec/models/projects/gate_spec.rb b/spec/models/project/gate_spec.rb
similarity index 96%
rename from spec/models/projects/gate_spec.rb
rename to spec/models/project/gate_spec.rb
index 333c9b0ee29..b4408cd86bc 100644
--- a/spec/models/projects/gate_spec.rb
+++ b/spec/models/project/gate_spec.rb
@@ -29,8 +29,8 @@
require "rails_helper"
require "support/shared/project_life_cycle_helpers"
-RSpec.describe Projects::Gate do
- it_behaves_like "a ProjectLifeCycle event"
+RSpec.describe Project::Gate do
+ it_behaves_like "a Project::LifeCycle event"
describe "validations" do
it { is_expected.to validate_presence_of(:date) }
diff --git a/spec/models/project_life_cycle_spec.rb b/spec/models/project/life_cycle_spec.rb
similarity index 93%
rename from spec/models/project_life_cycle_spec.rb
rename to spec/models/project/life_cycle_spec.rb
index 13b636699f9..48de1751bf3 100644
--- a/spec/models/project_life_cycle_spec.rb
+++ b/spec/models/project/life_cycle_spec.rb
@@ -28,7 +28,7 @@
require "rails_helper"
-RSpec.describe ProjectLifeCycle do
+RSpec.describe Project::LifeCycle do
it "cannot be instantiated" do
expect { described_class.new }.to raise_error(NotImplementedError)
end
@@ -38,7 +38,7 @@ RSpec.describe ProjectLifeCycle do
end
it "can be instantiated with a valid type" do
- expect { described_class.new(type: "Projects::Gate") }.not_to raise_error
+ expect { described_class.new(type: "Project::Gate") }.not_to raise_error
end
# For more specs see:
diff --git a/spec/models/projects/stage_spec.rb b/spec/models/project/stage_spec.rb
similarity index 95%
rename from spec/models/projects/stage_spec.rb
rename to spec/models/project/stage_spec.rb
index d3c988a4a4d..6e2ac4f2ee6 100644
--- a/spec/models/projects/stage_spec.rb
+++ b/spec/models/project/stage_spec.rb
@@ -29,8 +29,8 @@
require "rails_helper"
require "support/shared/project_life_cycle_helpers"
-RSpec.describe Projects::Stage do
- it_behaves_like "a ProjectLifeCycle event"
+RSpec.describe Project::Stage do
+ it_behaves_like "a Project::LifeCycle event"
describe "validations" do
it { is_expected.to validate_presence_of(:start_date) }
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index e168340094a..01e21868959 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -382,14 +382,8 @@ RSpec.describe Project do
end
describe "life_cycles" do
- it { is_expected.to have_many(:project_life_cycles).dependent(:destroy) }
-
- it do
- expect(subject)
- .to have_many(:life_cycles)
- .through(:project_life_cycles)
- .class_name("Projects::LifeCycle")
- end
+ it { is_expected.to have_many(:project_life_cycles).class_name("Project::LifeCycle").dependent(:destroy) }
+ it { is_expected.to have_many(:life_cycles).through(:project_life_cycles) }
end
describe "#enabled_module_names=", with_settings: { default_projects_modules: %w(work_package_tracking repository) } do
diff --git a/spec/models/work_package_spec.rb b/spec/models/work_package_spec.rb
index 7c247ab052a..f7feedf0786 100644
--- a/spec/models/work_package_spec.rb
+++ b/spec/models/work_package_spec.rb
@@ -70,7 +70,7 @@ RSpec.describe WorkPackage do
it { is_expected.to belong_to(:assigned_to).class_name("Principal").optional }
it { is_expected.to belong_to(:responsible).class_name("Principal").optional }
it { is_expected.to belong_to(:version).optional }
- it { is_expected.to belong_to(:life_cycle).optional }
+ it { is_expected.to belong_to(:project_life_cycle).class_name("Project::LifeCycle").optional }
it { is_expected.to belong_to(:priority).class_name("IssuePriority") }
it { is_expected.to belong_to(:category).optional }
it { is_expected.to have_many(:time_entries).dependent(:delete_all) }
diff --git a/spec/support/shared/project_life_cycle_helpers.rb b/spec/support/shared/project_life_cycle_helpers.rb
index 9201b7416ec..2a657268c03 100644
--- a/spec/support/shared/project_life_cycle_helpers.rb
+++ b/spec/support/shared/project_life_cycle_helpers.rb
@@ -26,9 +26,9 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-RSpec.shared_examples_for "a ProjectLifeCycle event" do
- it "inherits from ProjectLifeCycle" do
- expect(described_class < ProjectLifeCycle).to be true
+RSpec.shared_examples_for "a Project::LifeCycle event" do
+ it "inherits from Project::LifeCycle" do
+ expect(described_class < Project::LifeCycle).to be true
end
describe "associations" do