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