From 8a51b79ac3819c9951d9c4335050761bf4d332a5 Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Wed, 7 Feb 2024 18:42:13 -0500 Subject: [PATCH] convert ServiceTemplate.orderable? to supports?(:order) Trying to move this over to supports mixin (dropping orderable?) --- app/controllers/orchestration_stack_controller.rb | 4 ++-- .../button/orchestration_template_orderable.rb | 2 +- .../button/orchestration_template_view_in_catalog.rb | 2 +- .../_stack_orchestration_template.html.haml | 6 ++++-- spec/controllers/orchestration_stack_controller_spec.rb | 8 ++++---- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/controllers/orchestration_stack_controller.rb b/app/controllers/orchestration_stack_controller.rb index 54c23e1572e..c9af3448f21 100644 --- a/app/controllers/orchestration_stack_controller.rb +++ b/app/controllers/orchestration_stack_controller.rb @@ -174,7 +174,7 @@ def textual_group_list def make_ot_orderable stack = find_record_with_rbac(OrchestrationStack, params[:id]) template = stack.orchestration_template - if template.orderable? + if template.supports?(:order) add_flash(_("Orchestration template \"%{name}\" is already orderable") % {:name => template.name}, :error) render_flash else @@ -198,7 +198,7 @@ def make_ot_orderable def orchestration_template_copy @record = find_record_with_rbac(OrchestrationStack, params[:id]) - if @record.orchestration_template.orderable? + if @record.orchestration_template.supports?(:order) add_flash(_("Orchestration template \"%{name}\" is already orderable") % {:name => @record.orchestration_template.name}, :error) render_flash diff --git a/app/helpers/application_helper/button/orchestration_template_orderable.rb b/app/helpers/application_helper/button/orchestration_template_orderable.rb index 39265e02365..8121cabdb76 100644 --- a/app/helpers/application_helper/button/orchestration_template_orderable.rb +++ b/app/helpers/application_helper/button/orchestration_template_orderable.rb @@ -1,6 +1,6 @@ class ApplicationHelper::Button::OrchestrationTemplateOrderable < ApplicationHelper::Button::Basic def disabled? - @error_message = _('This Template is already orderable') if @record.orchestration_template.orderable? + @error_message = _('This Template is already orderable') if @record.orchestration_template.supports?(:order) @error_message.present? end end diff --git a/app/helpers/application_helper/button/orchestration_template_view_in_catalog.rb b/app/helpers/application_helper/button/orchestration_template_view_in_catalog.rb index 8e95464d5fe..126398ecd60 100644 --- a/app/helpers/application_helper/button/orchestration_template_view_in_catalog.rb +++ b/app/helpers/application_helper/button/orchestration_template_view_in_catalog.rb @@ -1,6 +1,6 @@ class ApplicationHelper::Button::OrchestrationTemplateViewInCatalog < ApplicationHelper::Button::Basic def disabled? - @error_message = _('This Template is not orderable') unless @record.orchestration_template.orderable? + @error_message = _('This Template is not orderable') unless @record.orchestration_template.supports?(:order) @error_message.present? end end diff --git a/app/views/orchestration_stack/_stack_orchestration_template.html.haml b/app/views/orchestration_stack/_stack_orchestration_template.html.haml index 6a63d85f25c..920df63ad84 100644 --- a/app/views/orchestration_stack/_stack_orchestration_template.html.haml +++ b/app/views/orchestration_stack/_stack_orchestration_template.html.haml @@ -18,8 +18,10 @@ = label %td - case sym - - when :draft, :orderable? - = @record.orchestration_template.send(sym) ? _("True") : _("False") + - when :draft + = @record.orchestration_template.draft ? _("True") : _("False") + - when :orderable? + = @record.orchestration_template.supports?(:order) ? _("True") : _("False") - when :read_only = @record.orchestration_template.in_use? ? _("True") : _("False") - else diff --git a/spec/controllers/orchestration_stack_controller_spec.rb b/spec/controllers/orchestration_stack_controller_spec.rb index 281e232c4e3..974f81833b7 100644 --- a/spec/controllers/orchestration_stack_controller_spec.rb +++ b/spec/controllers/orchestration_stack_controller_spec.rb @@ -119,7 +119,7 @@ def validate_format it "won't allow making stack's orchestration template orderable when already orderable" do record = FactoryBot.create(:orchestration_stack_cloud_with_template) post :button, :params => {:id => record.id, :pressed => "make_ot_orderable"} - expect(record.orchestration_template.orderable?).to be_truthy + expect(record.orchestration_template.supports?(:order)).to be_truthy expect(response.status).to eq(200) expect(response).to render_template(:partial => "layouts/_flash_msg") expect(assigns(:flash_array).first[:message]).to include('is already orderable') @@ -128,7 +128,7 @@ def validate_format it "makes stack's orchestration template orderable" do record = FactoryBot.create(:orchestration_stack_cloud, :orchestration_template => non_orderable_template) post :button, :params => {:id => record.id, :pressed => "make_ot_orderable"} - expect(record.orchestration_template.orderable?).to be_falsey + expect(record.orchestration_template.supports?(:order)).to be_falsey expect(response.status).to eq(200) expect(response).to render_template(:partial => "layouts/_flash_msg") expect(assigns(:flash_array).first[:message]).to include('is now orderable') @@ -139,7 +139,7 @@ def validate_format it "won't allow copying stack's orchestration template orderable when already orderable" do record = FactoryBot.create(:orchestration_stack_cloud_with_template) post :button, :params => {:id => record.id, :pressed => "orchestration_template_copy"} - expect(record.orchestration_template.orderable?).to be_truthy + expect(record.orchestration_template.supports?(:order)).to be_truthy expect(response.status).to eq(200) expect(response).to render_template(:partial => "layouts/_flash_msg") expect(assigns(:flash_array).first[:message]).to include('is already orderable') @@ -148,7 +148,7 @@ def validate_format it "renders orchestration template copying form" do record = FactoryBot.create(:orchestration_stack_cloud, :orchestration_template => non_orderable_template) post :button, :params => {:id => record.id, :pressed => "orchestration_template_copy"} - expect(record.orchestration_template.orderable?).to be_falsey + expect(record.orchestration_template.supports?(:order)).to be_falsey expect(response.status).to eq(200) expect(response).to render_template(:partial => "orchestration_stack/_copy_orchestration_template") end