Skip to content

Commit

Permalink
Merge pull request #220 from himdel/tasks-delete
Browse files Browse the repository at this point in the history
Tasks: delete support
  • Loading branch information
abellotti authored Dec 5, 2017
2 parents 12be4c1 + 74b36b6 commit 85f3153
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
10 changes: 9 additions & 1 deletion config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2780,7 +2780,7 @@
:identifier: tasks
:options:
- :collection
:verbs: *gp
:verbs: *gpd
:klass: MiqTask
:collection_actions:
:get:
Expand All @@ -2789,10 +2789,18 @@
:post:
- :name: query
:identifier: tasks_view
- :name: delete
:identifier: miq_task_delete
:resource_actions:
:get:
- :name: read
:identifier: tasks_view
:post:
- :name: delete
:identifier: miq_task_delete
:delete:
- :name: delete
:identifier: miq_task_delete
:templates:
:description: Templates
:identifier: miq_template
Expand Down
61 changes: 61 additions & 0 deletions spec/requests/tasks_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
describe 'TasksController' do
let(:task) { FactoryGirl.create(:miq_task, :state => MiqTask::STATE_FINISHED) }
let(:task2) { FactoryGirl.create(:miq_task, :state => MiqTask::STATE_FINISHED) }

def expect_deleted(*args)
args.each do |arg|
expect(MiqTask.find_by(:id => arg.id)).to be_nil
end
end

it 'deletes on DELETE' do
api_basic_authorize resource_action_identifier(:tasks, :delete, :delete)

delete(api_task_url(nil, task))

expect(response).to have_http_status(:no_content) # 204
expect_deleted(task)
end

it 'deletes on POST' do
api_basic_authorize resource_action_identifier(:tasks, :delete)

data = {
:action => 'delete'
}
post(api_task_url(nil, task), :params => data)

expect(response).to have_http_status(:ok) # 200
expect_deleted(task)

expected = {
'success' => true,
'message' => "tasks id: #{task.id} deleting"
}
expect(response.parsed_body).to include(expected)
end

it 'bulk deletes' do
api_basic_authorize collection_action_identifier(:tasks, :delete)

data = {
:action => 'delete',
:resources => [
{:href => api_task_url(nil, task)},
{:href => api_task_url(nil, task2)}
]
}
post(api_tasks_url, :params => data)

expect(response).to have_http_status(:ok) # 200
expect_deleted(task, task2)

expected = {
'results' => a_collection_including(
a_hash_including('success' => true, 'message' => "tasks id: #{task.id} deleting"),
a_hash_including('success' => true, 'message' => "tasks id: #{task2.id} deleting")
)
}
expect(response.parsed_body).to include(expected)
end
end
4 changes: 4 additions & 0 deletions spec/support/api/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def collection_action_identifier(type, action, method = :post)
action_identifier(type, action, :collection_actions, method)
end

def resource_action_identifier(type, action, method = :post)
action_identifier(type, action, :resource_actions, method)
end

def subcollection_action_identifier(type, subtype, action, method = :post)
subtype_actions = "#{subtype}_subcollection_actions".to_sym
if ::Api::ApiConfig.collections[type][subtype_actions]
Expand Down

0 comments on commit 85f3153

Please sign in to comment.