From 32ad562bc26a44a21a10e37bddce417e17a8b734 Mon Sep 17 00:00:00 2001 From: d-m-u Date: Fri, 13 Jul 2018 10:55:22 -0400 Subject: [PATCH] Return custom buttons for service having nil service template --- app/models/service.rb | 6 +++++- spec/models/service_spec.rb | 29 +++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/models/service.rb b/app/models/service.rb index aadae8a127be..ea55b4e01dce 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -109,7 +109,11 @@ def custom_actions end def custom_action_buttons - service_template&.custom_action_buttons(self) + if service_template.nil? + CustomButton.where(:applies_to_class => "Service") + else + service_template.custom_action_buttons(self) + end end def power_state diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index 64b4f312fff3..296e004a56cf 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -826,17 +826,30 @@ def create_deep_tree let(:service_template) { FactoryGirl.create(:service_template) } let(:service) { FactoryGirl.create(:service, :service_template => service_template) } - describe "#custom_actions" do - it "get list of custom actions from linked service template" do - expect(service_template).to receive(:custom_actions) - service.custom_actions + context "with template" do + describe "#custom_actions" do + it "get list of custom actions from linked service template" do + expect(service_template).to receive(:custom_actions) + service.custom_actions + end + end + + describe "#custom_action_buttons" do + it "get list of custom action buttons from linked service template" do + expect(service_template).to receive(:custom_action_buttons) + service.custom_action_buttons + end end end - describe "#custom_action_buttons" do - it "get list of custom action buttons from linked service template" do - expect(service_template).to receive(:custom_action_buttons) - service.custom_action_buttons + context "without valid template" do + let!(:custom_button) { FactoryGirl.create(:custom_button, :applies_to_class => "Service") } + let(:service) { FactoryGirl.create(:service, :service_template_id => -1) } + + describe "#custom_action_buttons" do + it "get list of custom action buttons on services" do + expect(service.custom_action_buttons).to include(custom_button) + end end end end