Skip to content

Commit

Permalink
Merge pull request #64 from jntullo/enhancement/generic_object_tags
Browse files Browse the repository at this point in the history
Tags Subcollection on Generic Objects
  • Loading branch information
abellotti authored Sep 21, 2017
2 parents 15cbf36 + ddd4618 commit c83fca7
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/api/generic_objects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Api
class GenericObjectsController < BaseController
include Subcollections::Tags

ADDITIONAL_ATTRS = %w(generic_object_definition associations).freeze

before_action :set_additional_attributes
Expand Down
8 changes: 8 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,8 @@
- :subcollection
:verbs: *gpd
:klass: GenericObject
:subcollections:
- :tags
:collection_actions:
:get:
- :name: read
Expand All @@ -911,6 +913,12 @@
:delete:
- :name: delete
:identifier: generic_object_delete
:tags_subcollection_actions:
:post:
- :name: assign
:identifier: generic_object_edit
- :name: unassign
:identifier: generic_object_edit
:groups:
:description: Groups
:identifier: rbac_group
Expand Down
73 changes: 73 additions & 0 deletions spec/requests/tag_collections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1108,4 +1108,77 @@ def expect_resource_has_tags(resource, tag_names)
expect(response.parsed_body).to include(expected)
end
end

context 'Generic Objects subcollection' do
let(:object) { FactoryGirl.create(:generic_object) }

describe 'POST /api/generic_objects/:id/tags' do
it 'cannot assign tags without an appropriate role' do
api_basic_authorize

post(api_generic_object_tags_url(nil, object), :params => { :action => 'assign' })

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

it 'can assign tags with an appropriate role' do
api_basic_authorize(subcollection_action_identifier(:generic_objects, :tags, :assign))

post(api_generic_object_tags_url(nil, object), :params => { :action => 'assign', :category => tag1[:category], :name => tag1[:name]})

expected = {
'results' => [
a_hash_including('success' => true, 'message' => a_string_including('Assigning Tag'))
]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'cannot assign tags without an appropriate role' do
api_basic_authorize

post(api_generic_object_tags_url(nil, object), :params => { :action => 'unassign' })

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

it 'can unassign tags with an appropriate role' do
Classification.classify(object, tag1[:category], tag1[:name])
api_basic_authorize(subcollection_action_identifier(:generic_objects, :tags, :assign))

post(api_generic_object_tags_url(nil, object), :params => { :action => 'unassign', :category => tag1[:category], :name => tag1[:name]})

expected = {
'results' => [
a_hash_including('success' => true, 'message' => a_string_including('Unassigning Tag'))
]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end

describe 'GET /api/generic_objects/:id/tags' do
before do
Classification.classify(object, tag1[:category], tag1[:name])
end

it 'returns tags for a generic object' do
api_basic_authorize

get(api_generic_object_tags_url(nil, object))

expected = {
'name' => 'tags',
'subcount' => 1,
'resources' => [
{ 'href' => a_string_including(api_generic_object_tags_url(nil, object)) }
]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end
end
end

0 comments on commit c83fca7

Please sign in to comment.