hydra-works 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -8
  3. data/README.md +9 -9
  4. data/hydra-works.gemspec +3 -4
  5. data/lib/hydra/works.rb +22 -13
  6. data/lib/hydra/works/characterization.rb +31 -0
  7. data/lib/hydra/works/characterization/schema/audio_schema.rb +12 -0
  8. data/lib/hydra/works/characterization/schema/base_schema.rb +17 -0
  9. data/lib/hydra/works/characterization/schema/document_schema.rb +18 -0
  10. data/lib/hydra/works/characterization/schema/image_schema.rb +22 -0
  11. data/lib/hydra/works/characterization/schema/video_schema.rb +9 -0
  12. data/lib/hydra/works/models/characterization/already_there_strategy.rb +12 -0
  13. data/lib/hydra/works/models/characterization/fits_datastream.rb +162 -0
  14. data/lib/hydra/works/models/concerns/collection_behavior.rb +42 -34
  15. data/lib/hydra/works/models/concerns/file_set/characterization/audio.rb +14 -0
  16. data/lib/hydra/works/models/concerns/file_set/characterization/base.rb +23 -0
  17. data/lib/hydra/works/models/concerns/file_set/characterization/document.rb +10 -0
  18. data/lib/hydra/works/models/concerns/file_set/characterization/image.rb +10 -0
  19. data/lib/hydra/works/models/concerns/file_set/characterization/video.rb +17 -0
  20. data/lib/hydra/works/models/concerns/{generic_file → file_set}/contained_files.rb +1 -1
  21. data/lib/hydra/works/models/concerns/file_set/derivatives.rb +27 -0
  22. data/lib/hydra/works/models/concerns/{generic_file → file_set}/mime_types.rb +1 -1
  23. data/lib/hydra/works/models/concerns/{generic_file → file_set}/versioned_content.rb +2 -2
  24. data/lib/hydra/works/models/concerns/{generic_file → file_set}/virus_check.rb +1 -1
  25. data/lib/hydra/works/models/concerns/file_set_behavior.rb +67 -0
  26. data/lib/hydra/works/models/concerns/generic_file_behavior.rb +4 -50
  27. data/lib/hydra/works/models/concerns/generic_work_behavior.rb +5 -77
  28. data/lib/hydra/works/models/concerns/work_behavior.rb +118 -0
  29. data/lib/hydra/works/models/file_set.rb +7 -0
  30. data/lib/hydra/works/models/generic_file.rb +8 -8
  31. data/lib/hydra/works/models/generic_work.rb +15 -4
  32. data/lib/hydra/works/models/work.rb +6 -0
  33. data/lib/hydra/works/services/{generic_file/add_file_to_generic_file.rb → add_file_to_file_set.rb} +20 -20
  34. data/lib/hydra/works/services/add_file_to_generic_file.rb +8 -0
  35. data/lib/hydra/works/services/characterization_service.rb +118 -0
  36. data/lib/hydra/works/services/persist_derivative.rb +35 -0
  37. data/lib/hydra/works/services/{generic_file/upload_file_to_generic_file.rb → upload_file_to_file_set.rb} +3 -3
  38. data/lib/hydra/works/services/upload_file_to_generic_file.rb +8 -0
  39. data/lib/hydra/works/version.rb +1 -1
  40. data/lib/hydra/works/vocab/works_terms.rb +2 -2
  41. data/spec/fixtures/fits_0.6.2_avi.xml +29 -0
  42. data/spec/fixtures/fits_0.6.2_jp2.xml +36 -0
  43. data/spec/fixtures/fits_0.6.2_jpg.xml +43 -0
  44. data/spec/fixtures/fits_0.6.2_pdf.xml +42 -0
  45. data/spec/fixtures/fits_0.8.5_avi.xml +50 -0
  46. data/spec/fixtures/fits_0.8.5_docx.xml +41 -0
  47. data/spec/fixtures/fits_0.8.5_jp2.xml +51 -0
  48. data/spec/fixtures/fits_0.8.5_mp3.xml +47 -0
  49. data/spec/fixtures/fits_0.8.5_mp4.xml +47 -0
  50. data/spec/fixtures/fits_0.8.5_pdf.xml +54 -0
  51. data/spec/fixtures/pdf_fits.xml +54 -0
  52. data/spec/hydra/works/models/collection_spec.rb +58 -326
  53. data/spec/hydra/works/models/concerns/{generic_file → file_set}/contained_files_spec.rb +16 -16
  54. data/spec/hydra/works/models/concerns/{generic_file → file_set}/mime_types_spec.rb +2 -2
  55. data/spec/hydra/works/models/concerns/file_set/versioned_content_spec.rb +32 -0
  56. data/spec/hydra/works/models/concerns/{generic_file → file_set}/virus_check_spec.rb +3 -3
  57. data/spec/hydra/works/models/concerns/file_set_behavior_spec.rb +12 -0
  58. data/spec/hydra/works/models/generic_file_spec.rb +16 -13
  59. data/spec/hydra/works/models/generic_work_spec.rb +148 -318
  60. data/spec/hydra/works/services/{generic_file/add_file_to_generic_file_spec.rb → add_file_to_file_set_spec.rb} +4 -4
  61. data/spec/hydra/works/services/characterization_service_spec.rb +199 -0
  62. data/spec/hydra/works/services/persist_derivatives_spec.rb +57 -29
  63. data/spec/hydra/works/services/{generic_file/upload_file_spec.rb → upload_file_spec.rb} +7 -17
  64. data/spec/hydra/works_spec.rb +23 -59
  65. data/spec/spec_helper.rb +4 -2
  66. data/spec/support/file_set_helper.rb +14 -0
  67. metadata +84 -55
  68. data/lib/hydra/works/errors/full_text_extraction_error.rb +0 -5
  69. data/lib/hydra/works/models/concerns/block_child_objects.rb +0 -22
  70. data/lib/hydra/works/models/concerns/generic_file/derivatives.rb +0 -26
  71. data/lib/hydra/works/services/generic_file/full_text_extraction_service.rb +0 -57
  72. data/lib/hydra/works/services/generic_file/generate_thumbnail.rb +0 -13
  73. data/lib/hydra/works/services/generic_file/persist_derivative.rb +0 -20
  74. data/spec/hydra/works/models/concerns/block_child_objects_spec.rb +0 -17
  75. data/spec/hydra/works/models/concerns/generic_file/versioned_content_spec.rb +0 -32
  76. data/spec/hydra/works/models/concerns/generic_file_behavior_spec.rb +0 -12
  77. data/spec/hydra/works/services/full_text_extraction_service_spec.rb +0 -89
  78. data/spec/hydra/works/services/generic_file/generate/thumbnail_spec.rb +0 -19
