Skip to content
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: 2 additions & 0 deletions .erb_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ linters:
- .rubocop.yml
Layout/InitialIndentation:
Enabled: false
Layout/LeadingEmptyLines:
Enabled: false
Layout/TrailingEmptyLines:
Enabled: false
Layout/TrailingWhitespace:
Expand Down
15 changes: 15 additions & 0 deletions app/decorators/enclosure_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class EnclosureDecorator < ApplicationDecorator
def display_name
composants = object.composants.pluck(:name)

composants_sentence = if composants.empty?
"0 #{Composant.model_name.human(count: 0).downcase}"
else
composants.map { |c| c.presence || "n/c" }.to_sentence
end

"#{object.class.model_name.human} #{position} (#{composants_sentence})"
end
end
1 change: 1 addition & 0 deletions app/models/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Cluster < ApplicationRecord
has_changelog

has_many :servers, dependent: :restrict_with_error
has_many :cluster_rooms, dependent: :destroy

scope :sorted, -> { order(Arel.sql("LOWER(name)")) }

Expand Down
2 changes: 1 addition & 1 deletion app/models/composant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Composant < ApplicationRecord
belongs_to :enclosure
has_one :modele, through: :enclosure

has_many :cards
has_many :cards, dependent: :restrict_with_error

validates :name, format: { without: /\s/ }, allow_blank: true

Expand Down
7 changes: 5 additions & 2 deletions app/models/frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ class Frame < ApplicationRecord # rubocop:disable Metrics/ClassLength
has_changelog

belongs_to :bay

has_one :islet, through: :bay
has_one :room, through: :islet

has_many :materials, -> { order("servers.position desc") }, class_name: "Server", dependent: :restrict_with_error
has_many :pdus, -> { only_pdus }, class_name: "Server", dependent: :restrict_with_error
has_many :servers, -> { no_pdus.order("servers.position desc") }, class_name: "Server", dependent: :restrict_with_error
has_one :islet, through: :bay
has_one :room, through: :islet

delegate :name, to: :room, prefix: true, allow_nil: true

validates :position, uniqueness: { scope: :bay_id }
Expand Down
9 changes: 5 additions & 4 deletions app/models/modele.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ class Modele < ApplicationRecord

has_changelog

has_many :servers, dependent: :restrict_with_error
has_many :enclosures, dependent: :restrict_with_error
has_many :composants, through: :enclosures

belongs_to :manufacturer, counter_cache: true
belongs_to :architecture, counter_cache: true
belongs_to :category, counter_cache: true

has_many :servers, dependent: :restrict_with_error
has_many :enclosures, dependent: :destroy

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe great to give a better display names for enclosure than #<Enclosure:0x0000000127f6a158>

Like Enclosure 1 (1 = position)

has_many :composants, through: :enclosures
has_many :cards, through: :composants

accepts_nested_attributes_for :enclosures,
allow_destroy: true,
reject_if: :all_blank
Expand Down
2 changes: 1 addition & 1 deletion app/models/port_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class PortType < ApplicationRecord
has_changelog

has_many :card_types
has_many :card_types, dependent: :restrict_with_error

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It missing the update of the test for the dependency


scope :sorted, -> { order(name: :asc) }

Expand Down
2 changes: 1 addition & 1 deletion app/models/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Server < ApplicationRecord # rubocop:disable Metrics/ClassLength
belongs_to :modele, counter_cache: true
has_one :manufacturer, through: :modele

has_many :cards, -> { joins(:composant).includes(:composant) }
has_many :cards, -> { joins(:composant).includes(:composant) }, dependent: :destroy
has_many :card_types, through: :cards
has_many :ports, through: :cards
has_many :connections, through: :ports
Expand Down
7 changes: 4 additions & 3 deletions app/views/clusters/destroy.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

<div class="col-12 p-4 border-top">
<%= render DeleteDependencyComponent.new(
@cluster,
confirmation_path: cluster_path(@cluster, confirm: true)
) %>
@cluster,
except: %i[cluster_rooms],
confirmation_path: cluster_path(@cluster, confirm: true),
) %>
</div>
7 changes: 4 additions & 3 deletions app/views/rooms/destroy.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

