Skip to content

Commit

Permalink
add authentications sub collection
Browse files Browse the repository at this point in the history
  • Loading branch information
Jillian Tullo committed Mar 1, 2017
1 parent 4e1ed16 commit 2f9b1fb
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module Api
class ConfigurationScriptPayloadsController < BaseController
include Subcollections::Authentications
end
end
9 changes: 9 additions & 0 deletions app/controllers/api/subcollections/authentications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Api
module Subcollections
module Authentications
def authentications_query_resource(object)
object.respond_to?(:authentications) ? object.authentications : []
end
end
end
end
7 changes: 7 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
:description: Authentications
:options:
- :collection
- :subcollection
:verbs: *gpd
:klass: Authentication
:collection_actions:
Expand All @@ -223,6 +224,10 @@
:delete:
- :name: delete
:identifier: embedded_automation_manager_credentials_delete
:subcollection_actions:
:get:
- :name: read
:identifier: embedded_automation_manager_credentials_view
:automate:
:description: Automate
:options:
Expand Down Expand Up @@ -525,6 +530,8 @@
- :collection
:verbs: *g
:klass: ConfigurationScriptPayload
:subcollections:
- :authentications
:collection_actions:
:get:
- :name: read
Expand Down
34 changes: 34 additions & 0 deletions spec/requests/api/configuration_script_payloads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,38 @@
expect(response).to have_http_status(:forbidden)
end
end

describe 'GET /api/configuration_script_payloads/:id/authentications' do
it 'returns the configuration script sources authentications' do
authentication = FactoryGirl.create(:authentication)
playbook = FactoryGirl.create(:configuration_script_payload, :authentications => [authentication])
api_basic_authorize subcollection_action_identifier(:configuration_script_payloads, :authentications, :read, :get)

run_get("#{configuration_script_payloads_url(playbook.id)}/authentications", :expand => 'resources')

expected = {
'resources' => [
a_hash_including('id' => authentication.id)
]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end

describe 'GET /api/configuration_script_payloads/:id/authentications/:id' do
it 'returns a specific authentication' do
authentication = FactoryGirl.create(:authentication)
playbook = FactoryGirl.create(:configuration_script_payload, :authentications => [authentication])
api_basic_authorize subcollection_action_identifier(:configuration_script_payloads, :authentications, :read, :get)

run_get("#{configuration_script_payloads_url(playbook.id)}/authentications/#{authentication.id}")

expected = {
'id' => authentication.id
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end
end

0 comments on commit 2f9b1fb

Please sign in to comment.