Skip to content

Commit

Permalink
Merge pull request #22902 from kbrock/supports_orders
Browse files Browse the repository at this point in the history
transition supports_orderable? to support?(:order)
  • Loading branch information
agrare committed Feb 23, 2024
2 parents 5ef4381 + dd2ac43 commit 7affc6b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
3 changes: 3 additions & 0 deletions app/models/orchestration_template.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'digest/md5'
class OrchestrationTemplate < ApplicationRecord
include SupportsFeatureMixin
include NewWithTypeStiMixin

acts_as_miq_taggable
Expand All @@ -19,6 +20,8 @@ class OrchestrationTemplate < ApplicationRecord

before_destroy :check_not_in_use

supports(:order) { _("Template not orderable") unless orderable? }

attr_accessor :remote_proxy
alias remote_proxy? remote_proxy

Expand Down
8 changes: 6 additions & 2 deletions app/models/service_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ class ServiceTemplate < ApplicationRecord
'Service template is not configured to be displayed'
end
end
alias orderable? supports_order?
alias validate_order supports_order?

# ui-classic calls "validate_#{action}"
def validate_order
supports?(:order)
end

alias orderable? validate_order

def self.with_tenant(tenant_id)
tenant = Tenant.find(tenant_id)
Expand Down
22 changes: 16 additions & 6 deletions spec/models/orchestration_template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
RSpec.describe OrchestrationTemplate do
let(:content) { "content of the test template" }
let(:existing_orderable_template) do
FactoryBot.create(:orchestration_template, :content => content, :orderable => true)
end
let(:existing_discovered_template) do
FactoryBot.create(:orchestration_template, :content => content, :orderable => false)
end

it "doesn't access database when unchanged model is saved" do
m = described_class.create
expect { m.valid? }.not_to make_database_queries
Expand Down Expand Up @@ -212,15 +220,17 @@
end
end

describe ".save_as_orderable!" do
let(:content) { "content of the test template" }
let(:existing_orderable_template) do
FactoryBot.create(:orchestration_template, :content => content, :orderable => true)
describe "supports(:order)" do
it "with orderable supports orders" do
expect(existing_orderable_template.supports?(:order)).to be_truthy
end
let(:existing_discovered_template) do
FactoryBot.create(:orchestration_template, :content => content, :orderable => false)

it "without orderable doesn't supports orders" do
expect(existing_discovered_template.supports?(:order)).to be_falsey
end
end

describe ".save_as_orderable!" do
context "save new template" do
let(:template) { FactoryBot.build(:orchestration_template, :content => content) }

Expand Down
6 changes: 4 additions & 2 deletions spec/models/service_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1146,15 +1146,17 @@
context 'when service_template cannot be displayed' do
it "returns the expected boolean value" do
st = FactoryBot.create(:service_template, :service_template_catalog => FactoryBot.create(:service_template_catalog), :display => false)
expect(st.supports_order?).to eql(false)
expect(st.supports?(:order)).to eql(false)
expect(st.validate_order).to eql(false)
expect(st.unsupported_reason(:order)).to eq('Service template is not configured to be displayed')
end
end

context 'when service_template can be displayed' do
it "returns the expected boolean value" do
st = FactoryBot.create(:service_template, :service_template_catalog => FactoryBot.create(:service_template_catalog), :display => true)
expect(st.supports_order?).to eql(true)
expect(st.supports?(:order)).to eql(true)
expect(st.validate_order).to eql(true)
end
end
end
Expand Down

0 comments on commit 7affc6b

Please sign in to comment.