Skip to content

Commit

Permalink
Merge pull request #4385 from romanblanco/test_2
Browse files Browse the repository at this point in the history
Refactoring method cloud_network_controller.rb to use new RBAC call
  • Loading branch information
mzazrivec authored Aug 20, 2018
2 parents c1ea8d4 + c736263 commit 1ae4c63
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
38 changes: 13 additions & 25 deletions app/controllers/cloud_network_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions spec/controllers/cloud_network_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1ae4c63

Please sign in to comment.