Skip to content

Commit

Permalink
Merge pull request ManageIQ#22670 from kbrock/guest_devices
Browse files Browse the repository at this point in the history
fix GuestDevice#child_device references
  • Loading branch information
agrare committed Aug 22, 2023
2 parents f6b1d9b + 732039f commit eacd100
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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, -> { where(:parent_device_id => ids) }, :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
11 changes: 11 additions & 0 deletions spec/models/guest_device_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,15 @@
expect(template_gd.host).to be_nil
expect(host_gd.host).to eq(host)
end

describe "#child_device" do
it "brings back children" do
parent = FactoryBot.create(:guest_device)
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])
end
end
end

0 comments on commit eacd100

Please sign in to comment.