Skip to content

Commit

Permalink
Add a relationship between generic objects and services.
Browse files Browse the repository at this point in the history
  • Loading branch information
lfu committed Aug 3, 2017
1 parent c70bc53 commit 3fc4088
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Service < ApplicationRecord
virtual_has_many :all_vms
virtual_has_many :power_states, :uses => :all_vms
virtual_has_many :orchestration_stacks
virtual_has_many :generic_objects
virtual_total :v_total_vms, :vms

virtual_has_one :custom_actions
Expand Down Expand Up @@ -203,6 +204,10 @@ def orchestration_stacks
service_resources.where(:resource_type => 'OrchestrationStack').collect(&:resource)
end

def generic_objects
service_resources.where(:resource_type => 'GenericObject').includes(:resource).collect(&:resource)
end

def group_resource_actions(action_name)
[].tap do |sa|
each_group_resource do |svc_rsc|
Expand Down
12 changes: 12 additions & 0 deletions spec/models/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,18 @@
end
end

describe '#generic_objects' do
let(:service) { FactoryGirl.create(:service) }
let(:go_def) { FactoryGirl.create(:generic_object_definition, :properties => {:attributes => {:limit => :integer}}) }
let(:generic_object) { FactoryGirl.create(:generic_object, :generic_object_definition => go_def).tap { |g| g.property_attributes = {"limit" => 1} } }

before { service.add_resource!(generic_object) }

it 'returns the generic_objects ' do
expect(service.generic_objects).to eq([generic_object])
end
end

describe '#my_zone' do
let(:service) { FactoryGirl.create(:service) }

Expand Down

0 comments on commit 3fc4088

Please sign in to comment.