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,123 +0,0 @@
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
@@ -1,156 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hydra::Works::AddGenericFileToGenericWork do
4
-
5
- let(:subject) { Hydra::Works::GenericWork::Base.create }
6
-
7
- describe '#call' do
8
- context 'with acceptable generic_works' do
9
- let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
10
- let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
11
- let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
12
- let(:generic_file2) { Hydra::Works::GenericFile::Base.create }
13
- let(:generic_file3) { Hydra::Works::GenericFile::Base.create }
14
-
15
- context 'with generic_files and generic_works' do
16
- before do
17
- Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file1 )
18
- Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file2 )
19
- Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 )
20
- Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work2 )
21
- subject.save
22
- end
23
-
24
- it 'should add generic_file to generic_work with generic_files and generic_works' do
25
- Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file3 )
26
- expect( Hydra::Works::GetGenericFilesFromGenericWork.call( subject ) ).to eq [generic_file1,generic_file2,generic_file3]
27
- end
28
-
29
- it 'should solrize member ids' do
30
- skip 'skipping this test because issue #109 needs to be addressed' do
31
- expect(subject.to_solr["generic_works_ssim"]).to include(generic_work1.id,generic_work2.id)
32
- expect(subject.to_solr["generic_works_ssim"]).not_to include(generic_file1.id,generic_file2.id,generic_file3.id)
33
- expect(subject.to_solr["generic_files_ssim"]).to include(generic_file1.id,generic_file2.id,generic_file3.id)
34
- expect(subject.to_solr["generic_files_ssim"]).not_to include(generic_work1.id,generic_work2.id)
35
- end
36
- end
37
- end
38
-
39
- describe 'aggregates generic_files that implement Hydra::Works::GenericFileBehavior' do
40
- before do
41
- class DummyIncFile < ActiveFedora::Base
42
- include Hydra::Works::GenericFileBehavior
43
- end
44
- end
45
- after { Object.send(:remove_const, :DummyIncFile) }
46
- let(:ifile1) { DummyIncFile.create }
47
-
48
- it 'should accept implementing generic_file as a child' do
49
- Hydra::Works::AddGenericFileToGenericWork.call( subject, ifile1 )
50
- subject.save
51
- expect( Hydra::Works::GetGenericFilesFromGenericWork.call( subject ) ).to eq [ifile1]
52
- end
53
-
54
- end
55
-
56
- describe 'aggregates generic_files that extend Hydra::Works::GenericFile::Base' do
57
- before do
58
- class DummyExtFile < Hydra::Works::GenericFile::Base
59
- end
60
- end
61
- after { Object.send(:remove_const, :DummyExtFile) }
62
- let(:efile1) { DummyExtFile.create }
63
-
64
- it 'should accept extending generic_file as a child' do
65
- Hydra::Works::AddGenericFileToGenericWork.call( subject, efile1 )
66
- subject.save
67
- expect( Hydra::Works::GetGenericFilesFromGenericWork.call( subject ) ).to eq [efile1]
68
- end
69
- end
70
- end
71
-
72
- context 'with unacceptable child generic_files' do
73
- let(:collection1) { Hydra::Works::Collection.create }
74
- let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
75
- let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
76
- let(:pcdm_object1) { Hydra::PCDM::Object.create }
77
- let(:pcdm_file1) { Hydra::PCDM::File.new }
78
- let(:non_PCDM_object) { "I'm not a PCDM object" }
79
- let(:af_base_object) { ActiveFedora::Base.create }
80
-
81
- let(:error_message) { 'child_generic_file must be a hydra-works generic file' }
82
-
83
- it 'should NOT aggregate Hydra::Works::Collection in generic files aggregation' do
84
- expect{ Hydra::Works::AddGenericFileToGenericWork.call( subject, collection1 ) }.to raise_error(ArgumentError,error_message)
85
- end
86
-
87
- it 'should NOT aggregate Hydra::Works::GenericWork in generic files aggregation' do
88
- expect{ Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_work1 ) }.to raise_error(ArgumentError,error_message)
89
- end
90
-
91
- it 'should NOT aggregate Hydra::PCDM::Collections in generic files aggregation' do
92
- expect{ Hydra::Works::AddGenericFileToGenericWork.call( subject, pcdm_collection1 ) }.to raise_error(ArgumentError,error_message)
93
- end
94
-
95
- it 'should NOT aggregate Hydra::PCDM::Objects in generic files aggregation' do
96
- expect{ Hydra::Works::AddGenericFileToGenericWork.call( subject, pcdm_object1 ) }.to raise_error(ArgumentError,error_message)
97
- end
98
-
99
- it 'should NOT aggregate Hydra::PCDM::Files in generic files aggregation' do
100
- expect{ Hydra::Works::AddGenericFileToGenericWork.call( subject, pcdm_file1 ) }.to raise_error(ArgumentError,error_message)
101
- end
102
-
103
- it 'should NOT aggregate non-PCDM objects in generic files aggregation' do
104
- expect{ Hydra::Works::AddGenericFileToGenericWork.call( subject, non_PCDM_object ) }.to raise_error(ArgumentError,error_message)
105
- end
106
-
107
- it 'should NOT aggregate AF::Base objects in generic files aggregation' do
108
- expect{ Hydra::Works::AddGenericFileToGenericWork.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message)
109
- end
110
- end
111
-
112
- context 'with unacceptable parent generic works' do
113
- let(:collection1) { Hydra::Works::Collection.create }
114
- let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
115
- let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
116
- let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
117
- let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
118
- let(:pcdm_object1) { Hydra::PCDM::Object.create }
119
- let(:pcdm_file1) { Hydra::PCDM::File.new }
120
- let(:non_PCDM_object) { "I'm not a PCDM object" }
121
- let(:af_base_object) { ActiveFedora::Base.create }
122
-
123
- let(:error_message) { 'parent_generic_work must be a hydra-works generic work' }
124
-
125
- it 'should NOT accept Hydra::Works::Collection as parent generic work' do
126
- expect{ Hydra::Works::AddGenericFileToGenericWork.call( collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
127
- end
128
-
129
- it 'should NOT accept Hydra::Works::GenericFile as parent generic work' do
130
- expect{ Hydra::Works::AddGenericFileToGenericWork.call( generic_file1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
131
- end
132
-
133
- it 'should NOT accept Hydra::PCDM::Collections as parent generic work' do
134
- expect{ Hydra::Works::AddGenericFileToGenericWork.call( pcdm_collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
135
- end
136
-
137
- it 'should NOT accept Hydra::PCDM::Objects as parent generic work' do
138
- expect{ Hydra::Works::AddGenericFileToGenericWork.call( pcdm_object1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
139
- end
140
-
141
- it 'should NOT accept Hydra::PCDM::Files as parent generic work' do
142
- expect{ Hydra::Works::AddGenericFileToGenericWork.call( pcdm_file1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
143
- end
144
-
145
- it 'should NOT accept non-PCDM objects as parent generic work' do
146
- expect{ Hydra::Works::AddGenericFileToGenericWork.call( non_PCDM_object, generic_work2 ) }.to raise_error(ArgumentError,error_message)
147
- end
148
-
149
- it 'should NOT accept AF::Base objects as parent generic work' do
150
- expect{ Hydra::Works::AddGenericFileToGenericWork.call( af_base_object, generic_work2 ) }.to raise_error(ArgumentError,error_message)
151
- end
152
- end
153
-
154
- end
155
-
156
- end
@@ -1,157 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hydra::Works::AddGenericWorkToGenericWork do
4
-
5
- let(:subject) { Hydra::Works::GenericWork::Base.create }
6
-
7
- describe '#call' do
8
- context 'with acceptable generic_works' do
9
- let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
10
- let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
11
- let(:generic_work3) { Hydra::Works::GenericWork::Base.create }
12
- let(:generic_work4) { Hydra::Works::GenericWork::Base.create }
13
- let(:generic_work5) { 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
- context 'with generic_files and generic_works' 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_work1 )
22
- Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work2 )
23
- subject.save
24
- end
25
-
26
- it 'should add generic_work to generic_work with generic_files and generic_works' do
27
- Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work3 )
28
- expect( Hydra::Works::GetGenericWorksFromGenericWork.call( subject ) ).to eq [generic_work1,generic_work2,generic_work3]
29
- end
30
-
31
- it 'should solrize member ids' do
32
- skip 'skipping this test because issue #109 needs to be addressed' do
33
- expect(subject.to_solr['generic_works_ssim']).to include(generic_work1.id,generic_work2.id,generic_work3.id)
34
- expect(subject.to_solr['generic_works_ssim']).not_to include(generic_file1.id,generic_file2.id)
35
- expect(subject.to_solr['generic_files_ssim']).to include(generic_file1.id,generic_file2.id)
36
- expect(subject.to_solr['generic_files_ssim']).not_to include(generic_work1.id,generic_work2.id,generic_work3.id)
37
- end
38
- end
39
- end
40
-
41
- describe 'aggregates generic_works that implement Hydra::Works::GenericWorkBehavior' do
42
- before do
43
- class DummyIncWork < ActiveFedora::Base
44
- include Hydra::Works::GenericWorkBehavior
45
- end
46
- end
47
- after { Object.send(:remove_const, :DummyIncWork) }
48
- let(:iwork1) { DummyIncWork.create }
49
-
50
- it 'should accept implementing generic_work as a child' do
51
- Hydra::Works::AddGenericWorkToGenericWork.call( subject, iwork1 )
52
- subject.save
53
- expect( Hydra::Works::GetGenericWorksFromGenericWork.call( subject ) ).to eq [iwork1]
54
- end
55
- end
56
-
57
- describe 'aggregates generic_works that extend Hydra::Works::GenericWork::Base' do
58
- before do
59
- class DummyExtWork < Hydra::Works::GenericWork::Base
60
- end
61
- end
62
- after { Object.send(:remove_const, :DummyExtWork) }
63
- let(:ework1) { DummyExtWork.create }
64
-
65
- it 'should accept extending generic_work as a child' do
66
- Hydra::Works::AddGenericWorkToGenericWork.call( subject, ework1 )
67
- subject.save
68
- expect( Hydra::Works::GetGenericWorksFromGenericWork.call( subject ) ).to eq [ework1]
69
- end
70
- end
71
- end
72
-
73
- context 'with unacceptable child generic_works' do
74
- let(:collection1) { Hydra::Works::Collection.create }
75
- let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
76
- let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
77
- let(:pcdm_object1) { Hydra::PCDM::Object.create }
78
- let(:pcdm_file1) { Hydra::PCDM::File.new }
79
- let(:non_PCDM_object) { "I'm not a PCDM object" }
80
- let(:af_base_object) { ActiveFedora::Base.create }
81
-
82
- let(:error_message) { 'child_generic_work must be a hydra-works generic work' }
83
-
84
- it 'should NOT aggregate Hydra::Works::Collection in generic works aggregation' do
85
- expect{ Hydra::Works::AddGenericWorkToGenericWork.call( subject, collection1 ) }.to raise_error(ArgumentError,error_message)
86
- end
87
-
88
- it 'should NOT aggregate Hydra::Works::GenericFile in generic works aggregation' do
89
- expect{ Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_file1 ) }.to raise_error(ArgumentError,error_message)
90
- end
91
-
92
- it 'should NOT aggregate Hydra::PCDM::Collections in generic works aggregation' do
93
- expect{ Hydra::Works::AddGenericWorkToGenericWork.call( subject, pcdm_collection1 ) }.to raise_error(ArgumentError,error_message)
94
- end
95
-
96
- it 'should NOT aggregate Hydra::PCDM::Objects in generic works aggregation' do
97
- expect{ Hydra::Works::AddGenericWorkToGenericWork.call( subject, pcdm_object1 ) }.to raise_error(ArgumentError,error_message)
98
- end
99
-
100
- it 'should NOT aggregate Hydra::PCDM::Files in generic works aggregation' do
101
- expect{ Hydra::Works::AddGenericWorkToGenericWork.call( subject, pcdm_file1 ) }.to raise_error(ArgumentError,error_message)
102
- end
103
-
104
- it 'should NOT aggregate non-PCDM objects in generic works aggregation' do
105
- expect{ Hydra::Works::AddGenericWorkToGenericWork.call( subject, non_PCDM_object ) }.to raise_error(ArgumentError,error_message)
106
- end
107
-
108
- it 'should NOT aggregate AF::Base objects in generic works aggregation' do
109
- expect{ Hydra::Works::AddGenericWorkToGenericWork.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message)
110
- end
111
- end
112
-
113
- context 'with unacceptable parent generic works' do
114
- let(:collection1) { Hydra::Works::Collection.create }
115
- let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
116
- let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
117
- let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
118
- let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
119
- let(:pcdm_object1) { Hydra::PCDM::Object.create }
120
- let(:pcdm_file1) { Hydra::PCDM::File.new }
121
- let(:non_PCDM_object) { "I'm not a PCDM object" }
122
- let(:af_base_object) { ActiveFedora::Base.create }
123
-
124
- let(:error_message) { 'parent_generic_work must be a hydra-works generic work' }
125
-
126
- it 'should NOT accept Hydra::Works::Collection as parent generic work' do
127
- expect{ Hydra::Works::AddGenericWorkToGenericWork.call( collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
128
- end
129
-
130
- it 'should NOT accept Hydra::Works::GenericFile as parent generic work' do
131
- expect{ Hydra::Works::AddGenericWorkToGenericWork.call( generic_file1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
132
- end
133
-
134
- it 'should NOT accept Hydra::PCDM::Collections as parent generic work' do
135
- expect{ Hydra::Works::AddGenericWorkToGenericWork.call( pcdm_collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
136
- end
137
-
138
- it 'should NOT accept Hydra::PCDM::Objects as parent generic work' do
139
- expect{ Hydra::Works::AddGenericWorkToGenericWork.call( pcdm_object1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
140
- end
141
-
142
- it 'should NOT accept Hydra::PCDM::Files as parent generic work' do
143
- expect{ Hydra::Works::AddGenericWorkToGenericWork.call( pcdm_file1, generic_work2 ) }.to raise_error(ArgumentError,error_message)
144
- end
145
-
146
- it 'should NOT accept non-PCDM objects as parent generic work' do
147
- expect{ Hydra::Works::AddGenericWorkToGenericWork.call( non_PCDM_object, generic_work2 ) }.to raise_error(ArgumentError,error_message)
148
- end
149
-
150
- it 'should NOT accept AF::Base objects as parent generic work' do
151
- expect{ Hydra::Works::AddGenericWorkToGenericWork.call( af_base_object, generic_work2 ) }.to raise_error(ArgumentError,error_message)
152
- end
153
- end
154
-
155
- end
156
-
157
- end
@@ -1,148 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hydra::Works::AddRelatedObjectToGenericWork do
4
-
5
- let(:subject) { Hydra::Works::GenericWork::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_work' do
18
- Hydra::Works::AddRelatedObjectToGenericWork.call( subject, generic_work1 )
19
- Hydra::Works::AddRelatedObjectToGenericWork.call( subject, generic_file1 )
20
- Hydra::Works::AddRelatedObjectToGenericWork.call( subject, object1 )
21
- related_objects = Hydra::Works::GetRelatedObjectsFromGenericWork.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 generic_works and generic_files' do
29
- before do
30
- Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file1 )
31
- Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file2 )
32
- Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 )
33
- Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work2 )
34
- Hydra::Works::AddRelatedObjectToGenericWork.call( subject, object1 )
35
- subject.save
36
- end
37
-
38
- it 'should add a related object to generic_work with generic_works and generic_files' do
39
- Hydra::Works::AddRelatedObjectToGenericWork.call( subject, object2 )
40
- related_objects = Hydra::Works::GetRelatedObjectsFromGenericWork.call( subject )
41
- expect( related_objects.include? object1 ).to be true
42
- expect( related_objects.include? object2 ).to be true
43
- expect( related_objects.size ).to eq 2
44
- end
45
-
46
- it 'should solrize member ids' do
47
- skip 'skipping this test because issue #109 needs to be addressed' do
48
- expect(subject.to_solr["generic_works_ssim"]).to include(generic_work1.id,generic_work2.id)
49
- expect(subject.to_solr["generic_works_ssim"]).not_to include(generic_file2.id,generic_file1.id,object1.id,object2.id)
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,generic_work1.id,generic_work2.id)
52
- expect(subject.to_solr["related_objects_ssim"]).to include(object1.id,object2.id)
53
- expect(subject.to_solr["related_objects_ssim"]).not_to include(generic_file2.id,generic_file1.id,generic_work1.id,generic_work2.id)
54
- end
55
- end
56
- end
57
- end
58
-
59
- context 'with unacceptable child related objects' do
60
- let(:collection1) { Hydra::Works::Collection.create }
61
- let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
62
- let(:pcdm_file1) { Hydra::PCDM::File.new }
63
- let(:non_PCDM_object) { "I'm not a PCDM object" }
64
- let(:af_base_object) { ActiveFedora::Base.create }
65
-
66
- let(:error_message) { 'child_related_object must be a pcdm object' }
67
-
68
- it 'should NOT aggregate Hydra::Works::Collection in related objects aggregation' do
69
- expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( subject, collection1 ) }.to raise_error(ArgumentError,error_message)
70
- end
71
-
72
- it 'should NOT aggregate Hydra::PCDM::Collections in related objects aggregation' do
73
- expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( subject, pcdm_collection1 ) }.to raise_error(ArgumentError,error_message)
74
- end
75
-
76
- it 'should NOT aggregate Hydra::PCDM::Files in related objects aggregation' do
77
- expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( subject, pcdm_file1 ) }.to raise_error(ArgumentError,error_message)
78
- end
79
-
80
- it 'should NOT aggregate non-PCDM objects in related objects aggregation' do
81
- expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( subject, non_PCDM_object ) }.to raise_error(ArgumentError,error_message)
82
- end
83
-
84
- it 'should NOT aggregate AF::Base objects in related objects aggregation' do
85
- expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message)
86
- end
87
- end
88
-
89
- context 'with unacceptable parent generic work' do
90
- let(:collection1) { Hydra::Works::Collection.create }
91
- let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
92
- let(:pcdm_collection1) { Hydra::PCDM::Collection.create }
93
- let(:pcdm_object1) { Hydra::PCDM::Object.create }
94
- let(:pcdm_object2) { 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) { 'parent_generic_work must be a hydra-works generic work' }
100
-
101
- it 'should NOT accept Hydra::Works::Collection as parent generic work' do
102
- expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( collection1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message)
103
- end
104
-
105
- it 'should NOT accept Hydra::Works::GenericFile as parent generic work' do
106
- expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( generic_file1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message)
107
- end
108
-
109
- it 'should NOT accept Hydra::PCDM::Collections as parent generic work' do
110
- expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( pcdm_collection1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message)
111
- end
112
-
113
- it 'should NOT accept Hydra::PCDM::Objects as parent generic work' do
114
- expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( pcdm_object1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message)
115
- end
116
-
117
- it 'should NOT accept Hydra::PCDM::Files as parent generic work' do
118
- expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( pcdm_file1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message)
119
- end
120
-
121
- it 'should NOT accept non-PCDM objects as parent generic work' do
122
- expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( non_PCDM_object, pcdm_object2 ) }.to raise_error(ArgumentError,error_message)
123
- end
124
-
125
- it 'should NOT accept AF::Base objects as parent generic work' do
126
- expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( af_base_object, pcdm_object2 ) }.to raise_error(ArgumentError,error_message)
127
- end
128
- end
129
-
130
-
131
- context 'with invalid bahaviors' do
132
- let(:object1) { Hydra::PCDM::Object.create }
133
- let(:object2) { Hydra::PCDM::Object.create }
134
-
135
- it 'should NOT allow related objects to repeat' do
136
- skip 'skipping this test because issue pcdm#92 needs to be addressed' do
137
- Hydra::Works::AddRelatedObjectToGenericWork.call( subject, object1 )
138
- Hydra::Works::AddRelatedObjectToGenericWork.call( subject, object2 )
139
- Hydra::Works::AddRelatedObjectToGenericWork.call( subject, object1 )
140
- related_objects = Hydra::Works::GetRelatedObjectsFromGenericWork.call( subject )
141
- expect( related_objects.include? object1 ).to be true
142
- expect( related_objects.include? object2 ).to be true
143
- expect( related_objects.size ).to eq 2
144
- end
145
- end
146
- end
147
- end
148
- end