hydra-works 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +17 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +14 -0
  6. data/CONTRIBUTING.md +115 -0
  7. data/Gemfile +14 -0
  8. data/LICENSE +16 -0
  9. data/README.md +80 -0
  10. data/Rakefile +23 -0
  11. data/hydra-works.gemspec +33 -0
  12. data/lib/hydra/works.rb +81 -0
  13. data/lib/hydra/works/models/collection.rb +5 -0
  14. data/lib/hydra/works/models/concerns/aggregates_collections.rb +16 -0
  15. data/lib/hydra/works/models/concerns/aggregates_generic_files.rb +20 -0
  16. data/lib/hydra/works/models/concerns/aggregates_generic_works.rb +20 -0
  17. data/lib/hydra/works/models/concerns/collection_behavior.rb +28 -0
  18. data/lib/hydra/works/models/concerns/generic_file/contained_files.rb +22 -0
  19. data/lib/hydra/works/models/concerns/generic_file/derivatives.rb +32 -0
  20. data/lib/hydra/works/models/concerns/generic_file/mime_types.rb +69 -0
  21. data/lib/hydra/works/models/concerns/generic_file_behavior.rb +25 -0
  22. data/lib/hydra/works/models/concerns/generic_work_behavior.rb +30 -0
  23. data/lib/hydra/works/models/generic_file.rb +17 -0
  24. data/lib/hydra/works/models/generic_work.rb +9 -0
  25. data/lib/hydra/works/processor.rb +9 -0
  26. data/lib/hydra/works/services/collection/add_collection.rb +19 -0
  27. data/lib/hydra/works/services/collection/add_generic_work.rb +19 -0
  28. data/lib/hydra/works/services/collection/add_related_object.rb +19 -0
  29. data/lib/hydra/works/services/collection/get_collections.rb +17 -0
  30. data/lib/hydra/works/services/collection/get_generic_works.rb +17 -0
  31. data/lib/hydra/works/services/collection/get_related_objects.rb +17 -0
  32. data/lib/hydra/works/services/collection/remove_collection.rb +19 -0
  33. data/lib/hydra/works/services/collection/remove_generic_work.rb +20 -0
  34. data/lib/hydra/works/services/collection/remove_related_object.rb +19 -0
  35. data/lib/hydra/works/services/generic_file/add_file.rb +55 -0
  36. data/lib/hydra/works/services/generic_file/add_generic_file.rb +19 -0
  37. data/lib/hydra/works/services/generic_file/add_original_file.rb +11 -0
  38. data/lib/hydra/works/services/generic_file/add_related_object.rb +19 -0
  39. data/lib/hydra/works/services/generic_file/add_versioned_original_file.rb +10 -0
  40. data/lib/hydra/works/services/generic_file/generate/thumbnail.rb +19 -0
  41. data/lib/hydra/works/services/generic_file/get_generic_files.rb +17 -0
  42. data/lib/hydra/works/services/generic_file/get_related_objects.rb +17 -0
  43. data/lib/hydra/works/services/generic_file/remove_generic_file.rb +20 -0
  44. data/lib/hydra/works/services/generic_file/remove_related_object.rb +19 -0
  45. data/lib/hydra/works/services/generic_file/upload_file.rb +32 -0
  46. data/lib/hydra/works/services/generic_work/add_generic_file.rb +19 -0
  47. data/lib/hydra/works/services/generic_work/add_generic_work.rb +19 -0
  48. data/lib/hydra/works/services/generic_work/add_related_object.rb +19 -0
  49. data/lib/hydra/works/services/generic_work/get_generic_files.rb +17 -0
  50. data/lib/hydra/works/services/generic_work/get_generic_works.rb +17 -0
  51. data/lib/hydra/works/services/generic_work/get_related_objects.rb +17 -0
  52. data/lib/hydra/works/services/generic_work/move_generic_file.rb +19 -0
  53. data/lib/hydra/works/services/generic_work/remove_generic_file.rb +20 -0
  54. data/lib/hydra/works/services/generic_work/remove_generic_work.rb +20 -0
  55. data/lib/hydra/works/services/generic_work/remove_related_object.rb +19 -0
  56. data/lib/hydra/works/version.rb +5 -0
  57. data/lib/hydra/works/vocab/works_terms.rb +12 -0
  58. data/spec/fixtures/sample-file.pdf +0 -0
  59. data/spec/fixtures/updated-file.txt +1 -0
  60. data/spec/hydra/works/models/collection_spec.rb +41 -0
  61. data/spec/hydra/works/models/concerns/file/contained_files_spec.rb +113 -0
  62. data/spec/hydra/works/models/concerns/generic_file_behavior_spec.rb +12 -0
  63. data/spec/hydra/works/models/generic_file_spec.rb +45 -0
  64. data/spec/hydra/works/models/generic_work_spec.rb +50 -0
  65. data/spec/hydra/works/services/collection/add_collection_spec.rb +166 -0
  66. data/spec/hydra/works/services/collection/add_generic_work_spec.rb +155 -0
  67. data/spec/hydra/works/services/collection/add_related_object_spec.rb +149 -0
  68. data/spec/hydra/works/services/collection/get_collections_spec.rb +35 -0
  69. data/spec/hydra/works/services/collection/get_generic_works_spec.rb +35 -0
  70. data/spec/hydra/works/services/collection/get_related_objects_spec.rb +49 -0
  71. data/spec/hydra/works/services/collection/remove_collection_spec.rb +133 -0
  72. data/spec/hydra/works/services/collection/remove_generic_work_spec.rb +133 -0
  73. data/spec/hydra/works/services/collection/remove_related_object_spec.rb +128 -0
  74. data/spec/hydra/works/services/generic_file/add_file_spec.rb +28 -0
  75. data/spec/hydra/works/services/generic_file/add_generic_file_spec.rb +174 -0
  76. data/spec/hydra/works/services/generic_file/add_related_object_spec.rb +150 -0
  77. data/spec/hydra/works/services/generic_file/generate/thumbnail_spec.rb +21 -0
  78. data/spec/hydra/works/services/generic_file/get_generic_files_spec.rb +19 -0
  79. data/spec/hydra/works/services/generic_file/get_related_objects_spec.rb +45 -0
  80. data/spec/hydra/works/services/generic_file/remove_generic_file_spec.rb +124 -0
  81. data/spec/hydra/works/services/generic_file/remove_related_object_spec.rb +123 -0
  82. data/spec/hydra/works/services/generic_file/upload_file_spec.rb +82 -0
  83. data/spec/hydra/works/services/generic_work/add_generic_file_spec.rb +156 -0
  84. data/spec/hydra/works/services/generic_work/add_generic_work_spec.rb +157 -0
  85. data/spec/hydra/works/services/generic_work/add_related_object_spec.rb +148 -0
  86. data/spec/hydra/works/services/generic_work/get_generic_files_spec.rb +35 -0
  87. data/spec/hydra/works/services/generic_work/get_generic_works_spec.rb +35 -0
  88. data/spec/hydra/works/services/generic_work/get_related_objects_spec.rb +46 -0
  89. data/spec/hydra/works/services/generic_work/move_generic_file_spec.rb +21 -0
  90. data/spec/hydra/works/services/generic_work/remove_generic_file_spec.rb +132 -0
  91. data/spec/hydra/works/services/generic_work/remove_generic_work_spec.rb +133 -0
  92. data/spec/hydra/works/services/generic_work/remove_related_object_spec.rb +128 -0
  93. data/spec/hydra/works_spec.rb +149 -0
  94. data/spec/spec_helper.rb +40 -0
  95. data/use-cases/conference_event_use_case.md +16 -0
  96. data/use-cases/lafayette_college_geospatial_use_case.md +80 -0
  97. data/use-cases/northwestern_adminset_use-case.md +19 -0
  98. data/use-cases/northwestern_displayset_use_case.md +23 -0
  99. data/use-cases/northwestern_playlist_use_case.md +21 -0
  100. data/use-cases/princeton_book_use_case.md +117 -0
  101. data/use-cases/scholarsphere_use_case.md +32 -0
  102. data/use-cases/stanford_data_model_use_case.md +86 -0
  103. data/use-cases/ucin_linked_resource_use_case.md +21 -0
  104. metadata +338 -0
