diff --git a/app/models/service.rb b/app/models/service.rb index 2086a937177..6c58864ae23 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -50,8 +50,6 @@ class Service < ApplicationRecord delegate :custom_actions, :custom_action_buttons, :to => :service_template, :allow_nil => true delegate :provision_dialog, :to => :miq_request, :allow_nil => true delegate :user, :to => :miq_request, :allow_nil => true - delegate :atomic?, :to => :service_template - delegate :composite?, :to => :service_template include ServiceMixin include OwnershipMixin @@ -211,6 +209,14 @@ def power_states_match?(action) false end + def composite? + service_template ? service_template.composite? : children.present? + end + + def atomic? + service_template ? service_template.atomic? : children.empty? + end + def map_composite_power_states(action) action_name = "#{action}_action" service_actions = service_resources.map(&action_name.to_sym).uniq diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index 2d8aeaeebb7..993a76a61ce 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -501,9 +501,19 @@ it "returns children" do create_deep_tree expect(@service.children).to match_array([@service_c1, @service_c2]) + expect(@service.service_template).to be_nil + expect(@service.composite?).to be_truthy + expect(@service.atomic?).to be_falsey expect(@service.services).to match_array([@service_c1, @service_c2]) # alias expect(@service.direct_service_children).to match_array([@service_c1, @service_c2]) # alias end + + it "returns no children" do + @service = FactoryGirl.create(:service) + expect(@service.children).to be_empty + expect(@service.composite?).to be_falsey + expect(@service.atomic?).to be_truthy + end end describe "#indirect_service_children" do