diff --git a/app/models/frame.rb b/app/models/frame.rb index 41ccc7dc4..33be68303 100644 --- a/app/models/frame.rb +++ b/app/models/frame.rb @@ -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 } diff --git a/spec/models/frame_spec.rb b/spec/models/frame_spec.rb index 855eee60b..16e553869 100644 --- a/spec/models/frame_spec.rb +++ b/spec/models/frame_spec.rb @@ -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