@@ -0,0 +1,150 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::AddRelatedObjectToGenericFile do
4
+
5
+ let(:subject) { Hydra::Works::GenericFile::Base.create }
6
+
7
+ describe '#call' do
8
+
9
+ context 'with acceptable related objects' do
10
+ let(:object1) { Hydra::PCDM::Object.create }
11
+ let(:object2) { Hydra::PCDM::Object.create }
12
+ let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
13
+ let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
14
+ let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
15
+ let(:generic_file2) { Hydra::Works::GenericFile::Base.create }
16
+
17
+ it 'should add various types of related objects to generic_file' do
18
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, generic_work1 )
19
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, generic_file1 )
20
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, object1 )
21
+ related_objects = Hydra::Works::GetRelatedObjectsFromGenericFile.call( subject )
22
+ expect( related_objects.include? generic_work1 ).to be true
23
+ expect( related_objects.include? generic_file1 ).to be true
24
+ expect( related_objects.include? object1 ).to be true
25
+ expect( related_objects.size ).to eq 3
26
+ end
27
+
28
+ context 'with files and generic_files' do
29
+ let(:file1) { subject.files.build }
30
+ let(:file2) { subject.files.build }
31
+
32
+ before do
33
+ file1.content = "I'm a file"
34
+ file2.content = "I am too"
35
+ Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file1 )
36
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, object1 )
37
+ subject.save!
38
+ end
39
+
40
+ it 'should add a related object to a generic_file with files and generic_files' do
41
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, object2 )
42
+ related_objects = Hydra::Works::GetRelatedObjectsFromGenericFile.call( subject )
43
+ expect( related_objects.include? object1 ).to be true
44
+ expect( related_objects.include? object2 ).to be true
45
+ expect( related_objects.size ).to eq 2
46
+ end
47
+
48
+ it 'should solrize member ids' do
49
+ skip 'skipping this test because issue #109 needs to be addressed' do
50
+ expect(subject.to_solr["generic_files_ssim"]).to include(generic_file2.id,generic_file1.id)
51
+ expect(subject.to_solr["generic_files_ssim"]).not_to include(object1.id,object2.id,file1.id,file2.id)
52
+ expect(subject.to_solr["files_ssim"]).to include(file1.id,file2.id)
53
+ expect(subject.to_solr["files_ssim"]).not_to include(object1.id,object2.id,generic_file1.id,generic_file2.id)
54
+ expect(subject.to_solr["related_objects_ssim"]).to include(object1.id,object2.id)
55
+ expect(subject.to_solr["related_objects_ssim"]).not_to include(generic_file2.id,generic_file1.id,file1.id,file2.id)
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ context 'with unacceptable child related objects' do
62
+ let(:collection1) { Hydra::Works::Collection.create }
63
+ let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
64
+ let(:pcdm_file1) { Hydra::PCDM::File.new }
65
+ let(:non_PCDM_object) { "I'm not a PCDM object" }
66
+ let(:af_base_object) { ActiveFedora::Base.create }
67
+
68
+ let(:error_message) { 'child_related_object must be a pcdm object' }
69
+
70
+ it 'should NOT aggregate Hydra::Works::Collection in related objects aggregation' do
71
+ expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, collection1 ) }.to raise_error(ArgumentError,error_message)
72
+ end
73
+
74
+ it 'should NOT aggregate Hydra::PCDM::Collections in related objects aggregation' do
75
+ expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, pcdm_collection1 ) }.to raise_error(ArgumentError,error_message)
76
+ end
77
+
78
+ it 'should NOT aggregate Hydra::PCDM::Files in related objects aggregation' do
79
+ expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, pcdm_file1 ) }.to raise_error(ArgumentError,error_message)
80
+ end
81
+
82
+ it 'should NOT aggregate non-PCDM objects in related objects aggregation' do
83
+ expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, non_PCDM_object ) }.to raise_error(ArgumentError,error_message)
84
+ end
85
+
86
+ it 'should NOT aggregate AF::Base objects in related objects aggregation' do
87
+ expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message)
88
+ end
89
+ end
90
+
91
+ context 'with unacceptable parent generic work' do
92
+ let(:collection1) { Hydra::Works::Collection.create }
93
+ let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
94
+ let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
95
+ let(:pcdm_object1) { Hydra::PCDM::Object.create }
96
+ let(:pcdm_object2) { 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_message) { 'parent_generic_file must be a hydra-works generic file' }
102
+
103
+ it 'should NOT accept Hydra::Works::Collection as parent generic file' do
104
+ expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( collection1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message)
105
+ end
106
+
107
+ it 'should NOT accept Hydra::Works::GenericWork as parent generic file' do
108
+ expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( generic_work1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message)
109
+ end
110
+
111
+ it 'should NOT accept Hydra::PCDM::Collections as parent generic file' do
112
+ expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( pcdm_collection1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message)
113
+ end
114
+
115
+ it 'should NOT accept Hydra::PCDM::Objects as parent generic file' do
116
+ expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( pcdm_object1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message)
117
+ end
118
+
119
+ it 'should NOT accept Hydra::PCDM::Files as parent generic file' do
120
+ expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( pcdm_file1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message)
121
+ end
122
+
123
+ it 'should NOT accept non-PCDM objects as parent generic file' do
124
+ expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( non_PCDM_object, pcdm_object2 ) }.to raise_error(ArgumentError,error_message)
125
+ end
126
+
127
+ it 'should NOT accept AF::Base objects as parent generic file' do
128
+ expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( af_base_object, pcdm_object2 ) }.to raise_error(ArgumentError,error_message)
129
+ end
130
+ end
131
+
132
+
133
+ context 'with invalid behaviors' do
134
+ let(:object1) { Hydra::PCDM::Object.create }
135
+ let(:object2) { Hydra::PCDM::Object.create }
136
+
137
+ it 'should NOT allow related objects to repeat' do
138
+ skip 'skipping this test because issue pcdm#92 needs to be addressed' do
139
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, object1 )
140
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, object2 )
141
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, object1 )
142
+ related_objects = Hydra::Works::GetRelatedObjectsFromGenericFile.call( subject )
143
+ expect( related_objects.include? object1 ).to be true
144
+ expect( related_objects.include? object2 ).to be true
145
+ expect( related_objects.size ).to eq 2
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::GenerateThumbnail do
4
+
5
+ context "when the object has no original file" do
6
+ let(:error_message) { "object has no content at original_file from which to generate a thumbnail" }
7
+ let(:object) { double("object", original_file: nil ) }
8
+ it "raises an error" do
9
+ expect(lambda{ described_class.call(object) }).to raise_error(ArgumentError, error_message)
10
+ end
11
+ end
12
+
13
+ context "when the object has no content at specified location" do
14
+ let(:error_message) { "object has no content at my_location from which to generate a thumbnail" }
15
+ let(:object) { double("object", my_location: nil ) }
16
+ it "raises an error" do
17
+ expect(lambda{ described_class.call(object, content: :my_location) }).to raise_error(ArgumentError, error_message)
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::GetGenericFilesFromGenericFile do
4
+
5
+ subject { Hydra::Works::GenericFile::Base.create }
6
+
7
+ let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
8
+ let(:generic_file2) { Hydra::Works::GenericFile::Base.create }
9
+
10
+ describe '#call' do
11
+ it 'should return generic_files when generic_files are aggregated' do
12
+ Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file1 )
13
+ Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file2 )
14
+ subject.save
15
+ expect(Hydra::Works::GetGenericFilesFromGenericFile.call( subject )).to eq [generic_file1,generic_file2]
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::GetRelatedObjectsFromGenericFile do
4
+
5
+ subject { Hydra::Works::GenericFile::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_file1) { Hydra::Works::GenericFile::Base.create }
12
+ let(:generic_file2) { Hydra::Works::GenericFile::Base.create }
13
+
14
+ describe '#call' do
15
+ context 'with generic files' do
16
+ before do
17
+ Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file1 )
18
+ Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file2 )
19
+ subject.save
20
+ end
21
+
22
+ it 'should return empty array when only generic files are aggregated' do
23
+ expect(Hydra::Works::GetRelatedObjectsFromGenericFile.call( subject )).to eq []
24
+ end
25
+
26
+ it 'should only return related objects' do
27
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, object2 )
28
+ expect(Hydra::Works::GetRelatedObjectsFromGenericFile.call( subject )).to eq [object2]
29
+ end
30
+
31
+ it 'should return related objects of various types' do
32
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, generic_work1 )
33
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, generic_file1 )
34
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, object1 )
35
+ related_objects = Hydra::Works::GetRelatedObjectsFromGenericFile.call( subject )
36
+ expect( related_objects.include? object1 ).to be true
37
+ expect( related_objects.include? generic_work1 ).to be true
38
+ expect( related_objects.include? generic_file1 ).to be true
39
+ expect( related_objects.size ).to eq 3
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::RemoveGenericFileFromGenericFile do
4
+
5
+ subject { Hydra::Works::GenericFile::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
+ describe '#call' do
14
+ context 'when multiple collections' do
15
+ before do
16
+ Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file1 )
17
+ Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file2 )
18
+ Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file3 )
19
+ Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file4 )
20
+ Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file5 )
21
+ subject.save
22
+ expect( Hydra::Works::GetGenericFilesFromGenericFile.call( subject.reload )).to eq [generic_file1,generic_file2,generic_file3,generic_file4,generic_file5]
23
+ end
24
+
25
+ it 'should remove first collection' do
26
+ expect( Hydra::Works::RemoveGenericFileFromGenericFile.call( subject, generic_file1 ) ).to eq generic_file1
27
+ expect( Hydra::Works::GetGenericFilesFromGenericFile.call( subject.reload )).to eq [generic_file2,generic_file3,generic_file4,generic_file5]
28
+ end
29
+
30
+ it 'should remove last collection' do
31
+ expect( Hydra::Works::RemoveGenericFileFromGenericFile.call( subject, generic_file5 ) ).to eq generic_file5
32
+ expect( Hydra::Works::GetGenericFilesFromGenericFile.call( subject.reload )).to eq [generic_file1,generic_file2,generic_file3,generic_file4]
33
+ end
34
+
35
+ it 'should remove middle collection' do
36
+ expect( Hydra::Works::RemoveGenericFileFromGenericFile.call( subject, generic_file3 ) ).to eq generic_file3
37
+ expect( Hydra::Works::GetGenericFilesFromGenericFile.call( subject.reload )).to eq [generic_file1,generic_file2,generic_file4,generic_file5]
38
+ end
39
+ end
40
+ end
41
+
42
+ context 'with unacceptable generic files' do
43
+ let(:collection1) { Hydra::Works::Collection.create }
44
+ let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
45
+ let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
46
+ let(:pcdm_object1) { Hydra::PCDM::Object.create }
47
+ let(:pcdm_file1) { Hydra::PCDM::File.new }
48
+ let(:non_PCDM_object) { "I'm not a PCDM object" }
49
+ let(:af_base_object) { ActiveFedora::Base.create }
50
+
51
+ let(:error_type) { ArgumentError }
52
+ let(:error_message) { 'child_generic_file must be a hydra-works generic file' }
53
+
54
+ it 'should NOT remove Hydra::Works::Collection from generic_files aggregation' do
55
+ expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( subject, collection1 ) }.to raise_error(ArgumentError,error_message)
56
+ end
57
+
58
+ it 'should NOT remove Hydra::Works::GenericWork from generic_files aggregation' do
59
+ expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( subject, generic_work1 ) }.to raise_error(ArgumentError,error_message)
60
+ end
61
+
62
+ it 'should NOT remove Hydra::PCDM::Collections from generic_files aggregation' do
63
+ expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( subject, pcdm_collection1 ) }.to raise_error(ArgumentError,error_message)
64
+ end
65
+
66
+ it 'should NOT remove Hydra::PCDM::Objects from generic_files aggregation' do
67
+ expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( subject, pcdm_object1 ) }.to raise_error(error_type,error_message)
68
+ end
69
+
70
+ it 'should NOT remove Hydra::PCDM::Files from generic_files aggregation' do
71
+ expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( subject, pcdm_file1 ) }.to raise_error(error_type,error_message)
72
+ end
73
+
74
+ it 'should NOT remove non-PCDM objects from generic_files aggregation' do
75
+ expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( subject, non_PCDM_object ) }.to raise_error(error_type,error_message)
76
+ end
77
+
78
+ it 'should NOT remove AF::Base objects from generic_works aggregation' do
79
+ expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( subject, af_base_object ) }.to raise_error(error_type,error_message)
80
+ end
81
+ end
82
+
83
+ context 'with unacceptable parent generic file' do
84
+ let(:generic_file2) { Hydra::Works::GenericFile::Base.create }
85
+ let(:collection1) { Hydra::Works::Collection.create }
86
+ let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
87
+ let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
88
+ let(:pcdm_object1) { Hydra::PCDM::Object.create }
89
+ let(:pcdm_file1) { Hydra::PCDM::File.new }
90
+ let(:non_PCDM_object) { "I'm not a PCDM object" }
91
+ let(:af_base_object) { ActiveFedora::Base.create }
92
+
93
+ let(:error_type) { ArgumentError }
94
+ let(:error_message) { 'parent_generic_file must be a hydra-works generic file' }
95
+
96
+ it 'should NOT accept Hydra::Works::Collection as parent generic file' do
97
+ expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( collection1, generic_file2 ) }.to raise_error(ArgumentError,error_message)
98
+ end
99
+
100
+ it 'should NOT accept Hydra::Works::GenericWork as parent generic file' do
101
+ expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( generic_work1, generic_file2 ) }.to raise_error(ArgumentError,error_message)
102
+ end
103
+
104
+ it 'should NOT accept Hydra::PCDM::Collections as parent generic file' do
105
+ expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( pcdm_collection1, generic_file2 ) }.to raise_error(ArgumentError,error_message)
106
+ end
107
+
108
+ it 'should NOT accept Hydra::PCDM::Objects as parent generic file' do
109
+ expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( pcdm_object1, generic_file2 ) }.to raise_error(error_type,error_message)
110
+ end
111
+
112
+ it 'should NOT accept Hydra::PCDM::Files as parent generic file' do
113
+ expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( pcdm_file1, generic_file2 ) }.to raise_error(error_type,error_message)
114
+ end
115
+
116
+ it 'should NOT accept non-PCDM objects as parent generic file' do
117
+ expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( non_PCDM_object, generic_file2 ) }.to raise_error(error_type,error_message)
118
+ end
119
+
120
+ it 'should NOT accept AF::Base objects as parent generic file' do
121
+ expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( af_base_object, generic_file2 ) }.to raise_error(error_type,error_message)
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::RemoveRelatedObjectFromGenericFile do
4
+
5
+ subject { Hydra::Works::GenericFile::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_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 related objects' do
19
+ before do
20
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, related_object1 )
21
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, related_work2 )
22
+ Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file2 )
23
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, related_file3 )
24
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, related_object4 )
25
+ Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file1 )
26
+ Hydra::Works::AddRelatedObjectToGenericFile.call( subject, related_work5 )
27
+ subject.save
28
+ expect( Hydra::Works::GetRelatedObjectsFromGenericFile.call( subject.reload )).to eq [related_object1,related_work2,related_file3,related_object4,related_work5]
29
+ end
30
+
31
+ it 'should remove first related object' do
32
+ expect( Hydra::Works::RemoveRelatedObjectFromGenericFile.call( subject, related_object1 ) ).to eq related_object1
33
+ expect( Hydra::Works::GetRelatedObjectsFromGenericFile.call( subject.reload )).to eq [related_work2,related_file3,related_object4,related_work5]
34
+ expect( Hydra::Works::GetGenericFilesFromGenericFile.call( subject.reload )).to eq [generic_file2,generic_file1]
35
+ end
36
+
37
+ it 'should remove last related object' do
38
+ expect( Hydra::Works::RemoveRelatedObjectFromGenericFile.call( subject, related_work5 ) ).to eq related_work5
39
+ expect( Hydra::Works::GetRelatedObjectsFromGenericFile.call( subject.reload )).to eq [related_object1,related_work2,related_file3,related_object4]
40
+ expect( Hydra::Works::GetGenericFilesFromGenericFile.call( subject.reload )).to eq [generic_file2,generic_file1]
41
+ end
42
+
43
+ it 'should remove middle related object' do
44
+ expect( Hydra::Works::RemoveRelatedObjectFromGenericFile.call( subject, related_file3 ) ).to eq related_file3
45
+ expect( Hydra::Works::GetRelatedObjectsFromGenericFile.call( subject.reload )).to eq [related_object1,related_work2,related_object4,related_work5]
46
+ expect( Hydra::Works::GetGenericFilesFromGenericFile.call( subject.reload )).to eq [generic_file2,generic_file1]
47
+ end
48
+ end
49
+ end
50
+
51
+ context 'with unacceptable related object' do
52
+ let(:collection1) { Hydra::Works::Collection.create }
53
+ let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
54
+ let(:pcdm_file1) { Hydra::PCDM::File.new }
55
+ let(:non_PCDM_object) { "I'm not a PCDM object" }
56
+ let(:af_base_object) { ActiveFedora::Base.create }
57
+
58
+ let(:error_type) { ArgumentError }
59
+ let(:error_message) { 'child_related_object must be a pcdm object' }
60
+
61
+ it 'should NOT remove Hydra::Works::Collection from related_objects aggregation' do
62
+ expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( subject, collection1 ) }.to raise_error(ArgumentError,error_message)
63
+ end
64
+
65
+ it 'should NOT remove Hydra::PCDM::Collections from related_objects aggregation' do
66
+ expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( subject, pcdm_collection1 ) }.to raise_error(ArgumentError,error_message)
67
+ end
68
+
69
+ it 'should NOT remove Hydra::PCDM::Files from related_objects aggregation' do
70
+ expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( subject, pcdm_file1 ) }.to raise_error(error_type,error_message)
71
+ end
72
+
73
+ it 'should NOT remove non-PCDM objects from related_objects aggregation' do
74
+ expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( subject, non_PCDM_object ) }.to raise_error(error_type,error_message)
75
+ end
76
+
77
+ it 'should NOT remove AF::Base objects from related_objects aggregation' do
78
+ expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( subject, af_base_object ) }.to raise_error(error_type,error_message)
79
+ end
80
+ end
81
+
82
+ context 'with unacceptable parent generic file' do
83
+ let(:related_object2) { Hydra::PCDM::Object.create }
84
+ let(:collection1) { Hydra::Works::Collection.create }
85
+ let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
86
+ let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
87
+ let(:pcdm_object1) { Hydra::PCDM::Object.create }
88
+ let(:pcdm_file1) { Hydra::PCDM::File.new }
89
+ let(:non_PCDM_object) { "I'm not a PCDM object" }
90
+ let(:af_base_object) { ActiveFedora::Base.create }
91
+
92
+ let(:error_type) { ArgumentError }
93
+ let(:error_message) { 'parent_generic_file must be a hydra-works generic file' }
94
+
95
+ it 'should NOT accept Hydra::Works::Collection as parent generic file' do
96
+ expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( collection1, related_object2 ) }.to raise_error(ArgumentError,error_message)
97
+ end
98
+
99
+ it 'should NOT accept Hydra::Works::GenericWork as parent generic file' do
100
+ expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( generic_work1, related_object2 ) }.to raise_error(ArgumentError,error_message)
101
+ end
102
+
103
+ it 'should NOT accept Hydra::PCDM::Collections as parent generic file' do
104
+ expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( pcdm_collection1, related_object2 ) }.to raise_error(ArgumentError,error_message)
105
+ end
106
+
107
+ it 'should NOT accept Hydra::PCDM::Objects as parent generic file' do
108
+ expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( pcdm_object1, related_object2 ) }.to raise_error(error_type,error_message)
109
+ end
110
+
111
+ it 'should NOT accept Hydra::PCDM::Files as parent generic file' do
112
+ expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( pcdm_file1, related_object2 ) }.to raise_error(error_type,error_message)
113
+ end
114
+
115
+ it 'should NOT accept non-PCDM objects as parent generic file' do
116
+ expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( non_PCDM_object, related_object2 ) }.to raise_error(error_type,error_message)
117
+ end
118
+
119
+ it 'should NOT accept AF::Base objects as parent generic file' do
120
+ expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( af_base_object, related_work2 ) }.to raise_error(error_type,error_message)
121
+ end
122
+ end
123
+ end