Skip to content

Commit

Permalink
GuestDevice#parent_device
Browse files Browse the repository at this point in the history
To be honest, I only added this to make rubocop happy.
But it did feel like it was missing and made the specs a little prettier.
  • Loading branch information
kbrock committed Aug 22, 2023
1 parent 7299d1a commit 732039f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/models/guest_device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ class GuestDevice < ApplicationRecord

belongs_to :switch # pNICs link to one switch
belongs_to :lan # vNICs link to one lan
belongs_to :parent_device, :class_name => "GuestDevice"

has_one :network, :foreign_key => "device_id", :dependent => :destroy, :inverse_of => :guest_device
has_many :miq_scsi_targets, :dependent => :destroy

has_many :firmwares, :dependent => :destroy
has_many :child_devices, :foreign_key => "parent_device_id", :class_name => "GuestDevice", :dependent => :destroy
has_many :child_devices, :foreign_key => "parent_device_id", :class_name => "GuestDevice", :dependent => :destroy, :inverse_of => :parent_device

has_many :physical_network_ports, :dependent => :destroy
has_many :connected_physical_switches, :through => :physical_network_ports
Expand Down
4 changes: 2 additions & 2 deletions spec/models/guest_device_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
describe "#child_device" do
it "brings back children" do
parent = FactoryBot.create(:guest_device)
child1 = FactoryBot.create(:guest_device, :parent_device_id => parent.id)
child2 = FactoryBot.create(:guest_device, :parent_device_id => parent.id)
child1 = FactoryBot.create(:guest_device, :parent_device => parent)
child2 = FactoryBot.create(:guest_device, :parent_device => parent)
FactoryBot.create(:guest_device) # sad path (though the let! probably created lots of those)

expect(parent.reload.child_devices).to match_array([child1, child2])
Expand Down

0 comments on commit 732039f

Please sign in to comment.