Skip to content

Commit

Permalink
Merge pull request #14000 from djberg96/vm_resource_group
Browse files Browse the repository at this point in the history
Add relationship between VM and ResourceGroup.
  • Loading branch information
Fryguy authored Mar 10, 2017
2 parents 4d8284f + 596d62b commit 02dc69f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/manageiq/providers/cloud_manager/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class ManageIQ::Providers::CloudManager::Vm < ::Vm
belongs_to :flavor
belongs_to :orchestration_stack
belongs_to :cloud_tenant
belongs_to :resource_group

has_many :network_ports, :as => :device
has_many :cloud_subnets, -> { distinct }, :through => :network_ports
Expand Down
1 change: 1 addition & 0 deletions app/models/resource_group.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class ResourceGroup < ApplicationRecord
has_many :vms
end
10 changes: 10 additions & 0 deletions spec/models/manageiq/providers/cloud_manager/vm_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
describe VmCloud do
subject { FactoryGirl.create(:vm_cloud) }

context "relationships" do
let(:resource_group) { FactoryGirl.create(:resource_group) }
before { subject.resource_group = resource_group }

it "has one resource group" do
expect(subject).to respond_to(:resource_group)
expect(subject.resource_group).to eql(resource_group)
end
end

it "#post_create_actions" do
expect(subject).to receive(:reconnect_events)
expect(subject).to receive(:classify_with_parent_folder_path)
Expand Down
30 changes: 30 additions & 0 deletions spec/models/resource_group_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe ResourceGroup do
let(:resource_group) do
FactoryGirl.create(
:resource_group,
:type => "ResourceGroup",
:name => "foo",
:ems_ref => "/subscriptions/xxx/resourceGroups/foo"
)
end

context "properties" do
it "has the expected resource group" do
expect(resource_group.type).to eql("ResourceGroup")
end

it "has the expected name" do
expect(resource_group.name).to eql("foo")
end

it "has the expected ems_ref" do
expect(resource_group.ems_ref).to eql("/subscriptions/xxx/resourceGroups/foo")
end
end

context "relationships" do
it "has many vms" do
expect(resource_group).to respond_to(:vms)
end
end
end

0 comments on commit 02dc69f

Please sign in to comment.