Skip to content
Snippets Groups Projects
Commit a89b048e authored by Andre Starosta's avatar Andre Starosta
Browse files

Scripts colocados no ar

parents
Branches
Tags
No related merge requests found
Showing
with 942 additions and 0 deletions
module Dspace
module Builders
module TempfileBuilder
def self.build(filename, contents = nil, bitstreams_path = '/tmp')
Tempfile.new([sanitize_filename(filename), File.extname(filename)], bitstreams_path, encoding: 'ascii-8bit').tap do |f|
f.write contents
f.close
end
end
def self.sanitize_filename(filename)
filename.strip!
# NOTE: File.basename doesn't work right with Windows paths on Unix
# get only the filename, not the whole path
filename.gsub!(/^.*(\\|\/)/, '')
# Strip out the non-ascii character
filename.gsub!(/[^0-9A-Za-z.\-]/, '_')
filename
end
end
end
end
module Dspace
class Client
DSPACE_API = 'https://demo.dspace.org'
attr_reader :access_token
def initialize(options = {})
@access_token = options.with_indifferent_access[:access_token]
@dspace_api = options.with_indifferent_access[:dspace_api]
@logger = options.with_indifferent_access[:logger]
end
def connection
Faraday.new(connection_options) do |req|
req.request :multipart
req.request :url_encoded
req.use(Faraday::Response::Logger, @logger) unless @logger.nil?
req.adapter :net_http_persistent
end
end
def self.resources
{
bitstreams: ::Dspace::Resources::BitstreamResource,
items: ::Dspace::Resources::ItemResource,
collections: ::Dspace::Resources::CollectionResource,
communities: ::Dspace::Resources::CommunityResource,
status: ::Dspace::Resources::StatusResource,
authentication: ::Dspace::Resources::AuthenticationResource
}
end
def method_missing(name, *args, &block)
resource(name) || super
end
def resources
@resources ||= {}
end
def is_running?
resource(:status).test
end
def login(email, password)
@access_token = resource(:authentication).login(email, password)
end
def logout
resource(:authentication).logout
@access_token = nil
end
private
def resource(name)
if self.class.resources.keys.include?(name)
resources[name] ||= self.class.resources[name].new(connection: connection)
resources[name]
end
end
def connection_options
{
url: @dspace_api || DSPACE_API,
ssl: {
verify: false
},
headers: {
content_type: 'application/json',
accept: 'application/json',
'rest-dspace-token' => access_token.to_s,
user_agent: "dspace-rest-client #{Dspace::VERSION}"
}
}
end
end
end
module Dspace
class Collection
include Dspace::Builders::HashBuilder
attr_accessor :name, :logo, :license, :copyright_text,
:introductory_text, :short_description, :sidebar_text
attr_reader :id, :handle, :type, :link, :parent_community,
:parent_community_list, :items,
:number_items, :expand
def initialize args
@id = args['id'] || args['uuid']
@name = args['name']
@handle = args['handle']
@type = args['type']
@link = args['link']
@logo = args['logo']
@license = args['license']
@copyright_text = args['copyrightText']
@introductory_text = args['introductoryText']
@short_description = args['shortDescription']
@sidebar_text = args['sidebarText']
@number_items = args['numberItems']
@expand = args['expand']
@parent_community = Dspace::Community.new(args['parentCommunity']) unless args['parentCommunity'].nil?
@parent_community_list = Dspace::Builders::ModelBuilder.build_communities(args['parentCommunityList'])
@items = Dspace::Builders::ModelBuilder.build_items(args['items'])
end
def to_h
{
id: @id,
name: @name,
handle: @handle,
type: @type,
link: @link,
logo: @logo,
parentCommunity: @parent_community,
parentCommunityList: @parent_community_list,
items: obj2hash(@items),
license: @license,
copyrightText: @copyright_text,
introductoryText: @introductory_text,
shortDescription: @short_description,
sidebarText: @sidebar_text,
numberItems: @number_items,
expand: @expand
}
end
end
end
module Dspace
class Community
attr_accessor :name, :logo, :copyright_text,
:introductory_text, :short_description, :sidebar_text
attr_reader :id, :handle, :type, :link, :parent_community,
:count_items, :sub_communities, :collections, :expand
def initialize(args={})
@id = args['id'] || args['uuid']
@name = args['name']
@handle = args['handle']
@type = args['type']
@link = args['link']
@logo = args['logo']
@parent_community = Dspace::Community.new(args['parentCommunity']) unless args['parentCommunity'].nil?
@copyright_text = args['copyrightText']
@introductory_text = args['introductoryText']
@short_description = args['shortDescription']
@sidebar_text = args['sidebarText']
@count_items = args['countItems']
@sub_communities = Dspace::Builders::ModelBuilder.build_communities(args['subcommunities']) unless args['subcommunities'].nil?
@collections = Dspace::Builders::ModelBuilder.build_collections(args['collections']) unless args['collections'].nil?
@expand = args['expand']
end
def to_h
{
id: @id,
name: @name,
handle: @handle,
type: @type,
link: @link,
logo: @logo,
parentCommunity: @parent_community,
subcommunities: obj2hash(@sub_communities),
collections: obj2hash(@collections),
copyrightText: @copyright_text,
introductoryText: @introductory_text,
shortDescription: @short_description,
sidebarText: @sidebar_text,
countItems: @count_items,
expand: @expand
}
end
private
def obj2hash(list)
Dspace::Builders::ModelBuilder.models2hash list if list.is_a? Array
end
end
end
module Dspace
class Item
include Dspace::Builders::HashBuilder
attr_accessor :name, :archived, :withdrawn
attr_reader :id, :handle, :type, :link, :last_modified, :parent_collection,
:parent_collection_list, :parent_community_list, :bit_streams,
:expand, :metadata
def initialize args
@id = args['id'] || args['uuid']
@name = args['name']
@handle = args['handle']
@type = args['type']
@link = args['link']
@last_modified = args['lastModified']
@parent_collection = Dspace::Collection.new(args['parentCollection']) unless args['parentCollection'].nil?
@parent_collection_list = Dspace::Builders::ModelBuilder.build_collections(args['parentCollectionList'])
@parent_community_list = Dspace::Builders::ModelBuilder.build_communities(args['parentCommunityList'])
@bit_streams = Dspace::Builders::ModelBuilder.build_bitstreams(args['bitstreams'])
@archived = args['archived']
@withdrawn = args['withdrawn']
@expand = args['expand']
@metadata = Dspace::Builders::ModelBuilder.build_metadatas(args['metadata']) || []
end
def to_h
{
id: @id,
name: @name,
handle: @handle,
type: @type,
link: @link,
lastModified: @last_modified,
parentCollection: @parent_collection.to_h,
parentCollectionList: obj2hash(@parent_collection_list),
parentCommunityList: obj2hash(@parent_community_list),
bitstreams: obj2hash(@bit_streams),
archived: @archived,
withdrawn: @withdrawn,
expand: @expand,
metadata: obj2hash(@metadata)
}
end
def add_metadata(key, value, language)
m = {}
m['key'] = key
m['value'] = value
m['language'] = language || ""
@metadata << Dspace::Metadata.new(m)
@metadata
end
def reset_metadata
@metadata = []
end
end
end
module Dspace
class Metadata
attr_accessor :key, :value, :language
def initialize args
@key = args['key']
@value = args['value']
@language = args['language'] || nil
end
def to_h
{key: @key, value: @value, language: @language}
end
end
end
module Dspace
class Policy
attr_reader :id, :action, :eperson_id, :group_id,
:resource_id, :resource_type, :rp_description,
:rp_name, :rp_type, :start_date, :end_date
def initialize args
@id = args['id']
@action = args['action']
@eperson_id = args['epersonId']
@group_id = args['groupId']
@resource_id = args['resourceId']
@resource_type = args['resourceType']
@rp_description = args['rpDescription']
@rp_name = args['rpName']
@rp_type = args['rpType']
@start_date = args['startDate']
@end_date = args['endDate']
end
def to_h
{
id: @id,
action: @action,
epersonId: @eperson_id,
groupId: @group_id,
resourceId: @resource_id,
resourceType: @resource_type,
rpDescription: @rp_description,
rpName: @rp_name,
rpType: @rp_type,
startDate: @start_date,
endDate: @end_date
}
end
end
end
module Dspace
module Resources
class AuthenticationResource < ResourceKit::Resource
resources do
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
action :login, 'POST /rest/login' do
body { |email, password| JSON.generate({email: email, password: password}) }
handler(200, 201) { |response| access_token = response.body }
end
action :logout, 'POST /rest/logout' do
body { |object| JSON.generate(object.to_h) }
handler(200, 201, 203, 204) { |response| true }
end
end
end
end
end
module Dspace
module Resources
class BitstreamResource < ResourceKit::Resource
resources do
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
action :all, 'GET /rest/bitstreams' do
query_keys :expand, :limit, :offset
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_items(JSON.parse(response.body))
end
end
action :find, 'GET /rest/bitstreams/:id' do
query_keys :expand
handler(200) do |response|
Dspace::Bitstream.new(JSON.parse(response.body))
end
end
action :policy, 'GET /rest/bitstreams/:id/policy' do
handler(200) do |response|
Dspace::Policy.new(JSON.parse(response.body))
end
end
action :retrieve, 'GET /rest/bitstreams/:id/retrieve' do
handler(200) { |response| response.body }
end
action :delete, 'DELETE /rest/bitstreams/:id' do
handler(200, 201, 204) { |response| true }
end
action :delete_policy, 'DELETE /rest/bitstreams/:id/policy/:policy_id' do
handler(200, 201, 204) { |response| true }
end
action :add_policy, 'POST /rest/bitstreams/:id/policy' do
body { |object| JSON.generate(object.to_h) }
handler(200, 201) { |response| true }
end
action :update, 'PUT /rest/bitstreams/:id' do
body { |object| JSON.generate(object.to_h) }
handler(200, 201) { |response| true }
end
action :update_data, 'PUT /rest/bitstreams/:id/data' do
body { |file| Base64.encode64(file.read) }
handler(200, 201) { |response| true }
end
end
def retrieve(args={})
bitstreams_path = args.fetch(:bitstreams_path, nil)
bitstream = ResourceKit::ActionInvoker.call(action(:find), self, id: args.fetch(:id))
return nil if bitstream.is_a? String
Dspace::Builders::TempfileBuilder.build(bitstream_filename(bitstream), ResourceKit::ActionInvoker.call(action(:retrieve), self, id: bitstream.id), bitstreams_path)
end
private
def bitstream_filename(bitstream)
name = bitstream.try(:name)
name = bitstream.id.to_s if !name || name.empty?
name
end
end
end
end
module Dspace
module Resources
class CollectionResource < ResourceKit::Resource
resources do
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
action :all, 'GET /rest/collections' do
query_keys :expand, :limit, :offset
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_collections(JSON.parse(response.body))
end
end
action :find, 'GET /rest/collections/:id' do
query_keys :expand
handler(200) do |response|
Dspace::Collection.new(JSON.parse(response.body))
end
end
action :update, 'PUT /rest/collections/:id' do
body { |object| JSON.generate(object.to_h) }
handler(200, 201) { |response| true }
end
action :delete, 'DELETE /rest/collections/:id' do
handler(200, 201, 204) { |response| true }
end
action :delete_item, 'DELETE /rest/collections/:id/items/:item_id' do
handler(200, 201, 204) { |response| true }
end
action :items, 'GET /rest/collections/:id/items' do
query_keys :expand, :limit, :offset
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_items(JSON.parse(response.body))
end
end
action :create_item, 'POST /rest/collections/:id/items' do
body { |object| JSON.generate(object.to_h) }
handler(200, 201) { |response| Dspace::Item.new(JSON.parse(response.body)) }
end
end
end
end
end
\ No newline at end of file
module Dspace
module Resources
class CommunityResource < ResourceKit::Resource
resources do
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
action :all, 'GET /rest/communities' do
query_keys :expand, :limit, :offset
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_communities(JSON.parse(response.body))
end
end
action :top_communities, 'GET /rest/communities/top-communities' do
query_keys :expand, :limit, :offset
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_communities(JSON.parse(response.body))
end
end
action :find, 'GET /rest/communities/:id' do
query_keys :expand
handler(200) do |response|
Dspace::Community.new(JSON.parse(response.body))
end
end
action :collections, 'GET /rest/communities/:id/collections' do
query_keys :expand, :limit, :offset
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_collections(JSON.parse(response.body))
end
end
action :sub_communities, 'GET /rest/communities/:id/communities' do
query_keys :expand, :limit, :offset
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_communities(JSON.parse(response.body))
end
end
action :create, 'POST /rest/communities' do
body { |object| JSON.generate(object.to_h) }
handler(200, 201) { |response| Dspace::Community.new(JSON.parse(response.body)) }
end
action :create_subcommunity, 'POST /rest/communities/:id/communities' do
body { |object| JSON.generate(object.to_h) }
handler(200, 201) { |response| Dspace::Community.new(JSON.parse(response.body)) }
end
action :create_collection, 'POST /rest/communities/:id/collections' do
body { |object| JSON.generate(object.to_h) }
handler(200, 201) { |response| Dspace::Collection.new(JSON.parse(response.body)) }
end
action :update, 'PUT /rest/communities/:id' do
body { |object| JSON.generate(object.to_h) }
handler(200, 201) { |response| true }
end
action :delete, 'DELETE /rest/communities/:id' do
handler(200, 201, 204) { |response| true }
end
action :delete_collection, 'DELETE /rest/communities/:id/collections/:collection_id' do
handler(200, 201, 204) { |response| true }
end
action :delete_subcommunity, 'DELETE /rest/communities/:id/communities/:subcommunity_id' do
handler(200, 201, 204) { |response| true }
end
end
end
end
end
module Dspace
module Resources
class ItemResource < ResourceKit::Resource
resources do
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
action :all, 'GET /rest/items' do
query_keys :expand, :limit, :offset
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_items(JSON.parse(response.body))
end
end
action :find, 'GET /rest/items/:id' do
query_keys :expand
handler(200) do |response|
Dspace::Item.new(JSON.parse(response.body))
end
end
action :find_by_metadata, 'POST /rest/items/find-by-metadata-field' do
body { |object| JSON.generate(object.to_h) }
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_items(JSON.parse(response.body))
end
end
action :metadata, 'GET /rest/items/:id/metadata' do
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_metadatas(JSON.parse(response.body))
end
end
action :bitstreams, 'GET /rest/items/:id/bitstreams' do
query_keys :expand, :limit, :offset
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_bitstreams(JSON.parse(response.body))
end
end
action :delete, 'DELETE /rest/items/:id' do
handler(200, 201, 204) { |response| true }
end
action :clear_metadata, 'DELETE /rest/items/:id/metadata' do
handler(200, 201, 204) { |response| true }
end
action :delete_bitstream, 'DELETE /rest/items/:id/bitstreams/:bitstream_id' do
handler(200, 201, 204) { |response| true }
end
action :add_metadata, 'POST /rest/items/:id/metadata' do
body { |objects| Dspace::Builders::ModelBuilder.models2hash(objects) }
handler(200, 201) { |response| true }
end
action :add_bitstream, 'POST /rest/items/:id/bitstreams' do
query_keys :name, :description, :bundle_name
body { |file| file.read }
handler(200) { |response| Dspace::Bitstream.new(JSON.parse(response.body)) }
end
action :update_metadata, 'PUT /rest/items/:id/metadata' do
body { |object| JSON.generate(object.to_h) }
handler(200, 201) { |response| true }
end
end
end
end
end
module Dspace
module Resources
class StatusResource < ResourceKit::Resource
resources do
action :test, 'GET /rest/test' do
handler(200, 201) { |response| true }
end
action :status, 'GET /rest/status' do
handler(200) { |response| JSON.parse(response.body) }
end
end
end
end
end
\ No newline at end of file
module Dspace
VERSION = "2.2.6"
end
require 'spec_helper'
RSpec.describe Dspace::Resources::AuthenticationResource, resource_kit: true do
subject(:resource) { Dspace::Resources::AuthenticationResource }
context 'login' do
it 'raise an exception when credentials are wrong' do
expect(resource).to have_action(:login).that_handles(403).at_path('/rest/login').with_verb(:post) do |handled|
expect(handled).to raise_error(Dspace::InvalidCredentialsError)
end
end
it 'returns an access token' do
expect(resource).to have_action(:login).that_handles(200, 201).at_path('/rest/login').with_verb(:post) do |handled|
expect(handled).to be_kind_of(String)
end
end
end
context 'logout' do
it 'raise an exception when access token is invalid' do
expect(resource).to have_action(:logout).that_handles(400).at_path('/rest/logout').with_verb(:post) do |handled|
expect(handled).to raise_error(Dspace::InvalidTokenError)
end
end
it 'performs the action' do
expect(resource).to have_action(:logout).that_handles(200, 201, 203, 204).at_path('/rest/logout').with_verb(:post) do |handled|
expect(handled).to eq(true)
end
end
end
end
\ No newline at end of file
require 'spec_helper'
RSpec.describe Dspace::Resources::BitstreamResource, resource_kit: true do
subject(:resource) { Dspace::Resources::BitstreamResource }
it 'get all bitstreams' do
expect(resource).to have_action(:all).that_handles(200).at_path('/rest/bitstreams').with_verb(:get) do |handled|
expect(handled).to all(be_kind_of(Dspace::Bitstream))
end
end
it 'find bitstream by id' do
expect(resource).to have_action(:find).that_handles(200).at_path('/rest/bitstreams/:id').with_verb(:get) do |handled|
expect(handled).to be_kind_of(Dspace::Bitstream)
end
end
it 'Delete bitstream' do
expect(resource).to have_action(:delete).that_handles(200).at_path('/rest/bitstreams/:id').with_verb(:delete) do |handled|
expect(handled).to eq(true)
end
end
it 'retrive bitstream' do
expect(resource).to have_action(:retrieve).that_handles(200).at_path('/rest/bitstreams/:id/retrieve').with_verb(:get)
#TODO: mock actions expectations for test if retrieve method returns a Tempfile
end
context 'Bitstream scope' do
it 'find bitstream policy' do
expect(resource).to have_action(:policy).that_handles(200).at_path('/rest/bitstreams/:id/policy').with_verb(:get) do |handled|
expect(handled).to be_kind_of(Dspace::Policy)
end
end
it 'delete bitstream policy' do
expect(resource).to have_action(:delete_policy).that_handles(200, 201, 204).at_path('/rest/bitstreams/:id/policy/:policy_id').with_verb(:delete) do |handled|
expect(handled).to eq(true)
end
end
end
end
\ No newline at end of file
require 'spec_helper'
RSpec.describe Dspace::Resources::CollectionResource, resource_kit: true do
subject(:resource) { Dspace::Resources::CollectionResource }
it 'get all collection' do
expect(resource).to have_action(:all).that_handles(200).at_path('/rest/collections').with_verb(:get) do |handled|
expect(handled).to all(be_kind_of(Dspace::Collection))
end
end
it 'find collection by id' do
expect(resource).to have_action(:find).that_handles(200).at_path('/rest/collections/:id').with_verb(:get) do |handled|
expect(handled).to be_kind_of(Dspace::Collection)
end
end
it 'Update collection' do
expect(resource).to have_action(:delete).that_handles(200).at_path('/rest/collections/:id').with_verb(:delete) do |handled|
expect(handled).to eq(true)
end
end
it 'Delete collection' do
expect(resource).to have_action(:update).that_handles(200).at_path('/rest/collections/:id').with_verb(:put) do |handled|
expect(handled).to eq(true)
end
end
context 'collection scope' do
it 'get all items' do
expect(resource).to have_action(:items).that_handles(200).at_path('/rest/collections/:id/items').with_verb(:get) do |handled|
expect(handled).to all(be_kind_of(Dspace::Item))
end
end
it 'create an item' do
expect(resource).to have_action(:create_item).that_handles(200).at_path('/rest/collections/:id/items').with_verb(:post) do |handled|
expect(handled).to be_kind_of(Dspace::Item)
end
end
it 'delete item by id' do
expect(resource).to have_action(:delete_item).that_handles(200).at_path('/rest/collections/:id/items/:item_id').with_verb(:delete) do |handled|
expect(handled).to eq(true)
end
end
end
end
\ No newline at end of file
require 'spec_helper'
RSpec.describe Dspace::Resources::CommunityResource, resource_kit: true do
subject(:resource) { Dspace::Resources::CommunityResource }
it 'get all communities' do
expect(resource).to have_action(:all).that_handles(200).at_path('/rest/communities').with_verb(:get) do |handled|
expect(handled).to all(be_kind_of(Dspace::Community))
end
end
it 'get top communities' do
expect(resource).to have_action(:top_communities).that_handles(200).at_path('/rest/communities/top-communities').with_verb(:get) do |handled|
expect(handled).to all(be_kind_of(Dspace::Community))
end
end
it 'find community' do
expect(resource).to have_action(:find).that_handles(200).at_path('/rest/communities/:id').with_verb(:get) do |handled|
expect(handled).to be_kind_of(Dspace::Community)
end
end
it 'create a new top-level community' do
expect(resource).to have_action(:create).that_handles(200, 201).at_path('/rest/communities').with_verb(:post) do |handled|
expect(handled).to eq(true)
end
end
it 'delete community' do
expect(resource).to have_action(:delete).that_handles(200, 201, 204).at_path('/rest/communities/:id').with_verb(:delete) do |handled|
expect(handled).to eq(true)
end
end
context "with community scope" do
it "get collections" do
expect(resource).to have_action(:collections).that_handles(200).at_path('/rest/communities/:id/collections').with_verb(:get) do |handled|
expect(handled).to all(be_kind_of(Dspace::Collection))
end
end
it "get sub communities" do
expect(resource).to have_action(:sub_communities).that_handles(200).at_path('/rest/communities/:id/communities').with_verb(:get) do |handled|
expect(handled).to all(be_kind_of(Dspace::Community))
end
end
it 'create a sub-community' do
expect(resource).to have_action(:create_subcommunity).that_handles(200, 201).at_path('/rest/communities/:id/communities').with_verb(:post) do |handled|
expect(handled).to eq(true)
end
end
it 'update a community' do
expect(resource).to have_action(:update).that_handles(200, 201).at_path('/rest/communities/:id').with_verb(:put) do |handled|
expect(handled).to eq(true)
end
end
it 'create a collection' do
expect(resource).to have_action(:create_collection).that_handles(200, 201).at_path('/rest/communities/:id/collections').with_verb(:post) do |handled|
expect(handled).to eq(true)
end
end
it 'delete collection' do
expect(resource).to have_action(:delete_collection).that_handles(200, 201, 204).at_path('/rest/communities/:id/collections/:collection_id').with_verb(:delete) do |handled|
expect(handled).to eq(true)
end
end
it 'delete sub-community' do
expect(resource).to have_action(:delete_subcommunity).that_handles(200, 201, 204).at_path('/rest/communities/:id/communities/:subcommunity_id').with_verb(:delete) do |handled|
expect(handled).to eq(true)
end
end
end
end
\ No newline at end of file
require 'spec_helper'
RSpec.describe Dspace::Resources::ItemResource, resource_kit: true do
subject(:resource) { Dspace::Resources::ItemResource }
it 'get all items' do
expect(resource).to have_action(:all).that_handles(200).at_path('/rest/items').with_verb(:get) do |handled|
expect(handled).to all(be_kind_of(Dspace::Item))
end
end
it 'find item by id' do
expect(resource).to have_action(:find).that_handles(200).at_path('/rest/items/:id').with_verb(:get) do |handled|
expect(handled).to be_kind_of(Dspace::Item)
end
end
it 'find item by metadata field' do
expect(resource).to have_action(:find_by_metadata).that_handles(200).at_path('/rest/items/find-by-metadata-field').with_verb(:post) do |handled|
expect(handled).to all(be_kind_of(Dspace::Item))
end
end
it 'Delete item' do
expect(resource).to have_action(:delete).that_handles(200).at_path('/rest/items/:id').with_verb(:delete) do |handled|
expect(handled).to eq(true)
end
end
context 'Item scope' do
it 'find item metadata' do
expect(resource).to have_action(:metadata).that_handles(200).at_path('/rest/items/:id/metadata').with_verb(:get) do |handled|
expect(handled).to all(be_kind_of(Dspace::Metadata))
end
end
it 'add item metadata' do
expect(resource).to have_action(:add_metadata).that_handles(200).at_path('/rest/items/:id/metadata').with_verb(:post) do |handled|
expect(handled).to eq(true)
end
end
it 'add item bitstreams' do
expect(resource).to have_action(:add_bitstream).that_handles(200).at_path('/rest/items/:id/bitstreams').with_verb(:post) do |handled|
expect(handled).to be_kind_of(Dspace::Bitstream)
end
end
it 'find item bitstream' do
expect(resource).to have_action(:bitstreams).that_handles(200).at_path('/rest/items/:id/bitstreams').with_verb(:get) do |handled|
expect(handled).to all(be_kind_of(Dspace::Bitstream))
end
end
it 'clear item metadata' do
expect(resource).to have_action(:clear_metadata).that_handles(200, 201, 204).at_path('/rest/items/:id/metadata').with_verb(:delete) do |handled|
expect(handled).to eq(true)
end
end
it 'Delete item bitstream' do
expect(resource).to have_action(:delete_bitstream).that_handles(200, 201, 204).at_path('/rest/items/:id/bitstreams/:bitstream_id').with_verb(:delete) do |handled|
expect(handled).to eq(true)
end
end
it 'update metadata' do
expect(resource).to have_action(:update_metadata).that_handles(200, 201).at_path('/rest/items/:id/metadata').with_verb(:put) do |handled|
expect(handled).to eq(true)
end
end
end
end
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
require 'resource_kit/testing'
require 'dspace'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment