diff --git a/app/models/concerns/foreman_rescue/provisioning_template_extensions.rb b/app/models/concerns/foreman_rescue/provisioning_template_extensions.rb index 70862de..37c3b11 100644 --- a/app/models/concerns/foreman_rescue/provisioning_template_extensions.rb +++ b/app/models/concerns/foreman_rescue/provisioning_template_extensions.rb @@ -2,7 +2,7 @@ module ForemanRescue module ProvisioningTemplateExtensions - def self.templates_by_kind(kind) + def templates_by_kind(kind) template_kind = TemplateKind.find_by(name: kind) ProvisioningTemplate.where(:template_kind => template_kind).pluck(:name, :name).to_h end diff --git a/lib/foreman_rescue/engine.rb b/lib/foreman_rescue/engine.rb index 8a5a887..5f01509 100644 --- a/lib/foreman_rescue/engine.rb +++ b/lib/foreman_rescue/engine.rb @@ -54,7 +54,7 @@ class Engine < ::Rails::Engine Host::Managed.prepend ForemanRescue::HostExtensions HostsHelper.prepend ForemanRescue::HostsHelperExtensions Nic::Managed.prepend ForemanRescue::Orchestration::TFTP - ProvisioningTemplate.prepend ForemanRescue::ProvisioningTemplateExtensions + ProvisioningTemplate.singleton_class.prepend ForemanRescue::ProvisioningTemplateExtensions rescue StandardError => e Rails.logger.warn "ForemanRescue: skipping engine hook (#{e})" end diff --git a/test/models/provisioning_template_test.rb b/test/models/provisioning_template_test.rb new file mode 100644 index 0000000..f348877 --- /dev/null +++ b/test/models/provisioning_template_test.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'test_plugin_helper' + +class ProvisioningHostTest < ActiveSupport::TestCase + setup do + User.current = FactoryBot.build(:user, :admin) + disable_orchestration + end + + context 'provisioning template query' do + context 'with type PXELinux' do + let(:type) do + 'PXELinux' + end + + test 'should return templates' do + templates = ProvisioningTemplate.templates_by_kind(type) + + assert_includes templates, 'PXE Default Menu' + assert_includes templates, 'PXELinux default local boot' + assert_includes templates, 'PXELinux global default' + end + end + end +end