<div class="col-12 p-4 border-top">
<%= render DeleteDependencyComponent.new(
@room,
confirmation_path: room_path(@room, confirm: true)
) %>
@room,
except: %i[cluster_rooms],
confirmation_path: room_path(@room, confirm: true),
) %>
</div>
3 changes: 3 additions & 0 deletions config/locales/activerecord.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ en:
one: Network hub cluster
other: Network hub clusters
color: Color
composant:
one: Component
other: Components
connection: Connection
contact: Contact
contact_assignment: Assignment
Expand Down
3 changes: 3 additions & 0 deletions config/locales/activerecord.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ fr:
other: Châssis
modele: Modèle
category: Catégorie
composant:
one: Composant
other: Composants
air_conditioner: Climatisation
air_conditioner_model: Modèle de climatisation
architecture: Architecture
Expand Down
26 changes: 26 additions & 0 deletions spec/decorators/enclosure_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require "rails_helper"

describe EnclosureDecorator, type: :decorator do
let(:object) { enclosures(:one) }
let(:decorated_user) { described_class.new(object) }

describe "#display_name" do
it { expect(decorated_user.display_name).to eq("Enclosure 1 (compo1, compo2 et SL3)") }

context "without composants" do
let(:object) { Enclosure.new(position: 1) }

it { expect(decorated_user.display_name).to eq("Enclosure 1 (0 composant)") }
end

context "with composant with empty name" do
let(:object) { Enclosure.new(position: 1) }

before { allow(object).to receive(:composants).and_return([Composant.new]) }

it { expect(decorated_user.display_name).to eq("Enclosure 1 (n/c)") }
end
end
end
3 changes: 2 additions & 1 deletion spec/models/cluster_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
it_behaves_like "changelogable", new_attributes: { name: "New name" }

describe "associations" do
it { is_expected.to have_many(:servers) }
it { is_expected.to have_many(:servers).dependent(:restrict_with_error) }
it { is_expected.to have_many(:cluster_rooms).dependent(:destroy) }
end

describe "#to_s" do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/composant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
describe "associations" do
it { is_expected.to belong_to(:enclosure) }
it { is_expected.to have_one(:modele).through(:enclosure) }
it { is_expected.to have_many(:cards) }
it { is_expected.to have_many(:cards).dependent(:restrict_with_error) }
end

describe "validations" do
Expand Down
8 changes: 5 additions & 3 deletions spec/models/frame_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
it { is_expected.to belong_to(:bay) }

it { is_expected.to have_one(:islet).through(:bay) }
it { is_expected.to have_many(:materials) }
it { is_expected.to have_many(:pdus) }
it { is_expected.to have_many(:servers) }
it { is_expected.to have_one(:room).through(:islet) }

it { is_expected.to have_many(:materials).dependent(:restrict_with_error) }
it { is_expected.to have_many(:pdus).dependent(:restrict_with_error) }
it { is_expected.to have_many(:servers).dependent(:restrict_with_error) }
end

describe "validations" do
Expand Down
6 changes: 4 additions & 2 deletions spec/models/modele_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
it { is_expected.to belong_to(:manufacturer) }
it { is_expected.to belong_to(:architecture) }
it { is_expected.to belong_to(:category) }
it { is_expected.to have_many(:servers) }
it { is_expected.to have_many(:enclosures) }

it { is_expected.to have_many(:servers).dependent(:restrict_with_error) }
it { is_expected.to have_many(:enclosures).dependent(:destroy) }
it { is_expected.to have_many(:composants).through(:enclosures) }
it { is_expected.to have_many(:cards).through(:composants) }
end

describe "#validate_network_types_values" do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/port_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
it_behaves_like "changelogable", new_attributes: { name: "New name" }

describe "associations" do
it { is_expected.to have_many(:card_types) }
it { is_expected.to have_many(:card_types).dependent(:restrict_with_error) }
end

describe "#is_power_input?" do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
it { is_expected.to have_one(:room).through(:islet) }
it { is_expected.to have_one(:manufacturer).through(:modele) }

it { is_expected.to have_many(:cards) }
it { is_expected.to have_many(:cards).dependent(:destroy) }
it { is_expected.to have_many(:card_types).through(:cards) }
it { is_expected.to have_many(:ports).through(:cards) }
it { is_expected.to have_many(:connections).through(:ports) }
Expand Down
Loading