Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flash message when OrchestrationStack delete returns an exception #2836

Merged
merged 2 commits into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/controllers/application_controller/ci_processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,15 @@ def deletehosts
# Delete all selected or single displayed stack(s)
def orchestration_stack_delete
assert_privileges("orchestration_stack_delete")
delete_elements(OrchestrationStack, :process_orchestration_stacks)
begin
delete_elements(OrchestrationStack, :process_orchestration_stacks)
rescue StandardError => err
add_flash(_("Error during deletion: %{error_message}") % {:error_message => err.message}, :error)
if @lastaction == "show_list"
show_list
@refresh_partial = "layouts/gtl"
end
end
end

def configuration_job_delete
Expand Down
34 changes: 34 additions & 0 deletions spec/controllers/application_controller/ci_processing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -944,3 +944,37 @@
end
end
end

describe OrchestrationStackController do
context "#orchestration_stack_delete" do
let(:orchestration_stack) { FactoryGirl.create(:orchestration_stack_cloud) }
let(:orchestration_stack_deleted) { FactoryGirl.create(:orchestration_stack_cloud) }

before do
EvmSpecHelper.create_guid_miq_server_zone
login_as FactoryGirl.create(:user_admin)
controller.instance_variable_set(:@lastaction, "show_list")
allow(controller).to receive(:role_allows?).and_return(true)
end

it "should render error flash message if OrchestrationStack doesn't exist" do
id = orchestration_stack_deleted.id
orchestration_stack_deleted.destroy
controller.instance_variable_set(:@_params, :miq_grid_checks => id.to_s) # Orchestration Stack id that doesn't exist
expect(controller).to receive(:show_list)
controller.send('orchestration_stack_delete')
flash_messages = assigns(:flash_array)
expect(flash_messages.first).to eq(:message => "Error during deletion: Unauthorized object or action",
:level => :error)
end

it "should render success flash message if OrchestrationStack deletion was initiated" do
controller.instance_variable_set(:@_params, :miq_grid_checks => orchestration_stack.id.to_s) # Orchestration Stack id that exists
expect(controller).to receive(:show_list)
controller.send('orchestration_stack_delete')
flash_messages = assigns(:flash_array)
expect(flash_messages.first).to eq(:message => "Delete initiated for 1 Orchestration Stacks from the ManageIQ Database",
:level => :success)
end
end
end