Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename LifeCycle to Project::LifeCycleStepDefinition and co #17248

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, class_name: "Project::LifeCycle", dependent: :destroy
has_many :life_cycle_steps, class_name: "Project::LifeCycleStep", dependent: :destroy

store_attribute :settings, :deactivate_work_package_attachments, :boolean

Expand Down
2 changes: 1 addition & 1 deletion app/models/project/gate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++

class Project::Gate < Project::LifeCycle
class Project::Gate < Project::LifeCycleStep
alias_attribute :date, :start_date

validates :date, presence: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
# See COPYRIGHT and LICENSE files for more details.
#++

require "rails_helper"
require "support/shared/life_cycle_helpers"

RSpec.describe Gate do
it_behaves_like "a LifeCycle event"
class Project::GateDefinition < Project::LifeCycleStepDefinition
has_many :gates, # Alias for life_cycle_steps
class_name: "Project::Gate",
foreign_key: :definition_id,
inverse_of: :definition,
dependent: :destroy
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@
# See COPYRIGHT and LICENSE files for more details.
#++

class Project::LifeCycle < ApplicationRecord
class Project::LifeCycleStep < ApplicationRecord
belongs_to :project, optional: false
belongs_to :life_cycle, optional: false, class_name: "::LifeCycle"
has_many :work_packages, inverse_of: :project_life_cycle, dependent: :nullify
belongs_to :definition,
optional: false,
class_name: "Project::LifeCycleStepDefinition"
has_many :work_packages, inverse_of: :project_life_cycle_step, dependent: :nullify

attr_readonly :life_cycle_id
attr_readonly :definition_id

validates :type, inclusion: { in: %w[Project::Stage Project::Gate], message: :must_be_a_stage_or_gate }

def initialize(*args)
if instance_of? Project::LifeCycle
if instance_of? Project::LifeCycleStep
# Do not allow directly instantiating this class
raise NotImplementedError, "Cannot instantiate the base Project::LifeCycle class directly. " \
raise NotImplementedError, "Cannot instantiate the base Project::LifeCycleStep class directly. " \
"Use Project::Stage or Project::Gate instead."
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,25 @@
# See COPYRIGHT and LICENSE files for more details.
#++

class LifeCycle < ApplicationRecord
has_many :project_life_cycles, class_name: "Project::LifeCycle", dependent: :destroy
has_many :projects, through: :project_life_cycles

class Project::LifeCycleStepDefinition < ApplicationRecord
has_many :life_cycle_steps,
class_name: "Project::LifeCycleStep",
foreign_key: :definition_id,
inverse_of: :definition,
dependent: :destroy
has_many :projects, through: :life_cycle_steps
belongs_to :color, optional: false

validates :name, presence: true
validates :type, inclusion: { in: %w[Stage Gate], message: :must_be_a_stage_or_gate }
validates :type, inclusion: { in: %w[Project::StageDefinition Project::GateDefinition], message: :must_be_a_stage_or_gate }

acts_as_list

def initialize(*args)
if instance_of? LifeCycle
if instance_of? Project::LifeCycleStepDefinition
# Do not allow directly instantiating this class
raise NotImplementedError, "Cannot instantiate the base LifeCycle class directly. " \
"Use Stage or Gate instead."
raise NotImplementedError, "Cannot instantiate the base Project::LifeCycleStepDefinition class directly. " \
"Use Project::StageDefinition or Project::GateDefinition instead."
end

super
Expand Down
2 changes: 1 addition & 1 deletion app/models/project/stage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
# See COPYRIGHT and LICENSE files for more details.
#++

class Project::Stage < Project::LifeCycle
class Project::Stage < Project::LifeCycleStep
validates :start_date, :end_date, presence: true
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@
# See COPYRIGHT and LICENSE files for more details.
#++

