Skip to content

Commit

Permalink
Add DELETE service_templates/X/schedules/X
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunne committed Jul 9, 2018
1 parent 74851f1 commit 22fd104
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/controllers/api/service_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def schedules_query_resource(object)
object.miq_schedules
end

def delete_resource_schedules(_parent, type, id, data)
delete_resource(type, id, data)
end
alias schedules_delete_resource delete_resource_schedules

private

def set_additional_attributes
Expand Down
11 changes: 10 additions & 1 deletion config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2518,16 +2518,25 @@
:identifier: miq_report_reports
:options:
- :subcollection
:verbs: *gp
:verbs: *gpd
:klass: MiqSchedule
:subcollection_actions:
:get:
- :name: read
:identifier: miq_report_view
:post:
- :name: delete
:identifier: schedule_delete
:subresource_actions:
:delete:
- :name: delete
:identifier: schedule_delete
:get:
- :name: read
:identifier: miq_report_view
:post:
- :name: delete
:identifier: schedule_delete
:search_filters:
:description: Filters
:verbs: *gpd
Expand Down
24 changes: 24 additions & 0 deletions spec/requests/service_templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,30 @@

expect(response).to have_http_status(:forbidden)
end

it "DELETE service_templates/x/schedules/x" do
api_basic_authorize(subresource_action_identifier(:service_templates, :schedules, :delete, :delete))

delete(api_service_template_schedule_url(nil, service_template, schedule_1))

expect(response).to have_http_status(:no_content)
expect { schedule_1.reload }.to raise_error(ActiveRecord::RecordNotFound)
end

it "POST service_templates/x/schedules/x Params " do
api_basic_authorize(subresource_action_identifier(:service_templates, :schedules, :delete))

expect do
post(api_service_template_schedule_url(nil, service_template, schedule_1), :params => { :action => "delete" })
end.to change(MiqSchedule, :count).by(-1)

expected = {
"message" => "schedules id: #{schedule_1.id} deleting",
"success" => true
}
expect(response.parsed_body).to include(expected)
expect(response).to have_http_status(:ok)
end
end

it "without any schedules" do
Expand Down

0 comments on commit 22fd104

Please sign in to comment.