From f45260675d9cfdcb3dd11f58698dcbf786dc6c87 Mon Sep 17 00:00:00 2001 From: Erez Freiberger Date: Fri, 9 Dec 2016 09:06:19 +0200 Subject: [PATCH] container common mixin: ui_lookup should get a string --- app/controllers/mixins/containers_common_mixin.rb | 11 ++++++----- spec/controllers/container_image_controller_spec.rb | 9 +++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/controllers/mixins/containers_common_mixin.rb b/app/controllers/mixins/containers_common_mixin.rb index 20126869024..7342b507ca5 100644 --- a/app/controllers/mixins/containers_common_mixin.rb +++ b/app/controllers/mixins/containers_common_mixin.rb @@ -184,7 +184,7 @@ def check_compliance(model) ids = showlist ? find_checked_items : find_current_item(model) if ids.empty? - add_flash(_("No %{model} were selected for %{task}") % {:model => ui_lookup(:models => model), + add_flash(_("No %{model} were selected for %{task}") % {:model => ui_lookup(:models => model.to_s), :task => "Compliance Check"}, :error) else process_check_compliance(model, ids) @@ -196,7 +196,7 @@ def check_compliance(model) def find_current_item(model) if params[:id].nil? || model.find_by(:id => params[:id].to_i).nil? - add_flash(_("%{model} no longer exists") % {:table => ui_lookup(:model => model)}, :error) + add_flash(_("%{model} no longer exists") % {:model => ui_lookup(:model => model.to_s)}, :error) [] else [params[:id].to_i] @@ -225,9 +225,10 @@ def process_check_compliance(model, ids) begin entity.check_compliance rescue StandardError => bang - add_flash(_("%{model} \"%{name}\": Error during 'Check Compliance': ") % - {:model => ui_lookup(:model => model), - :name => entity.name} << bang.message, + add_flash(_("%{model} \"%{name}\": Error during 'Check Compliance': %{error}") % + {:model => ui_lookup(:model => model.to_s), + :name => entity.name, + :error => bang.message}, :error) # Push msg and error flag else add_flash(_("\"%{record}\": Compliance check successfully initiated") % {:record => entity.name}) diff --git a/spec/controllers/container_image_controller_spec.rb b/spec/controllers/container_image_controller_spec.rb index 65bf7a440c0..974f9cf39b7 100644 --- a/spec/controllers/container_image_controller_spec.rb +++ b/spec/controllers/container_image_controller_spec.rb @@ -12,6 +12,15 @@ expect(controller.send(:flash_errors?)).not_to be_truthy end + it "when Check Compliance is pressed with no images" do + ApplicationController.handle_exceptions = true + + expect(controller).to receive(:check_compliance).and_call_original + expect(controller).to receive(:add_flash).with("Container Image no longer exists", :error) + expect(controller).to receive(:add_flash).with("No Container Images were selected for Compliance Check", :error) + post :button, :params => { :pressed => 'container_image_check_compliance', :format => :js } + end + it 'renders edit container image tags' do ApplicationController.handle_exceptions = true