Skip to content

Commit

Permalink
Add ServiceTemplate#schedules subcollection
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunne committed Jul 6, 2018
1 parent 39e81ec commit c58d1d4
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/api/service_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def unarchive_resource(type, id, _data)
action_result(false, "Could not unarchive Service Template - #{err}")
end

def schedules_query_resource(object)
object.miq_schedules
end

private

def set_additional_attributes
Expand Down
1 change: 1 addition & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2806,6 +2806,7 @@
:subcollections:
- :resource_actions
- :tags
- :schedules
- :service_requests
- :service_dialogs
:collection_actions:
Expand Down
66 changes: 66 additions & 0 deletions spec/requests/service_templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -690,4 +690,70 @@
expect(response.parsed_body).to include(expected)
end
end

context "schedules subcollection" do
let!(:service_template) { FactoryGirl.create(:service_template, :with_provision_resource_action_and_dialog) }

context "with schedules" do
let!(:schedule_1) { FactoryGirl.create(:miq_schedule, :towhat => "ServiceTemplate", :resource_id => service_template.id) }
let!(:schedule_2) { FactoryGirl.create(:miq_schedule, :towhat => "ServiceTemplate", :resource_id => service_template.id) }

it "can fetch all related schedules" do
api_basic_authorize subcollection_action_identifier(:service_templates, :schedules, :read, :get)

get(api_service_template_schedules_url(nil, service_template))

expect_result_resources_to_include_hrefs(
"resources",
[
api_service_template_schedule_url(nil, service_template, schedule_1),
api_service_template_schedule_url(nil, service_template, schedule_2),
]
)
expect(response).to have_http_status(:ok)
end

it "will not show the schedules without the appropriate role" do
api_basic_authorize

get(api_service_template_schedules_url(nil, service_template))

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

it "can show a single schedule" do
api_basic_authorize subcollection_action_identifier(:service_templates, :schedules, :read, :get)

get(api_service_template_schedule_url(nil, service_template, schedule_1))

expect_result_to_match_hash(
response.parsed_body,
"href" => api_service_template_schedule_url(nil, service_template, schedule_1),
"id" => schedule_1.id.to_s,
)
expect(response).to have_http_status(:ok)
end

it "will not show a schedule without the appropriate role" do
api_basic_authorize

get(api_service_template_schedule_url(nil, service_template, schedule_1))

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

it "without any schedules" do
api_basic_authorize subcollection_action_identifier(:service_templates, :schedules, :read, :get)

get(api_service_template_schedules_url(nil, service_template))

expect(response.parsed_body).to include(
"name" => "schedules",
"resources" => [],
"subcount" => 0
)
expect(response).to have_http_status(:ok)
end
end
end

0 comments on commit c58d1d4

Please sign in to comment.