hydra-pcdm 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +26 -0
- data/.travis.yml +14 -0
- data/CONTRIBUTING.md +115 -0
- data/Gemfile +13 -0
- data/LICENSE +12 -0
- data/README.md +87 -0
- data/Rakefile +20 -0
- data/config/jetty.yml +6 -0
- data/hydra-pcdm.gemspec +30 -0
- data/lib/hydra/pcdm/collection_indexer.rb +12 -0
- data/lib/hydra/pcdm/models/collection.rb +6 -0
- data/lib/hydra/pcdm/models/concerns/collection_behavior.rb +79 -0
- data/lib/hydra/pcdm/models/concerns/object_behavior.rb +104 -0
- data/lib/hydra/pcdm/models/file.rb +20 -0
- data/lib/hydra/pcdm/models/object.rb +6 -0
- data/lib/hydra/pcdm/object_indexer.rb +10 -0
- data/lib/hydra/pcdm/services/collection/add_collection.rb +20 -0
- data/lib/hydra/pcdm/services/collection/add_object.rb +19 -0
- data/lib/hydra/pcdm/services/collection/add_related_object.rb +21 -0
- data/lib/hydra/pcdm/services/collection/get_collections.rb +18 -0
- data/lib/hydra/pcdm/services/collection/get_objects.rb +18 -0
- data/lib/hydra/pcdm/services/collection/get_related_objects.rb +17 -0
- data/lib/hydra/pcdm/services/collection/remove_collection.rb +36 -0
- data/lib/hydra/pcdm/services/collection/remove_object.rb +43 -0
- data/lib/hydra/pcdm/services/collection/remove_related_object.rb +36 -0
- data/lib/hydra/pcdm/services/file/add_type.rb +20 -0
- data/lib/hydra/pcdm/services/file/get_mime_type.rb +11 -0
- data/lib/hydra/pcdm/services/object/add_object.rb +20 -0
- data/lib/hydra/pcdm/services/object/add_related_object.rb +21 -0
- data/lib/hydra/pcdm/services/object/get_objects.rb +18 -0
- data/lib/hydra/pcdm/services/object/get_related_objects.rb +17 -0
- data/lib/hydra/pcdm/services/object/remove_object.rb +43 -0
- data/lib/hydra/pcdm/services/object/remove_related_object.rb +36 -0
- data/lib/hydra/pcdm/version.rb +5 -0
- data/lib/hydra/pcdm/vocab/ebucore_terms.rb +33 -0
- data/lib/hydra/pcdm/vocab/pcdm_terms.rb +87 -0
- data/lib/hydra/pcdm/vocab/sweetjpl_terms.rb +10 -0
- data/lib/hydra/pcdm.rb +69 -0
- data/spec/hydra/pcdm/collection_indexer_spec.rb +26 -0
- data/spec/hydra/pcdm/models/collection_spec.rb +82 -0
- data/spec/hydra/pcdm/models/file_spec.rb +56 -0
- data/spec/hydra/pcdm/models/object_spec.rb +141 -0
- data/spec/hydra/pcdm/object_indexer_spec.rb +20 -0
- data/spec/hydra/pcdm/services/collection/add_collection_spec.rb +197 -0
- data/spec/hydra/pcdm/services/collection/add_object_spec.rb +132 -0
- data/spec/hydra/pcdm/services/collection/add_related_object_spec.rb +94 -0
- data/spec/hydra/pcdm/services/collection/get_collections_spec.rb +40 -0
- data/spec/hydra/pcdm/services/collection/get_objects_spec.rb +40 -0
- data/spec/hydra/pcdm/services/collection/get_related_objects_spec.rb +37 -0
- data/spec/hydra/pcdm/services/collection/remove_collection_spec.rb +143 -0
- data/spec/hydra/pcdm/services/collection/remove_object_spec.rb +180 -0
- data/spec/hydra/pcdm/services/collection/remove_related_object_spec.rb +146 -0
- data/spec/hydra/pcdm/services/file/add_type_spec.rb +19 -0
- data/spec/hydra/pcdm/services/file/get_mime_type_spec.rb +24 -0
- data/spec/hydra/pcdm/services/object/add_object_spec.rb +186 -0
- data/spec/hydra/pcdm/services/object/add_related_object_spec.rb +94 -0
- data/spec/hydra/pcdm/services/object/get_objects_spec.rb +33 -0
- data/spec/hydra/pcdm/services/object/get_related_objects_spec.rb +39 -0
- data/spec/hydra/pcdm/services/object/remove_object_spec.rb +158 -0
- data/spec/hydra/pcdm/services/object/remove_related_object_spec.rb +126 -0
- data/spec/hydra/pcdm_spec.rb +56 -0
- data/spec/spec_helper.rb +34 -0
- metadata +215 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::Collection do
|
4
|
+
|
5
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
6
|
+
let(:collection2) { Hydra::PCDM::Collection.create }
|
7
|
+
let(:collection3) { Hydra::PCDM::Collection.create }
|
8
|
+
|
9
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
10
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
11
|
+
|
12
|
+
describe '#child_collections=' do
|
13
|
+
it 'should aggregate collections' do
|
14
|
+
collection1.child_collections = [collection2, collection3]
|
15
|
+
collection1.save
|
16
|
+
expect(collection1.child_collections).to eq [collection2, collection3]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#objects=' do
|
21
|
+
it 'should aggregate objects' do
|
22
|
+
collection1.objects = [object1,object2]
|
23
|
+
collection1.save
|
24
|
+
expect(collection1.objects).to eq [object1,object2]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'Related objects' do
|
29
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
30
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
31
|
+
|
32
|
+
before do
|
33
|
+
collection1.related_objects = [object1]
|
34
|
+
collection1.save
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'persists' do
|
38
|
+
expect(collection1.reload.related_objects).to eq [object1]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe ".indexer" do
|
43
|
+
after do
|
44
|
+
Object.send(:remove_const, :Foo)
|
45
|
+
end
|
46
|
+
|
47
|
+
context "without overriding" do
|
48
|
+
before do
|
49
|
+
class Foo < ActiveFedora::Base
|
50
|
+
include Hydra::PCDM::CollectionBehavior
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
subject { Foo.indexer }
|
55
|
+
it { is_expected.to eq Hydra::PCDM::CollectionIndexer }
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when overridden with AS::Concern" do
|
59
|
+
before do
|
60
|
+
module IndexingStuff
|
61
|
+
extend ActiveSupport::Concern
|
62
|
+
|
63
|
+
class AltIndexer; end
|
64
|
+
|
65
|
+
module ClassMethods
|
66
|
+
def indexer
|
67
|
+
AltIndexer
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class Foo < ActiveFedora::Base
|
73
|
+
include Hydra::PCDM::CollectionBehavior
|
74
|
+
include IndexingStuff
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
subject { Foo.indexer }
|
79
|
+
it { is_expected.to eq IndexingStuff::AltIndexer }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::File do
|
4
|
+
|
5
|
+
let(:file) { Hydra::PCDM::File.new }
|
6
|
+
let(:reloaded) { Hydra::PCDM::File.new(file.uri) }
|
7
|
+
|
8
|
+
describe "when saving" do
|
9
|
+
it "sets an RDF type" do
|
10
|
+
file.content = 'stuff'
|
11
|
+
expect(file.save).to be true
|
12
|
+
expect(reloaded.metadata_node.query(predicate: RDF.type, object: RDFVocabularies::PCDMTerms.File).map(&:object)).to eq [RDFVocabularies::PCDMTerms.File]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#label" do
|
17
|
+
it "saves a label" do
|
18
|
+
file.content = 'stuff'
|
19
|
+
file.label = 'foo'
|
20
|
+
expect(file.label).to eq ['foo']
|
21
|
+
expect(file.save).to be true
|
22
|
+
expect(reloaded.label).to eq ['foo']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "technical metadata" do
|
27
|
+
let(:date_created) { Date.parse "Fri, 08 May 2015 08:00:00 -0400 (EDT)" }
|
28
|
+
let(:date_modified) { Date.parse "Sat, 09 May 2015 09:00:00 -0400 (EDT)" }
|
29
|
+
let(:content) { "hello world" }
|
30
|
+
let(:file) { Hydra::PCDM::File.new.tap { |ds| ds.content = content } }
|
31
|
+
it "saves technical metadata" do
|
32
|
+
file.file_name = "picture.jpg"
|
33
|
+
file.file_size = content.length.to_s
|
34
|
+
file.date_created = date_created
|
35
|
+
file.has_mime_type = "application/jpg"
|
36
|
+
file.date_modified = date_modified
|
37
|
+
file.byte_order = "little-endian"
|
38
|
+
expect(file.save).to be true
|
39
|
+
expect(reloaded.file_name).to eq ["picture.jpg"]
|
40
|
+
expect(reloaded.file_size).to eq [content.length.to_s]
|
41
|
+
expect(reloaded.has_mime_type).to eq ["application/jpg"]
|
42
|
+
expect(reloaded.date_created).to eq [date_created]
|
43
|
+
expect(reloaded.date_modified).to eq [date_modified]
|
44
|
+
expect(reloaded.byte_order).to eq ["little-endian"]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "does not save server managed properties" do
|
48
|
+
# Currently we can't write this property because Fedora
|
49
|
+
# complains that it's a server managed property. This test
|
50
|
+
# is mostly to document this situation.
|
51
|
+
file.file_hash = "the-hash"
|
52
|
+
expect{file.save}.to raise_error(Ldp::BadRequest)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::Object do
|
4
|
+
|
5
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
6
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
7
|
+
let(:object3) { Hydra::PCDM::Object.create }
|
8
|
+
|
9
|
+
describe '#objects=' do
|
10
|
+
it 'should aggregate objects' do
|
11
|
+
object1.objects = [object2, object3]
|
12
|
+
object1.save
|
13
|
+
expect(object1.objects).to eq [object2, object3]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'Related objects' do
|
18
|
+
before do
|
19
|
+
object1.related_objects = [object2]
|
20
|
+
object1.save
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'persists' do
|
24
|
+
expect(object1.reload.related_objects).to eq [object2]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#files' do
|
29
|
+
let(:object) { described_class.create }
|
30
|
+
let(:file1) { object.files.build }
|
31
|
+
let(:file2) { object.files.build }
|
32
|
+
|
33
|
+
before do
|
34
|
+
file1.content = "I'm a file"
|
35
|
+
file2.content = "I am too"
|
36
|
+
object.save!
|
37
|
+
end
|
38
|
+
|
39
|
+
subject { described_class.find(object.id).files }
|
40
|
+
|
41
|
+
it { is_expected.to eq [file1, file2] }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "filtering files" do
|
45
|
+
let(:object) { described_class.create }
|
46
|
+
let(:thumbnail) do
|
47
|
+
file = object.files.build
|
48
|
+
Hydra::PCDM::AddTypeToFile.call(file, pcdm_thumbnail_uri)
|
49
|
+
end
|
50
|
+
|
51
|
+
let(:file) { object.files.build }
|
52
|
+
let(:pcdm_thumbnail_uri) { ::RDF::URI("http://pcdm.org/ThumbnailImage") }
|
53
|
+
|
54
|
+
before do
|
55
|
+
object.files = [file]
|
56
|
+
object.save
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "filter_files_by_type" do
|
60
|
+
context "when the object has files with that type" do
|
61
|
+
before do
|
62
|
+
thumbnail
|
63
|
+
end
|
64
|
+
it "allows you to filter the contained files by type URI" do
|
65
|
+
expect( object.filter_files_by_type(pcdm_thumbnail_uri) ).to eq [thumbnail]
|
66
|
+
end
|
67
|
+
it "only overrides the #files method when you specify :type" do
|
68
|
+
expect( object.files ).to eq [file, thumbnail]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
context "when the object does NOT have any files with that type" do
|
72
|
+
it "returns an empty array" do
|
73
|
+
expect( object.filter_files_by_type(pcdm_thumbnail_uri) ).to eq []
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "file_of_type" do
|
79
|
+
context "when the object has files with that type" do
|
80
|
+
before do
|
81
|
+
thumbnail
|
82
|
+
end
|
83
|
+
it "returns the first file with the requested type" do
|
84
|
+
expect( object.file_of_type(pcdm_thumbnail_uri) ).to eq thumbnail
|
85
|
+
end
|
86
|
+
end
|
87
|
+
context "when the object does NOT have any files with that type" do
|
88
|
+
it "initializes a contained file with the requested type" do
|
89
|
+
returned_file = object.file_of_type(pcdm_thumbnail_uri)
|
90
|
+
expect(object.files).to include(returned_file)
|
91
|
+
expect(returned_file).to be_new_record
|
92
|
+
expect(returned_file.metadata_node.get_values(:type)).to include(pcdm_thumbnail_uri)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
describe ".indexer" do
|
101
|
+
after do
|
102
|
+
Object.send(:remove_const, :Foo)
|
103
|
+
end
|
104
|
+
|
105
|
+
context "without overriding" do
|
106
|
+
before do
|
107
|
+
class Foo < ActiveFedora::Base
|
108
|
+
include Hydra::PCDM::ObjectBehavior
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
subject { Foo.indexer }
|
113
|
+
it { is_expected.to eq Hydra::PCDM::ObjectIndexer }
|
114
|
+
end
|
115
|
+
|
116
|
+
context "when overridden with AS::Concern" do
|
117
|
+
before do
|
118
|
+
module IndexingStuff
|
119
|
+
extend ActiveSupport::Concern
|
120
|
+
|
121
|
+
class AltIndexer; end
|
122
|
+
|
123
|
+
module ClassMethods
|
124
|
+
def indexer
|
125
|
+
AltIndexer
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
class Foo < ActiveFedora::Base
|
131
|
+
include Hydra::PCDM::ObjectBehavior
|
132
|
+
include IndexingStuff
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
subject { Foo.indexer }
|
137
|
+
it { is_expected.to eq IndexingStuff::AltIndexer }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::ObjectIndexer do
|
4
|
+
let(:object) { Hydra::PCDM::Object.new }
|
5
|
+
let(:subobject1) { Hydra::PCDM::Object.new(id: '123') }
|
6
|
+
let(:subobject2) { Hydra::PCDM::Object.new(id: '456') }
|
7
|
+
let(:indexer) { described_class.new(object) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
allow(object).to receive(:objects).and_return([subobject1, subobject2])
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#generate_solr_document" do
|
14
|
+
subject { indexer.generate_solr_document }
|
15
|
+
|
16
|
+
it "has fields" do
|
17
|
+
expect(subject['objects_ssim']).to eq ['123', '456']
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::AddCollectionToCollection do
|
4
|
+
|
5
|
+
subject { Hydra::PCDM::Collection.create }
|
6
|
+
|
7
|
+
describe '#call' do
|
8
|
+
context 'with acceptable collections' do
|
9
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
10
|
+
let(:collection2) { Hydra::PCDM::Collection.create }
|
11
|
+
let(:collection3) { Hydra::PCDM::Collection.create }
|
12
|
+
let(:collection4) { Hydra::PCDM::Collection.create }
|
13
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
14
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
15
|
+
|
16
|
+
it 'should add a collection to empty collection' do
|
17
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
18
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject ) ).to eq [collection1]
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should add a collection to collection with collections' do
|
22
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
23
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
24
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject ) ).to eq [collection1,collection2]
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should aggregate collections in a sub-collection of a collection' do
|
28
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
29
|
+
Hydra::PCDM::AddCollectionToCollection.call( collection1, collection2 )
|
30
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject ) ).to eq [collection1]
|
31
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( collection1 ) ).to eq [collection2]
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should allow collections to repeat' do
|
35
|
+
skip 'skipping this test because issue #94 needs to be addressed' do
|
36
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
37
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
38
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
39
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject ) ).to eq [collection1,collection2,collection1]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with collections and objects' do
|
44
|
+
before do
|
45
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
46
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
47
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
48
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
49
|
+
subject.save
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should add an object to collection with collections and objects' do
|
53
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection3 )
|
54
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject ) ).to eq [collection1,collection2,collection3]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "adding collections that are ancestors" do
|
59
|
+
let(:error_message) { "a collection can't be an ancestor of itself" }
|
60
|
+
|
61
|
+
context "when the source collection is the same" do
|
62
|
+
it "raises an error" do
|
63
|
+
|
64
|
+
expect{ Hydra::PCDM::AddCollectionToCollection.call( subject, subject ) }.to raise_error(ArgumentError, error_message)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
before do
|
69
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
70
|
+
subject.save
|
71
|
+
end
|
72
|
+
|
73
|
+
it "raises and error" do
|
74
|
+
expect{ Hydra::PCDM::AddCollectionToCollection.call( collection1, subject ) }.to raise_error(ArgumentError, error_message)
|
75
|
+
end
|
76
|
+
|
77
|
+
context "with more ancestors" do
|
78
|
+
before do
|
79
|
+
Hydra::PCDM::AddCollectionToCollection.call( collection1, collection2 )
|
80
|
+
collection2.save
|
81
|
+
end
|
82
|
+
|
83
|
+
it "raises an error" do
|
84
|
+
expect{ Hydra::PCDM::AddCollectionToCollection.call( collection2, subject ) }.to raise_error(ArgumentError, error_message)
|
85
|
+
end
|
86
|
+
|
87
|
+
context "with a more complicated example" do
|
88
|
+
before do
|
89
|
+
Hydra::PCDM::AddCollectionToCollection.call( collection2, collection3 )
|
90
|
+
Hydra::PCDM::AddCollectionToCollection.call( collection2, collection4 )
|
91
|
+
collection2.save
|
92
|
+
end
|
93
|
+
|
94
|
+
it "raises errors" do
|
95
|
+
expect{ Hydra::PCDM::AddCollectionToCollection.call( collection3, subject ) }.to raise_error(ArgumentError, error_message)
|
96
|
+
expect{ Hydra::PCDM::AddCollectionToCollection.call( collection3, collection1 ) }.to raise_error(ArgumentError, error_message)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'aggregates collections that implement Hydra::PCDM' do
|
103
|
+
before do
|
104
|
+
class Kollection < ActiveFedora::Base
|
105
|
+
include Hydra::PCDM::CollectionBehavior
|
106
|
+
end
|
107
|
+
end
|
108
|
+
after { Object.send(:remove_const, :Kollection) }
|
109
|
+
let(:kollection1) { Kollection.create }
|
110
|
+
|
111
|
+
it 'should accept implementing collection as a child' do
|
112
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, kollection1 )
|
113
|
+
subject.save
|
114
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject ) ).to eq [kollection1]
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should accept implementing collection as a parent' do
|
118
|
+
Hydra::PCDM::AddCollectionToCollection.call( kollection1, collection1 )
|
119
|
+
subject.save
|
120
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( kollection1 ) ).to eq [collection1]
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe 'aggregates collections that extend Hydra::PCDM' do
|
125
|
+
before do
|
126
|
+
class Cullection < Hydra::PCDM::Collection
|
127
|
+
end
|
128
|
+
end
|
129
|
+
after { Object.send(:remove_const, :Cullection) }
|
130
|
+
let(:cullection1) { Cullection.create }
|
131
|
+
|
132
|
+
it 'should accept extending collection as a child' do
|
133
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, cullection1 )
|
134
|
+
subject.save
|
135
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject ) ).to eq [cullection1]
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should accept extending collection as a parent' do
|
139
|
+
Hydra::PCDM::AddCollectionToCollection.call( cullection1, collection1 )
|
140
|
+
subject.save
|
141
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( cullection1 ) ).to eq [collection1]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'with unacceptable collections' do
|
147
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
148
|
+
let(:file1) { Hydra::PCDM::File.new }
|
149
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
150
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
151
|
+
|
152
|
+
let(:error_message) { 'child_collection must be a pcdm collection' }
|
153
|
+
|
154
|
+
it 'should NOT aggregate Hydra::PCDM::Objects in collections aggregation' do
|
155
|
+
expect{ Hydra::PCDM::AddCollectionToCollection.call( subject, object1 ) }.to raise_error(ArgumentError,error_message)
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should NOT aggregate Hydra::PCDM::Files in collections aggregation' do
|
159
|
+
expect{ Hydra::PCDM::AddCollectionToCollection.call( subject, file1 ) }.to raise_error(ArgumentError,error_message)
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should NOT aggregate non-PCDM objects in collections aggregation' do
|
163
|
+
expect{ Hydra::PCDM::AddCollectionToCollection.call( subject, non_PCDM_object ) }.to raise_error(ArgumentError,error_message)
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should NOT aggregate AF::Base objects in collections aggregation' do
|
167
|
+
expect{ Hydra::PCDM::AddCollectionToCollection.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'with unacceptable parent collection' do
|
172
|
+
let(:collection2) { Hydra::PCDM::Collection.create }
|
173
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
174
|
+
let(:file1) { Hydra::PCDM::File.new }
|
175
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
176
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
177
|
+
|
178
|
+
let(:error_message) { 'parent_collection must be a pcdm collection' }
|
179
|
+
|
180
|
+
it 'should NOT accept Hydra::PCDM::Objects as parent collection' do
|
181
|
+
expect{ Hydra::PCDM::AddCollectionToCollection.call( object1, collection2 ) }.to raise_error(ArgumentError,error_message)
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should NOT accept Hydra::PCDM::Files as parent collection' do
|
185
|
+
expect{ Hydra::PCDM::AddCollectionToCollection.call( file1, collection2 ) }.to raise_error(ArgumentError,error_message)
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'should NOT accept non-PCDM objects as parent collection' do
|
189
|
+
expect{ Hydra::PCDM::AddCollectionToCollection.call( non_PCDM_object, collection2 ) }.to raise_error(ArgumentError,error_message)
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should NOT accept AF::Base objects as parent collection' do
|
193
|
+
expect{ Hydra::PCDM::AddCollectionToCollection.call( af_base_object, collection2 ) }.to raise_error(ArgumentError,error_message)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::AddObjectToCollection do
|
4
|
+
|
5
|
+
let(:subject) { Hydra::PCDM::Collection.create }
|
6
|
+
|
7
|
+
describe '#call' do
|
8
|
+
context 'with acceptable objects' do
|
9
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
10
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
11
|
+
let(:object3) { Hydra::PCDM::Object.create }
|
12
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
13
|
+
let(:collection2) { Hydra::PCDM::Collection.create }
|
14
|
+
|
15
|
+
it 'should add an object to empty collection' do
|
16
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
17
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject ) ).to eq [object1]
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should add an object to collection with objects' do
|
21
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
22
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
23
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject ) ).to eq [object1,object2]
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should allow objects to repeat' do
|
27
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
28
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
29
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
30
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject ) ).to eq [object1,object2,object1]
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with collections and objects' do
|
34
|
+
before do
|
35
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
36
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
37
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
38
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
39
|
+
subject.save
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should add an object to collection with collections and objects' do
|
43
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object3 )
|
44
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject ) ).to eq [object1,object2,object3]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'aggregates objects that implement Hydra::PCDM' do
|
49
|
+
before do
|
50
|
+
class Ahbject < ActiveFedora::Base
|
51
|
+
include Hydra::PCDM::ObjectBehavior
|
52
|
+
end
|
53
|
+
end
|
54
|
+
after { Object.send(:remove_const, :Ahbject) }
|
55
|
+
let(:ahbject1) { Ahbject.create }
|
56
|
+
|
57
|
+
it 'should accept implementing object as a child' do
|
58
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, ahbject1 )
|
59
|
+
subject.save
|
60
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject ) ).to eq [ahbject1]
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'aggregates objects that extend Hydra::PCDM' do
|
66
|
+
before do
|
67
|
+
class Awbject < Hydra::PCDM::Object
|
68
|
+
end
|
69
|
+
end
|
70
|
+
after { Object.send(:remove_const, :Awbject) }
|
71
|
+
let(:awbject1) { Awbject.create }
|
72
|
+
|
73
|
+
it 'should accept extending object as a child' do
|
74
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, awbject1 )
|
75
|
+
subject.save
|
76
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject ) ).to eq [awbject1]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'with unacceptable objects' do
|
82
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
83
|
+
let(:file1) { Hydra::PCDM::File.new }
|
84
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
85
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
86
|
+
|
87
|
+
let(:error_message) { 'child_object must be a pcdm object' }
|
88
|
+
|
89
|
+
it 'should NOT aggregate Hydra::PCDM::Collection in objects aggregation' do
|
90
|
+
expect{ Hydra::PCDM::AddObjectToCollection.call( subject, collection1 ) }.to raise_error(ArgumentError,error_message)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should NOT aggregate Hydra::PCDM::Files in objects aggregation' do
|
94
|
+
expect{ Hydra::PCDM::AddObjectToCollection.call( subject, file1 ) }.to raise_error(ArgumentError,error_message)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should NOT aggregate non-PCDM objects in objects aggregation' do
|
98
|
+
expect{ Hydra::PCDM::AddObjectToCollection.call( subject, non_PCDM_object ) }.to raise_error(ArgumentError,error_message)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should NOT aggregate AF::Base objects in objects aggregation' do
|
102
|
+
expect{ Hydra::PCDM::AddObjectToCollection.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'with unacceptable parent collection' do
|
107
|
+
let(:collection2) { Hydra::PCDM::Collection.create }
|
108
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
109
|
+
let(:file1) { Hydra::PCDM::File.new }
|
110
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
111
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
112
|
+
|
113
|
+
let(:error_message) { 'parent_collection must be a pcdm collection' }
|
114
|
+
|
115
|
+
it 'should NOT accept Hydra::PCDM::Objects as parent collection' do
|
116
|
+
expect{ Hydra::PCDM::AddObjectToCollection.call( object1, collection2 ) }.to raise_error(ArgumentError,error_message)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should NOT accept Hydra::PCDM::Files as parent collection' do
|
120
|
+
expect{ Hydra::PCDM::AddObjectToCollection.call( file1, collection2 ) }.to raise_error(ArgumentError,error_message)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should NOT accept non-PCDM objects as parent collection' do
|
124
|
+
expect{ Hydra::PCDM::AddObjectToCollection.call( non_PCDM_object, collection2 ) }.to raise_error(ArgumentError,error_message)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should NOT accept AF::Base objects as parent collection' do
|
128
|
+
expect{ Hydra::PCDM::AddObjectToCollection.call( af_base_object, collection2 ) }.to raise_error(ArgumentError,error_message)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|