class Gate < LifeCycle
class Project::StageDefinition < Project::LifeCycleStepDefinition
has_many :stages, # Alias for life_cycle_steps
class_name: "Project::Stage",
foreign_key: :definition_id,
inverse_of: :definition,
dependent: :destroy
end
30 changes: 0 additions & 30 deletions app/models/stage.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/models/work_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, class_name: "Project::LifeCycle", optional: true
belongs_to :project_life_cycle_step, class_name: "Project::LifeCycleStep", optional: true
belongs_to :priority, class_name: "IssuePriority"
belongs_to :category, class_name: "Category", optional: true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
# See COPYRIGHT and LICENSE files for more details.
#++
module BasicData
class LifeCycleSeeder < ModelSeeder
self.model_class = LifeCycle
class LifeCycleStepDefinitionSeeder < ModelSeeder
self.model_class = Project::LifeCycleStepDefinition
self.seed_data_model_key = "life_cycles"
self.needs = [
BasicData::LifeCycleColorSeeder
Expand Down
14 changes: 7 additions & 7 deletions app/seeders/standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,31 @@
life_cycles:
- reference: :default_life_cycle_initiating
t_name: Initiating
type: Stage
type: Project::StageDefinition
color_name: :default_color_pm2_orange
- reference: :default_life_cycle_ready_for_planning
t_name: Ready for Planning
type: Gate
type: Project::GateDefinition
color_name: :default_color_pm2_purple
- reference: :default_life_cycle_planning
t_name: Planning
type: Stage
type: Project::StageDefinition
color_name: :default_color_pm2_red
- reference: :default_life_cycle_ready_for_executing
t_name: Ready for Executing
type: Gate
type: Project::GateDefinition
color_name: :default_color_pm2_purple
- reference: :default_life_cycle_executing
t_name: Executing
type: Stage
type: Project::StageDefinition
color_name: :default_color_pm2_magenta
- reference: :default_life_cycle_ready_for_closing
t_name: Ready for Closing
type: Gate
type: Project::GateDefinition
color_name: :default_color_pm2_purple
- reference: :default_life_cycle_closing
t_name: Closing
type: Stage
type: Project::StageDefinition
color_name: :default_color_pm2_green_yellow

priorities:
Expand Down
2 changes: 1 addition & 1 deletion app/seeders/standard/basic_data_seeder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def data_seeder_classes
::BasicData::ColorSeeder,
::BasicData::ColorSchemeSeeder,
::BasicData::LifeCycleColorSeeder,
::BasicData::LifeCycleSeeder,
::BasicData::LifeCycleStepDefinitionSeeder,
::BasicData::WorkflowSeeder,
::BasicData::PrioritySeeder,
::BasicData::SettingSeeder,
Expand Down
12 changes: 6 additions & 6 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1069,10 +1069,6 @@ en:
name:
blank: "is mandatory. Please select a name."
not_unique: "is already in use. Please select another name."
life_cycle:
attributes:
type:
must_be_a_stage_or_gate: "must be either Stage or Gate"
meeting:
error_conflict: "Unable to save because the meeting was updated by someone else in the meantime. Please reload the page."
notifications:
Expand Down Expand Up @@ -1112,14 +1108,18 @@ en:
attributes:
project_ids:
blank: "Please select a project."
project/life_cycle:
project/life_cycle_step_definition:
attributes:
type:
must_be_a_stage_or_gate: "must be either Project::StageDefinition or Project::GateDefinition"
project/life_cycle_step:
attributes:
type:
must_be_a_stage_or_gate: "must be either Project::Stage or Project::Gate"
project/gate:
attributes:
base:
end_date_not_allowed: "Cannot assign `end_date` to a Gate"
end_date_not_allowed: "Cannot assign `end_date` to a Project::Gate"
query:
attributes:
project:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,28 @@
# See COPYRIGHT and LICENSE files for more details.
#++

class CreateLifeCycles < ActiveRecord::Migration[7.1]
class CreateProjectLifeCycles < ActiveRecord::Migration[7.1]
def change
create_table :life_cycles do |t|
create_table :project_life_cycle_step_definitions do |t|
t.string :type
t.string :name
t.integer :position, null: true
t.references :color, foreign_key: true

t.timestamps
end

create_table :project_life_cycle_steps do |t|
t.string :type
t.date :start_date
t.date :end_date
t.boolean :active, default: false, null: false
t.references :project, foreign_key: true
t.references :definition, foreign_key: { to_table: :project_life_cycle_step_definitions }

t.timestamps
end

add_reference :work_packages, :project_life_cycle_step, null: true
end
end
14 changes: 0 additions & 14 deletions db/migrate/20241105151352_create_project_life_cycles.rb

This file was deleted.

5 changes: 0 additions & 5 deletions db/migrate/20241105175000_add_life_cycle_to_work_packages.rb

This file was deleted.

2 changes: 1 addition & 1 deletion modules/bim/app/seeders/bim/basic_data_seeder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def data_seeder_classes
::BasicData::ColorSeeder,
::BasicData::ColorSchemeSeeder,
::BasicData::LifeCycleColorSeeder,
::BasicData::LifeCycleSeeder,
::BasicData::LifeCycleStepDefinitionSeeder,
::BasicData::WorkflowSeeder,
::BasicData::PrioritySeeder,
::Bim::BasicData::SettingSeeder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
#++

FactoryBot.define do
factory :life_cycle do
factory :project_life_cycle_step_definition, class: "Project::LifeCycleStepDefinition" do
color

factory :gate, class: "Gate" do
sequence(:name) { |n| "Gate No. #{n}" }
factory :project_gate_definition, class: "Project::GateDefinition" do
sequence(:name) { |n| "Gate Definition No. #{n}" }
end

factory :stage, class: "Stage" do
sequence(:name) { |n| "Stage No. #{n}" }
factory :project_stage_definition, class: "Project::StageDefinition" do
sequence(:name) { |n| "Stage Definition No. #{n}" }
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
#++

FactoryBot.define do
factory :project_life_cycle, class: "Project::LifeCycle" do
factory :project_life_cycle_step, class: "Project::LifeCycleStep" do
project
active { true }

factory :project_stage, class: "Project::Stage" do
life_cycle factory: :stage
definition factory: :project_stage_definition
start_date { Date.current - 2.days }
end_date { Date.current + 2.days }
end

factory :project_gate, class: "Project::Gate" do
life_cycle factory: :gate
definition factory: :project_gate_definition
date { Date.current + 2.days }
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@
#++

require "rails_helper"
require "support/shared/life_cycle_helpers"
require "support/shared/project_life_cycle_helpers"

RSpec.describe Stage do
it_behaves_like "a LifeCycle event"
RSpec.describe Project::GateDefinition do
it_behaves_like "a Project::LifeCycleStepDefinition event"

describe "associations" do
it "has many gates" do
expect(subject).to have_many(:gates).class_name("Project::Gate")
.with_foreign_key(:definition_id)
.inverse_of(:definition)
.dependent(:destroy)
end
end
end
5 changes: 3 additions & 2 deletions spec/models/project/gate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
require "support/shared/project_life_cycle_helpers"

RSpec.describe Project::Gate do
it_behaves_like "a Project::LifeCycle event"
it_behaves_like "a Project::LifeCycleStep event"

describe "validations" do
it { is_expected.to validate_presence_of(:date) }
Expand All @@ -39,7 +39,8 @@
gate_with_end_date = build(:project_gate, end_date: Time.zone.today)

expect(gate_with_end_date).not_to be_valid
expect(gate_with_end_date.errors[:base]).to include("Cannot assign `end_date` to a Gate")
expect(gate_with_end_date.errors[:base])
.to include("Cannot assign `end_date` to a Project::Gate")
end

it "is valid if `end_date` is not present" do
Expand Down
Loading
Loading