Skip to content

Commit

Permalink
Add support for /api/container_templates
Browse files Browse the repository at this point in the history
- New collection
- GETS and bulk query
- supports custom_actions
  • Loading branch information
Jillian Tullo committed Nov 21, 2017
1 parent f80b70b commit 19cf712
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/api/container_templates_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Api
class ContainerTemplatesController < BaseController
end
end
19 changes: 19 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,25 @@
:get:
- :name: read
:identifier: container_project_show
:container_templates:
:description: Container Templates
:identifier: container_template
:klass: ContainerTemplate
:verbs: *gp
:options:
- :collection
- :custom_actions
:collection_actions:
:get:
- :name: read
:identifier: container_template_show_list
:post:
- :name: query
:identifier: container_template_show_list
:resource_actions:
:get:
- :name: read
:identifier: container_template_show
:currencies:
:description: Currencies
:identifier: currency
Expand Down
10 changes: 10 additions & 0 deletions spec/requests/collections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
FactoryGirl.create(:guest_device)
test_collection_query(:guest_devices, api_guest_devices_url, GuestDevice)
end

it 'query ContainerTemplates' do
FactoryGirl.create(:container_template)
test_collection_query(:container_templates, api_container_templates_url, ContainerTemplate)
end
end

context "Collections Bulk Queries" do
Expand Down Expand Up @@ -674,5 +679,10 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
FactoryGirl.create(:container_project)
test_collection_bulk_query(:container_projects, api_container_projects_url, ContainerProject)
end

it 'bulk query container templates' do
FactoryGirl.create(:container_template)
test_collection_bulk_query(:container_templates, api_container_templates_url, ContainerTemplate)
end
end
end
48 changes: 48 additions & 0 deletions spec/requests/container_templates_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
describe "Container Templates API" do
context 'GET /api/container_templates' do
it 'forbids access to container templates without an appropriate role' do
api_basic_authorize

get(api_container_templates_url)

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

it 'returns container templates with an appropriate role' do
container_template = FactoryGirl.create(:container_template)
api_basic_authorize(collection_action_identifier(:container_templates, :read, :get))

get(api_container_templates_url)

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

context 'GET /api/container_templates' do
let(:container_template) { FactoryGirl.create(:container_template) }

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

get(api_container_template_url(nil, container_template))

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

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

get(api_container_template_url(nil, container_template))

expected = {
'href' => api_container_template_url(nil, container_template)
}
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 "ContainerTemplate" do
before(:each) do
@resource = FactoryGirl.create(:container_template)
@button = define_custom_button1(@resource)
end

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

get api_container_template_url(nil, @resource)

expect(response.parsed_body).to include(
"id" => @resource.id.to_s,
"href" => api_container_template_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_template_url(nil, @resource), :params => gen_request(@button.name, "key1" => "value1")

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

describe "Generic Objects" do
before do
@object_definition = FactoryGirl.create(:generic_object_definition, :name => 'object def')
Expand Down

0 comments on commit 19cf712

Please sign in to comment.