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,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::AddRelatedObjectToCollection do
|
4
|
+
|
5
|
+
let(:subject) { Hydra::PCDM::Collection.create }
|
6
|
+
|
7
|
+
describe '#call' do
|
8
|
+
|
9
|
+
context 'with acceptable collections' do
|
10
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
11
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
12
|
+
let(:object3) { Hydra::PCDM::Object.create }
|
13
|
+
let(:object4) { Hydra::PCDM::Object.create }
|
14
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
15
|
+
let(:collection2) { Hydra::PCDM::Collection.create }
|
16
|
+
|
17
|
+
it 'should add a related object to empty collection' do
|
18
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object1 )
|
19
|
+
expect( Hydra::PCDM::GetRelatedObjectsFromCollection.call( subject ) ).to eq [object1]
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should add a related object to collection with related objects' do
|
23
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object1 )
|
24
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object2 )
|
25
|
+
related_objects = Hydra::PCDM::GetRelatedObjectsFromCollection.call( subject )
|
26
|
+
expect( related_objects.include? object1 ).to be true
|
27
|
+
expect( related_objects.include? object2 ).to be true
|
28
|
+
expect( related_objects.size ).to eq 2
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with collections and objects' do
|
32
|
+
before do
|
33
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
34
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
35
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
36
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
37
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object3 )
|
38
|
+
subject.save
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should add an object to collection with collections and objects' do
|
42
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object4 )
|
43
|
+
related_objects = Hydra::PCDM::GetRelatedObjectsFromCollection.call( subject )
|
44
|
+
expect( related_objects.include? object3 ).to be true
|
45
|
+
expect( related_objects.include? object4 ).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::AddRelatedObjectToCollection.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::AddRelatedObjectToCollection.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::AddRelatedObjectToCollection.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::AddRelatedObjectToCollection.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::AddRelatedObjectToCollection.call( subject, object1 )
|
84
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object2 )
|
85
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object1 )
|
86
|
+
related_objects = Hydra::PCDM::GetRelatedObjectsFromCollection.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,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::GetCollectionsFromCollection do
|
4
|
+
|
5
|
+
subject { Hydra::PCDM::Collection.create }
|
6
|
+
|
7
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
8
|
+
let(:collection2) { Hydra::PCDM::Collection.create }
|
9
|
+
|
10
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
11
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
12
|
+
|
13
|
+
describe '#call' do
|
14
|
+
it 'should return empty array when no members' do
|
15
|
+
subject.save
|
16
|
+
expect(Hydra::PCDM::GetCollectionsFromCollection.call( subject )).to eq []
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should return empty array when only objects are aggregated' do
|
20
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
21
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
22
|
+
subject.save
|
23
|
+
expect(Hydra::PCDM::GetCollectionsFromCollection.call( subject )).to eq []
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with other collections & objects' do
|
27
|
+
before do
|
28
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
29
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
30
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
31
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
32
|
+
subject.save
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should only return collections' do
|
36
|
+
expect(Hydra::PCDM::GetCollectionsFromCollection.call( subject )).to eq [collection1,collection2]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::GetObjectsFromCollection do
|
4
|
+
|
5
|
+
subject { Hydra::PCDM::Collection.create }
|
6
|
+
|
7
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
8
|
+
let(:collection2) { Hydra::PCDM::Collection.create }
|
9
|
+
|
10
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
11
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
12
|
+
|
13
|
+
describe '#call' do
|
14
|
+
it 'should return empty array when no members' do
|
15
|
+
subject.save
|
16
|
+
expect(Hydra::PCDM::GetObjectsFromCollection.call( subject )).to eq []
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should return empty array when only collections are aggregated' do
|
20
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
21
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
22
|
+
subject.save
|
23
|
+
expect(Hydra::PCDM::GetObjectsFromCollection.call( subject )).to eq []
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with collections and objects' do
|
27
|
+
before do
|
28
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
29
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
30
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
31
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
32
|
+
subject.save
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should only return related objects' do
|
36
|
+
expect(Hydra::PCDM::GetObjectsFromCollection.call( subject )).to eq [object1,object2]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::GetRelatedObjectsFromCollection do
|
4
|
+
|
5
|
+
subject { Hydra::PCDM::Collection.create }
|
6
|
+
|
7
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
8
|
+
let(:collection2) { Hydra::PCDM::Collection.create }
|
9
|
+
|
10
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
11
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
12
|
+
|
13
|
+
describe '#call' do
|
14
|
+
it 'should return empty array when no related object' do
|
15
|
+
subject.save
|
16
|
+
expect(Hydra::PCDM::GetRelatedObjectsFromCollection.call( subject )).to eq []
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with collections and objects' do
|
20
|
+
before do
|
21
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
22
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
23
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
24
|
+
subject.save
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should return empty array when only collections and object are aggregated' do
|
28
|
+
expect(Hydra::PCDM::GetRelatedObjectsFromCollection.call( subject )).to eq []
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should only return related objects' do
|
32
|
+
Hydra::PCDM::AddRelatedObjectToCollection.call( subject, object2 )
|
33
|
+
expect(Hydra::PCDM::GetRelatedObjectsFromCollection.call( subject )).to eq [object2]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::RemoveCollectionFromCollection do
|
4
|
+
|
5
|
+
subject { Hydra::PCDM::Collection.create }
|
6
|
+
|
7
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
8
|
+
let(:collection2) { Hydra::PCDM::Collection.create }
|
9
|
+
let(:collection3) { Hydra::PCDM::Collection.create }
|
10
|
+
let(:collection4) { Hydra::PCDM::Collection.create }
|
11
|
+
let(:collection5) { Hydra::PCDM::Collection.create }
|
12
|
+
|
13
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
14
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
15
|
+
|
16
|
+
|
17
|
+
describe '#call' do
|
18
|
+
context 'when it is the only collection' do
|
19
|
+
|
20
|
+
before do
|
21
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
22
|
+
subject.save
|
23
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject.reload )).to eq [collection1]
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should remove collection' do
|
27
|
+
expect( Hydra::PCDM::RemoveCollectionFromCollection.call( subject, collection1 ) ).to eq collection1
|
28
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject.reload )).to eq []
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should remove collection only when objects' do
|
32
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
33
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
34
|
+
expect( Hydra::PCDM::RemoveCollectionFromCollection.call( subject, collection1 ) ).to eq collection1
|
35
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject.reload )).to eq []
|
36
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject )).to eq [object1,object2]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when multiple collections' do
|
41
|
+
before do
|
42
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
43
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
44
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection3 )
|
45
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection4 )
|
46
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection5 )
|
47
|
+
subject.save
|
48
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject.reload )).to eq [collection1,collection2,collection3,collection4,collection5]
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should remove first collection' do
|
52
|
+
expect( Hydra::PCDM::RemoveCollectionFromCollection.call( subject, collection1 ) ).to eq collection1
|
53
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject.reload )).to eq [collection2,collection3,collection4,collection5]
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should remove last collection' do
|
57
|
+
expect( Hydra::PCDM::RemoveCollectionFromCollection.call( subject, collection5 ) ).to eq collection5
|
58
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject.reload )).to eq [collection1,collection2,collection3,collection4]
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should remove middle collection' do
|
62
|
+
expect( Hydra::PCDM::RemoveCollectionFromCollection.call( subject, collection3 ) ).to eq collection3
|
63
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject.reload )).to eq [collection1,collection2,collection4,collection5]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when collection is missing' do
|
68
|
+
it 'should return nil' do
|
69
|
+
subject.save
|
70
|
+
expect( Hydra::PCDM::RemoveCollectionFromCollection.call( subject.reload, collection1 ) ).to be nil
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should return nil' do
|
74
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
75
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
76
|
+
subject.save
|
77
|
+
expect( Hydra::PCDM::RemoveCollectionFromCollection.call( subject.reload, collection1 ) ).to be nil
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should return nil' do
|
81
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
82
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
83
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection4 )
|
84
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection5 )
|
85
|
+
subject.save
|
86
|
+
expect( Hydra::PCDM::RemoveCollectionFromCollection.call( subject.reload, collection3 ) ).to be nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'with unacceptable collections' do
|
92
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
93
|
+
let(:file1) { Hydra::PCDM::File.new }
|
94
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
95
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
96
|
+
|
97
|
+
let(:error_type) { ArgumentError }
|
98
|
+
let(:error_message) { 'child_collection must be a pcdm collection' }
|
99
|
+
|
100
|
+
it 'should NOT remove Hydra::PCDM::Objects from collections aggregation' do
|
101
|
+
expect{ Hydra::PCDM::RemoveCollectionFromCollection.call( subject, object1 ) }.to raise_error(error_type,error_message)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should NOT remove Hydra::PCDM::Files from collections aggregation' do
|
105
|
+
expect{ Hydra::PCDM::RemoveCollectionFromCollection.call( subject, file1 ) }.to raise_error(error_type,error_message)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should NOT remove non-PCDM objects from collections aggregation' do
|
109
|
+
expect{ Hydra::PCDM::RemoveCollectionFromCollection.call( subject, non_PCDM_object ) }.to raise_error(error_type,error_message)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should NOT remove AF::Base objects from collections aggregation' do
|
113
|
+
expect{ Hydra::PCDM::RemoveCollectionFromCollection.call( subject, af_base_object ) }.to raise_error(error_type,error_message)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'with unacceptable parent collection' do
|
118
|
+
let(:collection2) { Hydra::PCDM::Collection.create }
|
119
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
120
|
+
let(:file1) { Hydra::PCDM::File.new }
|
121
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
122
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
123
|
+
|
124
|
+
let(:error_type) { ArgumentError }
|
125
|
+
let(:error_message) { 'parent_collection must be a pcdm collection' }
|
126
|
+
|
127
|
+
it 'should NOT accept Hydra::PCDM::Objects as parent collection' do
|
128
|
+
expect{ Hydra::PCDM::RemoveCollectionFromCollection.call( object1, collection2 ) }.to raise_error(error_type,error_message)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should NOT accept Hydra::PCDM::Files as parent collection' do
|
132
|
+
expect{ Hydra::PCDM::RemoveCollectionFromCollection.call( file1, collection2 ) }.to raise_error(error_type,error_message)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should NOT accept non-PCDM objects as parent collection' do
|
136
|
+
expect{ Hydra::PCDM::RemoveCollectionFromCollection.call( non_PCDM_object, collection2 ) }.to raise_error(error_type,error_message)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should NOT accept AF::Base objects as parent collection' do
|
140
|
+
expect{ Hydra::PCDM::RemoveCollectionFromCollection.call( af_base_object, collection2 ) }.to raise_error(error_type,error_message)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::PCDM::RemoveObjectFromCollection 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 object' do
|
18
|
+
before do
|
19
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
20
|
+
subject.save
|
21
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject.reload )).to eq [object1]
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should remove object' do
|
25
|
+
expect( Hydra::PCDM::RemoveObjectFromCollection.call( subject, object1 ) ).to eq object1
|
26
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject.reload )).to eq []
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should remove object only when collections' do
|
30
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
31
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
32
|
+
expect( Hydra::PCDM::RemoveObjectFromCollection.call( subject, object1 ) ).to eq object1
|
33
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject.reload )).to eq []
|
34
|
+
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject )).to eq [collection1,collection2]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when multiple objects' do
|
39
|
+
before do
|
40
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
41
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
42
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object3 )
|
43
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object4 )
|
44
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object5 )
|
45
|
+
subject.save
|
46
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject.reload )).to eq [object1,object2,object3,object4,object5]
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should remove first object' do
|
50
|
+
expect( Hydra::PCDM::RemoveObjectFromCollection.call( subject, object1 ) ).to eq object1
|
51
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject.reload )).to eq [object2,object3,object4,object5]
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should remove last object' do
|
55
|
+
expect( Hydra::PCDM::RemoveObjectFromCollection.call( subject, object5 ) ).to eq object5
|
56
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject.reload )).to eq [object1,object2,object3,object4]
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should remove middle object' do
|
60
|
+
expect( Hydra::PCDM::RemoveObjectFromCollection.call( subject, object3 ) ).to eq object3
|
61
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject.reload )).to eq [object1,object2,object4,object5]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when object repeats' do
|
66
|
+
before do
|
67
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
68
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
69
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object3 )
|
70
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
71
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object4 )
|
72
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
73
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object5 )
|
74
|
+
subject.save
|
75
|
+
end
|
76
|
+
|
77
|
+
# TODO pending implementation of multiple objects
|
78
|
+
|
79
|
+
it 'should remove first occurrence' do
|
80
|
+
skip 'skipping this test because issue #102 needs to be addressed' do
|
81
|
+
expect(Hydra::PCDM::GetObjectsFromCollection.call( subject.reload )).to eq [object1,object2,object3,object2,object4,object2,object5]
|
82
|
+
expect( Hydra::PCDM::RemoveObjectFromCollection.call( subject, object2 ) ).to eq object2
|
83
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject.reload )).to eq [object1,object3,object2,object4,object2,object5]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should remove last occurrence' do
|
88
|
+
skip 'skipping this test because issue #102 needs to be addressed' do
|
89
|
+
expect(Hydra::PCDM::GetObjectsFromCollection.call( subject.reload )).to eq [object1,object2,object3,object2,object4,object2,object5]
|
90
|
+
expect( Hydra::PCDM::RemoveObjectFromCollection.call( subject, object2, -1 ) ).to eq object2
|
91
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject.reload )).to eq [object1,object2,object3,object2,object4,object5]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should remove nth occurrence' do
|
96
|
+
skip 'skipping this test because issue #102 needs to be addressed' do
|
97
|
+
expect(Hydra::PCDM::GetObjectsFromCollection.call( subject.reload )).to eq [object1,object2,object3,object2,object4,object2,object5]
|
98
|
+
expect( Hydra::PCDM::RemoveObjectFromCollection.call( subject, object2, 2 ) ).to eq object2
|
99
|
+
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject.reload )).to eq [object1,object2,object3,object4,object2,object5]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when object is missing' do
|
105
|
+
it 'should return nil' do
|
106
|
+
subject.save
|
107
|
+
expect( Hydra::PCDM::RemoveObjectFromCollection.call( subject.reload, object1 )).to be nil
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should return nil' do
|
111
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
112
|
+
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
113
|
+
subject.save
|
114
|
+
expect( Hydra::PCDM::RemoveObjectFromCollection.call( subject.reload, object1 )).to be nil
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should return nil' do
|
118
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
119
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
120
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object4 )
|
121
|
+
Hydra::PCDM::AddObjectToCollection.call( subject, object5 )
|
122
|
+
subject.save
|
123
|
+
expect( Hydra::PCDM::RemoveObjectFromCollection.call( subject.reload, object3 )).to be nil
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'with unacceptable objects' do
|
129
|
+
let(:collection1) { Hydra::PCDM::Collection.create }
|
130
|
+
let(:file1) { Hydra::PCDM::File.new }
|
131
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
132
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
133
|
+
|
134
|
+
let(:error_type) { ArgumentError }
|
135
|
+
let(:error_message) { 'child_object must be a pcdm object' }
|
136
|
+
|
137
|
+
it 'should NOT remove Hydra::PCDM::Collections from objects aggregation' do
|
138
|
+
expect{ Hydra::PCDM::RemoveObjectFromCollection.call( subject, collection1 ) }.to raise_error(error_type,error_message)
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should NOT remove Hydra::PCDM::Files from objects aggregation' do
|
142
|
+
expect{ Hydra::PCDM::RemoveObjectFromCollection.call( subject, file1 ) }.to raise_error(error_type,error_message)
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should NOT remove non-PCDM objects from objects aggregation' do
|
146
|
+
expect{ Hydra::PCDM::RemoveObjectFromCollection.call( subject, non_PCDM_object ) }.to raise_error(error_type,error_message)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'should NOT remove AF::Base objects from objects aggregation' do
|
150
|
+
expect{ Hydra::PCDM::RemoveObjectFromCollection.call( subject, af_base_object ) }.to raise_error(error_type,error_message)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'with unacceptable parent collection' do
|
155
|
+
let(:collection2) { Hydra::PCDM::Collection.create }
|
156
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
157
|
+
let(:file1) { Hydra::PCDM::File.new }
|
158
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
159
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
160
|
+
|
161
|
+
let(:error_type) { ArgumentError }
|
162
|
+
let(:error_message) { 'parent_collection must be a pcdm collection' }
|
163
|
+
|
164
|
+
it 'should NOT accept Hydra::PCDM::Objects as parent collection' do
|
165
|
+
expect{ Hydra::PCDM::RemoveObjectFromCollection.call( object1, collection2 ) }.to raise_error(error_type,error_message)
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should NOT accept Hydra::PCDM::Files as parent collection' do
|
169
|
+
expect{ Hydra::PCDM::RemoveObjectFromCollection.call( file1, collection2 ) }.to raise_error(error_type,error_message)
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should NOT accept non-PCDM objects as parent collection' do
|
173
|
+
expect{ Hydra::PCDM::RemoveObjectFromCollection.call( non_PCDM_object, collection2 ) }.to raise_error(error_type,error_message)
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should NOT accept AF::Base objects as parent collection' do
|
177
|
+
expect{ Hydra::PCDM::RemoveObjectFromCollection.call( af_base_object, collection2 ) }.to raise_error(error_type,error_message)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|