hydra-works 0.0.1

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