diff --git a/app/controllers/cloud_network_controller.rb b/app/controllers/cloud_network_controller.rb index 6da088f25a1..2e1e794e9e9 100644 --- a/app/controllers/cloud_network_controller.rb +++ b/app/controllers/cloud_network_controller.rb @@ -92,33 +92,21 @@ def create_finished def delete_networks assert_privileges("cloud_network_delete") - - networks = if @lastaction == "show_list" || (@lastaction == "show" && @layout != "cloud_network") || @lastaction.nil? - find_checked_ids_with_rbac(CloudNetwork) - else - [find_id_with_rbac(CloudNetwork, params[:id])] - end - if networks.empty? - add_flash(_("No Cloud Network were selected for deletion."), :error) - else - networks_to_delete = [] - networks.each do |s| - network = CloudNetwork.find_by_id(s) - if network.nil? - add_flash(_("Cloud Network no longer exists."), :error) - elsif network.supports_delete? - networks_to_delete.push(network) - else - add_flash(_("Couldn't initiate deletion of Network \"%{name}\": %{details}") % { - :name => network.name, - :details => network.unsupported_reason(:delete) - }, :error) - end - end - unless networks_to_delete.empty? - process_cloud_networks(networks_to_delete, "destroy") + networks = find_records_with_rbac(CloudNetwork, checked_or_params) + networks_to_delete = [] + networks.each do |network| + if network.supports_delete? + networks_to_delete.push(network) + else + add_flash(_("Couldn't initiate deletion of Network \"%{name}\": %{details}") % { + :name => network.name, + :details => network.unsupported_reason(:delete) + }, :error) end end + unless networks_to_delete.empty? + process_cloud_networks(networks_to_delete, "destroy") + end # refresh the list if applicable if @lastaction == "show_list" diff --git a/spec/controllers/cloud_network_controller_spec.rb b/spec/controllers/cloud_network_controller_spec.rb index 72d131443d8..9900d7549b2 100644 --- a/spec/controllers/cloud_network_controller_spec.rb +++ b/spec/controllers/cloud_network_controller_spec.rb @@ -267,4 +267,19 @@ end end end + + describe "#delete_networks" do + let(:admin_user) { FactoryGirl.create(:user, :role => "super_administrator") } + let(:network) { FactoryGirl.create(:cloud_network) } + before do + EvmSpecHelper.create_guid_miq_server_zone + login_as admin_user + controller.instance_variable_set(:@_params, :id => network.id, :pressed => 'cloud_network_delete') + end + + it "testing " do + allow(controller).to receive(:process_cloud_networks).with([network], "destroy") + controller.send(:delete_networks) + end + end end