hydra-pcdm 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,146 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::RemoveRelatedObjectFromCollection do
|
4
|
+
|
5
|
+
subject { Hydra::PCDM::Collection.create }
|
6
|
+
|
7
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
8
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
9
|
+
let(:object3) { Hydra::PCDM::Object.create }
|
10
|
+
let(:object4) { Hydra::PCDM::Object.create }
|
11
|
+
let(:object5) { Hydra::PCDM::Object.create }
|
12
|
+
|
13
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
14
|
+
let(:collection2) { Hydra::PCDM::Collection.create }
|
15
|
+
|
16
|
+
describe '#call' do
|
17
|
+
context 'when it is the only related object' do
|
18
|
+
before do
|
19
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object1 )
|
20
|
+
subject.save
|
21
|
+
expect( Hydra::PCDM::GetRelatedObjectsFromCollection.call( subject.reload )).to eq [object1]
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should remove related object' do
|
25
|
+
expect( Hydra::PCDM::RemoveRelatedObjectFromCollection.call( subject, object1 ) ).to eq object1
|
26
|
+
expect( Hydra::PCDM::GetRelatedObjectsFromCollection.call( subject.reload )).to eq []
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should remove related object only when objects & collections' do
|
30
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
31
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
32
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object3 )
|
33
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
34
|
+
expect( Hydra::PCDM::RemoveRelatedObjectFromCollection.call( subject, object1 ) ).to eq object1
|
35
|
+
expect( Hydra::PCDM::GetRelatedObjectsFromCollection.call( subject.reload )).to eq []
|
36
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject )).to eq [collection1,collection2]
|
37
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject )).to eq [object3,object2]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when multiple related objects' do
|
42
|
+
before do
|
43
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object1 )
|
44
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object2 )
|
45
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object3 )
|
46
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object4 )
|
47
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object5 )
|
48
|
+
subject.save
|
49
|
+
expect( Hydra::PCDM::GetRelatedObjectsFromCollection.call( subject.reload )).to eq [object1,object2,object3,object4,object5]
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should remove first related object' do
|
53
|
+
expect( Hydra::PCDM::RemoveRelatedObjectFromCollection.call( subject, object1 ) ).to eq object1
|
54
|
+
expect( Hydra::PCDM::GetRelatedObjectsFromCollection.call( subject.reload )).to eq [object2,object3,object4,object5]
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should remove last related object' do
|
58
|
+
expect( Hydra::PCDM::RemoveRelatedObjectFromCollection.call( subject, object5 ) ).to eq object5
|
59
|
+
expect( Hydra::PCDM::GetRelatedObjectsFromCollection.call( subject.reload )).to eq [object1,object2,object3,object4]
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should remove middle related object' do
|
63
|
+
expect( Hydra::PCDM::RemoveRelatedObjectFromCollection.call( subject, object3 ) ).to eq object3
|
64
|
+
expect( Hydra::PCDM::GetRelatedObjectsFromCollection.call( subject.reload )).to eq [object1,object2,object4,object5]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when related object is missing' do
|
69
|
+
it 'should return nil when 0 related objects and 0 collections and objects' do
|
70
|
+
subject.save
|
71
|
+
expect( Hydra::PCDM::RemoveRelatedObjectFromCollection.call( subject.reload, object1 )).to be nil
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should return nil when 0 related objects, but has collections and objects' do
|
75
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
76
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
77
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
78
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
79
|
+
subject.save
|
80
|
+
expect( Hydra::PCDM::RemoveRelatedObjectFromCollection.call( subject.reload, object1 )).to be nil
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should return nil when other related objects' do
|
84
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object1 )
|
85
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object2 )
|
86
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object4 )
|
87
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object5 )
|
88
|
+
subject.save
|
89
|
+
expect( Hydra::PCDM::RemoveRelatedObjectFromCollection.call( subject.reload, object3 )).to be nil
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'with unacceptable related objects' do
|
95
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
96
|
+
let(:file1) { Hydra::PCDM::File.new }
|
97
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
98
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
99
|
+
|
100
|
+
let(:error_type) { ArgumentError }
|
101
|
+
let(:error_message) { 'child_related_object must be a pcdm object' }
|
102
|
+
|
103
|
+
it 'should NOT remove Hydra::PCDM::Collections from related_objects aggregation' do
|
104
|
+
expect{ Hydra::PCDM::RemoveRelatedObjectFromCollection.call( subject, collection1 ) }.to raise_error(error_type,error_message)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should NOT remove Hydra::PCDM::Files from related_objects aggregation' do
|
108
|
+
expect{ Hydra::PCDM::RemoveRelatedObjectFromCollection.call( subject, file1 ) }.to raise_error(error_type,error_message)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should NOT remove non-PCDM objects from related_objects aggregation' do
|
112
|
+
expect{ Hydra::PCDM::RemoveRelatedObjectFromCollection.call( subject, non_PCDM_object ) }.to raise_error(error_type,error_message)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should NOT remove AF::Base objects from related_objects aggregation' do
|
116
|
+
expect{ Hydra::PCDM::RemoveRelatedObjectFromCollection.call( subject, af_base_object ) }.to raise_error(error_type,error_message)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'with unacceptable parent collection' do
|
121
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
122
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
123
|
+
let(:file1) { Hydra::PCDM::File.new }
|
124
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
125
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
126
|
+
|
127
|
+
let(:error_type) { ArgumentError }
|
128
|
+
let(:error_message) { 'parent_collection must be a pcdm collection' }
|
129
|
+
|
130
|
+
it 'should NOT accept Hydra::PCDM::Objects as parent collection' do
|
131
|
+
expect{ Hydra::PCDM::RemoveRelatedObjectFromCollection.call( object1, object2 ) }.to raise_error(error_type,error_message)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should NOT accept Hydra::PCDM::Files as parent collection' do
|
135
|
+
expect{ Hydra::PCDM::RemoveRelatedObjectFromCollection.call( file1, object2 ) }.to raise_error(error_type,error_message)
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should NOT accept non-PCDM objects as parent collection' do
|
139
|
+
expect{ Hydra::PCDM::RemoveRelatedObjectFromCollection.call( non_PCDM_object, object2 ) }.to raise_error(error_type,error_message)
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should NOT accept AF::Base objects as parent collection' do
|
143
|
+
expect{ Hydra::PCDM::RemoveRelatedObjectFromCollection.call( af_base_object, object2 ) }.to raise_error(error_type,error_message)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::AddTypeToFile do
|
4
|
+
|
5
|
+
let(:file) { Hydra::PCDM::File.new }
|
6
|
+
|
7
|
+
context "with a file that has no type" do
|
8
|
+
let(:uri) { ::RDF::URI("http://example.com/MyType") }
|
9
|
+
subject { described_class.call(file, uri).metadata_node.type }
|
10
|
+
it { is_expected.to include(uri)}
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when adding a type that already exists" do
|
14
|
+
let(:uri) { RDFVocabularies::PCDMTerms.File }
|
15
|
+
subject { described_class.call(file, uri).metadata_node.type }
|
16
|
+
it { is_expected.to eql [uri] }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::GetMimeTypeForFile do
|
4
|
+
|
5
|
+
context "with faulty input" do
|
6
|
+
let(:error_message) { "supplied argument should be a path to a file" }
|
7
|
+
it "raises and error" do
|
8
|
+
expect( lambda{described_class.call(["bad input"])}).to raise_error(ArgumentError, error_message)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "with a standard file type" do
|
13
|
+
let(:path) { "/path/file.jpg" }
|
14
|
+
subject { described_class.call(path) }
|
15
|
+
it { is_expected.to eql "image/jpeg" }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with an unknown file type" do
|
19
|
+
let(:path) { "/path/file.jkl" }
|
20
|
+
subject { described_class.call(path) }
|
21
|
+
it { is_expected.to eql "application/octet-stream" }
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::AddObjectToObject do
|
4
|
+
|
5
|
+
let(:subject) { Hydra::PCDM::Object.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(:object4) { Hydra::PCDM::Object.create }
|
13
|
+
let(:object5) { Hydra::PCDM::Object.create }
|
14
|
+
|
15
|
+
it 'should add an object to empty object' do
|
16
|
+
Hydra::PCDM::AddObjectToObject.call( subject, object1 )
|
17
|
+
expect( Hydra::PCDM::GetObjectsFromObject.call( subject ) ).to eq [object1]
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should add an object to an object with objects' do
|
21
|
+
Hydra::PCDM::AddObjectToObject.call( subject, object1 )
|
22
|
+
Hydra::PCDM::AddObjectToObject.call( subject, object2 )
|
23
|
+
expect( Hydra::PCDM::GetObjectsFromObject.call( subject ) ).to eq [object1,object2]
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should allow objects to repeat' do
|
27
|
+
Hydra::PCDM::AddObjectToObject.call( subject, object1 )
|
28
|
+
Hydra::PCDM::AddObjectToObject.call( subject, object2 )
|
29
|
+
Hydra::PCDM::AddObjectToObject.call( subject, object1 )
|
30
|
+
expect( Hydra::PCDM::GetObjectsFromObject.call( subject ) ).to eq [object1,object2,object1]
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should aggregate objects in a sub-object of a object' do
|
34
|
+
Hydra::PCDM::AddObjectToObject.call( subject, object1 )
|
35
|
+
object1.save
|
36
|
+
Hydra::PCDM::AddObjectToObject.call( object1, object2 )
|
37
|
+
object2.save
|
38
|
+
expect(subject.objects).to eq [object1]
|
39
|
+
expect(object1.objects).to eq [object2]
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with files and objects' do
|
43
|
+
let(:file1) { subject.files.build }
|
44
|
+
let(:file2) { subject.files.build }
|
45
|
+
|
46
|
+
before do
|
47
|
+
file1.content = "I'm a file"
|
48
|
+
file2.content = "I am too"
|
49
|
+
Hydra::PCDM::AddObjectToObject.call( subject, object1 )
|
50
|
+
Hydra::PCDM::AddObjectToObject.call( subject, object2 )
|
51
|
+
subject.save!
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should add an object to an object with files and objects' do
|
55
|
+
Hydra::PCDM::AddObjectToObject.call( subject, object3 )
|
56
|
+
expect( Hydra::PCDM::GetObjectsFromObject.call( subject ) ).to eq [object1,object2,object3]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'adding objects that are ancestors' do
|
61
|
+
let(:error_message) { "an object can't be an ancestor of itself" }
|
62
|
+
|
63
|
+
context 'when the source object is the same' do
|
64
|
+
it 'raises an error' do
|
65
|
+
expect{ Hydra::PCDM::AddObjectToObject.call( object1, object1 )}.to raise_error(ArgumentError, error_message)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
before do
|
70
|
+
Hydra::PCDM::AddObjectToObject.call( object1, object2 )
|
71
|
+
object1.save
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'raises and error' do
|
75
|
+
expect{ Hydra::PCDM::AddObjectToObject.call( object2, object1 )}.to raise_error(ArgumentError, error_message)
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'with more ancestors' do
|
79
|
+
before do
|
80
|
+
Hydra::PCDM::AddObjectToObject.call( object2, object3 )
|
81
|
+
object2.save
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'raises an error' do
|
85
|
+
expect{ Hydra::PCDM::AddObjectToObject.call( object3, object1 )}.to raise_error(ArgumentError, error_message)
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'with a more complicated example' do
|
89
|
+
before do
|
90
|
+
Hydra::PCDM::AddObjectToObject.call( object3, object4 )
|
91
|
+
Hydra::PCDM::AddObjectToObject.call( object3, object5 )
|
92
|
+
object3.save
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'raises errors' do
|
96
|
+
expect{ Hydra::PCDM::AddObjectToObject.call( object4, object1 )}.to raise_error(ArgumentError, error_message)
|
97
|
+
expect{ Hydra::PCDM::AddObjectToObject.call( object4, object2 )}.to raise_error(ArgumentError, error_message)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe 'aggregates objects that implement Hydra::PCDM' do
|
104
|
+
before do
|
105
|
+
class DummyIncObject < ActiveFedora::Base
|
106
|
+
include Hydra::PCDM::ObjectBehavior
|
107
|
+
end
|
108
|
+
end
|
109
|
+
after { Object.send(:remove_const, :DummyIncObject) }
|
110
|
+
let(:iobject1) { DummyIncObject.create }
|
111
|
+
|
112
|
+
it 'should accept implementing object as a child' do
|
113
|
+
Hydra::PCDM::AddObjectToObject.call( subject, iobject1 )
|
114
|
+
subject.save
|
115
|
+
expect( Hydra::PCDM::GetObjectsFromObject.call( subject ) ).to eq [iobject1]
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe 'aggregates objects that extend Hydra::PCDM' do
|
120
|
+
before do
|
121
|
+
class DummyExtObject < Hydra::PCDM::Object
|
122
|
+
end
|
123
|
+
end
|
124
|
+
after { Object.send(:remove_const, :DummyExtObject) }
|
125
|
+
let(:eobject1) { DummyExtObject.create }
|
126
|
+
|
127
|
+
it 'should accept extending object as a child' do
|
128
|
+
Hydra::PCDM::AddObjectToObject.call( subject, eobject1 )
|
129
|
+
subject.save
|
130
|
+
expect( Hydra::PCDM::GetObjectsFromObject.call( subject ) ).to eq [eobject1]
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'with unacceptable objects' do
|
136
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
137
|
+
let(:file1) { Hydra::PCDM::File.new }
|
138
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
139
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
140
|
+
|
141
|
+
let(:error_message) { 'child_object must be a pcdm object' }
|
142
|
+
|
143
|
+
it 'should NOT aggregate Hydra::PCDM::Collection in objects aggregation' do
|
144
|
+
expect{ Hydra::PCDM::AddObjectToObject.call( subject, collection1 ) }.to raise_error(ArgumentError,error_message)
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should NOT aggregate Hydra::PCDM::Files in objects aggregation' do
|
148
|
+
expect{ Hydra::PCDM::AddObjectToObject.call( subject, file1 ) }.to raise_error(ArgumentError,error_message)
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should NOT aggregate non-PCDM objects in objects aggregation' do
|
152
|
+
expect{ Hydra::PCDM::AddObjectToObject.call( subject, non_PCDM_object ) }.to raise_error(ArgumentError,error_message)
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should NOT aggregate AF::Base objects in objects aggregation' do
|
156
|
+
expect{ Hydra::PCDM::AddObjectToObject.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'with unacceptable parent object' do
|
161
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
162
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
163
|
+
let(:file1) { Hydra::PCDM::File.new }
|
164
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
165
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
166
|
+
|
167
|
+
let(:error_message) { 'parent_object must be a pcdm object' }
|
168
|
+
|
169
|
+
it 'should NOT accept Hydra::PCDM::Collections as parent object' do
|
170
|
+
expect{ Hydra::PCDM::AddObjectToObject.call( collection1, object2 ) }.to raise_error(ArgumentError,error_message)
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'should NOT accept Hydra::PCDM::Files as parent object' do
|
174
|
+
expect{ Hydra::PCDM::AddObjectToObject.call( file1, object2 ) }.to raise_error(ArgumentError,error_message)
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should NOT accept non-PCDM objects as parent object' do
|
178
|
+
expect{ Hydra::PCDM::AddObjectToObject.call( non_PCDM_object, object2 ) }.to raise_error(ArgumentError,error_message)
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'should NOT accept AF::Base objects as parent object' do
|
182
|
+
expect{ Hydra::PCDM::AddObjectToObject.call( af_base_object, object2 ) }.to raise_error(ArgumentError,error_message)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::AddRelatedObjectToObject do
|
4
|
+
|
5
|
+
let(:subject) { Hydra::PCDM::Object.create }
|
6
|
+
|
7
|
+
describe '#call' do
|
8
|
+
|
9
|
+
context 'with acceptable objects' do
|
10
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
11
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
12
|
+
let(:object3) { Hydra::PCDM::Object.create }
|
13
|
+
let(:file1) { Hydra::PCDM::File.new }
|
14
|
+
|
15
|
+
it 'should add a related object to empty object' do
|
16
|
+
Hydra::PCDM::AddRelatedObjectToObject.call( subject, object1 )
|
17
|
+
expect( Hydra::PCDM::GetRelatedObjectsFromObject.call( subject ) ).to eq [object1]
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should add a related object to object with related objects' do
|
21
|
+
Hydra::PCDM::AddRelatedObjectToObject.call( subject, object1 )
|
22
|
+
Hydra::PCDM::AddRelatedObjectToObject.call( subject, object2 )
|
23
|
+
related_objects = Hydra::PCDM::GetRelatedObjectsFromObject.call( subject )
|
24
|
+
expect( related_objects.include? object1 ).to be true
|
25
|
+
expect( related_objects.include? object2 ).to be true
|
26
|
+
expect( related_objects.size ).to eq 2
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with files and objects' do
|
30
|
+
let(:file1) { subject.files.build }
|
31
|
+
let(:file2) { subject.files.build }
|
32
|
+
|
33
|
+
before do
|
34
|
+
file1.content = "I'm a file"
|
35
|
+
file2.content = "I am too"
|
36
|
+
Hydra::PCDM::AddObjectToObject.call( subject, object1 )
|
37
|
+
Hydra::PCDM::AddRelatedObjectToObject.call( subject, object2 )
|
38
|
+
subject.save!
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should add an object to an object with files and objects' do
|
42
|
+
Hydra::PCDM::AddRelatedObjectToObject.call( subject, object3 )
|
43
|
+
related_objects = Hydra::PCDM::GetRelatedObjectsFromObject.call( subject )
|
44
|
+
expect( related_objects.include? object2 ).to be true
|
45
|
+
expect( related_objects.include? object3 ).to be true
|
46
|
+
expect( related_objects.size ).to eq 2
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with unacceptable objects' do
|
52
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
53
|
+
let(:file1) { Hydra::PCDM::File.new }
|
54
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
55
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
56
|
+
|
57
|
+
let(:error_message) { 'child_related_object must be a pcdm object' }
|
58
|
+
|
59
|
+
it 'should NOT aggregate Hydra::PCDM::Collection in related objects aggregation' do
|
60
|
+
expect{ Hydra::PCDM::AddRelatedObjectToObject.call( subject, collection1 ) }.to raise_error(ArgumentError,error_message)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should NOT aggregate Hydra::PCDM::Files in related objects aggregation' do
|
64
|
+
expect{ Hydra::PCDM::AddRelatedObjectToObject.call( subject, file1 ) }.to raise_error(ArgumentError,error_message)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should NOT aggregate non-PCDM objects in related objects aggregation' do
|
68
|
+
expect{ Hydra::PCDM::AddRelatedObjectToObject.call( subject, non_PCDM_object ) }.to raise_error(ArgumentError,error_message)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should NOT aggregate AF::Base objects in related objects aggregation' do
|
72
|
+
expect{ Hydra::PCDM::AddRelatedObjectToObject.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'with invalid bahaviors' do
|
78
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
79
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
80
|
+
|
81
|
+
it 'should NOT allow related objects to repeat' do
|
82
|
+
skip 'skipping this test because issue #92 needs to be addressed' do
|
83
|
+
Hydra::PCDM::AddRelatedObjectToObject.call( subject, object1 )
|
84
|
+
Hydra::PCDM::AddRelatedObjectToObject.call( subject, object2 )
|
85
|
+
Hydra::PCDM::AddRelatedObjectToObject.call( subject, object1 )
|
86
|
+
related_objects = Hydra::PCDM::GetRelatedObjectsFromObject.call( subject )
|
87
|
+
expect( related_objects.include? object1 ).to be true
|
88
|
+
expect( related_objects.include? object2 ).to be true
|
89
|
+
expect( related_objects.size ).to eq 2
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::GetObjectsFromObject do
|
4
|
+
|
5
|
+
subject { Hydra::PCDM::Object.create }
|
6
|
+
|
7
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
8
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
9
|
+
|
10
|
+
describe '#call' do
|
11
|
+
it 'should return empty array when no members' do
|
12
|
+
subject.save
|
13
|
+
expect(Hydra::PCDM::GetObjectsFromObject.call( subject )).to eq []
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with files and objects' do
|
17
|
+
let(:file1) { subject.files.build }
|
18
|
+
let(:file2) { subject.files.build }
|
19
|
+
|
20
|
+
before do
|
21
|
+
file1.content = "I'm a file"
|
22
|
+
file2.content = "I am too"
|
23
|
+
Hydra::PCDM::AddObjectToObject.call( subject, object1 )
|
24
|
+
Hydra::PCDM::AddObjectToObject.call( subject, object2 )
|
25
|
+
subject.save!
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should only return objects' do
|
29
|
+
expect(Hydra::PCDM::GetObjectsFromObject.call( subject )).to eq [object1,object2]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::GetRelatedObjectsFromObject do
|
4
|
+
|
5
|
+
subject { Hydra::PCDM::Object.create }
|
6
|
+
|
7
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
8
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
9
|
+
|
10
|
+
describe '#call' do
|
11
|
+
it 'should return empty array when no related object' do
|
12
|
+
subject.save
|
13
|
+
expect(Hydra::PCDM::GetRelatedObjectsFromObject.call( subject )).to eq []
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
context 'with files and objects' do
|
18
|
+
let(:file1) { subject.files.build }
|
19
|
+
let(:file2) { subject.files.build }
|
20
|
+
|
21
|
+
before do
|
22
|
+
file1.content = "I'm a file"
|
23
|
+
file2.content = "I am too"
|
24
|
+
Hydra::PCDM::AddObjectToObject.call( subject, object1 )
|
25
|
+
Hydra::PCDM::AddObjectToObject.call( subject, object2 )
|
26
|
+
subject.save!
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should return empty array when only files and object are aggregated' do
|
30
|
+
expect(Hydra::PCDM::GetRelatedObjectsFromObject.call( subject )).to eq []
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should only return related objects' do
|
34
|
+
Hydra::PCDM::AddRelatedObjectToObject.call( subject, object2 )
|
35
|
+
expect(Hydra::PCDM::GetRelatedObjectsFromObject.call( subject )).to eq [object2]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|