Skip to content

Commit

Permalink
Merge pull request #13389 from enoodle/rescue_annotate_errors_euwe
Browse files Browse the repository at this point in the history
[EUWE] container common mixin: ui_lookup should get a string
  • Loading branch information
simaishi authored Jan 10, 2017
2 parents 2d7da8f + f452606 commit 4ff0863
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/controllers/mixins/containers_common_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
Expand Down Expand Up @@ -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})
Expand Down
9 changes: 9 additions & 0 deletions spec/controllers/container_image_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4ff0863

Please sign in to comment.