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,155 @@
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
@@ -0,0 +1,149 @@
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
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::GetCollectionsFromCollection do
4
+
5
+ subject { Hydra::Works::Collection.create }
6
+
7
+ let(:collection1) { Hydra::Works::Collection.create }
8
+ let(:collection2) { Hydra::Works::Collection.create }
9
+
10
+ let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
11
+ let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
12
+
13
+ describe '#call' do
14
+ it 'should return empty array when only generic_works are aggregated' do
15
+ Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work1 )
16
+ Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work2 )
17
+ subject.save
18
+ expect(Hydra::Works::GetCollectionsFromCollection.call( subject )).to eq []
19
+ end
20
+
21
+ context 'with other collections & generic_works' do
22
+ before do
23
+ Hydra::Works::AddCollectionToCollection.call( subject, collection1 )
24
+ Hydra::Works::AddCollectionToCollection.call( subject, collection2 )
25
+ Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work1 )
26
+ Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work2 )
27
+ subject.save
28
+ end
29
+
30
+ it 'should only return collections' do
31
+ expect(Hydra::Works::GetCollectionsFromCollection.call( subject )).to eq [collection1,collection2]
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::GetGenericWorksFromCollection do
4
+
5
+ subject { Hydra::Works::Collection.create }
6
+
7
+ let(:collection1) { Hydra::Works::Collection.create }
8
+ let(:collection2) { Hydra::Works::Collection.create }
9
+
10
+ let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
11
+ let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
12
+
13
+ describe '#call' do
14
+ it 'should return empty array when only collections are aggregated' do
15
+ Hydra::Works::AddCollectionToCollection.call( subject, collection1 )
16
+ Hydra::Works::AddCollectionToCollection.call( subject, collection2 )
17
+ subject.save
18
+ expect(Hydra::Works::GetGenericWorksFromCollection.call( subject )).to eq []
19
+ end
20
+
21
+ context 'with collections and generic works' do
22
+ before do
23
+ Hydra::Works::AddCollectionToCollection.call( subject, collection1 )
24
+ Hydra::Works::AddCollectionToCollection.call( subject, collection2 )
25
+ Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work1 )
26
+ Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work2 )
27
+ subject.save
28
+ end
29
+
30
+ it 'should only return generic works' do
31
+ expect(Hydra::Works::GetGenericWorksFromCollection.call( subject )).to eq [generic_work1,generic_work2]
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::GetRelatedObjectsFromCollection do
4
+
5
+ subject { Hydra::Works::Collection.create }
6
+
7
+ let(:collection1) { Hydra::Works::Collection.create }
8
+ let(:collection2) { Hydra::Works::Collection.create }
9
+
10
+ let(:object1) { Hydra::PCDM::Object.create }
11
+ let(:object2) { Hydra::PCDM::Object.create }
12
+
13
+ let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
14
+ let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
15
+ let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
16
+
17
+ describe '#call' do
18
+ context 'with collections and generic works' do
19
+ before do
20
+ Hydra::Works::AddCollectionToCollection.call( subject, collection1 )
21
+ Hydra::Works::AddCollectionToCollection.call( subject, collection2 )
22
+ Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work1 )
23
+ subject.save
24
+ end
25
+
26
+ it 'should return empty array when only collections and generic works are aggregated' do
27
+ expect(Hydra::Works::GetRelatedObjectsFromCollection.call( subject )).to eq []
28
+ end
29
+
30
+ it 'should only return related objects' do
31
+ Hydra::Works::AddRelatedObjectToCollection.call( subject, object2 )
32
+ expect(Hydra::Works::GetRelatedObjectsFromCollection.call( subject )).to eq [object2]
33
+ end
34
+
35
+ it 'should return related objects of various types' do
36
+ Hydra::Works::AddRelatedObjectToCollection.call( subject, generic_work2 )
37
+ Hydra::Works::AddRelatedObjectToCollection.call( subject, generic_file1 )
38
+ Hydra::Works::AddRelatedObjectToCollection.call( subject, object1 )
39
+ related_objects = Hydra::Works::GetRelatedObjectsFromCollection.call( subject )
40
+ expect( related_objects.include? object1 ).to be true
41
+ expect( related_objects.include? generic_work2 ).to be true
42
+ expect( related_objects.include? generic_file1 ).to be true
43
+ expect( related_objects.size ).to eq 3
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::RemoveCollectionFromCollection do
4
+
5
+ subject { Hydra::Works::Collection.create }
6
+
7
+ let(:collection1) { Hydra::Works::Collection.create }
8
+ let(:collection2) { Hydra::Works::Collection.create }
9
+ let(:collection3) { Hydra::Works::Collection.create }
10
+ let(:collection4) { Hydra::Works::Collection.create }
11
+ let(:collection5) { Hydra::Works::Collection.create }
12
+
13
+ let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
14
+ let(:generic_work2) { Hydra::Works::GenericWork::Base.create }
15
+
16
+
17
+ describe '#call' do
18
+ context 'when multiple collections' do
19
+ before do
20
+ Hydra::Works::AddCollectionToCollection.call( subject, collection1 )
21
+ Hydra::Works::AddCollectionToCollection.call( subject, collection2 )
22
+ Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work2 )
23
+ Hydra::Works::AddCollectionToCollection.call( subject, collection3 )
24
+ Hydra::Works::AddCollectionToCollection.call( subject, collection4 )
25
+ Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work1 )
26
+ Hydra::Works::AddCollectionToCollection.call( subject, collection5 )
27
+ subject.save
28
+ expect( Hydra::Works::GetCollectionsFromCollection.call( subject.reload )).to eq [collection1,collection2,collection3,collection4,collection5]
29
+ end
30
+
31
+ it 'should remove first collection' do
32
+ expect( Hydra::Works::RemoveCollectionFromCollection.call( subject, collection1 ) ).to eq collection1
33
+ expect( Hydra::Works::GetCollectionsFromCollection.call( subject.reload )).to eq [collection2,collection3,collection4,collection5]
34
+ expect( Hydra::Works::GetGenericWorksFromCollection.call( subject.reload )).to eq [generic_work2,generic_work1]
35
+ end
36
+
37
+ it 'should remove last collection' do
38
+ expect( Hydra::Works::RemoveCollectionFromCollection.call( subject, collection5 ) ).to eq collection5
39
+ expect( Hydra::Works::GetCollectionsFromCollection.call( subject.reload )).to eq [collection1,collection2,collection3,collection4]
40
+ expect( Hydra::Works::GetGenericWorksFromCollection.call( subject.reload )).to eq [generic_work2,generic_work1]
41
+ end
42
+
43
+ it 'should remove middle collection' do
44
+ expect( Hydra::Works::RemoveCollectionFromCollection.call( subject, collection3 ) ).to eq collection3
45
+ expect( Hydra::Works::GetCollectionsFromCollection.call( subject.reload )).to eq [collection1,collection2,collection4,collection5]
46
+ expect( Hydra::Works::GetGenericWorksFromCollection.call( subject.reload )).to eq [generic_work2,generic_work1]
47
+ end
48
+ end
49
+ end
50
+
51
+ context 'with unacceptable collections' do
52
+ let(:generic_work1) { Hydra::Works::GenericWork::Base.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_collection must be a hydra-works collection' }
62
+
63
+ it 'should NOT remove Hydra::Works::GenericWork from collections aggregation' do
64
+ expect{ Hydra::Works::RemoveCollectionFromCollection.call( subject, generic_work1 ) }.to raise_error(ArgumentError,error_message)
65
+ end
66
+
67
+ it 'should NOT remove Hydra::Works::GenericFile from collections aggregation' do
68
+ expect{ Hydra::Works::RemoveCollectionFromCollection.call( subject, generic_file1 ) }.to raise_error(ArgumentError,error_message)
69
+ end
70
+
71
+ it 'should NOT remove Hydra::PCDM::Collections from collections aggregation' do
72
+ expect{ Hydra::Works::RemoveCollectionFromCollection.call( subject, pcdm_collection1 ) }.to raise_error(ArgumentError,error_message)
73
+ end
74
+
75
+ it 'should NOT remove Hydra::PCDM::Objects from collections aggregation' do
76
+ expect{ Hydra::Works::RemoveCollectionFromCollection.call( subject, pcdm_object1 ) }.to raise_error(error_type,error_message)
77
+ end
78
+
79
+ it 'should NOT remove Hydra::PCDM::Files from collections aggregation' do
80
+ expect{ Hydra::Works::RemoveCollectionFromCollection.call( subject, pcdm_file1 ) }.to raise_error(error_type,error_message)
81
+ end
82
+
83
+ it 'should NOT remove non-PCDM objects from collections aggregation' do
84
+ expect{ Hydra::Works::RemoveCollectionFromCollection.call( subject, non_PCDM_object ) }.to raise_error(error_type,error_message)
85
+ end
86
+
87
+ it 'should NOT remove AF::Base objects from collections aggregation' do
88
+ expect{ Hydra::Works::RemoveCollectionFromCollection.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(:collection2) { Hydra::Works::Collection.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::RemoveCollectionFromCollection.call( generic_work1, collection2 ) }.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::RemoveCollectionFromCollection.call( generic_file1, collection2 ) }.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::RemoveCollectionFromCollection.call( pcdm_collection1, collection2 ) }.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::RemoveCollectionFromCollection.call( pcdm_object1, collection2 ) }.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::RemoveCollectionFromCollection.call( pcdm_file1, collection2 ) }.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::RemoveCollectionFromCollection.call( non_PCDM_object, collection2 ) }.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::RemoveCollectionFromCollection.call( af_base_object, collection2 ) }.to raise_error(error_type,error_message)
131
+ end
132
+ end
133
+ end