hydra-works 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 +17 -0
- data/.rspec +1 -0
- data/.travis.yml +14 -0
- data/CONTRIBUTING.md +115 -0
- data/Gemfile +14 -0
- data/LICENSE +16 -0
- data/README.md +80 -0
- data/Rakefile +23 -0
- data/hydra-works.gemspec +33 -0
- data/lib/hydra/works.rb +81 -0
- data/lib/hydra/works/models/collection.rb +5 -0
- data/lib/hydra/works/models/concerns/aggregates_collections.rb +16 -0
- data/lib/hydra/works/models/concerns/aggregates_generic_files.rb +20 -0
- data/lib/hydra/works/models/concerns/aggregates_generic_works.rb +20 -0
- data/lib/hydra/works/models/concerns/collection_behavior.rb +28 -0
- data/lib/hydra/works/models/concerns/generic_file/contained_files.rb +22 -0
- data/lib/hydra/works/models/concerns/generic_file/derivatives.rb +32 -0
- data/lib/hydra/works/models/concerns/generic_file/mime_types.rb +69 -0
- data/lib/hydra/works/models/concerns/generic_file_behavior.rb +25 -0
- data/lib/hydra/works/models/concerns/generic_work_behavior.rb +30 -0
- data/lib/hydra/works/models/generic_file.rb +17 -0
- data/lib/hydra/works/models/generic_work.rb +9 -0
- data/lib/hydra/works/processor.rb +9 -0
- data/lib/hydra/works/services/collection/add_collection.rb +19 -0
- data/lib/hydra/works/services/collection/add_generic_work.rb +19 -0
- data/lib/hydra/works/services/collection/add_related_object.rb +19 -0
- data/lib/hydra/works/services/collection/get_collections.rb +17 -0
- data/lib/hydra/works/services/collection/get_generic_works.rb +17 -0
- data/lib/hydra/works/services/collection/get_related_objects.rb +17 -0
- data/lib/hydra/works/services/collection/remove_collection.rb +19 -0
- data/lib/hydra/works/services/collection/remove_generic_work.rb +20 -0
- data/lib/hydra/works/services/collection/remove_related_object.rb +19 -0
- data/lib/hydra/works/services/generic_file/add_file.rb +55 -0
- data/lib/hydra/works/services/generic_file/add_generic_file.rb +19 -0
- data/lib/hydra/works/services/generic_file/add_original_file.rb +11 -0
- data/lib/hydra/works/services/generic_file/add_related_object.rb +19 -0
- data/lib/hydra/works/services/generic_file/add_versioned_original_file.rb +10 -0
- data/lib/hydra/works/services/generic_file/generate/thumbnail.rb +19 -0
- data/lib/hydra/works/services/generic_file/get_generic_files.rb +17 -0
- data/lib/hydra/works/services/generic_file/get_related_objects.rb +17 -0
- data/lib/hydra/works/services/generic_file/remove_generic_file.rb +20 -0
- data/lib/hydra/works/services/generic_file/remove_related_object.rb +19 -0
- data/lib/hydra/works/services/generic_file/upload_file.rb +32 -0
- data/lib/hydra/works/services/generic_work/add_generic_file.rb +19 -0
- data/lib/hydra/works/services/generic_work/add_generic_work.rb +19 -0
- data/lib/hydra/works/services/generic_work/add_related_object.rb +19 -0
- data/lib/hydra/works/services/generic_work/get_generic_files.rb +17 -0
- data/lib/hydra/works/services/generic_work/get_generic_works.rb +17 -0
- data/lib/hydra/works/services/generic_work/get_related_objects.rb +17 -0
- data/lib/hydra/works/services/generic_work/move_generic_file.rb +19 -0
- data/lib/hydra/works/services/generic_work/remove_generic_file.rb +20 -0
- data/lib/hydra/works/services/generic_work/remove_generic_work.rb +20 -0
- data/lib/hydra/works/services/generic_work/remove_related_object.rb +19 -0
- data/lib/hydra/works/version.rb +5 -0
- data/lib/hydra/works/vocab/works_terms.rb +12 -0
- data/spec/fixtures/sample-file.pdf +0 -0
- data/spec/fixtures/updated-file.txt +1 -0
- data/spec/hydra/works/models/collection_spec.rb +41 -0
- data/spec/hydra/works/models/concerns/file/contained_files_spec.rb +113 -0
- data/spec/hydra/works/models/concerns/generic_file_behavior_spec.rb +12 -0
- data/spec/hydra/works/models/generic_file_spec.rb +45 -0
- data/spec/hydra/works/models/generic_work_spec.rb +50 -0
- data/spec/hydra/works/services/collection/add_collection_spec.rb +166 -0
- data/spec/hydra/works/services/collection/add_generic_work_spec.rb +155 -0
- data/spec/hydra/works/services/collection/add_related_object_spec.rb +149 -0
- data/spec/hydra/works/services/collection/get_collections_spec.rb +35 -0
- data/spec/hydra/works/services/collection/get_generic_works_spec.rb +35 -0
- data/spec/hydra/works/services/collection/get_related_objects_spec.rb +49 -0
- data/spec/hydra/works/services/collection/remove_collection_spec.rb +133 -0
- data/spec/hydra/works/services/collection/remove_generic_work_spec.rb +133 -0
- data/spec/hydra/works/services/collection/remove_related_object_spec.rb +128 -0
- data/spec/hydra/works/services/generic_file/add_file_spec.rb +28 -0
- data/spec/hydra/works/services/generic_file/add_generic_file_spec.rb +174 -0
- data/spec/hydra/works/services/generic_file/add_related_object_spec.rb +150 -0
- data/spec/hydra/works/services/generic_file/generate/thumbnail_spec.rb +21 -0
- data/spec/hydra/works/services/generic_file/get_generic_files_spec.rb +19 -0
- data/spec/hydra/works/services/generic_file/get_related_objects_spec.rb +45 -0
- data/spec/hydra/works/services/generic_file/remove_generic_file_spec.rb +124 -0
- data/spec/hydra/works/services/generic_file/remove_related_object_spec.rb +123 -0
- data/spec/hydra/works/services/generic_file/upload_file_spec.rb +82 -0
- data/spec/hydra/works/services/generic_work/add_generic_file_spec.rb +156 -0
- data/spec/hydra/works/services/generic_work/add_generic_work_spec.rb +157 -0
- data/spec/hydra/works/services/generic_work/add_related_object_spec.rb +148 -0
- data/spec/hydra/works/services/generic_work/get_generic_files_spec.rb +35 -0
- data/spec/hydra/works/services/generic_work/get_generic_works_spec.rb +35 -0
- data/spec/hydra/works/services/generic_work/get_related_objects_spec.rb +46 -0
- data/spec/hydra/works/services/generic_work/move_generic_file_spec.rb +21 -0
- data/spec/hydra/works/services/generic_work/remove_generic_file_spec.rb +132 -0
- data/spec/hydra/works/services/generic_work/remove_generic_work_spec.rb +133 -0
- data/spec/hydra/works/services/generic_work/remove_related_object_spec.rb +128 -0
- data/spec/hydra/works_spec.rb +149 -0
- data/spec/spec_helper.rb +40 -0
- data/use-cases/conference_event_use_case.md +16 -0
- data/use-cases/lafayette_college_geospatial_use_case.md +80 -0
- data/use-cases/northwestern_adminset_use-case.md +19 -0
- data/use-cases/northwestern_displayset_use_case.md +23 -0
- data/use-cases/northwestern_playlist_use_case.md +21 -0
- data/use-cases/princeton_book_use_case.md +117 -0
- data/use-cases/scholarsphere_use_case.md +32 -0
- data/use-cases/stanford_data_model_use_case.md +86 -0
- data/use-cases/ucin_linked_resource_use_case.md +21 -0
- metadata +338 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::Works::GetGenericFilesFromGenericWork do
|
4
|
+
|
5
|
+
subject { Hydra::Works::GenericWork::Base.create }
|
6
|
+
|
7
|
+
let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
|
8
|
+
let(:generic_file2) { Hydra::Works::GenericFile::Base.create }
|
9
|
+
|
10
|
+
let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
|
11
|
+
let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
|
12
|
+
|
13
|
+
describe '#call' do
|
14
|
+
it 'should return empty array when only generic_works are aggregated' do
|
15
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 )
|
16
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work2 )
|
17
|
+
subject.save
|
18
|
+
expect(Hydra::Works::GetGenericFilesFromGenericWork.call( subject )).to eq []
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with generic_files and generic_works' do
|
22
|
+
before do
|
23
|
+
Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file1 )
|
24
|
+
Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file2 )
|
25
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 )
|
26
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work2 )
|
27
|
+
subject.save
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should only return generic_files' do
|
31
|
+
expect(Hydra::Works::GetGenericFilesFromGenericWork.call( subject )).to eq [generic_file1,generic_file2]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::Works::GetGenericWorksFromGenericWork do
|
4
|
+
|
5
|
+
subject { Hydra::Works::GenericWork::Base.create }
|
6
|
+
|
7
|
+
let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
|
8
|
+
let(:generic_file2) { Hydra::Works::GenericFile::Base.create }
|
9
|
+
|
10
|
+
let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
|
11
|
+
let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
|
12
|
+
|
13
|
+
describe '#call' do
|
14
|
+
it 'should return empty array when only generic_files are aggregated' do
|
15
|
+
Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file1 )
|
16
|
+
Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file2 )
|
17
|
+
subject.save
|
18
|
+
expect(Hydra::Works::GetGenericWorksFromGenericWork.call( subject )).to eq []
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with generic_files and generic_works' do
|
22
|
+
before do
|
23
|
+
Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file1 )
|
24
|
+
Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file2 )
|
25
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 )
|
26
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work2 )
|
27
|
+
subject.save
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should only return generic_works' do
|
31
|
+
expect(Hydra::Works::GetGenericWorksFromGenericWork.call( subject )).to eq [generic_work1,generic_work2]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::Works::GetRelatedObjectsFromGenericWork do
|
4
|
+
|
5
|
+
subject { Hydra::Works::GenericWork::Base.create }
|
6
|
+
|
7
|
+
let(:object1) { Hydra::PCDM::Object.create }
|
8
|
+
let(:object2) { Hydra::PCDM::Object.create }
|
9
|
+
|
10
|
+
let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
|
11
|
+
let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
|
12
|
+
let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
|
13
|
+
|
14
|
+
describe '#call' do
|
15
|
+
context 'with generic files and works' do
|
16
|
+
before do
|
17
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 )
|
18
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 )
|
19
|
+
Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file1 )
|
20
|
+
subject.save
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should return empty array when only generic files and generic works are aggregated' do
|
24
|
+
expect(Hydra::Works::GetRelatedObjectsFromGenericWork.call( subject )).to eq []
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should only return related objects' do
|
28
|
+
Hydra::Works::AddRelatedObjectToGenericWork.call( subject, object2 )
|
29
|
+
expect(Hydra::Works::GetRelatedObjectsFromGenericWork.call( subject )).to eq [object2]
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should return related objects of various types' do
|
33
|
+
Hydra::Works::AddRelatedObjectToGenericWork.call( subject, generic_work2 )
|
34
|
+
Hydra::Works::AddRelatedObjectToGenericWork.call( subject, generic_file1 )
|
35
|
+
Hydra::Works::AddRelatedObjectToGenericWork.call( subject, object1 )
|
36
|
+
related_objects = Hydra::Works::GetRelatedObjectsFromGenericWork.call( subject )
|
37
|
+
expect( related_objects.include? object1 ).to be true
|
38
|
+
expect( related_objects.include? generic_work2 ).to be true
|
39
|
+
expect( related_objects.include? generic_file1 ).to be true
|
40
|
+
expect( related_objects.size ).to eq 3
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::Works::MoveGenericFileToGenericWork do
|
4
|
+
let(:source_work) { Hydra::Works::GenericWork::Base.create }
|
5
|
+
let(:target_work) { Hydra::Works::GenericWork::Base.create }
|
6
|
+
let(:file1) { Hydra::Works::GenericFile::Base.create }
|
7
|
+
let(:file2) { Hydra::Works::GenericFile::Base.create }
|
8
|
+
context "move generic file" do
|
9
|
+
before do
|
10
|
+
Hydra::Works::AddGenericFileToGenericWork.call(source_work, file1)
|
11
|
+
Hydra::Works::AddGenericFileToGenericWork.call(source_work, file2)
|
12
|
+
end
|
13
|
+
it "moves file from one work to another" do
|
14
|
+
expect(source_work.generic_files).to eq([file1, file2])
|
15
|
+
expect(target_work.generic_files).to eq([])
|
16
|
+
Hydra::Works::MoveGenericFileToGenericWork.call(source_work, target_work, file1)
|
17
|
+
expect(source_work.generic_files).to eq([file2])
|
18
|
+
expect(target_work.generic_files).to eq([file1])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::Works::RemoveGenericFileFromGenericWork do
|
4
|
+
|
5
|
+
subject { Hydra::Works::GenericWork::Base.create }
|
6
|
+
|
7
|
+
let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
|
8
|
+
let(:generic_file2) { Hydra::Works::GenericFile::Base.create }
|
9
|
+
let(:generic_file3) { Hydra::Works::GenericFile::Base.create }
|
10
|
+
let(:generic_file4) { Hydra::Works::GenericFile::Base.create }
|
11
|
+
let(:generic_file5) { Hydra::Works::GenericFile::Base.create }
|
12
|
+
|
13
|
+
let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
|
14
|
+
let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
|
15
|
+
|
16
|
+
describe '#call' do
|
17
|
+
context 'when multiple collections' do
|
18
|
+
before do
|
19
|
+
Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file1 )
|
20
|
+
Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file2 )
|
21
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work2 )
|
22
|
+
Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file3 )
|
23
|
+
Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file4 )
|
24
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 )
|
25
|
+
Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file5 )
|
26
|
+
subject.save
|
27
|
+
expect( Hydra::Works::GetGenericFilesFromGenericWork.call( subject.reload )).to eq [generic_file1,generic_file2,generic_file3,generic_file4,generic_file5]
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should remove first collection' do
|
31
|
+
expect( Hydra::Works::RemoveGenericFileFromGenericWork.call( subject, generic_file1 ) ).to eq generic_file1
|
32
|
+
expect( Hydra::Works::GetGenericFilesFromGenericWork.call( subject.reload )).to eq [generic_file2,generic_file3,generic_file4,generic_file5]
|
33
|
+
expect( Hydra::Works::GetGenericWorksFromGenericWork.call( subject.reload )).to eq [generic_work2,generic_work1]
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should remove last collection' do
|
37
|
+
expect( Hydra::Works::RemoveGenericFileFromGenericWork.call( subject, generic_file5 ) ).to eq generic_file5
|
38
|
+
expect( Hydra::Works::GetGenericFilesFromGenericWork.call( subject.reload )).to eq [generic_file1,generic_file2,generic_file3,generic_file4]
|
39
|
+
expect( Hydra::Works::GetGenericWorksFromGenericWork.call( subject.reload )).to eq [generic_work2,generic_work1]
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should remove middle collection' do
|
43
|
+
expect( Hydra::Works::RemoveGenericFileFromGenericWork.call( subject, generic_file3 ) ).to eq generic_file3
|
44
|
+
expect( Hydra::Works::GetGenericFilesFromGenericWork.call( subject.reload )).to eq [generic_file1,generic_file2,generic_file4,generic_file5]
|
45
|
+
expect( Hydra::Works::GetGenericWorksFromGenericWork.call( subject.reload )).to eq [generic_work2,generic_work1]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'with unacceptable generic files' do
|
51
|
+
let(:collection1) { Hydra::Works::Collection.create }
|
52
|
+
let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
|
53
|
+
let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
|
54
|
+
let(:pcdm_object1) { Hydra::PCDM::Object.create }
|
55
|
+
let(:pcdm_file1) { Hydra::PCDM::File.new }
|
56
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
57
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
58
|
+
|
59
|
+
let(:error_type) { ArgumentError }
|
60
|
+
let(:error_message) { 'child_generic_file must be a hydra-works generic file' }
|
61
|
+
|
62
|
+
it 'should NOT remove Hydra::Works::Collection from generic_files aggregation' do
|
63
|
+
expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( subject, collection1 ) }.to raise_error(ArgumentError,error_message)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should NOT remove Hydra::Works::GenericWork from generic_files aggregation' do
|
67
|
+
expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( subject, generic_work1 ) }.to raise_error(ArgumentError,error_message)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should NOT remove Hydra::PCDM::Collections from generic_files aggregation' do
|
71
|
+
expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( subject, pcdm_collection1 ) }.to raise_error(ArgumentError,error_message)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should NOT remove Hydra::PCDM::Objects from generic_files aggregation' do
|
75
|
+
expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( subject, pcdm_object1 ) }.to raise_error(error_type,error_message)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should NOT remove Hydra::PCDM::Files from generic_files aggregation' do
|
79
|
+
expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( subject, pcdm_file1 ) }.to raise_error(error_type,error_message)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should NOT remove non-PCDM objects from generic_files aggregation' do
|
83
|
+
expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( subject, non_PCDM_object ) }.to raise_error(error_type,error_message)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should NOT remove AF::Base objects from generic_works aggregation' do
|
87
|
+
expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( subject, af_base_object ) }.to raise_error(error_type,error_message)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'with unacceptable parent generic work' do
|
92
|
+
let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
|
93
|
+
let(:collection1) { Hydra::Works::Collection.create }
|
94
|
+
let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
|
95
|
+
let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
|
96
|
+
let(:pcdm_object1) { Hydra::PCDM::Object.create }
|
97
|
+
let(:pcdm_file1) { Hydra::PCDM::File.new }
|
98
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
99
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
100
|
+
|
101
|
+
let(:error_type) { ArgumentError }
|
102
|
+
let(:error_message) { 'parent_generic_work must be a hydra-works generic work' }
|
103
|
+
|
104
|
+
it 'should NOT accept Hydra::Works::Collection as parent generic work' do
|
105
|
+
expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should NOT accept Hydra::Works::GenericFile as parent generic work' do
|
109
|
+
expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( generic_file1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should NOT accept Hydra::PCDM::Collections as parent generic work' do
|
113
|
+
expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( pcdm_collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should NOT accept Hydra::PCDM::Objects as parent generic work' do
|
117
|
+
expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( pcdm_object1, generic_work2 ) }.to raise_error(error_type,error_message)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should NOT accept Hydra::PCDM::Files as parent generic work' do
|
121
|
+
expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( pcdm_file1, generic_work2 ) }.to raise_error(error_type,error_message)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should NOT accept non-PCDM objects as parent generic work' do
|
125
|
+
expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( non_PCDM_object, generic_work2 ) }.to raise_error(error_type,error_message)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should NOT accept AF::Base objects as parent generic work' do
|
129
|
+
expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( af_base_object, generic_work2 ) }.to raise_error(error_type,error_message)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::Works::RemoveGenericWorkFromGenericWork do
|
4
|
+
|
5
|
+
subject { Hydra::Works::GenericWork::Base.create }
|
6
|
+
|
7
|
+
let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
|
8
|
+
let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
|
9
|
+
let(:generic_work3) { Hydra::Works::GenericWork::Base.create }
|
10
|
+
let(:generic_work4) { Hydra::Works::GenericWork::Base.create }
|
11
|
+
let(:generic_work5) { Hydra::Works::GenericWork::Base.create }
|
12
|
+
|
13
|
+
let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
|
14
|
+
let(:generic_file2) { Hydra::Works::GenericFile::Base.create }
|
15
|
+
|
16
|
+
|
17
|
+
describe '#call' do
|
18
|
+
context 'when multiple collections' do
|
19
|
+
before do
|
20
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 )
|
21
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work2 )
|
22
|
+
Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file2 )
|
23
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work3 )
|
24
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work4 )
|
25
|
+
Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file1 )
|
26
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work5 )
|
27
|
+
subject.save
|
28
|
+
expect( Hydra::Works::GetGenericWorksFromGenericWork.call( subject.reload )).to eq [generic_work1,generic_work2,generic_work3,generic_work4,generic_work5]
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should remove first collection' do
|
32
|
+
expect( Hydra::Works::RemoveGenericWorkFromGenericWork.call( subject, generic_work1 ) ).to eq generic_work1
|
33
|
+
expect( Hydra::Works::GetGenericWorksFromGenericWork.call( subject.reload )).to eq [generic_work2,generic_work3,generic_work4,generic_work5]
|
34
|
+
expect( Hydra::Works::GetGenericFilesFromGenericWork.call( subject.reload )).to eq [generic_file2,generic_file1]
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should remove last collection' do
|
38
|
+
expect( Hydra::Works::RemoveGenericWorkFromGenericWork.call( subject, generic_work5 ) ).to eq generic_work5
|
39
|
+
expect( Hydra::Works::GetGenericWorksFromGenericWork.call( subject.reload )).to eq [generic_work1,generic_work2,generic_work3,generic_work4]
|
40
|
+
expect( Hydra::Works::GetGenericFilesFromGenericWork.call( subject.reload )).to eq [generic_file2,generic_file1]
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should remove middle collection' do
|
44
|
+
expect( Hydra::Works::RemoveGenericWorkFromGenericWork.call( subject, generic_work3 ) ).to eq generic_work3
|
45
|
+
expect( Hydra::Works::GetGenericWorksFromGenericWork.call( subject.reload )).to eq [generic_work1,generic_work2,generic_work4,generic_work5]
|
46
|
+
expect( Hydra::Works::GetGenericFilesFromGenericWork.call( subject.reload )).to eq [generic_file2,generic_file1]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with unacceptable generic works' do
|
52
|
+
let(:collection1) { Hydra::Works::Collection.create }
|
53
|
+
let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
|
54
|
+
let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
|
55
|
+
let(:pcdm_object1) { Hydra::PCDM::Object.create }
|
56
|
+
let(:pcdm_file1) { Hydra::PCDM::File.new }
|
57
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
58
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
59
|
+
|
60
|
+
let(:error_type) { ArgumentError }
|
61
|
+
let(:error_message) { 'child_generic_work must be a hydra-works generic work' }
|
62
|
+
|
63
|
+
it 'should NOT remove Hydra::Works::Collection from generic_works aggregation' do
|
64
|
+
expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( subject, collection1 ) }.to raise_error(ArgumentError,error_message)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should NOT remove Hydra::Works::GenericFile from generic_works aggregation' do
|
68
|
+
expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( subject, generic_file1 ) }.to raise_error(ArgumentError,error_message)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should NOT remove Hydra::PCDM::Collections from generic_works aggregation' do
|
72
|
+
expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( subject, pcdm_collection1 ) }.to raise_error(ArgumentError,error_message)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should NOT remove Hydra::PCDM::Objects from generic_works aggregation' do
|
76
|
+
expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( subject, pcdm_object1 ) }.to raise_error(error_type,error_message)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should NOT remove Hydra::PCDM::Files from generic_works aggregation' do
|
80
|
+
expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( subject, pcdm_file1 ) }.to raise_error(error_type,error_message)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should NOT remove non-PCDM objects from generic_works aggregation' do
|
84
|
+
expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( subject, non_PCDM_object ) }.to raise_error(error_type,error_message)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should NOT remove AF::Base objects from generic_works aggregation' do
|
88
|
+
expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( subject, af_base_object ) }.to raise_error(error_type,error_message)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'with unacceptable parent generic work' do
|
93
|
+
let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
|
94
|
+
let(:collection1) { Hydra::Works::Collection.create }
|
95
|
+
let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
|
96
|
+
let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
|
97
|
+
let(:pcdm_object1) { Hydra::PCDM::Object.create }
|
98
|
+
let(:pcdm_file1) { Hydra::PCDM::File.new }
|
99
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
100
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
101
|
+
|
102
|
+
let(:error_type) { ArgumentError }
|
103
|
+
let(:error_message) { 'parent_generic_work must be a hydra-works generic work' }
|
104
|
+
|
105
|
+
it 'should NOT accept Hydra::Works::Collection as parent generic work' do
|
106
|
+
expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should NOT accept Hydra::Works::GenericFile as parent generic work' do
|
110
|
+
expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( generic_file1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should NOT accept Hydra::PCDM::Collections as parent generic work' do
|
114
|
+
expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( pcdm_collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should NOT accept Hydra::PCDM::Objects as parent generic work' do
|
118
|
+
expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( pcdm_object1, generic_work2 ) }.to raise_error(error_type,error_message)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should NOT accept Hydra::PCDM::Files as parent generic work' do
|
122
|
+
expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( pcdm_file1, generic_work2 ) }.to raise_error(error_type,error_message)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should NOT accept non-PCDM objects as parent generic work' do
|
126
|
+
expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( non_PCDM_object, generic_work2 ) }.to raise_error(error_type,error_message)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should NOT accept AF::Base objects as parent generic work' do
|
130
|
+
expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( af_base_object, generic_work2 ) }.to raise_error(error_type,error_message)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::Works::RemoveRelatedObjectFromGenericWork do
|
4
|
+
|
5
|
+
subject { Hydra::Works::GenericWork::Base.create }
|
6
|
+
|
7
|
+
let(:related_object1) { Hydra::PCDM::Object.create }
|
8
|
+
let(:related_work2) { Hydra::Works::GenericWork::Base.create }
|
9
|
+
let(:related_file3) { Hydra::Works::GenericFile::Base.create }
|
10
|
+
let(:related_object4) { Hydra::PCDM::Object.create }
|
11
|
+
let(:related_work5) { Hydra::Works::GenericWork::Base.create }
|
12
|
+
|
13
|
+
let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
|
14
|
+
let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
|
15
|
+
let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
|
16
|
+
|
17
|
+
|
18
|
+
describe '#call' do
|
19
|
+
context 'when multiple related objects' do
|
20
|
+
before do
|
21
|
+
Hydra::Works::AddRelatedObjectToGenericWork.call( subject, related_object1 )
|
22
|
+
Hydra::Works::AddRelatedObjectToGenericWork.call( subject, related_work2 )
|
23
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work2 )
|
24
|
+
Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file1 )
|
25
|
+
Hydra::Works::AddRelatedObjectToGenericWork.call( subject, related_file3 )
|
26
|
+
Hydra::Works::AddRelatedObjectToGenericWork.call( subject, related_object4 )
|
27
|
+
Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 )
|
28
|
+
Hydra::Works::AddRelatedObjectToGenericWork.call( subject, related_work5 )
|
29
|
+
subject.save
|
30
|
+
expect( Hydra::Works::GetRelatedObjectsFromGenericWork.call( subject.reload )).to eq [related_object1,related_work2,related_file3,related_object4,related_work5]
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should remove first related object' do
|
34
|
+
expect( Hydra::Works::RemoveRelatedObjectFromGenericWork.call( subject, related_object1 ) ).to eq related_object1
|
35
|
+
expect( Hydra::Works::GetRelatedObjectsFromGenericWork.call( subject.reload )).to eq [related_work2,related_file3,related_object4,related_work5]
|
36
|
+
expect( Hydra::Works::GetGenericWorksFromGenericWork.call( subject.reload )).to eq [generic_work2,generic_work1]
|
37
|
+
expect( Hydra::Works::GetGenericFilesFromGenericWork.call( subject.reload )).to eq [generic_file1]
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should remove last related object' do
|
41
|
+
expect( Hydra::Works::RemoveRelatedObjectFromGenericWork.call( subject, related_work5 ) ).to eq related_work5
|
42
|
+
expect( Hydra::Works::GetRelatedObjectsFromGenericWork.call( subject.reload )).to eq [related_object1,related_work2,related_file3,related_object4]
|
43
|
+
expect( Hydra::Works::GetGenericWorksFromGenericWork.call( subject.reload )).to eq [generic_work2,generic_work1]
|
44
|
+
expect( Hydra::Works::GetGenericFilesFromGenericWork.call( subject.reload )).to eq [generic_file1]
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should remove middle related object' do
|
48
|
+
expect( Hydra::Works::RemoveRelatedObjectFromGenericWork.call( subject, related_file3 ) ).to eq related_file3
|
49
|
+
expect( Hydra::Works::GetRelatedObjectsFromGenericWork.call( subject.reload )).to eq [related_object1,related_work2,related_object4,related_work5]
|
50
|
+
expect( Hydra::Works::GetGenericWorksFromGenericWork.call( subject.reload )).to eq [generic_work2,generic_work1]
|
51
|
+
expect( Hydra::Works::GetGenericFilesFromGenericWork.call( subject.reload )).to eq [generic_file1]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'with unacceptable related object' do
|
57
|
+
let(:collection1) { Hydra::Works::Collection.create }
|
58
|
+
let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
|
59
|
+
let(:pcdm_file1) { Hydra::PCDM::File.new }
|
60
|
+
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
61
|
+
let(:af_base_object) { ActiveFedora::Base.create }
|
62
|
+
|
63
|
+
let(:error_type) { ArgumentError }
|
64
|
+
let(:error_message) { 'child_related_object must be a pcdm object' }
|
65
|
+
|
66
|
+
it 'should NOT remove Hydra::Works::Collection from related_objects aggregation' do
|
67
|
+
expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( subject, collection1 ) }.to raise_error(ArgumentError,error_message)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should NOT remove Hydra::PCDM::Collections from related_objects aggregation' do
|
71
|
+
expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( subject, pcdm_collection1 ) }.to raise_error(ArgumentError,error_message)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should NOT remove Hydra::PCDM::Files from related_objects aggregation' do
|
75
|
+
expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( subject, pcdm_file1 ) }.to raise_error(error_type,error_message)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should NOT remove non-PCDM objects from related_objects aggregation' do
|
79
|
+
expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( subject, non_PCDM_object ) }.to raise_error(error_type,error_message)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should NOT remove AF::Base objects from related_objects aggregation' do
|
83
|
+
expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( subject, af_base_object ) }.to raise_error(error_type,error_message)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'with unacceptable parent generic work' do
|
88
|
+
let(:related_object2) { Hydra::PCDM::Object.create }
|
89
|
+
let(:collection1) { Hydra::Works::Collection.create }
|
90
|
+
let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
|
91
|
+
let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
|
92
|
+
let(:pcdm_object1) { Hydra::PCDM::Object.create }
|
93
|
+
let(:pcdm_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) { 'parent_generic_work must be a hydra-works generic work' }
|
99
|
+
|
100
|
+
it 'should NOT accept Hydra::Works::Collection as parent generic work' do
|
101
|
+
expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( collection1, related_object2 ) }.to raise_error(ArgumentError,error_message)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should NOT accept Hydra::Works::GenericFile as parent generic work' do
|
105
|
+
expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( generic_file1, related_object2 ) }.to raise_error(ArgumentError,error_message)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should NOT accept Hydra::PCDM::Collections as parent generic work' do
|
109
|
+
expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( pcdm_collection1, related_object2 ) }.to raise_error(ArgumentError,error_message)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should NOT accept Hydra::PCDM::Objects as parent generic work' do
|
113
|
+
expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( pcdm_object1, related_object2 ) }.to raise_error(error_type,error_message)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should NOT accept Hydra::PCDM::Files as parent generic work' do
|
117
|
+
expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( pcdm_file1, related_object2 ) }.to raise_error(error_type,error_message)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should NOT accept non-PCDM objects as parent generic work' do
|
121
|
+
expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( non_PCDM_object, related_object2 ) }.to raise_error(error_type,error_message)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should NOT accept AF::Base objects as parent generic work' do
|
125
|
+
expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( af_base_object, related_work2 ) }.to raise_error(error_type,error_message)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|