hydra-works 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +72 -0
- data/Gemfile +5 -4
- data/README.md +17 -11
- data/Rakefile +18 -8
- data/config/solrconfig.xml +223 -0
- data/hydra-works.gemspec +15 -15
- data/lib/hydra/works.rb +28 -17
- data/lib/hydra/works/errors/full_text_extraction_error.rb +5 -0
- data/lib/hydra/works/models/concerns/block_child_objects.rb +12 -6
- data/lib/hydra/works/models/concerns/collection_behavior.rb +44 -6
- data/lib/hydra/works/models/concerns/generic_file/contained_files.rb +3 -3
- data/lib/hydra/works/models/concerns/generic_file/derivatives.rb +2 -4
- data/lib/hydra/works/models/concerns/generic_file/mime_types.rb +1 -3
- data/lib/hydra/works/models/concerns/generic_file/versioned_content.rb +4 -6
- data/lib/hydra/works/models/concerns/generic_file/virus_check.rb +13 -14
- data/lib/hydra/works/models/concerns/generic_file_behavior.rb +13 -3
- data/lib/hydra/works/models/concerns/generic_work_behavior.rb +34 -9
- data/lib/hydra/works/models/generic_file.rb +0 -3
- data/lib/hydra/works/services/generic_file/add_file_to_generic_file.rb +14 -16
- data/lib/hydra/works/services/generic_file/full_text_extraction_service.rb +57 -0
- data/lib/hydra/works/services/generic_file/generate_thumbnail.rb +13 -0
- data/lib/hydra/works/services/generic_file/persist_derivative.rb +3 -5
- data/lib/hydra/works/services/generic_file/{upload_file.rb → upload_file_to_generic_file.rb} +1 -3
- data/lib/hydra/works/version.rb +1 -1
- data/lib/hydra/works/vocab/works_terms.rb +9 -9
- data/lib/tasks/hydra-works_tasks.rake +80 -0
- data/lib/tasks/jetty.rake +15 -0
- data/spec/hydra/works/models/collection_spec.rb +258 -246
- data/spec/hydra/works/models/concerns/block_child_objects_spec.rb +6 -8
- data/spec/hydra/works/models/concerns/generic_file/contained_files_spec.rb +40 -48
- data/spec/hydra/works/models/concerns/generic_file/mime_types_spec.rb +16 -18
- data/spec/hydra/works/models/concerns/generic_file/versioned_content_spec.rb +11 -11
- data/spec/hydra/works/models/concerns/generic_file/virus_check_spec.rb +11 -8
- data/spec/hydra/works/models/concerns/generic_file_behavior_spec.rb +1 -1
- data/spec/hydra/works/models/generic_file_spec.rb +87 -85
- data/spec/hydra/works/models/generic_work_spec.rb +167 -169
- data/spec/hydra/works/services/full_text_extraction_service_spec.rb +89 -0
- data/spec/hydra/works/services/generic_file/add_file_to_generic_file_spec.rb +36 -38
- data/spec/hydra/works/services/generic_file/generate/thumbnail_spec.rb +10 -12
- data/spec/hydra/works/services/generic_file/upload_file_spec.rb +39 -42
- data/spec/hydra/works/services/persist_derivatives_spec.rb +2 -3
- data/spec/hydra/works_spec.rb +57 -61
- data/spec/spec_helper.rb +2 -4
- metadata +23 -15
- data/lib/hydra/works/services/generic_file/generate/thumbnail.rb +0 -18
@@ -0,0 +1,57 @@
|
|
1
|
+
module Hydra::Works
|
2
|
+
# Extract the full text from the content using Solr's extract handler
|
3
|
+
class FullTextExtractionService
|
4
|
+
def self.run(generic_file)
|
5
|
+
new(generic_file).extract
|
6
|
+
end
|
7
|
+
|
8
|
+
delegate :original_file, :id, to: :@generic_file
|
9
|
+
|
10
|
+
def initialize(generic_file)
|
11
|
+
@generic_file = generic_file
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Extract full text from the content using Solr's extract handler.
|
16
|
+
# This will extract text from the file uploaded to generic_file.
|
17
|
+
# The file uploaded to @generic_file can be accessed via :original_file.
|
18
|
+
#
|
19
|
+
# @return [String] The extracted text
|
20
|
+
def extract
|
21
|
+
JSON.parse(fetch)[''].rstrip
|
22
|
+
rescue Hydra::Works::FullTextExtractionError => e
|
23
|
+
raise e
|
24
|
+
rescue => e
|
25
|
+
raise Hydra::Works::FullTextExtractionError.new, "Error extracting content from #{id}: #{e.inspect}"
|
26
|
+
end
|
27
|
+
|
28
|
+
# send the request to the extract service and return the response if it was successful.
|
29
|
+
# TODO: this pulls the whole file into memory. We should stream it from Fedora instead
|
30
|
+
# @return [String] the result of calling the extract service
|
31
|
+
def fetch
|
32
|
+
req = Net::HTTP.new(uri.host, uri.port)
|
33
|
+
resp = req.post(uri.to_s, original_file.content, request_headers)
|
34
|
+
raise Hydra::Works::FullTextExtractionError.new, "Solr Extract service was unsuccessful. '#{uri}' returned code #{resp.code} for #{id}\n#{resp.body}" unless resp.code == '200'
|
35
|
+
original_file.content.rewind if original_file.content.respond_to?(:rewind)
|
36
|
+
|
37
|
+
resp.body
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Hash] the request headers to send to the Solr extract service
|
41
|
+
def request_headers
|
42
|
+
{ Faraday::Request::UrlEncoded::CONTENT_TYPE => "#{original_file.mime_type};charset=utf-8",
|
43
|
+
Faraday::Adapter::CONTENT_LENGTH => original_file.size.to_s }
|
44
|
+
end
|
45
|
+
|
46
|
+
# @returns [URI] path to the extract service
|
47
|
+
def uri
|
48
|
+
@uri ||= URI("#{connection_url}/update/extract?extractOnly=true&wt=json&extractFormat=text")
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def connection_url
|
54
|
+
ActiveFedora.solr_config[:url]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Hydra::Works
|
2
|
+
class GenerateThumbnail
|
3
|
+
def self.call(object, content: :original_file)
|
4
|
+
fail ArgumentError, "object has no content at #{content} from which to generate a thumbnail" if object.send(content).nil?
|
5
|
+
|
6
|
+
# Always replace the thumbnail with whatever is from the original file
|
7
|
+
object.build_thumbnail if object.thumbnail.nil?
|
8
|
+
|
9
|
+
object.create_derivatives
|
10
|
+
object
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -2,21 +2,19 @@ require 'hydra/derivatives'
|
|
2
2
|
|
3
3
|
module Hydra::Works
|
4
4
|
class PersistDerivative < Hydra::Derivatives::PersistOutputFileService
|
5
|
-
|
6
5
|
##
|
7
6
|
# Persists a derivative to a GenericFile
|
8
|
-
# This Service conforms to the signature of `Hydra::Derivatives::PersistOutputFileService`.
|
7
|
+
# This Service conforms to the signature of `Hydra::Derivatives::PersistOutputFileService`.
|
9
8
|
# The purpose of this Service is for use as an alternative to the default Hydra::Derivatives::PersistOutputFileService. It's necessary because the default behavior in Hydra::Derivatives assumes that you're using LDP Basic Containment. Hydra::Works::GenericFiles use IndirectContainment. This Service handles that case.
|
10
9
|
# This service will always update existing and does not do versioning of persisted files.
|
11
|
-
#
|
10
|
+
#
|
12
11
|
# @param [Hydra::Works::GenericFile::Base] object the file will be added to
|
13
|
-
# @param [
|
12
|
+
# @param [Hydra::Derivatives::IoDecorator] file the derivative filestream
|
14
13
|
# @param [String] extract file type symbol (e.g. :thumbnail) from Hydra::Derivatives created destination_name
|
15
14
|
|
16
15
|
def self.call(object, file, destination_name)
|
17
16
|
type = destination_name.gsub(/^original_file_/, '').to_sym
|
18
17
|
Hydra::Works::AddFileToGenericFile.call(object, file, type, update_existing: true, versioning: false)
|
19
18
|
end
|
20
|
-
|
21
19
|
end
|
22
20
|
end
|
data/lib/hydra/works/services/generic_file/{upload_file.rb → upload_file_to_generic_file.rb}
RENAMED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Hydra::Works
|
2
2
|
class UploadFileToGenericFile
|
3
|
-
|
4
3
|
# Sets a file as the primary file (original_file) of the generic_file
|
5
4
|
# @param [Hydra::PCDM::GenericFile::Base] generic_file the file will be added to
|
6
5
|
# @param [IO,File,Rack::Multipart::UploadedFile, #read] object that will be the contents. If file responds to :mime_type or :original_name, those will be called to provide technical metadata.
|
@@ -8,7 +7,7 @@ module Hydra::Works
|
|
8
7
|
# @param [Boolean] update_existing whether to update an existing file if there is one. When set to true, performs a create_or_update. When set to false, always creates a new file within generic_file.files.
|
9
8
|
# @param [Boolean] versioning whether to create new version entries (only applicable if +type+ corresponds to a versionable file)
|
10
9
|
|
11
|
-
|
10
|
+
def self.call(generic_file, file, additional_services: [], update_existing: true, versioning: true)
|
12
11
|
Hydra::Works::AddFileToGenericFile.call(generic_file, file, :original_file, update_existing: update_existing, versioning: versioning)
|
13
12
|
|
14
13
|
# Call any additional services
|
@@ -19,6 +18,5 @@ module Hydra::Works
|
|
19
18
|
generic_file.save
|
20
19
|
generic_file
|
21
20
|
end
|
22
|
-
|
23
21
|
end
|
24
22
|
end
|
data/lib/hydra/works/version.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'rdf'
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
module Hydra::Works
|
3
|
+
module Vocab
|
4
|
+
class WorksTerms < RDF::Vocabulary('http://projecthydra.org/works/models#')
|
5
|
+
# Class definitions
|
6
|
+
term :Collection
|
7
|
+
term :GenericWork
|
8
|
+
term :GenericFile
|
9
|
+
term :File
|
10
|
+
end
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
namespace :hydra_works do
|
4
|
+
namespace :jetty do
|
5
|
+
|
6
|
+
FULLTEXT_JARS = %w(
|
7
|
+
org/apache/james/apache-mime4j-core/0.7.2/apache-mime4j-core-0.7.2.jar
|
8
|
+
org/apache/james/apache-mime4j-dom/0.7.2/apache-mime4j-dom-0.7.2.jar
|
9
|
+
org/apache/solr/solr-cell/4.0.0/solr-cell-4.0.0.jar
|
10
|
+
org/bouncycastle/bcmail-jdk15/1.45/bcmail-jdk15-1.45.jar
|
11
|
+
org/bouncycastle/bcprov-jdk15/1.45/bcprov-jdk15-1.45.jar
|
12
|
+
de/l3s/boilerpipe/boilerpipe/1.1.0/boilerpipe-1.1.0.jar
|
13
|
+
org/apache/commons/commons-compress/1.4.1/commons-compress-1.4.1.jar
|
14
|
+
dom4j/dom4j/1.6.1/dom4j-1.6.1.jar
|
15
|
+
org/apache/pdfbox/fontbox/1.7.0/fontbox-1.7.0.jar
|
16
|
+
com/ibm/icu/icu4j/49.1/icu4j-49.1.jar
|
17
|
+
com/googlecode/mp4parser/isoparser/1.0-RC-1/isoparser-1.0-RC-1.jar
|
18
|
+
jdom/jdom/1.0/jdom-1.0.jar
|
19
|
+
org/apache/pdfbox/jempbox/1.7.0/jempbox-1.7.0.jar
|
20
|
+
com/googlecode/juniversalchardet/juniversalchardet/1.0.3/juniversalchardet-1.0.3.jar
|
21
|
+
com/drewnoakes/metadata-extractor/2.4.0-beta-1/metadata-extractor-2.4.0-beta-1.jar
|
22
|
+
edu/ucar/netcdf/4.2-min/netcdf-4.2-min.jar
|
23
|
+
org/apache/pdfbox/pdfbox/1.7.0/pdfbox-1.7.0.jar
|
24
|
+
org/apache/poi/poi/3.8/poi-3.8.jar
|
25
|
+
org/apache/poi/poi-ooxml/3.8/poi-ooxml-3.8.jar
|
26
|
+
org/apache/poi/poi-ooxml-schemas/3.8/poi-ooxml-schemas-3.8.jar
|
27
|
+
org/apache/poi/poi-scratchpad/3.8/poi-scratchpad-3.8.jar
|
28
|
+
rome/rome/0.9/rome-0.9.jar
|
29
|
+
org/ccil/cowan/tagsoup/tagsoup/1.2.1/tagsoup-1.2.1.jar
|
30
|
+
org/apache/tika/tika-core/1.2/tika-core-1.2.jar
|
31
|
+
org/apache/tika/tika-parsers/1.2/tika-parsers-1.2.jar
|
32
|
+
org/gagravarr/vorbis-java-core/0.1/vorbis-java-core-0.1.jar
|
33
|
+
org/gagravarr/vorbis-java-tika/0.1/vorbis-java-tika-0.1.jar
|
34
|
+
xerces/xercesImpl/2.9.1/xercesImpl-2.9.1.jar
|
35
|
+
org/apache/xmlbeans/xmlbeans/2.3.0/xmlbeans-2.3.0.jar
|
36
|
+
org/tukaani/xz/1.0/xz-1.0.jar
|
37
|
+
org/aspectj/aspectjrt/1.8.5/aspectjrt-1.8.5.jar
|
38
|
+
)
|
39
|
+
|
40
|
+
desc 'Configure jetty with full-text indexing'
|
41
|
+
task config: :download_jars do
|
42
|
+
Rake::Task['jetty:config'].invoke
|
43
|
+
end
|
44
|
+
|
45
|
+
desc 'Download Solr full-text extraction jars'
|
46
|
+
task :download_jars do
|
47
|
+
puts "Copying new solrconfig.xml"
|
48
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'config', 'solrconfig.xml')
|
49
|
+
dest = File.join('solr_conf','conf')
|
50
|
+
FileUtils.mkdir_p(dest) unless File.directory?(dest)
|
51
|
+
cp source, dest
|
52
|
+
puts "Downloading full-text jars from maven.org ..."
|
53
|
+
fulltext_dir = 'jetty/solr/lib/contrib/extraction/lib'
|
54
|
+
FileUtils.mkdir_p(fulltext_dir) unless File.directory?(fulltext_dir)
|
55
|
+
Dir.chdir(fulltext_dir) do
|
56
|
+
FULLTEXT_JARS.each do |jar|
|
57
|
+
destination = jar.split('/').last
|
58
|
+
download_from_maven(jar, destination) unless File.exists?(destination)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def download_from_maven url, dst
|
66
|
+
full_url = '/remotecontent?filepath=' + url
|
67
|
+
file = File.open(dst, "wb")
|
68
|
+
endpoint = Net::HTTP.new('search.maven.org', 443)
|
69
|
+
endpoint.use_ssl = true
|
70
|
+
endpoint.start do |http|
|
71
|
+
puts "Fetching #{full_url}"
|
72
|
+
begin
|
73
|
+
http.request_get(full_url) do |resp|
|
74
|
+
resp.read_body { |segment| file.write(segment) }
|
75
|
+
end
|
76
|
+
ensure
|
77
|
+
file.close
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
namespace :jetty do
|
2
|
+
desc "Copies the default Solr & Fedora configs into the bundled Hydra Testing Server"
|
3
|
+
task :config do
|
4
|
+
Rake::Task['hydra_works:jetty:download_jars'].invoke
|
5
|
+
Rake::Task["jetty:config_solr"].invoke
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Copies the contents of solr_conf into the Solr development-core and test-core of Testing Server"
|
9
|
+
task :config_solr do
|
10
|
+
FileList['solr_conf/conf/*'].each do |f|
|
11
|
+
cp("#{f}", 'jetty/solr/development-core/conf/', verbose: true)
|
12
|
+
cp("#{f}", 'jetty/solr/test-core/conf/', verbose: true)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,51 +1,52 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Hydra::Works::Collection do
|
4
|
+
subject { described_class.new }
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
let(:
|
8
|
-
let(:
|
9
|
-
let(:collection3) { Hydra::Works::Collection.new }
|
6
|
+
let(:collection1) { described_class.new }
|
7
|
+
let(:collection2) { described_class.new }
|
8
|
+
let(:collection3) { described_class.new }
|
9
|
+
let(:collection4) { described_class.new }
|
10
10
|
|
11
11
|
let(:generic_work1) { Hydra::Works::GenericWork::Base.new }
|
12
12
|
let(:generic_work2) { Hydra::Works::GenericWork::Base.new }
|
13
13
|
let(:generic_work3) { Hydra::Works::GenericWork::Base.new }
|
14
|
+
let(:generic_work4) { Hydra::Works::GenericWork::Base.new }
|
14
15
|
|
15
|
-
describe '#
|
16
|
-
it '
|
17
|
-
subject.
|
18
|
-
subject.
|
19
|
-
expect(subject.
|
16
|
+
describe '#collections' do
|
17
|
+
it 'returns empty array when only generic_works are aggregated' do
|
18
|
+
subject.generic_works << generic_work1
|
19
|
+
subject.generic_works << generic_work2
|
20
|
+
expect(subject.collections).to eq []
|
20
21
|
end
|
21
22
|
|
22
|
-
context 'with other collections & generic_works' do
|
23
|
-
before do
|
24
|
-
subject.
|
25
|
-
subject.
|
26
|
-
subject.
|
27
|
-
subject.
|
23
|
+
context 'with other collections & generic_works' do
|
24
|
+
before do
|
25
|
+
subject.collections << collection1
|
26
|
+
subject.collections << collection2
|
27
|
+
subject.generic_works << generic_work1
|
28
|
+
subject.generic_works << generic_work2
|
28
29
|
end
|
29
30
|
|
30
|
-
it '
|
31
|
-
expect(subject.
|
31
|
+
it 'returns only collections' do
|
32
|
+
expect(subject.collections).to eq [collection1, collection2]
|
32
33
|
end
|
33
|
-
end
|
34
|
+
end
|
34
35
|
end
|
35
36
|
|
36
|
-
describe '#
|
37
|
+
describe '#collections <<' do
|
37
38
|
context 'with acceptable collections' do
|
38
39
|
context 'with collections and generic_works' do
|
39
40
|
before do
|
40
|
-
subject.
|
41
|
-
subject.
|
42
|
-
subject.
|
43
|
-
subject.
|
41
|
+
subject.collections << collection1
|
42
|
+
subject.collections << collection2
|
43
|
+
subject.generic_works << generic_work1
|
44
|
+
subject.generic_works << generic_work2
|
44
45
|
end
|
45
46
|
|
46
|
-
it '
|
47
|
-
subject.
|
48
|
-
expect(
|
47
|
+
it 'adds an generic_work to collection with collections and generic_works' do
|
48
|
+
subject.collections << collection3
|
49
|
+
expect(subject.collections).to eq [collection1, collection2, collection3]
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
@@ -58,14 +59,14 @@ describe Hydra::Works::Collection do
|
|
58
59
|
after { Object.send(:remove_const, :Kollection) }
|
59
60
|
let(:kollection1) { Kollection.new }
|
60
61
|
|
61
|
-
it '
|
62
|
-
subject.
|
63
|
-
expect(
|
62
|
+
it 'accepts implementing collection as a child' do
|
63
|
+
subject.collections << kollection1
|
64
|
+
expect(subject.collections).to eq [kollection1]
|
64
65
|
end
|
65
66
|
|
66
|
-
it '
|
67
|
-
subject.
|
68
|
-
expect(
|
67
|
+
it 'accepts implementing collection as a parent' do
|
68
|
+
subject.collections << collection1
|
69
|
+
expect(subject.collections).to eq [collection1]
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
@@ -77,137 +78,135 @@ describe Hydra::Works::Collection do
|
|
77
78
|
after { Object.send(:remove_const, :Cullection) }
|
78
79
|
let(:cullection1) { Cullection.new }
|
79
80
|
|
80
|
-
it '
|
81
|
-
subject.
|
82
|
-
expect(
|
81
|
+
it 'accepts extending collection as a child' do
|
82
|
+
subject.collections << cullection1
|
83
|
+
expect(subject.collections).to eq [cullection1]
|
83
84
|
end
|
84
85
|
|
85
|
-
it '
|
86
|
-
subject.
|
87
|
-
expect(
|
86
|
+
it 'accepts extending collection as a parent' do
|
87
|
+
subject.collections << collection1
|
88
|
+
expect(subject.collections).to eq [collection1]
|
88
89
|
end
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
92
93
|
context 'with unacceptable inputs' do
|
93
94
|
before(:all) do
|
94
|
-
@works_collection101 =
|
95
|
+
@works_collection101 = described_class.new
|
95
96
|
@generic_work101 = Hydra::Works::GenericWork::Base.new
|
96
97
|
@generic_file101 = Hydra::Works::GenericFile::Base.new
|
97
98
|
@pcdm_collection101 = Hydra::PCDM::Collection.new
|
98
99
|
@pcdm_object101 = Hydra::PCDM::Object.new
|
99
100
|
@pcdm_file101 = Hydra::PCDM::File.new
|
100
|
-
@
|
101
|
+
@non_pcdm_object = "I'm not a PCDM object"
|
101
102
|
@af_base_object = ActiveFedora::Base.new
|
102
103
|
end
|
103
104
|
|
104
105
|
context 'that are unacceptable child collections' do
|
105
|
-
|
106
106
|
let(:error_type1) { ArgumentError }
|
107
107
|
let(:error_message1) { /Hydra::Works::Generic(Work|File)::Base with ID: was expected to works_collection\?, but it was false/ }
|
108
108
|
let(:error_type2) { NoMethodError }
|
109
109
|
let(:error_message2) { /undefined method `works_collection\?' for .*/ }
|
110
110
|
|
111
|
-
it '
|
112
|
-
expect{ subject.
|
111
|
+
it 'does not aggregate Hydra::Works::GenericWork in collections aggregation' do
|
112
|
+
expect { subject.collections << @generic_work101 }.to raise_error(error_type1, error_message1)
|
113
113
|
end
|
114
114
|
|
115
|
-
it '
|
116
|
-
expect{ subject.
|
115
|
+
it 'does not aggregate Hydra::Works::GenericFile in collections aggregation' do
|
116
|
+
expect { subject.collections << @generic_file101 }.to raise_error(error_type1, error_message1)
|
117
117
|
end
|
118
118
|
|
119
|
-
it '
|
120
|
-
expect{ subject.
|
119
|
+
it 'does not aggregate Hydra::PCDM::Collections in collections aggregation' do
|
120
|
+
expect { subject.collections << @pcdm_collection101 }.to raise_error(error_type2, error_message2)
|
121
121
|
end
|
122
122
|
|
123
|
-
it '
|
124
|
-
expect{ subject.
|
123
|
+
it 'does not aggregate Hydra::PCDM::Objects in collections aggregation' do
|
124
|
+
expect { subject.collections << @pcdm_object101 }.to raise_error(error_type2, error_message2)
|
125
125
|
end
|
126
126
|
|
127
|
-
it '
|
128
|
-
expect{ subject.
|
127
|
+
it 'does not aggregate Hydra::PCDM::Files in collections aggregation' do
|
128
|
+
expect { subject.collections << @pcdm_file101 }.to raise_error(error_type2, error_message2)
|
129
129
|
end
|
130
130
|
|
131
|
-
it '
|
132
|
-
expect{ subject.
|
131
|
+
it 'does not aggregate non-PCDM objects in collections aggregation' do
|
132
|
+
expect { subject.collections << @non_pcdm_object }.to raise_error(error_type2, error_message2)
|
133
133
|
end
|
134
134
|
|
135
|
-
it '
|
136
|
-
expect{ subject.
|
135
|
+
it 'does not aggregate AF::Base objects in collections aggregation' do
|
136
|
+
expect { subject.collections << @af_base_object }.to raise_error(error_type2, error_message2)
|
137
137
|
end
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
-
describe '
|
142
|
+
describe 'collections.delete' do
|
143
143
|
context 'when multiple collections' do
|
144
144
|
before do
|
145
|
-
subject.
|
146
|
-
subject.
|
147
|
-
subject.
|
148
|
-
subject.
|
149
|
-
subject.
|
150
|
-
expect(
|
151
|
-
end
|
152
|
-
|
153
|
-
it '
|
154
|
-
expect(
|
155
|
-
expect(
|
156
|
-
expect(
|
157
|
-
end
|
158
|
-
|
159
|
-
it '
|
160
|
-
expect(
|
161
|
-
expect(
|
162
|
-
expect(
|
163
|
-
end
|
164
|
-
|
165
|
-
it '
|
166
|
-
expect(
|
167
|
-
expect(
|
168
|
-
expect(
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
describe '#
|
174
|
-
it '
|
175
|
-
subject.
|
176
|
-
subject.
|
177
|
-
expect(subject.
|
145
|
+
subject.collections << collection1
|
146
|
+
subject.collections << collection2
|
147
|
+
subject.generic_works << generic_work2
|
148
|
+
subject.collections << collection3
|
149
|
+
subject.generic_works << generic_work1
|
150
|
+
expect(subject.collections).to eq [collection1, collection2, collection3]
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'removes first collection' do
|
154
|
+
expect(subject.collections.delete collection1).to eq [collection1]
|
155
|
+
expect(subject.collections).to eq [collection2, collection3]
|
156
|
+
expect(subject.generic_works).to eq [generic_work2, generic_work1]
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'removes last collection' do
|
160
|
+
expect(subject.collections.delete collection3).to eq [collection3]
|
161
|
+
expect(subject.collections).to eq [collection1, collection2]
|
162
|
+
expect(subject.generic_works). to eq [generic_work2, generic_work1]
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'removes middle collection' do
|
166
|
+
expect(subject.collections.delete collection2).to eq [collection2]
|
167
|
+
expect(subject.collections).to eq [collection1, collection3]
|
168
|
+
expect(subject.generic_works). to eq [generic_work2, generic_work1]
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe '#generic_works' do
|
174
|
+
it 'returns empty array when only collections are aggregated' do
|
175
|
+
subject.collections << collection1
|
176
|
+
subject.collections << collection2
|
177
|
+
expect(subject.generic_works). to eq []
|
178
178
|
end
|
179
179
|
|
180
180
|
context 'with collections and generic works' do
|
181
|
-
before do
|
182
|
-
subject.
|
183
|
-
subject.
|
184
|
-
subject.
|
185
|
-
subject.
|
181
|
+
before do
|
182
|
+
subject.collections << collection1
|
183
|
+
subject.collections << collection2
|
184
|
+
subject.generic_works << generic_work1
|
185
|
+
subject.generic_works << generic_work2
|
186
186
|
end
|
187
187
|
|
188
|
-
it '
|
189
|
-
expect(subject.
|
188
|
+
it 'returns only generic works' do
|
189
|
+
expect(subject.generic_works). to eq [generic_work1, generic_work2]
|
190
190
|
end
|
191
191
|
end
|
192
|
-
end
|
192
|
+
end
|
193
193
|
|
194
|
-
describe '#
|
195
|
-
|
194
|
+
describe '#generic_works <<' do
|
196
195
|
context 'with acceptable generic_works' do
|
197
196
|
context 'with collections and generic_works' do
|
198
197
|
before do
|
199
|
-
subject.
|
200
|
-
subject.
|
201
|
-
subject.
|
202
|
-
subject.
|
198
|
+
subject.collections << collection1
|
199
|
+
subject.collections << collection2
|
200
|
+
subject.generic_works << generic_work1
|
201
|
+
subject.generic_works << generic_work2
|
203
202
|
end
|
204
203
|
|
205
|
-
it '
|
206
|
-
subject.
|
207
|
-
expect(
|
204
|
+
it 'adds generic_work to collection with collections and generic_works' do
|
205
|
+
subject.generic_works << generic_work3
|
206
|
+
expect(subject.generic_works).to eq [generic_work1, generic_work2, generic_work3]
|
208
207
|
end
|
209
208
|
end
|
210
|
-
|
209
|
+
|
211
210
|
describe 'aggregates generic_works that implement Hydra::Works' do
|
212
211
|
before do
|
213
212
|
class DummyIncWork < ActiveFedora::Base
|
@@ -216,12 +215,12 @@ describe Hydra::Works::Collection do
|
|
216
215
|
end
|
217
216
|
after { Object.send(:remove_const, :DummyIncWork) }
|
218
217
|
let(:iwork1) { DummyIncWork.new }
|
219
|
-
|
220
|
-
it '
|
221
|
-
subject.
|
222
|
-
expect(
|
218
|
+
|
219
|
+
it 'accepts implementing generic_work as a child' do
|
220
|
+
subject.generic_works << iwork1
|
221
|
+
expect(subject.generic_works).to eq [iwork1]
|
223
222
|
end
|
224
|
-
end
|
223
|
+
end
|
225
224
|
|
226
225
|
describe 'aggregates generic_works that extend Hydra::Works' do
|
227
226
|
before do
|
@@ -231,93 +230,92 @@ describe Hydra::Works::Collection do
|
|
231
230
|
after { Object.send(:remove_const, :DummyExtWork) }
|
232
231
|
let(:ework1) { DummyExtWork.new }
|
233
232
|
|
234
|
-
it '
|
235
|
-
subject.
|
236
|
-
expect(
|
233
|
+
it 'accepts extending generic_work as a child' do
|
234
|
+
subject.generic_works << ework1
|
235
|
+
expect(subject.generic_works).to eq [ework1]
|
237
236
|
end
|
238
237
|
end
|
239
238
|
end
|
240
239
|
|
241
240
|
context 'with unacceptable inputs' do
|
242
241
|
before(:all) do
|
243
|
-
@works_collection101 =
|
244
|
-
@works_collection102 =
|
242
|
+
@works_collection101 = described_class.new
|
243
|
+
@works_collection102 = described_class.new
|
245
244
|
@generic_file101 = Hydra::Works::GenericFile::Base.new
|
246
245
|
@pcdm_collection101 = Hydra::PCDM::Collection.new
|
247
246
|
@pcdm_object101 = Hydra::PCDM::Object.new
|
248
247
|
@pcdm_file101 = Hydra::PCDM::File.new
|
249
|
-
@
|
248
|
+
@non_pcdm_object = "I'm not a PCDM object"
|
250
249
|
@af_base_object = ActiveFedora::Base.new
|
251
250
|
end
|
252
251
|
|
253
252
|
context 'that are unacceptable child generic works' do
|
254
|
-
|
255
253
|
let(:error_type1) { ArgumentError }
|
256
254
|
let(:error_message1) { /Hydra::Works::(GenericFile::Base|Collection) with ID: was expected to works_generic_work\?, but it was false/ }
|
257
255
|
let(:error_type2) { NoMethodError }
|
258
256
|
let(:error_message2) { /undefined method `works_generic_work\?' for .*/ }
|
259
257
|
|
260
|
-
it '
|
261
|
-
expect{ subject.
|
258
|
+
it 'does not aggregate Hydra::Works::Collection in generic works aggregation' do
|
259
|
+
expect { subject.generic_works << @works_collection101 }.to raise_error(error_type1, error_message1)
|
262
260
|
end
|
263
261
|
|
264
|
-
it '
|
265
|
-
expect{ subject.
|
262
|
+
it 'does not aggregate Hydra::Works::GenericFile in generic works aggregation' do
|
263
|
+
expect { subject.generic_works << @generic_file101 }.to raise_error(error_type1, error_message1)
|
266
264
|
end
|
267
265
|
|
268
|
-
it '
|
269
|
-
expect{ subject.
|
266
|
+
it 'does not aggregate Hydra::PCDM::Collections in generic works aggregation' do
|
267
|
+
expect { subject.generic_works << @pcdm_collection101 }.to raise_error(error_type2, error_message2)
|
270
268
|
end
|
271
269
|
|
272
|
-
it '
|
273
|
-
expect{ subject.
|
270
|
+
it 'does not aggregate Hydra::PCDM::Objects in generic works aggregation' do
|
271
|
+
expect { subject.generic_works << @pcdm_object101 }.to raise_error(error_type2, error_message2)
|
274
272
|
end
|
275
273
|
|
276
|
-
it '
|
277
|
-
expect{ subject.
|
274
|
+
it 'does not aggregate Hydra::PCDM::Files in generic works aggregation' do
|
275
|
+
expect { subject.generic_works << @pcdm_file101 }.to raise_error(error_type2, error_message2)
|
278
276
|
end
|
279
277
|
|
280
|
-
it '
|
281
|
-
expect{ subject.
|
278
|
+
it 'does not aggregate non-PCDM objects in generic works aggregation' do
|
279
|
+
expect { subject.generic_works << @non_pcdm_object }.to raise_error(error_type2, error_message2)
|
282
280
|
end
|
283
281
|
|
284
|
-
it '
|
285
|
-
expect{ subject.
|
282
|
+
it 'does not aggregate AF::Base objects in generic works aggregation' do
|
283
|
+
expect { subject.generic_works << @af_base_object }.to raise_error(error_type2, error_message2)
|
286
284
|
end
|
287
285
|
end
|
288
286
|
end
|
289
287
|
end
|
290
288
|
|
291
|
-
describe '#
|
289
|
+
describe '#generic_works.delete' do
|
292
290
|
context 'when multiple generic works' do
|
293
291
|
before do
|
294
|
-
subject.
|
295
|
-
subject.
|
296
|
-
subject.
|
297
|
-
subject.
|
298
|
-
subject.
|
299
|
-
expect(
|
300
|
-
end
|
301
|
-
|
302
|
-
it '
|
303
|
-
expect(
|
304
|
-
expect(
|
305
|
-
expect(
|
306
|
-
end
|
307
|
-
|
308
|
-
it '
|
309
|
-
expect(
|
310
|
-
expect(
|
311
|
-
expect(
|
312
|
-
end
|
313
|
-
|
314
|
-
it '
|
315
|
-
expect(
|
316
|
-
expect(
|
317
|
-
expect(
|
318
|
-
end
|
319
|
-
end
|
320
|
-
end
|
292
|
+
subject.generic_works << generic_work1
|
293
|
+
subject.generic_works << generic_work2
|
294
|
+
subject.collections << collection2
|
295
|
+
subject.generic_works << generic_work3
|
296
|
+
subject.collections << collection1
|
297
|
+
expect(subject.generic_works). to eq [generic_work1, generic_work2, generic_work3]
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'removes first generic work' do
|
301
|
+
expect(subject.generic_works.delete generic_work1).to eq [generic_work1]
|
302
|
+
expect(subject.generic_works). to eq [generic_work2, generic_work3]
|
303
|
+
expect(subject.collections).to eq [collection2, collection1]
|
304
|
+
end
|
305
|
+
|
306
|
+
it 'removes last generic work' do
|
307
|
+
expect(subject.generic_works.delete generic_work3).to eq [generic_work3]
|
308
|
+
expect(subject.generic_works). to eq [generic_work1, generic_work2]
|
309
|
+
expect(subject.collections).to eq [collection2, collection1]
|
310
|
+
end
|
311
|
+
|
312
|
+
it 'removes middle generic work' do
|
313
|
+
expect(subject.generic_works.delete generic_work2).to eq [generic_work2]
|
314
|
+
expect(subject.generic_works). to eq [generic_work1, generic_work3]
|
315
|
+
expect(subject.collections).to eq [collection2, collection1]
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
321
319
|
|
322
320
|
describe '#related_objects' do
|
323
321
|
let(:generic_file1) { Hydra::Works::GenericFile::Base.new }
|
@@ -326,69 +324,68 @@ describe Hydra::Works::Collection do
|
|
326
324
|
|
327
325
|
context 'with collections and generic works' do
|
328
326
|
before do
|
329
|
-
subject.
|
330
|
-
subject.
|
331
|
-
subject.
|
327
|
+
subject.collections << collection1
|
328
|
+
subject.collections << collection2
|
329
|
+
subject.generic_works << generic_work1
|
332
330
|
end
|
333
|
-
|
334
|
-
it '
|
335
|
-
expect(subject.related_objects
|
331
|
+
|
332
|
+
it 'returns empty array when only collections and generic works are aggregated' do
|
333
|
+
expect(subject.related_objects).to eq []
|
336
334
|
end
|
337
|
-
|
338
|
-
it '
|
335
|
+
|
336
|
+
it 'returns only related objects' do
|
339
337
|
subject.related_objects << object2
|
340
|
-
expect(subject.related_objects
|
338
|
+
expect(subject.related_objects).to eq [object2]
|
341
339
|
end
|
342
|
-
|
343
|
-
it '
|
340
|
+
|
341
|
+
it 'returns related objects of various types' do
|
344
342
|
subject.related_objects << generic_work2
|
345
343
|
subject.related_objects << generic_file1
|
346
344
|
subject.related_objects << object1
|
347
345
|
subject.save
|
348
346
|
subject.reload
|
349
|
-
expect(
|
350
|
-
expect(
|
351
|
-
expect(
|
352
|
-
expect(
|
347
|
+
expect(subject.related_objects.include? object1).to be true
|
348
|
+
expect(subject.related_objects.include? generic_work2).to be true
|
349
|
+
expect(subject.related_objects.include? generic_file1).to be true
|
350
|
+
expect(subject.related_objects.size).to eq 3
|
353
351
|
end
|
354
352
|
end
|
355
353
|
end
|
356
354
|
|
357
355
|
describe '#related_objects <<' do
|
358
|
-
|
359
356
|
context 'with acceptable related objects' do
|
360
357
|
let(:object1) { Hydra::PCDM::Object.new }
|
361
358
|
let(:object2) { Hydra::PCDM::Object.new }
|
362
359
|
let(:generic_file1) { Hydra::Works::GenericFile::Base.new }
|
363
360
|
|
364
|
-
it '
|
361
|
+
it 'adds various types of related objects to collection' do
|
365
362
|
subject.related_objects << generic_work1
|
366
363
|
subject.related_objects << generic_file1
|
367
364
|
subject.related_objects << object1
|
368
365
|
subject.save
|
369
366
|
subject.reload
|
370
|
-
expect(
|
371
|
-
expect(
|
372
|
-
expect(
|
373
|
-
expect(
|
367
|
+
expect(subject.related_objects.include? generic_work1).to be true
|
368
|
+
expect(subject.related_objects.include? generic_file1).to be true
|
369
|
+
expect(subject.related_objects.include? object1).to be true
|
370
|
+
expect(subject.related_objects.size).to eq 3
|
374
371
|
end
|
375
372
|
|
376
373
|
context 'with collections and generic_works' do
|
377
374
|
before do
|
378
|
-
subject.
|
379
|
-
subject.
|
380
|
-
subject.
|
381
|
-
subject.
|
375
|
+
subject.collections << collection1
|
376
|
+
subject.collections << collection2
|
377
|
+
subject.generic_works << generic_work1
|
378
|
+
subject.generic_works << generic_work2
|
382
379
|
subject.related_objects << object1
|
383
380
|
end
|
384
381
|
|
385
|
-
it '
|
382
|
+
it 'adds a related object to collection with collections and generic_works' do
|
386
383
|
subject.related_objects << object2
|
387
384
|
subject.save
|
388
385
|
subject.reload
|
389
|
-
expect(
|
390
|
-
expect(
|
391
|
-
expect(
|
386
|
+
expect(subject.related_objects.include? object1).to be true
|
387
|
+
expect(subject.related_objects.include? object2).to be true
|
388
|
+
expect(subject.related_objects.size).to eq 2
|
392
389
|
end
|
393
390
|
end
|
394
391
|
end
|
@@ -399,24 +396,24 @@ describe Hydra::Works::Collection do
|
|
399
396
|
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
400
397
|
let(:af_base_object) { ActiveFedora::Base.new }
|
401
398
|
|
402
|
-
it '
|
403
|
-
expect{ subject.related_objects << collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::Works::Collection:.*> is not a PCDM object./)
|
399
|
+
it 'does not aggregate Hydra::Works::Collection in related objects aggregation' do
|
400
|
+
expect { subject.related_objects << collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::Works::Collection:.*> is not a PCDM object./)
|
404
401
|
end
|
405
402
|
|
406
|
-
it '
|
407
|
-
expect{ subject.related_objects << pcdm_collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::PCDM::Collection:.* is not a PCDM object./)
|
403
|
+
it 'does not aggregate Hydra::PCDM::Collections in related objects aggregation' do
|
404
|
+
expect { subject.related_objects << pcdm_collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::PCDM::Collection:.* is not a PCDM object./)
|
408
405
|
end
|
409
406
|
|
410
|
-
it '
|
411
|
-
expect{ subject.related_objects << pcdm_file1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got Hydra::PCDM::File.*/)
|
407
|
+
it 'does not aggregate Hydra::PCDM::Files in related objects aggregation' do
|
408
|
+
expect { subject.related_objects << pcdm_file1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got Hydra::PCDM::File.*/)
|
412
409
|
end
|
413
410
|
|
414
|
-
it '
|
415
|
-
expect{ subject.related_objects << non_PCDM_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got String.*/)
|
411
|
+
it 'does not aggregate non-PCDM objects in related objects aggregation' do
|
412
|
+
expect { subject.related_objects << non_PCDM_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got String.*/)
|
416
413
|
end
|
417
414
|
|
418
|
-
it '
|
419
|
-
expect{ subject.related_objects << af_base_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* is not a PCDM object./)
|
415
|
+
it 'does not aggregate AF::Base objects in related objects aggregation' do
|
416
|
+
expect { subject.related_objects << af_base_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* is not a PCDM object./)
|
420
417
|
end
|
421
418
|
end
|
422
419
|
|
@@ -424,16 +421,16 @@ describe Hydra::Works::Collection do
|
|
424
421
|
let(:object1) { Hydra::PCDM::Object.new }
|
425
422
|
let(:object2) { Hydra::PCDM::Object.new }
|
426
423
|
|
427
|
-
it '
|
424
|
+
it 'does not allow related objects to repeat' do
|
428
425
|
skip 'skipping this test because issue pcdm#92 needs to be addressed' do
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
426
|
+
subject.related_objects << object1
|
427
|
+
subject.related_objects << object2
|
428
|
+
subject.related_objects << object1
|
429
|
+
related_objects = subject.related_objects
|
430
|
+
expect(related_objects.include? object1).to be true
|
431
|
+
expect(related_objects.include? object2).to be true
|
432
|
+
expect(related_objects.size).to eq 2
|
433
|
+
end
|
437
434
|
end
|
438
435
|
end
|
439
436
|
end
|
@@ -449,55 +446,55 @@ describe Hydra::Works::Collection do
|
|
449
446
|
before do
|
450
447
|
subject.related_objects << related_object1
|
451
448
|
subject.related_objects << related_work2
|
452
|
-
subject.
|
453
|
-
subject.
|
449
|
+
subject.collections << collection2
|
450
|
+
subject.generic_works << generic_work1
|
454
451
|
subject.related_objects << related_file3
|
455
452
|
subject.related_objects << related_object4
|
456
|
-
subject.
|
453
|
+
subject.collections << collection1
|
457
454
|
subject.related_objects << related_work5
|
458
|
-
expect(
|
455
|
+
expect(subject.related_objects).to eq [related_object1, related_work2, related_file3, related_object4, related_work5]
|
459
456
|
end
|
460
|
-
|
461
|
-
it '
|
462
|
-
expect(
|
463
|
-
expect(
|
464
|
-
expect(
|
465
|
-
expect(
|
457
|
+
|
458
|
+
it 'removes first related object' do
|
459
|
+
expect(subject.related_objects.delete related_object1).to eq [related_object1]
|
460
|
+
expect(subject.related_objects).to eq [related_work2, related_file3, related_object4, related_work5]
|
461
|
+
expect(subject.collections).to eq [collection2, collection1]
|
462
|
+
expect(subject.generic_works). to eq [generic_work1]
|
466
463
|
end
|
467
464
|
|
468
|
-
it '
|
469
|
-
expect(
|
470
|
-
expect(
|
471
|
-
expect(
|
472
|
-
expect(
|
465
|
+
it 'removes last related object' do
|
466
|
+
expect(subject.related_objects.delete related_work5).to eq [related_work5]
|
467
|
+
expect(subject.related_objects).to eq [related_object1, related_work2, related_file3, related_object4]
|
468
|
+
expect(subject.collections).to eq [collection2, collection1]
|
469
|
+
expect(subject.generic_works). to eq [generic_work1]
|
473
470
|
end
|
474
|
-
|
475
|
-
it '
|
476
|
-
expect(
|
477
|
-
expect(
|
478
|
-
expect(
|
479
|
-
expect(
|
471
|
+
|
472
|
+
it 'removes middle related object' do
|
473
|
+
expect(subject.related_objects.delete related_file3).to eq [related_file3]
|
474
|
+
expect(subject.related_objects).to eq [related_object1, related_work2, related_object4, related_work5]
|
475
|
+
expect(subject.collections).to eq [collection2, collection1]
|
476
|
+
expect(subject.generic_works). to eq [generic_work1]
|
480
477
|
end
|
481
|
-
end
|
482
|
-
end
|
478
|
+
end
|
479
|
+
end
|
483
480
|
|
484
481
|
describe '#collections=' do
|
485
|
-
it '
|
486
|
-
collection1.
|
487
|
-
expect(collection1.
|
482
|
+
it 'aggregates collections' do
|
483
|
+
collection1.collections = [collection2, collection3]
|
484
|
+
expect(collection1.collections).to eq [collection2, collection3]
|
488
485
|
end
|
489
486
|
end
|
490
487
|
|
491
|
-
describe '#
|
492
|
-
it '
|
493
|
-
collection1.
|
494
|
-
expect(collection1.
|
488
|
+
describe '#generic_works=' do
|
489
|
+
it 'aggregates generic_works' do
|
490
|
+
collection1.generic_works = [generic_work1, generic_work2]
|
491
|
+
expect(collection1.generic_works).to eq [generic_work1, generic_work2]
|
495
492
|
end
|
496
493
|
end
|
497
494
|
|
498
495
|
describe 'Related objects' do
|
499
496
|
let(:object) { Hydra::PCDM::Object.new }
|
500
|
-
let(:collection) {
|
497
|
+
let(:collection) { described_class.new }
|
501
498
|
|
502
499
|
before do
|
503
500
|
collection.related_objects = [object]
|
@@ -508,17 +505,32 @@ describe Hydra::Works::Collection do
|
|
508
505
|
end
|
509
506
|
end
|
510
507
|
|
511
|
-
describe
|
508
|
+
describe 'should have parent collection accessors' do
|
512
509
|
before do
|
513
|
-
collection1.
|
510
|
+
collection1.collections << collection2
|
514
511
|
collection1.save
|
515
512
|
end
|
516
513
|
|
517
|
-
it '
|
518
|
-
expect(collection2.
|
514
|
+
it 'has parents' do
|
515
|
+
expect(collection2.member_of).to eq [collection1]
|
516
|
+
end
|
517
|
+
it 'has a parent collection' do
|
518
|
+
expect(collection2.in_collections).to eq [collection1]
|
519
519
|
end
|
520
|
-
|
520
|
+
end
|
521
|
+
|
522
|
+
describe 'make sure deprecated methods still work' do
|
523
|
+
it 'deprecated methods should pass' do
|
524
|
+
expect(collection1.child_collections = [collection2]).to eq [collection2]
|
525
|
+
expect(collection1.child_collections << collection3).to eq [collection2, collection3]
|
526
|
+
expect(collection1.child_collections += [collection4]).to eq [collection2, collection3, collection4]
|
527
|
+
expect(collection1.child_generic_works = [generic_work1]).to eq [generic_work1]
|
528
|
+
expect(collection1.child_generic_works << generic_work2).to eq [generic_work1, generic_work2]
|
529
|
+
expect(collection1.child_generic_works += [generic_work3]).to eq [generic_work1, generic_work2, generic_work3]
|
530
|
+
collection1.save # required until issue AF-Agg-75 is fixed
|
521
531
|
expect(collection2.parent_collections).to eq [collection1]
|
532
|
+
expect(collection2.parents).to eq [collection1]
|
533
|
+
expect(collection2.parent_collection_ids).to eq [collection1.id]
|
522
534
|
end
|
523
535
|
end
|
524
536
|
end
|