-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a subcollection under VMs for displaying CD-ROMs
- Loading branch information
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Api | ||
module Subcollections | ||
module Cdroms | ||
def cdroms_query_resource(object) | ||
object.hardware.cdroms | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
RSpec.describe "CD-ROMs API" do | ||
let(:hw) { FactoryBot.create(:hardware) } | ||
let(:vm) { FactoryBot.create(:vm_vmware, :hardware => hw) } | ||
let!(:cdrom) { FactoryBot.create(:disk, :hardware => hw, :device_type => 'cdrom') } | ||
describe "as a subcollection of VMs" do | ||
describe "GET /api/vms/:c_id/cdroms" do | ||
it "can list the CD-ROMs of a VM" do | ||
api_basic_authorize(subcollection_action_identifier(:vms, :cdroms, :read, :get)) | ||
|
||
_other_disk = FactoryBot.create(:disk, :device_type => 'cdrom') | ||
|
||
get(api_vm_cdroms_url(nil, vm)) | ||
|
||
expected = { | ||
"count" => 2, | ||
"name" => "cdroms", | ||
"subcount" => 1, | ||
"resources" => [ | ||
{"href" => api_vm_cdrom_url(nil, vm, cdrom)} | ||
] | ||
} | ||
|
||
expect(response.parsed_body).to include(expected) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
|
||
describe "GET /api/vms/:c_id/cdroms/:s_id" do | ||
it "can show a VM's CD-ROM" do | ||
api_basic_authorize(subcollection_action_identifier(:vms, :cdroms, :read, :get)) | ||
|
||
get(api_vm_cdrom_url(nil, vm, cdrom)) | ||
|
||
expected = { | ||
"href" => api_vm_cdrom_url(nil, vm, cdrom), | ||
"id" => cdrom.id.to_s, | ||
} | ||
expect(response.parsed_body).to include(expected) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it "will not show a CD-ROM unless authorized" do | ||
api_basic_authorize | ||
|
||
get(api_vm_cdrom_url(nil, vm, cdrom)) | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
end | ||
end |