hydra-works 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.travis.yml +2 -5
  4. data/Gemfile +1 -3
  5. data/README.md +28 -13
  6. data/hydra-works.gemspec +4 -3
  7. data/lib/hydra/works.rb +7 -57
  8. data/lib/hydra/works/models/concerns/block_child_objects.rb +16 -0
  9. data/lib/hydra/works/models/concerns/collection_behavior.rb +27 -2
  10. data/lib/hydra/works/models/concerns/generic_file/contained_files.rb +5 -13
  11. data/lib/hydra/works/models/concerns/generic_file/derivatives.rb +9 -13
  12. data/lib/hydra/works/models/concerns/generic_file/mime_types.rb +14 -9
  13. data/lib/hydra/works/models/concerns/generic_file/versioned_content.rb +18 -0
  14. data/lib/hydra/works/models/concerns/generic_file/virus_check.rb +48 -0
  15. data/lib/hydra/works/models/concerns/generic_file_behavior.rb +24 -1
  16. data/lib/hydra/works/models/concerns/generic_work_behavior.rb +32 -3
  17. data/lib/hydra/works/models/generic_file.rb +3 -0
  18. data/lib/hydra/works/services/generic_file/add_file_to_generic_file.rb +127 -0
  19. data/lib/hydra/works/services/generic_file/generate/thumbnail.rb +1 -2
  20. data/lib/hydra/works/services/generic_file/persist_derivative.rb +22 -0
  21. data/lib/hydra/works/services/generic_file/upload_file.rb +11 -19
  22. data/lib/hydra/works/version.rb +1 -1
  23. data/lib/hydra/works/vocab/works_terms.rb +1 -1
  24. data/spec/fixtures/Example.ogg +0 -0
  25. data/spec/fixtures/charter.docx +0 -0
  26. data/spec/fixtures/countdown.avi +0 -0
  27. data/spec/fixtures/image.jp2 +0 -0
  28. data/spec/fixtures/piano_note.wav +0 -0
  29. data/spec/fixtures/test5.mp3 +0 -0
  30. data/spec/fixtures/world.png +0 -0
  31. data/spec/hydra/works/models/collection_spec.rb +499 -16
  32. data/spec/hydra/works/models/concerns/block_child_objects_spec.rb +19 -0
  33. data/spec/hydra/works/models/concerns/{file → generic_file}/contained_files_spec.rb +20 -17
  34. data/spec/hydra/works/models/concerns/generic_file/mime_types_spec.rb +76 -0
  35. data/spec/hydra/works/models/concerns/generic_file/versioned_content_spec.rb +32 -0
  36. data/spec/hydra/works/models/concerns/generic_file/virus_check_spec.rb +50 -0
  37. data/spec/hydra/works/models/concerns/generic_file_behavior_spec.rb +1 -1
  38. data/spec/hydra/works/models/generic_file_spec.rb +201 -14
  39. data/spec/hydra/works/models/generic_work_spec.rb +530 -14
  40. data/spec/hydra/works/services/generic_file/add_file_to_generic_file_spec.rb +110 -0
  41. data/spec/hydra/works/services/generic_file/upload_file_spec.rb +45 -28
  42. data/spec/hydra/works/services/persist_derivatives_spec.rb +93 -0
  43. data/spec/hydra/works_spec.rb +35 -35
  44. data/spec/spec_helper.rb +6 -0
  45. metadata +56 -95
  46. data/lib/hydra/works/models/concerns/aggregates_collections.rb +0 -16
  47. data/lib/hydra/works/models/concerns/aggregates_generic_files.rb +0 -20
  48. data/lib/hydra/works/models/concerns/aggregates_generic_works.rb +0 -20
  49. data/lib/hydra/works/processor.rb +0 -9
  50. data/lib/hydra/works/services/collection/add_collection.rb +0 -19
  51. data/lib/hydra/works/services/collection/add_generic_work.rb +0 -19
  52. data/lib/hydra/works/services/collection/add_related_object.rb +0 -19
  53. data/lib/hydra/works/services/collection/get_collections.rb +0 -17
  54. data/lib/hydra/works/services/collection/get_generic_works.rb +0 -17
  55. data/lib/hydra/works/services/collection/get_related_objects.rb +0 -17
  56. data/lib/hydra/works/services/collection/remove_collection.rb +0 -19
  57. data/lib/hydra/works/services/collection/remove_generic_work.rb +0 -20
  58. data/lib/hydra/works/services/collection/remove_related_object.rb +0 -19
  59. data/lib/hydra/works/services/generic_file/add_file.rb +0 -55
  60. data/lib/hydra/works/services/generic_file/add_generic_file.rb +0 -19
  61. data/lib/hydra/works/services/generic_file/add_original_file.rb +0 -11
  62. data/lib/hydra/works/services/generic_file/add_related_object.rb +0 -19
  63. data/lib/hydra/works/services/generic_file/add_versioned_original_file.rb +0 -10
  64. data/lib/hydra/works/services/generic_file/get_generic_files.rb +0 -17
  65. data/lib/hydra/works/services/generic_file/get_related_objects.rb +0 -17
  66. data/lib/hydra/works/services/generic_file/remove_generic_file.rb +0 -20
  67. data/lib/hydra/works/services/generic_file/remove_related_object.rb +0 -19
  68. data/lib/hydra/works/services/generic_work/add_generic_file.rb +0 -19
  69. data/lib/hydra/works/services/generic_work/add_generic_work.rb +0 -19
  70. data/lib/hydra/works/services/generic_work/add_related_object.rb +0 -19
  71. data/lib/hydra/works/services/generic_work/get_generic_files.rb +0 -17
  72. data/lib/hydra/works/services/generic_work/get_generic_works.rb +0 -17
  73. data/lib/hydra/works/services/generic_work/get_related_objects.rb +0 -17
  74. data/lib/hydra/works/services/generic_work/move_generic_file.rb +0 -19
  75. data/lib/hydra/works/services/generic_work/remove_generic_file.rb +0 -20
  76. data/lib/hydra/works/services/generic_work/remove_generic_work.rb +0 -20
  77. data/lib/hydra/works/services/generic_work/remove_related_object.rb +0 -19
  78. data/spec/hydra/works/services/collection/add_collection_spec.rb +0 -166
  79. data/spec/hydra/works/services/collection/add_generic_work_spec.rb +0 -155
  80. data/spec/hydra/works/services/collection/add_related_object_spec.rb +0 -149
  81. data/spec/hydra/works/services/collection/get_collections_spec.rb +0 -35
  82. data/spec/hydra/works/services/collection/get_generic_works_spec.rb +0 -35
  83. data/spec/hydra/works/services/collection/get_related_objects_spec.rb +0 -49
  84. data/spec/hydra/works/services/collection/remove_collection_spec.rb +0 -133
  85. data/spec/hydra/works/services/collection/remove_generic_work_spec.rb +0 -133
  86. data/spec/hydra/works/services/collection/remove_related_object_spec.rb +0 -128
  87. data/spec/hydra/works/services/generic_file/add_file_spec.rb +0 -28
  88. data/spec/hydra/works/services/generic_file/add_generic_file_spec.rb +0 -174
  89. data/spec/hydra/works/services/generic_file/add_related_object_spec.rb +0 -150
  90. data/spec/hydra/works/services/generic_file/get_generic_files_spec.rb +0 -19
  91. data/spec/hydra/works/services/generic_file/get_related_objects_spec.rb +0 -45
  92. data/spec/hydra/works/services/generic_file/remove_generic_file_spec.rb +0 -124
  93. data/spec/hydra/works/services/generic_file/remove_related_object_spec.rb +0 -123
  94. data/spec/hydra/works/services/generic_work/add_generic_file_spec.rb +0 -156
  95. data/spec/hydra/works/services/generic_work/add_generic_work_spec.rb +0 -157
  96. data/spec/hydra/works/services/generic_work/add_related_object_spec.rb +0 -148
  97. data/spec/hydra/works/services/generic_work/get_generic_files_spec.rb +0 -35
  98. data/spec/hydra/works/services/generic_work/get_generic_works_spec.rb +0 -35
  99. data/spec/hydra/works/services/generic_work/get_related_objects_spec.rb +0 -46
  100. data/spec/hydra/works/services/generic_work/move_generic_file_spec.rb +0 -21
  101. data/spec/hydra/works/services/generic_work/remove_generic_file_spec.rb +0 -132
  102. data/spec/hydra/works/services/generic_work/remove_generic_work_spec.rb +0 -133
  103. data/spec/hydra/works/services/generic_work/remove_related_object_spec.rb +0 -128
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hydra::Works::AddFileToGenericFile do
4
-
5
- let(:generic_file) { Hydra::Works::GenericFile::Base.create }
6
- let(:filename) { "sample-file.pdf" }
7
- let(:path) { File.join(fixture_path, filename) }
8
- let(:type) { ::RDF::URI("http://pcdm.org/ExtractedText") }
9
- let(:replace) { false }
10
-
11
- it "adds the given file and applies the specified type to it" do
12
- Hydra::Works::AddFileToGenericFile.call(generic_file, path, type, replace)
13
- expect(generic_file.filter_files_by_type(type).first.content).to start_with("%PDF-1.3")
14
- end
15
-
16
- context "type_to_uri" do
17
- it "maps supported symbols to corresponding URIs" do
18
- expect(Hydra::Works::AddFileToGenericFile.send(:type_to_uri, :original_file)).to eq(::RDF::URI("http://pcdm.org/OriginalFile"))
19
- expect(Hydra::Works::AddFileToGenericFile.send(:type_to_uri, :thumbnail)).to eq(::RDF::URI("http://pcdm.org/ThumbnailImage"))
20
- expect(Hydra::Works::AddFileToGenericFile.send(:type_to_uri, :extracted_text)).to eq(::RDF::URI("http://pcdm.org/ExtractedText"))
21
- end
22
-
23
- it "converts URI strings to RDF::URI" do
24
- expect(Hydra::Works::AddFileToGenericFile.send(:type_to_uri, "http://example.com/CustomURI" )).to eq(::RDF::URI("http://example.com/CustomURI"))
25
- end
26
- end
27
-
28
- end
@@ -1,174 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hydra::Works::AddGenericFileToGenericFile do
4
-
5
- let(:subject) { Hydra::Works::GenericFile::Base.create }
6
-
7
- describe '#call' do
8
- context 'with acceptable generic_files' do
9
- let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
10
- let(:generic_file2) { Hydra::Works::GenericFile::Base.create }
11
- let(:generic_file3) { Hydra::Works::GenericFile::Base.create }
12
- let(:generic_file4) { Hydra::Works::GenericFile::Base.create }
13
- let(:generic_file5) { Hydra::Works::GenericFile::Base.create }
14
-
15
- it 'should aggregate generic_files in a sub-generic_file of a generic_file' do
16
- Hydra::Works::AddGenericFileToGenericFile.call( generic_file1, generic_file2 )
17
- generic_file1.save
18
- Hydra::Works::AddGenericFileToGenericFile.call( generic_file2, generic_file3 )
19
- generic_file2.save
20
- expect( Hydra::Works::GetGenericFilesFromGenericFile.call( generic_file1 ) ).to eq [generic_file2]
21
- expect( Hydra::Works::GetGenericFilesFromGenericFile.call( generic_file2 ) ).to eq [generic_file3]
22
- end
23
-
24
- it 'should allow generic_files to repeat' do
25
- Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file1 )
26
- Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file2 )
27
- Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file1 )
28
- expect( Hydra::Works::GetGenericFilesFromGenericFile.call( subject ) ).to eq [generic_file1,generic_file2,generic_file1]
29
- end
30
-
31
- context 'with files and generic_files' do
32
- let(:file1) { subject.files.build }
33
- let(:file2) { subject.files.build }
34
-
35
- before do
36
- file1.content = "I'm a file"
37
- file2.content = "I am too"
38
- Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file1 )
39
- Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file2 )
40
- subject.save!
41
- end
42
-
43
- it 'should add generic_file to generic_file with generic_files and files' do
44
- Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file3 )
45
- expect( Hydra::Works::GetGenericFilesFromGenericFile.call( subject ) ).to eq [generic_file1,generic_file2,generic_file3]
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(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(generic_file1.id,generic_file2.id)
54
- end
55
- end
56
- end
57
-
58
- describe 'aggregates generic_files that implement Hydra::Works::GenericFileBehavior' do
59
- before do
60
- class DummyIncFile < ActiveFedora::Base
61
- include Hydra::Works::GenericFileBehavior
62
- end
63
- end
64
- after { Object.send(:remove_const, :DummyIncFile) }
65
- let(:ifile1) { DummyIncFile.create }
66
-
67
- it 'should accept implementing generic_file as a child' do
68
- Hydra::Works::AddGenericFileToGenericFile.call( subject, ifile1 )
69
- subject.save
70
- expect( Hydra::Works::GetGenericFilesFromGenericFile.call( subject ) ).to eq [ifile1]
71
- end
72
- end
73
-
74
- describe 'aggregates generic_files that extend Hydra::Works::GenericFile::Base' do
75
- before do
76
- class DummyExtFile < Hydra::Works::GenericFile::Base
77
- end
78
- end
79
- after { Object.send(:remove_const, :DummyExtFile) }
80
- let(:efile1) { DummyExtFile.create }
81
-
82
- it 'should accept extending generic_file as a child' do
83
- Hydra::Works::AddGenericFileToGenericFile.call( subject, efile1 )
84
- subject.save
85
- expect( Hydra::Works::GetGenericFilesFromGenericFile.call( subject ) ).to eq [efile1]
86
- end
87
- end
88
- end
89
-
90
- context 'with unacceptable child generic_files' do
91
- let(:collection1) { Hydra::Works::Collection.create }
92
- let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
93
- let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
94
- let(:pcdm_object1) { Hydra::PCDM::Object.create }
95
- let(:pcdm_file1) { Hydra::PCDM::File.new }
96
- let(:non_PCDM_object) { "I'm not a PCDM object" }
97
- let(:af_base_object) { ActiveFedora::Base.create }
98
-
99
- let(:error_message) { 'child_generic_file must be a hydra-works generic file' }
100
-
101
- it 'should NOT aggregate Hydra::Works::Collection in generic files aggregation' do
102
- expect{ Hydra::Works::AddGenericFileToGenericFile.call( subject, collection1 ) }.to raise_error(ArgumentError,error_message)
103
- end
104
-
105
- it 'should NOT aggregate Hydra::Works::GenericWork in generic files aggregation' do
106
- expect{ Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_work1 ) }.to raise_error(ArgumentError,error_message)
107
- end
108
-
109
- it 'should NOT aggregate Hydra::PCDM::Collections in generic files aggregation' do
110
- expect{ Hydra::Works::AddGenericFileToGenericFile.call( subject, pcdm_collection1 ) }.to raise_error(ArgumentError,error_message)
111
- end
112
-
113
- it 'should NOT aggregate Hydra::PCDM::Objects in generic files aggregation' do
114
- expect{ Hydra::Works::AddGenericFileToGenericFile.call( subject, pcdm_object1 ) }.to raise_error(ArgumentError,error_message)
115
- end
116
-
117
- it 'should NOT aggregate Hydra::PCDM::Files in generic files aggregation' do
118
- expect{ Hydra::Works::AddGenericFileToGenericFile.call( subject, pcdm_file1 ) }.to raise_error(ArgumentError,error_message)
119
- end
120
-
121
- it 'should NOT aggregate non-PCDM objects in generic files aggregation' do
122
- expect{ Hydra::Works::AddGenericFileToGenericFile.call( subject, non_PCDM_object ) }.to raise_error(ArgumentError,error_message)
123
- end
124
-
125
- it 'should NOT aggregate AF::Base objects in generic files aggregation' do
126
- expect{ Hydra::Works::AddGenericFileToGenericFile.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message)
127
- end
128
- end
129
-
130
- context 'with unacceptable parent generic works' do
131
- let(:collection1) { Hydra::Works::Collection.create }
132
- let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
133
- let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
134
- let(:generic_file2) { Hydra::Works::GenericFile::Base.create }
135
- let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
136
- let(:pcdm_object1) { Hydra::PCDM::Object.create }
137
- let(:pcdm_file1) { Hydra::PCDM::File.new }
138
- let(:non_PCDM_object) { "I'm not a PCDM object" }
139
- let(:af_base_object) { ActiveFedora::Base.create }
140
-
141
- let(:error_message) { 'parent_generic_file must be a hydra-works generic file' }
142
-
143
- it 'should NOT accept Hydra::Works::Collection as parent generic file' do
144
- expect{ Hydra::Works::AddGenericFileToGenericFile.call( collection1, generic_file2 ) }.to raise_error(ArgumentError,error_message)
145
- end
146
-
147
- it 'should NOT accept Hydra::Works::GenericWork as parent generic file' do
148
- expect{ Hydra::Works::AddGenericFileToGenericFile.call( generic_work1, generic_file2 ) }.to raise_error(ArgumentError,error_message)
149
- end
150
-
151
- it 'should NOT accept Hydra::PCDM::Collections as parent generic file' do
152
- expect{ Hydra::Works::AddGenericFileToGenericFile.call( pcdm_collection1, generic_file2 ) }.to raise_error(ArgumentError,error_message)
153
- end
154
-
155
- it 'should NOT accept Hydra::PCDM::Objects as parent generic file' do
156
- expect{ Hydra::Works::AddGenericFileToGenericFile.call( pcdm_object1, generic_file2 ) }.to raise_error(ArgumentError,error_message)
157
- end
158
-
159
- it 'should NOT accept Hydra::PCDM::Files as parent generic file' do
160
- expect{ Hydra::Works::AddGenericFileToGenericFile.call( pcdm_file1, generic_file2 ) }.to raise_error(ArgumentError,error_message)
161
- end
162
-
163
- it 'should NOT accept non-PCDM objects as parent generic file' do
164
- expect{ Hydra::Works::AddGenericFileToGenericFile.call( non_PCDM_object, generic_file2 ) }.to raise_error(ArgumentError,error_message)
165
- end
166
-
167
- it 'should NOT accept AF::Base objects as parent generic file' do
168
- expect{ Hydra::Works::AddGenericFileToGenericFile.call( af_base_object, generic_file2 ) }.to raise_error(ArgumentError,error_message)
169
- end
170
- end
171
-
172
- end
173
-
174
- end
@@ -1,150 +0,0 @@
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
@@ -1,19 +0,0 @@
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
@@ -1,45 +0,0 @@
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
-
@@ -1,124 +0,0 @@
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