diff --git a/app/models/switch.rb b/app/models/switch.rb index 3c808c41611..f3a48b87127 100644 --- a/app/models/switch.rb +++ b/app/models/switch.rb @@ -3,6 +3,7 @@ class Switch < ApplicationRecord include CustomActionsMixin belongs_to :host, :inverse_of => :host_virtual_switches + has_one :ext_management_system, :through => :host has_many :host_switches, :dependent => :destroy has_many :hosts, :through => :host_switches diff --git a/spec/models/switch_spec.rb b/spec/models/switch_spec.rb new file mode 100644 index 00000000000..b0c7cd974a3 --- /dev/null +++ b/spec/models/switch_spec.rb @@ -0,0 +1,9 @@ +RSpec.describe Switch do + let(:ems) { FactoryBot.create(:ext_management_system) } + let(:host) { FactoryBot.create(:host, :ext_management_system => ems) } + let(:switch) { FactoryBot.create(:switch, :host => host) } + + it "#ext_management_system" do + expect(switch.ext_management_system).to eq(ems) + end +end