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 16, 2018
1 parent f07d954 commit db92445
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
6 changes: 5 additions & 1 deletion app/models/mixins/custom_actions_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def generic_button_group
end

def custom_button_sets_with_generics
custom_button_sets + generic_button_group.map(&:parent).uniq.flatten
custom_button_sets_list + generic_button_group.map(&:parent).uniq.flatten
end

def custom_button_sets_list
CustomButtonSet.all.select { |f| f.set_data[:applies_to_class] == self.class.base_model.name }
end

def custom_buttons
Expand Down
5 changes: 3 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

prepend CustomActionsMixin
include ServiceMixin
include OwnershipMixin
include CustomAttributeMixin
Expand Down Expand Up @@ -105,11 +106,11 @@ def power_states
end

def custom_actions
service_template&.custom_actions(self)
service_template ? service_template.custom_action_buttons(self) : service.custom_actions
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 => CustomButton.where(:applies_to_class => "Service"), :button_groups => [])
end
end
end
end
Expand Down

0 comments on commit db92445

Please sign in to comment.