@@ -1,29 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Hydra::Works::GenericFile::ContainedFiles do
4
- let(:generic_file) do
5
- Hydra::Works::GenericFile::Base.create
3
+ describe Hydra::Works::ContainedFiles do
4
+ let(:file_set) do
5
+ Hydra::Works::FileSet.create
6
6
  end
7
7
 
8
8
  let(:thumbnail) do
9
- file = generic_file.files.build
9
+ file = file_set.files.build
10
10
  Hydra::PCDM::AddTypeToFile.call(file, pcdm_thumbnail_uri)
11
11
  end
12
12
 
13
- let(:file) { generic_file.files.build }
13
+ let(:file) { file_set.files.build }
14
14
  let(:pcdm_thumbnail_uri) { ::RDF::URI('http://pcdm.org/use#ThumbnailImage') }
15
15
 
16
16
  before do
17
- generic_file.files = [file]
17
+ file_set.files = [file]
18
18
  end
19
19
 
20
20
  describe '#thumbnail' do
21
21
  context 'when a thumbnail is present' do
22
22
  before do
23
- original_file = generic_file.build_thumbnail
23
+ original_file = file_set.build_thumbnail
24
24
  original_file.content = 'thumbnail'
25
25
  end
26
- subject { generic_file.thumbnail }
26
+ subject { file_set.thumbnail }
27
27
  it 'can be saved without errors' do
28
28
  expect(subject.save).to be_truthy
29
29
  end
@@ -37,7 +37,7 @@ describe Hydra::Works::GenericFile::ContainedFiles do
37
37
  end
38
38
 
39
39
  context 'when building new thumbnail' do
40
- subject { generic_file.build_thumbnail }
40
+ subject { file_set.build_thumbnail }
41
41
  it 'initializes an unsaved File object with Thumbnail type' do
42
42
  expect(subject).to be_new_record
43
43
  expect(subject.metadata_node.type).to include(pcdm_thumbnail_uri)
@@ -49,10 +49,10 @@ describe Hydra::Works::GenericFile::ContainedFiles do
49
49
  describe '#original_file' do
50
50
  context 'when an original file is present' do
51
51
  before do
52
- original_file = generic_file.build_original_file
52
+ original_file = file_set.build_original_file
53
53
  original_file.content = 'original_file'
54
54
  end
55
- subject { generic_file.original_file }
55
+ subject { file_set.original_file }
56
56
 
57
57
  it 'can be saved without errors' do
58
58
  expect(subject.save).to be_truthy
@@ -63,12 +63,12 @@ describe Hydra::Works::GenericFile::ContainedFiles do
63
63
  end
64
64
  it 'retains origin pcdm.File RDF type' do
65
65
  expect(subject.metadata_node.type).to include(::RDF::URI('http://pcdm.org/use#OriginalFile'))
66
- expect(generic_file.original_file.metadata_node.type).to include(Hydra::PCDM::Vocab::PCDMTerms.File)
66
+ expect(file_set.original_file.metadata_node.type).to include(Hydra::PCDM::Vocab::PCDMTerms.File)
67
67
  end
68
68
  end
69
69
 
70
70
  context 'when building original file' do
71
- subject { generic_file.build_original_file }
71
+ subject { file_set.build_original_file }
72
72
  it 'initializes an unsaved File object with OrignalFile type' do
73
73
  expect(subject).to be_new_record
74
74
  expect(subject.metadata_node.type).to include(::RDF::URI('http://pcdm.org/use#OriginalFile'))
@@ -80,10 +80,10 @@ describe Hydra::Works::GenericFile::ContainedFiles do
80
80
  describe '#extracted_text' do
81
81
  context 'when extracted text is present' do
82
82
  before do
83
- extracted_text = generic_file.build_extracted_text
83
+ extracted_text = file_set.build_extracted_text
84
84
  extracted_text.content = 'extracted_text'
85
85
  end
86
- subject { generic_file.extracted_text }
86
+ subject { file_set.extracted_text }
87
87
  it 'can be saved without errors' do
88
88
  expect(subject.save).to be_truthy
89
89
  end
@@ -97,7 +97,7 @@ describe Hydra::Works::GenericFile::ContainedFiles do
97
97
  end
98
98
 
99
99
  context 'when building new extracted text object' do
100
- subject { generic_file.build_extracted_text }
100
+ subject { file_set.build_extracted_text }
101
101
  it 'initializes an unsaved File object with ExtractedText type' do
102
102
  expect(subject).to be_new_record
103
103
  expect(subject.metadata_node.type).to include(::RDF::URI('http://pcdm.org/use#ExtractedText'))
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Hydra::Works::GenericFile::MimeTypes do
4
- subject { Hydra::Works::GenericFile::Base.new }
3
+ describe Hydra::Works::MimeTypes do
4
+ subject { Hydra::Works::FileSet.new }
5
5
 
6
6
  describe '#pdf?' do
