From 994844b5cbb7e2dea0d68d2b9d7e5a0f39346a7b 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 | 31 +++++++++++++++++++++++-------- 2 files changed, 28 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..f9001e889607 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -826,17 +826,32 @@ 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 + @custom_button = CustomButton.create(:name => "drewasdfafs", :description => "drewtwoasfda", :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).to receive(:custom_action_buttons).and_return(@custom_button) + service.custom_action_buttons + end end end end