Skip to content

Commit

Permalink
Merge pull request #412 from bdunne/service_template_view_schedules
Browse files Browse the repository at this point in the history
[DEPENDS ON ManageIQ/manageiq#17672] Add ServiceTemplate#schedules subcollection
(cherry picked from commit 74851f1)

https://bugzilla.redhat.com/show_bug.cgi?id=1608351
  • Loading branch information
gtanzillo authored and simaishi committed Jul 25, 2018
1 parent da69225 commit 78795eb
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 @@ -45,6 +45,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 @@ -2346,6 +2346,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 @@ -655,4 +655,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 78795eb

Please sign in to comment.