Skip to content

Commit

Permalink
Return custom buttons for service having nil service template
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Jul 13, 2018
1 parent d101c79 commit 32ad562
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
6 changes: 5 additions & 1 deletion app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 21 additions & 8 deletions spec/models/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 32ad562

Please sign in to comment.