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