Skip to content
Draft
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
5 changes: 5 additions & 0 deletions app/models/frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class Frame < ApplicationRecord # rubocop:disable Metrics/ClassLength
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

# TODO: Confirm this should be present and that we use dependent nullify. If yes, then we should update schema too.
has_many :target_moves, class_name: "Move", inverse_of: :frame, dependent: :nullify
has_many :origin_moves, class_name: "Move", foreign_key: :prev_frame_id, inverse_of: :prev_frame, dependent: :nullify

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

validates :position, uniqueness: { scope: :bay_id }
Expand Down
10 changes: 7 additions & 3 deletions spec/models/frame_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
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) }
it { is_expected.to have_many(:target_moves).dependent(:nullify) }
it { is_expected.to have_many(:origin_moves).dependent(:nullify) }
end

describe "validations" do
Expand Down
Loading