Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return custom buttons for service having nil service template #17703

Merged
merged 1 commit into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Service < ApplicationRecord
delegate :provision_dialog, :to => :miq_request, :allow_nil => true
delegate :user, :to => :miq_request, :allow_nil => true

include CustomActionsMixin
include ServiceMixin
include OwnershipMixin
include CustomAttributeMixin
Expand Down Expand Up @@ -104,12 +105,14 @@ def power_states
vms.map(&:power_state)
end

# renaming method from custom_actions_mixin
alias_method :custom_service_actions, :custom_actions
def custom_actions
service_template&.custom_actions(self)
service_template ? service_template.custom_actions(self) : custom_service_actions(self)
end

def custom_action_buttons
service_template&.custom_action_buttons(self)
service_template ? service_template.custom_action_buttons(self) : generic_custom_buttons
end

def power_state
Expand Down
35 changes: 27 additions & 8 deletions spec/models/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -826,17 +826,36 @@ 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 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

describe "#custom_actions" do
it "get list of custom actions on services" do
expect(service.custom_actions).to include(:buttons => [a_hash_including("id" => custom_button.id)], :button_groups => [])
end
end
end
end
Expand Down