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 994844b
Show file tree
Hide file tree
Showing 2 changed files with 28 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
31 changes: 23 additions & 8 deletions spec/models/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 994844b

Please sign in to comment.