7
7
  before do
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::VersionedContent do
4
+ let(:file_set) { Hydra::Works::FileSet.new }
5
+ before do
6
+ Hydra::Works::UploadFileToFileSet.call(file_set, File.open(File.join(fixture_path, 'sample-file.pdf')))
7
+ Hydra::Works::UploadFileToFileSet.call(file_set, File.open(File.join(fixture_path, 'updated-file.txt')))
8
+ end
9
+
10
+ describe 'content_versions' do
11
+ subject { file_set.content_versions }
12
+ it 'lists all of the versions of original_file' do
13
+ expect(subject.count).to eq(2)
14
+ expect(subject.map(&:uri)).to eq(file_set.original_file.versions.all.map(&:uri))
15
+ end
16
+ end
17
+
18
+ describe 'latest_content_version' do
19
+ subject { file_set.latest_content_version }
20
+ it 'returns the most recent version entry for original_file' do
21
+ # Can't use a simple equivalence because they are actually different ResourceVersion objects
22
+ expect(subject.uri).to eq(file_set.original_file.versions.last.uri)
23
+ expect(subject.label).to eq(file_set.original_file.versions.last.label)
24
+ end
25
+ end
26
+
27
+ describe 'current_content_version_uri' do
28
+ it 'returns the URI of the most recent version of original_file' do
29
+ expect(file_set.current_content_version_uri).to eq(file_set.original_file.versions.last.uri)
30
+ end
31
+ end
32
+ end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Hydra::Works::GenericFile::VirusCheck do
3
+ describe Hydra::Works::VirusCheck do
4
4
  before do
5
5
  class FileWithVirusCheck < ActiveFedora::Base
6
- include Hydra::Works::GenericFileBehavior
7
- include Hydra::Works::GenericFile::VirusCheck
6
+ include Hydra::Works::FileSetBehavior
7
+ include Hydra::Works::VirusCheck
8
8
  end
9
9
  class ClamAV
10
10
  def self.instance
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::FileSetBehavior do
4
+ class IncludesFileSetBehavior < ActiveFedora::Base
5
+ include Hydra::Works::FileSetBehavior
6
+ end
7
+ subject { IncludesFileSetBehavior.new }
8
+
9
+ it 'ensures that objects will be recognized as file_sets' do
10
+ expect(subject).to be_file_set
11
+ end
12
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Hydra::Works::GenericFile::Base do
3
+ describe Hydra::Works::FileSet do
4
4
  let(:generic_file1) { described_class.new }
5
5
 
6
6
  describe 'Related objects' do
@@ -38,8 +38,8 @@ describe Hydra::Works::GenericFile::Base do
38
38
  context 'with acceptable related objects' do
39
39
  let(:object1) { Hydra::PCDM::Object.create }
40
40
  let(:object2) { Hydra::PCDM::Object.new }
41
- let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
42
- let(:generic_work2) { Hydra::Works::GenericWork::Base.new }
41
+ let(:generic_work1) { Hydra::Works::GenericWork.create }
42
+ let(:generic_work2) { Hydra::Works::GenericWork.new }
43
43
  let(:generic_file1) { described_class.create }
44
44
 
45
45
  it 'adds various types of related objects to generic_file' do
@@ -135,7 +135,7 @@ describe Hydra::Works::GenericFile::Base do
135
135
  let(:object1) { Hydra::PCDM::Object.new }
136
136
  let(:object2) { Hydra::PCDM::Object.new }
137
137
 
138
- let(:generic_work1) { Hydra::Works::GenericWork::Base.new }
138
+ let(:generic_work1) { Hydra::Works::GenericWork.new }
139
139
  let(:generic_file1) { described_class.new }
140
140
 
141
141
  context 'with generic files' do
@@ -167,10 +167,10 @@ describe Hydra::Works::GenericFile::Base do
167
167
  subject { described_class.new }
168
168
 
169
169
  let(:related_object1) { Hydra::PCDM::Object.new }
170
- let(:related_work2) { Hydra::Works::GenericWork::Base.new }
170
+ let(:related_work2) { Hydra::Works::GenericWork.new }
171
171
  let(:related_file3) { described_class.new }
172
172
  let(:related_object4) { Hydra::PCDM::Object.new }
173
- let(:related_work5) { Hydra::Works::GenericWork::Base.new }
173
+ let(:related_work5) { Hydra::Works::GenericWork.new }
174
174
 
175
175
  let(:generic_file1) { described_class.new }
176
176
  let(:generic_file2) { described_class.new }
@@ -207,28 +207,31 @@ describe Hydra::Works::GenericFile::Base do
207
207
  end
208
208
 
209
209
  describe 'should have parent work accessors' do
210
- let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
210
+ let(:generic_work1) { Hydra::Works::GenericWork.create }
211
211
  before do
212
- generic_work1.generic_files << generic_file1
212
+ generic_work1.ordered_members << generic_file1
213
+ generic_work1.save
213
214
  end
214
215
 
215
216
  it 'has parents' do
216
217
  expect(generic_file1.member_of).to eq [generic_work1]
217
218
  end
218
219
  it 'has a parent work' do
219
- expect(generic_file1.in_generic_works).to eq [generic_work1]
220
+ expect(generic_file1.in_works).to eq [generic_work1]
220
221
  end
221
222
  end
222
223
 
223
224
  describe 'make sure deprecated methods still work' do
224
- let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
225
+ let(:generic_work1) { Hydra::Works::GenericWork.create }
225
226
  before do
226
- generic_work1.generic_files << generic_file1
227
+ generic_work1.ordered_members << generic_file1
227
228
  generic_work1.save # required until issue AF-Agg-75 is fixed
228
229
  end
229
230
  it 'deprecated methods should pass' do
230
- expect(generic_file1.generic_works).to eq [generic_work1]
231
- expect(generic_file1.parents).to eq [generic_work1]
231
+ Deprecation.silence(Hydra::Works::GenericFileBehavior) do
232
+ expect(generic_file1.generic_works).to eq [generic_work1]
233
+ expect(generic_file1.parents).to eq [generic_work1]
234
+ end
232
235
  end
233
236
  end
234
237
  end
@@ -1,58 +1,82 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Hydra::Works::GenericWork do
4
- subject { Hydra::Works::GenericWork::Base.new }
4
+ subject { described_class.new }
5
5
 
6
- let(:generic_work1) { Hydra::Works::GenericWork::Base.new }
7
- let(:generic_work2) { Hydra::Works::GenericWork::Base.new }
8
- let(:generic_work3) { Hydra::Works::GenericWork::Base.new }
9
- let(:generic_work4) { Hydra::Works::GenericWork::Base.new }
10
- let(:generic_work5) { Hydra::Works::GenericWork::Base.new }
6
+ let(:generic_work1) { described_class.new }
7
+ let(:generic_work2) { described_class.new }
8
+ let(:generic_work3) { described_class.new }
9
+ let(:generic_work4) { described_class.new }
10
+ let(:generic_work5) { described_class.new }
11
11
 
