Skip to content

Commit

Permalink
Merge pull request #3607 from romanblanco/cloud_object_store_object_c…
Browse files Browse the repository at this point in the history
…onsistency

Generalized case statement so it responds to the method change in the core
  • Loading branch information
h-kataria authored May 9, 2018
2 parents 7ff1402 + 5934489 commit 393d218
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
10 changes: 2 additions & 8 deletions app/controllers/application_controller/ci_processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,8 @@ def check_supports_task(items, klass, task, display_name)

def cloud_object_store_button_operation(klass, task)
display_name = _(task.capitalize)

# Map task to instance method name
case task
when 'delete'
method = "#{task}_#{klass.name.underscore.to_sym}"
else
method = task = "#{klass.name.underscore.to_sym}_#{task}"
end
method = "#{klass.name.underscore.to_sym}_#{task}"
task = method unless task == 'delete'

items = []
# Either a list or coming from a different controller
Expand Down
32 changes: 16 additions & 16 deletions spec/controllers/application_controller/ci_processing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
controller.params[:miq_grid_checks] = "#{container1.id}, #{container2.id}"
expect(controller).to receive(:process_objects).with(
[container1.id, container2.id],
'delete_cloud_object_store_container',
'cloud_object_store_container_delete',
'Delete'
)
controller.send(:cloud_object_store_button_operation, CloudObjectStoreContainer, 'delete')
Expand All @@ -64,18 +64,18 @@
it "invokes process_tasks on container class" do
expect(CloudObjectStoreContainer).to receive(:process_tasks).with(
:ids => [container1.id, container2.id],
:task => 'delete_cloud_object_store_container',
:task => 'cloud_object_store_container_delete',
:userid => anything
)
controller.send(:process_objects, [container1.id, container2.id], 'delete_cloud_object_store_container',
controller.send(:process_objects, [container1.id, container2.id], 'cloud_object_store_container_delete',
'delete')
end

it "invokes process_tasks overall (when selected)" do
controller.params[:miq_grid_checks] = "#{container1.id}, #{container2.id}"
expect(CloudObjectStoreContainer).to receive(:process_tasks).with(
:ids => [container1.id, container2.id],
:task => 'delete_cloud_object_store_container',
:task => 'cloud_object_store_container_delete',
:userid => anything
)
controller.send(:process_cloud_object_storage_buttons, "cloud_object_store_container_delete")
Expand Down Expand Up @@ -132,7 +132,7 @@
controller.params[:id] = container.id
expect(controller).to receive(:process_objects).with(
[container.id],
'delete_cloud_object_store_container',
'cloud_object_store_container_delete',
'Delete'
)
controller.send(:cloud_object_store_button_operation, CloudObjectStoreContainer, 'delete')
Expand All @@ -141,17 +141,17 @@
it "invokes process_tasks on container class" do
expect(CloudObjectStoreContainer).to receive(:process_tasks).with(
:ids => [container.id],
:task => 'delete_cloud_object_store_container',
:task => 'cloud_object_store_container_delete',
:userid => anything
)
controller.send(:process_objects, [container.id], 'delete_cloud_object_store_container', 'delete')
controller.send(:process_objects, [container.id], 'cloud_object_store_container_delete', 'delete')
end

it "invokes process_tasks overall" do
controller.params[:id] = container.id
expect(CloudObjectStoreContainer).to receive(:process_tasks).with(
:ids => [container.id],
:task => 'delete_cloud_object_store_container',
:task => 'cloud_object_store_container_delete',
:userid => anything
)
controller.send(:process_cloud_object_storage_buttons, "cloud_object_store_container_delete")
Expand Down Expand Up @@ -212,7 +212,7 @@
controller.params[:miq_grid_checks] = "#{object1.id}, #{object2.id}"
expect(controller).to receive(:process_objects).with(
[object1.id, object2.id],
"delete_cloud_object_store_object",
"cloud_object_store_object_delete",
"Delete"
)
controller.send(:cloud_object_store_button_operation, CloudObjectStoreObject, "delete")
Expand All @@ -222,17 +222,17 @@
controller.params[:miq_grid_checks] = "#{object1.id}, #{object2.id}"
expect(CloudObjectStoreObject).to receive(:process_tasks).with(
:ids => [object1.id, object2.id],
:task => "delete_cloud_object_store_object",
:task => "cloud_object_store_object_delete",
:userid => anything
)
controller.send(:process_objects, [object1.id, object2.id], "delete_cloud_object_store_object", "delete")
controller.send(:process_objects, [object1.id, object2.id], "cloud_object_store_object_delete", "delete")
end

it "invokes process_tasks overall (when selected)" do
controller.params[:miq_grid_checks] = "#{object1.id}, #{object2.id}"
expect(CloudObjectStoreObject).to receive(:process_tasks).with(
:ids => [object1.id, object2.id],
:task => "delete_cloud_object_store_object",
:task => "cloud_object_store_object_delete",
:userid => anything
)
controller.send(:process_cloud_object_storage_buttons, "cloud_object_store_object_delete")
Expand Down Expand Up @@ -289,7 +289,7 @@
controller.params[:id] = object.id.to_s
expect(controller).to receive(:process_objects).with(
[object.id.to_s],
"delete_cloud_object_store_object",
"cloud_object_store_object_delete",
"Delete"
)
controller.send(:cloud_object_store_button_operation, CloudObjectStoreObject, "delete")
Expand All @@ -299,17 +299,17 @@
controller.params[:id] = object.id.to_s
expect(CloudObjectStoreObject).to receive(:process_tasks).with(
:ids => [object.id.to_s],
:task => "delete_cloud_object_store_object",
:task => "cloud_object_store_object_delete",
:userid => anything
)
controller.send(:process_objects, [object.id.to_s], "delete_cloud_object_store_object", "delete")
controller.send(:process_objects, [object.id.to_s], "cloud_object_store_object_delete", "delete")
end

it "invokes process_tasks overall" do
controller.params[:id] = object.id.to_s
expect(CloudObjectStoreObject).to receive(:process_tasks).with(
:ids => [object.id.to_s],
:task => "delete_cloud_object_store_object",
:task => "cloud_object_store_object_delete",
:userid => anything
)
controller.send(:process_cloud_object_storage_buttons, "cloud_object_store_object_delete")
Expand Down

0 comments on commit 393d218

Please sign in to comment.