diff --git a/app/models/service_template.rb b/app/models/service_template.rb index f4b33111d66..9f8dafa5f10 100644 --- a/app/models/service_template.rb +++ b/app/models/service_template.rb @@ -183,15 +183,15 @@ def create_service(service_task, parent_svc = nil) (nh.keys - Service.column_names + %w(created_at guid service_template_id updated_at id type prov_type)).each { |key| nh.delete(key) } # Hide child services by default - nh[:display] = false if parent_svc + nh['display'] = false if parent_svc # If display is nil, set it to false - nh[:display] = false if nh[:display].nil? + nh['display'] ||= false # convert template class name to service class name by naming convention - nh[:type] = self.class.name.sub('Template', '') + nh['type'] = self.class.name.sub('Template', '') - nh[:initiator] = service_task.options[:initiator] if service_task.options[:initiator] + nh['initiator'] = service_task.options[:initiator] if service_task.options[:initiator] # Determine service name # target_name = self.get_option(:target_name) diff --git a/spec/models/service_template_spec.rb b/spec/models/service_template_spec.rb index 65893692a9d..9cc20c4f436 100644 --- a/spec/models/service_template_spec.rb +++ b/spec/models/service_template_spec.rb @@ -193,6 +193,22 @@ @svc_a.create_service(sub_svc) end + + it "should pass display attribute to created top level service" do + @svc_a.display = true + expect(@svc_a.create_service(double(:options => {:dialog => {}})).display).to eq(true) + end + + it "should set created child service's display to false" do + @svc_a.display = true + allow(@svc_b).to receive(:add_resource!) + expect(@svc_a.create_service(double(:options => {:dialog => {}}), @svc_b).display).to eq(false) + end + + it "should set created service's display to false by default" do + expect(@svc_a.create_service(double(:options => {:dialog => {}})).display).to eq(false) + end + it "should return all parent services for a service" do add_and_save_service(@svc_a, @svc_b) add_and_save_service(@svc_a, @svc_c)