12
- let(:generic_file1) { Hydra::Works::GenericFile::Base.new }
13
- let(:generic_file2) { Hydra::Works::GenericFile::Base.new }
12
+ let(:file_set1) { Hydra::Works::FileSet.new }
13
+ let(:file_set2) { Hydra::Works::FileSet.new }
14
14
 
15
15
  let(:object1) { Hydra::PCDM::Object.new }
16
16
  let(:object2) { Hydra::PCDM::Object.new }
17
17
 
18
18
  let(:pcdm_file1) { Hydra::PCDM::File.new }
19
19
 
20
- describe '#generic_works=' do
21
- it 'aggregates generic_works' do
22
- generic_work1.generic_works = [generic_work2, generic_work3]
23
- expect(generic_work1.generic_works).to eq [generic_work2, generic_work3]
20
+ describe "#file_set_ids" do
21
+ it "returns non-ordered file set IDs" do
22
+ generic_work1.members << file_set1
23
+ generic_work1.ordered_members << file_set2
24
+
25
+ expect(generic_work1.file_set_ids).to eq [file_set1.id, file_set2.id]
26
+ expect(generic_work1.ordered_file_set_ids).to eq [file_set2.id]
27
+ end
28
+ end
29
+
30
+ describe "#file_sets" do
31
+ it "returns non-ordered file sets" do
32
+ generic_work1.members << file_set1
33
+ generic_work1.ordered_members << file_set2
34
+
35
+ expect(generic_work1.file_sets).to eq [file_set1, file_set2]
36
+ end
37
+ end
38
+
39
+ describe "#work_ids" do
40
+ it "returns non-ordered file set IDs" do
41
+ generic_work1.members << generic_work2
42
+ generic_work1.ordered_members << generic_work3
43
+
44
+ expect(generic_work1.work_ids).to eq [generic_work2.id, generic_work3.id]
45
+ expect(generic_work1.ordered_work_ids).to eq [generic_work3.id]
24
46
  end
25
47
  end
26
48
 
27
- describe '#generic_files=' do
28
- it 'aggregates generic_files' do
29
- generic_work1.generic_files = [generic_file1, generic_file2]
30
- expect(generic_work1.generic_files).to eq [generic_file1, generic_file2]
49
+ describe "#works" do
50
+ it "returns non-ordered file sets" do
51
+ generic_work1.members << generic_work2
52
+ generic_work1.ordered_members << generic_work3
53
+
54
+ expect(generic_work1.works).to eq [generic_work2, generic_work3]
31
55
  end
32
56
  end
33
57
 
34
- describe '#generic_file_ids' do
35
- it 'lists generic_file ids' do
36
- generic_work1.generic_files = [generic_file1, generic_file2]
37
- expect(generic_work1.generic_file_ids).to eq [generic_file1.id, generic_file2.id]
58
+ describe '#ordered_file_set_ids' do
59
+ it 'lists file_set ids' do
60
+ generic_work1.ordered_members = [file_set1, file_set2]
61
+ expect(generic_work1.ordered_file_set_ids).to eq [file_set1.id, file_set2.id]
38
62
  end
39
63
  end
40
64
 
41
65
  context 'sub-class' do
42
66
  before do
43
- class TestWork < Hydra::Works::GenericWork::Base
67
+ class TestWork < Hydra::Works::GenericWork
44
68
  end
45
69
  end
46
70
 
47
- subject { TestWork.new(generic_files: [generic_file1]) }
71
+ subject { TestWork.new(ordered_members: [file_set1]) }
48
72
 
49
73
  it 'has many generic files' do
50
- expect(subject.generic_files).to eq [generic_file1]
74
+ expect(subject.ordered_file_sets).to eq [file_set1]
51
75
  end
52
76
  end
53
77
 
54
78
  describe 'Related objects' do
55
- let(:generic_work1) { Hydra::Works::GenericWork::Base.new }
79
+ let(:generic_work1) { described_class.new }
56
80
  let(:object1) { Hydra::PCDM::Object.new }
57
81
 
58
82
  before do
@@ -64,249 +88,48 @@ describe Hydra::Works::GenericWork do
64
88
  end
65
89
  end
66
90
 
67
- describe '#generic_works' do
68
- context 'with acceptable generic_works' do
69
- context 'with generic_files and generic_works' do
91
+ describe '#ordered_works' do
92
+ context 'with acceptable works' do
93
+ context 'with file_sets and works' do
70
94
  before do
71
- subject.generic_files << generic_file1
72
- subject.generic_files << generic_file2
73
- subject.generic_works << generic_work1
74
- subject.generic_works << generic_work2
95
+ subject.ordered_members << file_set1
96
+ subject.ordered_members << file_set2
97
+ subject.ordered_members << generic_work1
98
+ subject.ordered_members << generic_work2
75
99
  end
76
100
 
77
- it 'adds generic_work to generic_work with generic_files and generic_works' do
78
- subject.generic_works << generic_work3
79
- expect(subject.generic_works).to eq [generic_work1, generic_work2, generic_work3]
101
+ it 'adds generic_work to generic_work with file_sets and works' do
102
+ subject.ordered_members << generic_work3
103
+ expect(subject.ordered_works).to eq [generic_work1, generic_work2, generic_work3]
80
104
  end
81
105
  end
82
106
 
83
- describe 'aggregates generic_works that implement Hydra::Works::GenericWorkBehavior' do
107
+ describe 'aggregates works that implement Hydra::Works::WorkBehavior' do
84
108
  before do
85
109
  class DummyIncWork < ActiveFedora::Base
86
- include Hydra::Works::GenericWorkBehavior
110
+ include Hydra::Works::WorkBehavior
87
111
  end
88
112
  end
89
113
  after { Object.send(:remove_const, :DummyIncWork) }
90
114
  let(:iwork1) { DummyIncWork.new }
91
115
 
