Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for /api/container_images #185

Merged
merged 2 commits into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/controllers/api/container_images_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Api
class ContainerImagesController < BaseController
end
end
16 changes: 16 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,22 @@
:get:
- :name: read
:identifier: container_group_show
:container_images:
:description: Container Images
:identifier: container_image
:options:
- :collection
- :custom_actions
:verbs: *gp
:klass: ContainerImage
:collection_actions:
:get:
- :name: read
:identifier: container_image_show_list
:resource_actions:
:get:
- :name: read
:identifier: container_image_show
:container_nodes:
:description: Container Nodes
:identifier: container_node
Expand Down
5 changes: 5 additions & 0 deletions spec/requests/collections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
test_collection_query(:container_groups, api_container_groups_url, ContainerGroup)
end

it "query ContainerImage" do
FactoryGirl.create(:container_image)
test_collection_query(:container_images, api_container_images_url, ContainerImage)
end

it "query Currencies" do
FactoryGirl.create(:chargeback_rate_detail_currency)
test_collection_query(:currencies, "/api/currencies", ChargebackRateDetailCurrency)
Expand Down
48 changes: 48 additions & 0 deletions spec/requests/container_images_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
describe "Container Images API" do
context 'GET /api/container_images' do
it 'forbids access to container images without an appropriate role' do
api_basic_authorize

get(api_container_images_url)

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

it 'returns container images with an appropriate role' do
container_images = FactoryGirl.create(:container_image)
api_basic_authorize(collection_action_identifier(:container_images, :read, :get))

get(api_container_images_url)

expected = {
'resources' => [{'href' => api_container_image_url(nil, container_images)}]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end

context 'GET /api/container_images' do
let(:container_image) { FactoryGirl.create(:container_image) }

it 'forbids access to a container image without an appropriate role' do
api_basic_authorize

get(api_container_image_url(nil, container_image))

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

it 'returns the container image with an appropriate role' do
api_basic_authorize(action_identifier(:container_images, :read, :resource_actions, :get))

get(api_container_image_url(nil, container_image))

expected = {
'href' => api_container_image_url(nil, container_image)
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end
end
27 changes: 27 additions & 0 deletions spec/requests/custom_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,33 @@ def define_custom_button1(resource)
end
end

describe "Container Image" do
before do
@resource = FactoryGirl.create(:container_image)
@button = define_custom_button1(@resource)
end

it "queries return custom actions defined" do
api_basic_authorize(action_identifier(:container_images, :read, :resource_actions, :get))

get api_container_image_url(nil, @resource)

expect(response.parsed_body).to include(
"id" => @resource.id.to_s,
"href" => api_container_image_url(nil, @resource),
"actions" => a_collection_including(a_hash_including("name" => @button.name))
)
end

it "accept custom actions" do
api_basic_authorize

post api_container_image_url(nil, @resource), :params => gen_request(@button.name, "key1" => "value1")

expect_single_action_result(:success => true, :message => /.*/, :href => api_container_image_url(nil, @resource))
end
end

describe "ContainerNode" do
before do
@resource = FactoryGirl.create(:container_node)
Expand Down