92
116
  it 'accepts implementing generic_work as a child' do
93
- subject.generic_works << iwork1
94
- expect(subject.generic_works).to eq [iwork1]
117
+ subject.ordered_members << iwork1
118
+ expect(subject.ordered_works).to eq [iwork1]
95
119
  end
96
120
  end
97
121
 
98
- describe 'aggregates generic_works that extend Hydra::Works::GenericWork::Base' do
122
+ describe 'aggregates works that extend Hydra::Works::GenericWork' do
99
123
  before do
100
- class DummyExtWork < Hydra::Works::GenericWork::Base
124
+ class DummyExtWork < Hydra::Works::GenericWork
101
125
  end
102
126
  end
103
127
  after { Object.send(:remove_const, :DummyExtWork) }
104
128
  let(:ework1) { DummyExtWork.new }
105
129
 
106
130
  it 'accepts extending generic_work as a child' do
107
- subject.generic_works << ework1
108
- expect(subject.generic_works).to eq [ework1]
109
- end
110
- end
111
- end
112
-
113
- context 'with unacceptable inputs' do
114
- before(:all) do
115
- @generic_work102 = Hydra::Works::GenericWork::Base.new
116
-
117
- @works_collection101 = Hydra::Works::Collection.new
118
- @generic_file101 = Hydra::Works::GenericFile::Base.new
119
- @pcdm_collection101 = Hydra::PCDM::Collection.new
120
- @pcdm_object101 = Hydra::PCDM::Object.new
121
- @pcdm_file101 = Hydra::PCDM::File.new
122
- @non_pcdm_object = "I'm not a PCDM object"
123
- @af_base_object = ActiveFedora::Base.new
124
- end
125
-
126
- context 'that are unacceptable child generic works' do
127
- let(:error_type1) { ArgumentError }
128
- let(:error_message1) { /Hydra::Works::(GenericFile::Base|Collection) with ID: was expected to works_generic_work\?, but it was false/ }
129
- let(:error_type2) { NoMethodError }
130
- let(:error_message2) { /undefined method `works_generic_work\?' for .*/ }
131
-
132
- it 'does not aggregate Hydra::Works::Collection in generic works aggregation' do
133
- expect { subject.generic_works << @works_collection101 }.to raise_error(error_type1, error_message1)
134
- end
135
-
136
- it 'does not aggregate Hydra::Works::GenericFile in generic works aggregation' do
137
- expect { subject.generic_works << @generic_file101 }.to raise_error(error_type1, error_message1)
138
- end
139
-
140
- it 'does not aggregate Hydra::PCDM::Collections in generic works aggregation' do
141
- expect { subject.generic_works << @pcdm_collection101 }.to raise_error(error_type2, error_message2)
142
- end
143
-
144
- it 'does not aggregate Hydra::PCDM::Objects in generic works aggregation' do
145
- expect { subject.generic_works << @pcdm_object101 }.to raise_error(error_type2, error_message2)
146
- end
147
-
148
- it 'does not aggregate Hydra::PCDM::Files in generic works aggregation' do
149
- expect { subject.generic_works << @pcdm_file101 }.to raise_error(error_type2, error_message2)
150
- end
151
-
152
- it 'does not aggregate non-PCDM objects in generic works aggregation' do
153
- expect { subject.generic_works << @non_pcdm_object }.to raise_error(error_type2, error_message2)
154
- end
155
-
156
- it 'does not aggregate AF::Base objects in generic works aggregation' do
157
- expect { subject.generic_works << @af_base_object }.to raise_error(error_type2, error_message2)
158
- end
159
- end
160
- end
161
- end
162
-
163
- describe '#generic_files <<' do
164
- it 'returns empty array when only generic_files are aggregated' do
165
- subject.generic_files << generic_file1
166
- subject.generic_files << generic_file2
167
- expect(subject.generic_works).to eq []
168
- end
169
-
170
- context 'with generic_files and generic_works' do
171
- before do
172
- subject.generic_files << generic_file1
173
- subject.generic_files << generic_file2
174
- subject.generic_works << generic_work1
175
- subject.generic_works << generic_work2
176
- end
177
-
178
- it 'returns only generic_works' do
179
- expect(subject.generic_works).to eq [generic_work1, generic_work2]
180
- end
181
- end
182
- end
183
-
184
- describe '#generic_works.delete' do
185
- context 'when multiple collections' do
186
- before do
187
- subject.generic_works << generic_work1
188
- subject.generic_works << generic_work2
189
- subject.generic_files << generic_file2
190
- subject.generic_works << generic_work3
191
- subject.generic_works << generic_work4
192
- subject.generic_files << generic_file1
193
- subject.generic_works << generic_work5
194
- expect(subject.generic_works).to eq [generic_work1, generic_work2, generic_work3, generic_work4, generic_work5]
195
- end
196
-
197
- it 'removes first collection' do
198
- expect(subject.generic_works.delete generic_work1).to eq [generic_work1]
199
- expect(subject.generic_works).to eq [generic_work2, generic_work3, generic_work4, generic_work5]
200
- expect(subject.generic_files).to eq [generic_file2, generic_file1]
201
- end
202
-
203
- it 'removes last collection' do
204
- expect(subject.generic_works.delete generic_work5).to eq [generic_work5]
205
- expect(subject.generic_works).to eq [generic_work1, generic_work2, generic_work3, generic_work4]
206
- expect(subject.generic_files).to eq [generic_file2, generic_file1]
207
- end
208
-
209
- it 'removes middle collection' do
210
- expect(subject.generic_works.delete generic_work3).to eq [generic_work3]
211
- expect(subject.generic_works).to eq [generic_work1, generic_work2, generic_work4, generic_work5]
212
- expect(subject.generic_files).to eq [generic_file2, generic_file1]
213
- end
214
- end
215
- end
216
-
217
- describe '#generic_works <<' do
218
- context 'with acceptable generic_works' do
219
- context 'with generic_files and generic_works' do
220
- let(:generic_file3) { Hydra::Works::GenericFile::Base.new }
221
- before do
222
- subject.generic_files << generic_file1
223
- subject.generic_files << generic_file2
224
- subject.generic_works << generic_work1
225
- subject.generic_works << generic_work2
226
- end
227
-
228
- it 'adds generic_file to generic_work with generic_files and generic_works' do
229
- subject.generic_files << generic_file3
230
- expect(subject.generic_files).to eq [generic_file1, generic_file2, generic_file3]
231
- end
232
- end
233
-
234
- describe 'aggregates generic_files that implement Hydra::Works::GenericFileBehavior' do
235
- before do
236
- class DummyIncFile < ActiveFedora::Base
237
- include Hydra::Works::GenericFileBehavior
238
- end
239
- end
240
- after { Object.send(:remove_const, :DummyIncFile) }
241
- let(:ifile1) { DummyIncFile.new }
242
-
243
- it 'accepts implementing generic_file as a child' do
244
- subject.generic_files << ifile1
245
- expect(subject.generic_files).to eq [ifile1]
246
- end
247
- end
248
-
249
- describe 'aggregates generic_files that extend Hydra::Works::GenericFile::Base' do
250
- before do
251
- class DummyExtFile < Hydra::Works::GenericFile::Base
252
- end
253
- end
254
- after { Object.send(:remove_const, :DummyExtFile) }
255
- let(:efile1) { DummyExtFile.new }
256
-
257
- it 'accepts extending generic_file as a child' do
258
- subject.generic_files << efile1
259
- expect(subject.generic_files).to eq [efile1]
260
- end
261
- end
262
- end
263
-
264
- context 'with unacceptable inputs' do
265
- before(:all) do
266
- @generic_work102 = Hydra::Works::GenericWork::Base.new
267
-
268
- @works_collection101 = Hydra::Works::Collection.new
269
- @generic_work101 = Hydra::Works::GenericWork::Base.new
270
- @generic_file101 = Hydra::Works::GenericFile::Base.new
271
- @pcdm_collection101 = Hydra::PCDM::Collection.new
272
- @pcdm_object101 = Hydra::PCDM::Object.new
273
- @pcdm_file101 = Hydra::PCDM::File.new
274
- @non_pcdm_object = "I'm not a PCDM object"
275
- @af_base_object = ActiveFedora::Base.new
276
- end
277
-
278
- context 'that are unacceptable child generic files' do
279
- let(:error_type1) { ArgumentError }
280
- let(:error_message1) { /Hydra::Works::(GenericWork::Base|Collection) with ID: was expected to works_generic_file\?, but it was false/ }
281
- let(:error_type2) { NoMethodError }
282
- let(:error_message2) { /undefined method `works_generic_file\?' for .*/ }
283
-
284
- it 'does not aggregate Hydra::Works::Collection in generic files aggregation' do
285
- expect { subject.generic_files << @works_collection101 }.to raise_error(error_type1, error_message1)
286
- end
287
-
288
- it 'does not aggregate Hydra::Works::GenericWork in generic files aggregation' do
289
- expect { subject.generic_files << @generic_work101 }.to raise_error(error_type1, error_message1)
290
- end
291
-
292
- it 'does not aggregate Hydra::PCDM::Collections in generic files aggregation' do
293
- expect { subject.generic_files << @pcdm_collection101 }.to raise_error(error_type2, error_message2)
294
- end
295
-
296
- it 'does not aggregate Hydra::PCDM::Objects in generic files aggregation' do
297
- expect { subject.generic_files << @pcdm_object101 }.to raise_error(error_type2, error_message2)
298
- end
299
-
300
- it 'does not aggregate Hydra::PCDM::Files in generic files aggregation' do
301
- expect { subject.generic_files << @pcdm_file101 }.to raise_error(error_type2, error_message2)
302
- end
303
-
304
- it 'does not aggregate non-PCDM objects in generic files aggregation' do
305
- expect { subject.generic_files << @non_pcdm_object }.to raise_error(error_type2, error_message2)
306
- end
307
-
308
- it 'does not aggregate AF::Base objects in generic files aggregation' do
309
- expect { subject.generic_files << @af_base_object }.to raise_error(error_type2, error_message2)
131
+ subject.ordered_members << ework1
132
+ expect(subject.ordered_works).to eq [ework1]
310
133
  end
311
134
  end
312
135
  end
@@ -314,71 +137,72 @@ describe Hydra::Works::GenericWork do
314
137
 
315
138
  context 'move generic file' do
316
139
  before do
317
- subject.generic_files << generic_file1
318
- subject.generic_files << generic_file2
140
+ subject.ordered_members << file_set1
141
+ subject.ordered_members << file_set2
319
142
  end
320
143
  it 'moves file from one work to another' do
321
- expect(subject.generic_files).to eq([generic_file1, generic_file2])
322
- expect(generic_work1.generic_files).to eq([])
323
- generic_work1.generic_files << subject.generic_files.delete(generic_file1)
324
- expect(subject.generic_files).to eq([generic_file2])
325
- expect(generic_work1.generic_files).to eq([generic_file1])
144
+ expect(subject.ordered_file_sets).to eq([file_set1, file_set2])
145
+ expect(generic_work1.ordered_file_sets).to eq([])
146
+ subject.ordered_member_proxies.delete_at(0)
147
+ generic_work1.ordered_members << file_set1
148
+ expect(subject.ordered_file_sets).to eq([file_set2])
149
+ expect(generic_work1.ordered_file_sets).to eq([file_set1])
326
150
  end
327
151
  end
328
152
 
329
- describe '#generic_files' do
330
- it 'returns empty array when only generic_works are aggregated' do
331
- subject.generic_works << generic_work1
332
- subject.generic_works << generic_work2
333
- expect(subject.generic_files).to eq []
153
+ describe '#file_sets' do
154
+ it 'returns empty array when only works are aggregated' do
155
+ subject.ordered_members << generic_work1
156
+ subject.ordered_members << generic_work2
157
+ expect(subject.ordered_file_sets).to eq []
334
158
  end
335
159
 
336
- context 'with generic_files and generic_works' do
160
+ context 'with file_sets and works' do
337
161
  before do
338
- subject.generic_files << generic_file1
339
- subject.generic_files << generic_file2
340
- subject.generic_works << generic_work1
341
- subject.generic_works << generic_work2
162
+ subject.ordered_members << file_set1
163
+ subject.ordered_members << file_set2
164
+ subject.ordered_members << generic_work1
165
+ subject.ordered_members << generic_work2
342
166
  end
343
167
 
344
- it 'returns only generic_files' do
345
- expect(subject.generic_files).to eq [generic_file1, generic_file2]
168
+ it 'returns only file_sets' do
169
+ expect(subject.ordered_file_sets).to eq [file_set1, file_set2]
346
170
  end
347
171
  end
348
172
  end
349
173
 
350
- describe '#generic_files.delete' do
174
+ describe '#file_sets.delete' do
351
175
  context 'when multiple collections' do
352
- let(:generic_file3) { Hydra::Works::GenericFile::Base.new }
353
- let(:generic_file4) { Hydra::Works::GenericFile::Base.new }
354
- let(:generic_file5) { Hydra::Works::GenericFile::Base.new }
176
+ let(:file_set3) { Hydra::Works::FileSet.new }
177
+ let(:file_set4) { Hydra::Works::FileSet.new }
178
+ let(:file_set5) { Hydra::Works::FileSet.new }
355
179
  before do
356
- subject.generic_files << generic_file1
357
- subject.generic_files << generic_file2
358
- subject.generic_works << generic_work2
359
- subject.generic_files << generic_file3
360
- subject.generic_files << generic_file4
361
- subject.generic_works << generic_work1
362
- subject.generic_files << generic_file5
363
- expect(subject.generic_files).to eq [generic_file1, generic_file2, generic_file3, generic_file4, generic_file5]
180
+ subject.ordered_members << file_set1
181
+ subject.ordered_members << file_set2
182
+ subject.ordered_members << generic_work2
183
+ subject.ordered_members << file_set3
184
+ subject.ordered_members << file_set4
185
+ subject.ordered_members << generic_work1
186
+ subject.ordered_members << file_set5
187
+ expect(subject.ordered_file_sets).to eq [file_set1, file_set2, file_set3, file_set4, file_set5]
364
188
  end
365
189
 
366
190
  it 'removes first collection' do
367
- expect(subject.generic_files.delete generic_file1).to eq [generic_file1]
368
- expect(subject.generic_files).to eq [generic_file2, generic_file3, generic_file4, generic_file5]
369
- expect(subject.generic_works).to eq [generic_work2, generic_work1]
191
+ subject.ordered_member_proxies.delete_at(0)
192
+ expect(subject.ordered_file_sets).to eq [file_set2, file_set3, file_set4, file_set5]
193
+ expect(subject.ordered_works).to eq [generic_work2, generic_work1]
370
194
  end
371
195
 
372
196
  it 'removes last collection' do
373
- expect(subject.generic_files.delete generic_file5).to eq [generic_file5]
374
- expect(subject.generic_files).to eq [generic_file1, generic_file2, generic_file3, generic_file4]
375
- expect(subject.generic_works).to eq [generic_work2, generic_work1]
197
+ subject.ordered_member_proxies.delete_at(6)
198
+ expect(subject.ordered_file_sets).to eq [file_set1, file_set2, file_set3, file_set4]
199
+ expect(subject.ordered_works).to eq [generic_work2, generic_work1]
376
200
  end
377
201
 
378
202
  it 'removes middle collection' do
379
- expect(subject.generic_files.delete generic_file3).to eq [generic_file3]
380
- expect(subject.generic_files).to eq [generic_file1, generic_file2, generic_file4, generic_file5]
381
- expect(subject.generic_works).to eq [generic_work2, generic_work1]
203
+ subject.ordered_member_proxies.delete_at(3)
204
+ expect(subject.ordered_file_sets).to eq [file_set1, file_set2, file_set4, file_set5]
205
+ expect(subject.ordered_works).to eq [generic_work2, generic_work1]
382
206
  end
383
207
  end
384
208
  end
@@ -387,26 +211,26 @@ describe Hydra::Works::GenericWork do
387
211
  context 'with acceptable related objects' do
388
212
  it 'adds various types of related objects to generic_work' do
389
213
  subject.related_objects << generic_work1
390
- subject.related_objects << generic_file1
214
+ subject.related_objects << file_set1
391
215
  subject.related_objects << object1
392
216
  subject.save
393
217
  subject.reload
394
218
  expect(subject.related_objects.include? generic_work1).to be true
395
- expect(subject.related_objects.include? generic_file1).to be true
219
+ expect(subject.related_objects.include? file_set1).to be true
396
220
  expect(subject.related_objects.include? object1).to be true
397
221
  expect(subject.related_objects.size).to eq 3
398
222
  end
399
223
 
400
- context 'with generic_works and generic_files' do
224
+ context 'with works and file_sets' do
401
225
  before do
402
- subject.generic_files << generic_file1
403
- subject.generic_files << generic_file2
404
- subject.generic_works << generic_work1
405
- subject.generic_works << generic_work2
226
+ subject.ordered_file_sets << file_set1
227
+ subject.ordered_file_sets << file_set2
228
+ subject.ordered_works << generic_work1
229
+ subject.ordered_works << generic_work2
406
230
  subject.related_objects << object1
407
231
  end
408
232
 
409
- it 'adds a related object to generic_work with generic_works and generic_files' do
233
+ it 'adds a related object to file_set with works and file_sets' do
410
234
  subject.related_objects << object2
411
235
  subject.save
412
236
  subject.reload
@@ -462,11 +286,11 @@ describe Hydra::Works::GenericWork do
462
286
  end
463
287
 
464
288
  describe '#related_objects <<' do
465
- context 'with generic files and works' do
289
+ context 'with file sets and works' do
466
290
  before do
467
- subject.generic_works << generic_work1
468
- subject.generic_works << generic_work1
469
- subject.generic_files << generic_file1
291
+ subject.ordered_members << generic_work1
292
+ subject.ordered_members << generic_work1
293
+ subject.ordered_members << file_set1
470
294
  end
471
295
 
472
296
  it 'returns empty array when only generic files and generic works are aggregated' do
@@ -480,9 +304,9 @@ describe Hydra::Works::GenericWork do
480
304
 
481
305
  it 'returns related objects of various types' do
482
306
  subject.related_objects << generic_work2
483
- subject.related_objects << generic_file1
307
+ subject.related_objects << file_set1
484
308
  subject.related_objects << object1
485
- expect(subject.related_objects).to eq [generic_work2, generic_file1, object1]
309
+ expect(subject.related_objects).to eq [generic_work2, file_set1, object1]
486
310
  expect(subject.related_objects.size).to eq 3
487
311
  end
488
312
  end
@@ -491,18 +315,18 @@ describe Hydra::Works::GenericWork do
491
315
  describe '#related_objects.delete' do
492
316
  context 'when multiple related objects' do
493
317
  let(:related_object1) { Hydra::PCDM::Object.new }
494
- let(:related_work2) { Hydra::Works::GenericWork::Base.new }
495
- let(:related_file3) { Hydra::Works::GenericFile::Base.new }
318
+ let(:related_work2) { described_class.new }
319
+ let(:related_file3) { Hydra::Works::FileSet.new }
496
320
  let(:related_object4) { Hydra::PCDM::Object.new }
497
- let(:related_work5) { Hydra::Works::GenericWork::Base.new }
321
+ let(:related_work5) { described_class.new }
498
322
  before do
499
323
  subject.related_objects << related_object1
500
324
  subject.related_objects << related_work2
501
- subject.generic_works << generic_work2
502
- subject.generic_files << generic_file1
325
+ subject.ordered_members << generic_work2
326
+ subject.ordered_members << file_set1
503
327
  subject.related_objects << related_file3
504
328
  subject.related_objects << related_object4
505
- subject.generic_works << generic_work1
329
+ subject.ordered_members << generic_work1
506
330
  subject.related_objects << related_work5
507
331
  expect(subject.related_objects).to eq [related_object1, related_work2, related_file3, related_object4, related_work5]
508
332
  end
@@ -510,22 +334,22 @@ describe Hydra::Works::GenericWork do
510
334
  it 'removes first related object' do
511
335
  expect(subject.related_objects.delete related_object1).to eq [related_object1]
512
336
  expect(subject.related_objects).to eq [related_work2, related_file3, related_object4, related_work5]
513
- expect(subject.generic_works).to eq [generic_work2, generic_work1]
514
- expect(subject.generic_files).to eq [generic_file1]
337
+ expect(subject.ordered_works).to eq [generic_work2, generic_work1]
338
+ expect(subject.ordered_file_sets).to eq [file_set1]
515
339
  end
516
340
 
517
341
  it 'removes last related object' do
518
342
  expect(subject.related_objects.delete related_work5).to eq [related_work5]
519
343
  expect(subject.related_objects).to eq [related_object1, related_work2, related_file3, related_object4]
520
- expect(subject.generic_works).to eq [generic_work2, generic_work1]
521
- expect(subject.generic_files).to eq [generic_file1]
344
+ expect(subject.ordered_works).to eq [generic_work2, generic_work1]
345
+ expect(subject.ordered_file_sets).to eq [file_set1]
522
346
  end
523
347
 
524
348
  it 'removes middle related object' do
525
349
  expect(subject.related_objects.delete related_file3).to eq [related_file3]
526
350
  expect(subject.related_objects).to eq [related_object1, related_work2, related_object4, related_work5]
527
- expect(subject.generic_works).to eq [generic_work2, generic_work1]
528
- expect(subject.generic_files).to eq [generic_file1]
351
+ expect(subject.ordered_works).to eq [generic_work2, generic_work1]
352
+ expect(subject.ordered_file_sets).to eq [file_set1]
529
353
  end
530
354
  end
531
355
  end
@@ -533,8 +357,8 @@ describe Hydra::Works::GenericWork do
533
357
  describe 'should have parent work and collection accessors' do
534
358
  let(:collection1) { Hydra::Works::Collection.new }
535
359
  before do
536
- collection1.generic_works << generic_work2
537
- generic_work1.generic_works << generic_work2
360
+ collection1.ordered_members << generic_work2
361
+ generic_work1.ordered_members << generic_work2
538
362
  collection1.save
539
363
  generic_work1.save
540
364
  generic_work2.save
@@ -547,18 +371,24 @@ describe Hydra::Works::GenericWork do
547
371
  expect(generic_work2.in_collections).to eq [collection1]
548
372
  end
549
373
  it 'has a parent generic_work' do
550
- expect(generic_work2.in_generic_works).to eq [generic_work1]
374
+ expect(generic_work2.in_works).to eq [generic_work1]
551
375
  end
552
376
  end
553
377
 
554
378
  describe 'make sure deprecated methods still work' do
379
+ let(:collection1) { Hydra::Works::Collection.new }
555
380
  it 'deprecated methods should pass' do
556
- expect(generic_work1.child_generic_works = [generic_work2]).to eq [generic_work2]
557
- expect(generic_work1.child_generic_works << generic_work3).to eq [generic_work2, generic_work3]
558
- expect(generic_work1.child_generic_works += [generic_work4]).to eq [generic_work2, generic_work3, generic_work4]
559
- generic_work1.save # required until issue AF-Agg-75 is fixed
560
- expect(generic_work2.parent_generic_works).to eq [generic_work1]
561
- expect(generic_work2.parents).to eq [generic_work1]
381
+ Deprecation.silence(Hydra::Works::WorkBehavior) do
382
+ collection1.ordered_members << generic_work1
383
+ generic_work1.ordered_members << generic_work2
384
+ expect(generic_work1.child_generic_works).to eq [generic_work2]
385
+ expect(generic_work1.child_generic_work_ids).to eq [generic_work2.id]
386
+ generic_work1.save # required until issue AF-Agg-75 is fixed
387
+ collection1.save
388
+ expect(generic_work2.parent_generic_works).to eq [generic_work1]
389
+ expect(generic_work1.parent_collections).to eq [collection1]
390
+ expect(generic_work2.parents).to eq [generic_work1]
391
+ end
562
392
  end
563
393
  end
564
394
  end