hydra-works 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.travis.yml +2 -5
  4. data/Gemfile +1 -3
  5. data/README.md +28 -13
  6. data/hydra-works.gemspec +4 -3
  7. data/lib/hydra/works.rb +7 -57
  8. data/lib/hydra/works/models/concerns/block_child_objects.rb +16 -0
  9. data/lib/hydra/works/models/concerns/collection_behavior.rb +27 -2
  10. data/lib/hydra/works/models/concerns/generic_file/contained_files.rb +5 -13
  11. data/lib/hydra/works/models/concerns/generic_file/derivatives.rb +9 -13
  12. data/lib/hydra/works/models/concerns/generic_file/mime_types.rb +14 -9
  13. data/lib/hydra/works/models/concerns/generic_file/versioned_content.rb +18 -0
  14. data/lib/hydra/works/models/concerns/generic_file/virus_check.rb +48 -0
  15. data/lib/hydra/works/models/concerns/generic_file_behavior.rb +24 -1
  16. data/lib/hydra/works/models/concerns/generic_work_behavior.rb +32 -3
  17. data/lib/hydra/works/models/generic_file.rb +3 -0
  18. data/lib/hydra/works/services/generic_file/add_file_to_generic_file.rb +127 -0
  19. data/lib/hydra/works/services/generic_file/generate/thumbnail.rb +1 -2
  20. data/lib/hydra/works/services/generic_file/persist_derivative.rb +22 -0
  21. data/lib/hydra/works/services/generic_file/upload_file.rb +11 -19
  22. data/lib/hydra/works/version.rb +1 -1
  23. data/lib/hydra/works/vocab/works_terms.rb +1 -1
  24. data/spec/fixtures/Example.ogg +0 -0
  25. data/spec/fixtures/charter.docx +0 -0
  26. data/spec/fixtures/countdown.avi +0 -0
  27. data/spec/fixtures/image.jp2 +0 -0
  28. data/spec/fixtures/piano_note.wav +0 -0
  29. data/spec/fixtures/test5.mp3 +0 -0
  30. data/spec/fixtures/world.png +0 -0
  31. data/spec/hydra/works/models/collection_spec.rb +499 -16
  32. data/spec/hydra/works/models/concerns/block_child_objects_spec.rb +19 -0
  33. data/spec/hydra/works/models/concerns/{file → generic_file}/contained_files_spec.rb +20 -17
  34. data/spec/hydra/works/models/concerns/generic_file/mime_types_spec.rb +76 -0
  35. data/spec/hydra/works/models/concerns/generic_file/versioned_content_spec.rb +32 -0
  36. data/spec/hydra/works/models/concerns/generic_file/virus_check_spec.rb +50 -0
  37. data/spec/hydra/works/models/concerns/generic_file_behavior_spec.rb +1 -1
  38. data/spec/hydra/works/models/generic_file_spec.rb +201 -14
  39. data/spec/hydra/works/models/generic_work_spec.rb +530 -14
  40. data/spec/hydra/works/services/generic_file/add_file_to_generic_file_spec.rb +110 -0
  41. data/spec/hydra/works/services/generic_file/upload_file_spec.rb +45 -28
  42. data/spec/hydra/works/services/persist_derivatives_spec.rb +93 -0
  43. data/spec/hydra/works_spec.rb +35 -35
  44. data/spec/spec_helper.rb +6 -0
  45. metadata +56 -95
  46. data/lib/hydra/works/models/concerns/aggregates_collections.rb +0 -16
  47. data/lib/hydra/works/models/concerns/aggregates_generic_files.rb +0 -20
  48. data/lib/hydra/works/models/concerns/aggregates_generic_works.rb +0 -20
  49. data/lib/hydra/works/processor.rb +0 -9
  50. data/lib/hydra/works/services/collection/add_collection.rb +0 -19
  51. data/lib/hydra/works/services/collection/add_generic_work.rb +0 -19
  52. data/lib/hydra/works/services/collection/add_related_object.rb +0 -19
  53. data/lib/hydra/works/services/collection/get_collections.rb +0 -17
  54. data/lib/hydra/works/services/collection/get_generic_works.rb +0 -17
  55. data/lib/hydra/works/services/collection/get_related_objects.rb +0 -17
  56. data/lib/hydra/works/services/collection/remove_collection.rb +0 -19
  57. data/lib/hydra/works/services/collection/remove_generic_work.rb +0 -20
  58. data/lib/hydra/works/services/collection/remove_related_object.rb +0 -19
  59. data/lib/hydra/works/services/generic_file/add_file.rb +0 -55
  60. data/lib/hydra/works/services/generic_file/add_generic_file.rb +0 -19
  61. data/lib/hydra/works/services/generic_file/add_original_file.rb +0 -11
  62. data/lib/hydra/works/services/generic_file/add_related_object.rb +0 -19
  63. data/lib/hydra/works/services/generic_file/add_versioned_original_file.rb +0 -10
  64. data/lib/hydra/works/services/generic_file/get_generic_files.rb +0 -17
  65. data/lib/hydra/works/services/generic_file/get_related_objects.rb +0 -17
  66. data/lib/hydra/works/services/generic_file/remove_generic_file.rb +0 -20
  67. data/lib/hydra/works/services/generic_file/remove_related_object.rb +0 -19
  68. data/lib/hydra/works/services/generic_work/add_generic_file.rb +0 -19
  69. data/lib/hydra/works/services/generic_work/add_generic_work.rb +0 -19
  70. data/lib/hydra/works/services/generic_work/add_related_object.rb +0 -19
  71. data/lib/hydra/works/services/generic_work/get_generic_files.rb +0 -17
  72. data/lib/hydra/works/services/generic_work/get_generic_works.rb +0 -17
  73. data/lib/hydra/works/services/generic_work/get_related_objects.rb +0 -17
  74. data/lib/hydra/works/services/generic_work/move_generic_file.rb +0 -19
  75. data/lib/hydra/works/services/generic_work/remove_generic_file.rb +0 -20
  76. data/lib/hydra/works/services/generic_work/remove_generic_work.rb +0 -20
  77. data/lib/hydra/works/services/generic_work/remove_related_object.rb +0 -19
  78. data/spec/hydra/works/services/collection/add_collection_spec.rb +0 -166
  79. data/spec/hydra/works/services/collection/add_generic_work_spec.rb +0 -155
  80. data/spec/hydra/works/services/collection/add_related_object_spec.rb +0 -149
  81. data/spec/hydra/works/services/collection/get_collections_spec.rb +0 -35
  82. data/spec/hydra/works/services/collection/get_generic_works_spec.rb +0 -35
  83. data/spec/hydra/works/services/collection/get_related_objects_spec.rb +0 -49
  84. data/spec/hydra/works/services/collection/remove_collection_spec.rb +0 -133
  85. data/spec/hydra/works/services/collection/remove_generic_work_spec.rb +0 -133
  86. data/spec/hydra/works/services/collection/remove_related_object_spec.rb +0 -128
  87. data/spec/hydra/works/services/generic_file/add_file_spec.rb +0 -28
  88. data/spec/hydra/works/services/generic_file/add_generic_file_spec.rb +0 -174
  89. data/spec/hydra/works/services/generic_file/add_related_object_spec.rb +0 -150
  90. data/spec/hydra/works/services/generic_file/get_generic_files_spec.rb +0 -19
  91. data/spec/hydra/works/services/generic_file/get_related_objects_spec.rb +0 -45
  92. data/spec/hydra/works/services/generic_file/remove_generic_file_spec.rb +0 -124
  93. data/spec/hydra/works/services/generic_file/remove_related_object_spec.rb +0 -123
  94. data/spec/hydra/works/services/generic_work/add_generic_file_spec.rb +0 -156
  95. data/spec/hydra/works/services/generic_work/add_generic_work_spec.rb +0 -157
  96. data/spec/hydra/works/services/generic_work/add_related_object_spec.rb +0 -148
  97. data/spec/hydra/works/services/generic_work/get_generic_files_spec.rb +0 -35
  98. data/spec/hydra/works/services/generic_work/get_generic_works_spec.rb +0 -35
  99. data/spec/hydra/works/services/generic_work/get_related_objects_spec.rb +0 -46
  100. data/spec/hydra/works/services/generic_work/move_generic_file_spec.rb +0 -21
  101. data/spec/hydra/works/services/generic_work/remove_generic_file_spec.rb +0 -132
  102. data/spec/hydra/works/services/generic_work/remove_generic_work_spec.rb +0 -133
  103. data/spec/hydra/works/services/generic_work/remove_related_object_spec.rb +0 -128
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::BlockChildObjects do
4
+
5
+ subject { Hydra::Works::GenericFile::Base.new }
6
+
7
+ describe "#child_objects=?" do
8
+ it "should raise an error" do
9
+ expect { subject.child_objects = [] }.to raise_error(StandardError, /method `child_objects=' not allowed for #<Hydra::Works::GenericFile::Base.*/)
10
+ end
11
+ end
12
+
13
+ describe "#child_objects" do
14
+ it "should raise an error" do
15
+ expect { subject.child_objects }.to raise_error(StandardError, /method `child_objects' not allowed for #<Hydra::Works::GenericFile::Base.*/)
16
+ end
17
+ end
18
+
19
+ end
@@ -12,18 +12,18 @@ describe Hydra::Works::GenericFile::ContainedFiles do
12
12
  end
13
13
 
14
14
  let(:file) { generic_file.files.build }
15
- let(:pcdm_thumbnail_uri) { ::RDF::URI("http://pcdm.org/ThumbnailImage") }
15
+ let(:pcdm_thumbnail_uri) { ::RDF::URI("http://pcdm.org/use#ThumbnailImage") }
16
16
 
17
17
  before do
18
18
  generic_file.files = [file]
19
- generic_file.save
20
19
  end
21
20
 
22
21
  describe "#thumbnail" do
23
22
 
24
23
  context "when a thumbnail is present" do
25
24
  before do
26
- generic_file.thumbnail.content = "thumbnail"
25
+ original_file = generic_file.build_thumbnail
26
+ original_file.content = "thumbnail"
27
27
  end
28
28
  subject { generic_file.thumbnail }
29
29
  it "can be saved without errors" do
@@ -33,13 +33,13 @@ describe Hydra::Works::GenericFile::ContainedFiles do
33
33
  expect(subject.content).to eql "thumbnail"
34
34
  end
35
35
  it "retains origin pcdm.File RDF type" do
36
- expect(subject.metadata_node.type).to include( ::RDF::URI("http://pcdm.org/ThumbnailImage") )
36
+ expect(subject.metadata_node.type).to include( ::RDF::URI("http://pcdm.org/use#ThumbnailImage") )
37
37
  expect(subject.metadata_node.type).to include(RDFVocabularies::PCDMTerms.File)
38
38
  end
39
39
  end
40
40
 
41
- context "when no thumbnail is present" do
42
- subject { generic_file.thumbnail }
41
+ context "when building new thumbnail" do
42
+ subject { generic_file.build_thumbnail }
43
43
  it "initializes an unsaved File object with Thumbnail type" do
44
44
  expect(subject).to be_new_record
45
45
  expect(subject.metadata_node.type).to include(pcdm_thumbnail_uri)
@@ -53,27 +53,29 @@ describe Hydra::Works::GenericFile::ContainedFiles do
53
53
 
54
54
  context "when an original file is present" do
55
55
  before do
56
- generic_file.original_file.content = "original_file"
56
+ original_file = generic_file.build_original_file
57
+ original_file.content = "original_file"
57
58
  end
58
59
  subject { generic_file.original_file }
59
60
 
60
61
  it "can be saved without errors" do
61
62
  expect(subject.save).to be_truthy
62
63
  end
63
- it "retrieves content of the original_file" do
64
+ it "retrieves content of the original_file as a PCDM File" do
64
65
  expect(subject.content).to eql "original_file"
66
+ expect(subject).to be_instance_of Hydra::PCDM::File
65
67
  end
66
68
  it "retains origin pcdm.File RDF type" do
67
- expect(subject.metadata_node.type).to include(::RDF::URI("http://pcdm.org/OriginalFile") )
69
+ expect(subject.metadata_node.type).to include(::RDF::URI("http://pcdm.org/use#OriginalFile") )
68
70
  expect(generic_file.original_file.metadata_node.type).to include(RDFVocabularies::PCDMTerms.File)
69
71
  end
70
72
  end
71
73
 
72
- context "when no original file is present" do
73
- subject { generic_file.original_file }
74
+ context "when building original file" do
75
+ subject { generic_file.build_original_file }
74
76
  it "initializes an unsaved File object with OrignalFile type" do
75
77
  expect(subject).to be_new_record
76
- expect(subject.metadata_node.type).to include(::RDF::URI("http://pcdm.org/OriginalFile") )
78
+ expect(subject.metadata_node.type).to include(::RDF::URI("http://pcdm.org/use#OriginalFile") )
77
79
  expect(subject.metadata_node.type).to include(RDFVocabularies::PCDMTerms.File)
78
80
  end
79
81
  end
@@ -84,7 +86,8 @@ describe Hydra::Works::GenericFile::ContainedFiles do
84
86
 
85
87
  context "when extracted text is present" do
86
88
  before do
87
- generic_file.extracted_text.content = "extracted_text"
89
+ extracted_text = generic_file.build_extracted_text
90
+ extracted_text.content = "extracted_text"
88
91
  end
89
92
  subject { generic_file.extracted_text }
90
93
  it "can be saved without errors" do
@@ -94,16 +97,16 @@ describe Hydra::Works::GenericFile::ContainedFiles do
94
97
  expect(subject.content).to eql "extracted_text"
95
98
  end
96
99
  it "retains origin pcdm.File RDF type" do
97
- expect(subject.metadata_node.type).to include(::RDF::URI("http://pcdm.org/ExtractedText") )
100
+ expect(subject.metadata_node.type).to include(::RDF::URI("http://pcdm.org/use#ExtractedText") )
98
101
  expect(subject.metadata_node.type).to include(RDFVocabularies::PCDMTerms.File)
99
102
  end
100
103
  end
101
104
 
102
- context "when no extracted text is present" do
103
- subject { generic_file.extracted_text }
105
+ context "when building new extracted text object" do
106
+ subject { generic_file.build_extracted_text }
104
107
  it "initializes an unsaved File object with ExtractedText type" do
105
108
  expect(subject).to be_new_record
106
- expect(subject.metadata_node.type).to include(::RDF::URI("http://pcdm.org/ExtractedText") )
109
+ expect(subject.metadata_node.type).to include(::RDF::URI("http://pcdm.org/use#ExtractedText") )
107
110
  expect(subject.metadata_node.type).to include(RDFVocabularies::PCDMTerms.File)
108
111
  end
109
112
  end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::GenericFile::MimeTypes do
4
+
5
+ subject { Hydra::Works::GenericFile::Base.new }
6
+
7
+ describe "#pdf?" do
8
+ before do
9
+ allow(subject).to receive(:mime_type).and_return('application/pdf')
10
+ end
11
+ it "should be true" do
12
+ expect(subject.pdf?).to be true
13
+ end
14
+ end
15
+
16
+ describe "#image?" do
17
+ before do
18
+ allow(subject).to receive(:mime_type).and_return('image/jpeg')
19
+ end
20
+ it "should be true" do
21
+ expect(subject.image?).to be true
22
+ end
23
+ end
24
+
25
+ describe "#video?" do
26
+ before do
27
+ allow(subject).to receive(:mime_type).and_return('video/mp4')
28
+ end
29
+ it "should be true" do
30
+ expect(subject.video?).to be true
31
+ end
32
+ end
33
+
34
+ describe "#audio?" do
35
+ before do
36
+ allow(subject).to receive(:mime_type).and_return('audio/mp3')
37
+ end
38
+ it "should be true" do
39
+ expect(subject.audio?).to be true
40
+ end
41
+ end
42
+
43
+ describe "#office_document?" do
44
+ before do
45
+ allow(subject).to receive(:mime_type).and_return('application/msword')
46
+ end
47
+ it "should be true" do
48
+ expect(subject.office_document?).to be true
49
+ end
50
+ end
51
+
52
+ describe "#collection?" do
53
+ it "should be false" do
54
+ expect(subject.collection?).to be false
55
+ end
56
+ end
57
+
58
+ describe "#file_format?" do
59
+ it "should handle both mime and format_label" do
60
+ allow(subject).to receive(:mime_type).and_return('image/png')
61
+ allow(subject).to receive(:format_label).and_return(['Portable Network Graphics'])
62
+ expect(subject.file_format).to eq 'png (Portable Network Graphics)'
63
+ end
64
+ it "should handle just mime type" do
65
+ allow(subject).to receive(:mime_type).and_return('image/png')
66
+ allow(subject).to receive(:format_label).and_return([])
67
+ expect(subject.file_format).to eq 'png'
68
+ end
69
+ it "should handle just format_label" do
70
+ allow(subject).to receive(:mime_type).and_return('')
71
+ allow(subject).to receive(:format_label).and_return(['Portable Network Graphics'])
72
+ expect(subject.file_format).to eq ['Portable Network Graphics']
73
+ end
74
+ end
75
+
76
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::GenericFile::VersionedContent do
4
+ let(:generic_file) { Hydra::Works::GenericFile::Base.new }
5
+ before do
6
+ Hydra::Works::UploadFileToGenericFile.call(generic_file, File.open(File.join(fixture_path, "sample-file.pdf")))
7
+ Hydra::Works::UploadFileToGenericFile.call(generic_file, File.open(File.join(fixture_path, "updated-file.txt")))
8
+ end
9
+
10
+ describe "content_versions" do
11
+ subject {generic_file.content_versions}
12
+ it "lists all of the versions of original_file" do
13
+ expect(subject.count).to eq(2)
14
+ expect(subject.map { |v| v.uri }).to eq(generic_file.original_file.versions.all.map { |v| v.uri })
15
+ end
16
+ end
17
+
18
+ describe "latest_content_version" do
19
+ subject { generic_file.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(generic_file.original_file.versions.last.uri)
23
+ expect(subject.label).to eq(generic_file.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(generic_file.current_content_version_uri).to eq(generic_file.original_file.versions.last.uri)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Works::GenericFile::VirusCheck do
4
+ before do
5
+ class FileWithVirusCheck < ActiveFedora::Base
6
+ include Hydra::Works::GenericFileBehavior
7
+ include Hydra::Works::GenericFile::VirusCheck
8
+ end
9
+ class ClamAV
10
+ def self.instance; @instance ||= ClamAV.new; end
11
+ def scanfile(path); puts "scanfile: #{path}"; end
12
+ end
13
+ end
14
+ after do
15
+ Object.send(:remove_const, :ClamAV)
16
+ Object.send(:remove_const, :FileWithVirusCheck)
17
+ end
18
+
19
+ subject { FileWithVirusCheck.new }
20
+ let(:file) { Hydra::PCDM::File.new File.join(fixture_path, 'sample-file.pdf') }
21
+
22
+ before do
23
+ allow(subject).to receive(:original_file) { file }
24
+ allow(subject).to receive(:warn) # suppress virus warning messages
25
+ end
26
+
27
+ context 'with an infected file' do
28
+
29
+ before do
30
+ expect(ClamAV.instance).to receive(:scanfile).and_return(1)
31
+ end
32
+ it "should fail to save" do
33
+ expect(subject.save).to eq false
34
+ end
35
+ it "should fail to validate" do
36
+ expect(subject.validate).to eq false
37
+ end
38
+ end
39
+
40
+ context "with a clean file" do
41
+ before do
42
+ expect(ClamAV.instance).to receive(:scanfile).and_return(0)
43
+ end
44
+
45
+ it "should not detect viruses" do
46
+ expect(subject.detect_viruses).to eq true
47
+ end
48
+ end
49
+
50
+ end
@@ -7,6 +7,6 @@ describe Hydra::Works::GenericFileBehavior do
7
7
  subject { IncludesGenericFileBehavior.new }
8
8
 
9
9
  it "ensures that objects will be recognized as generic_files" do
10
- expect(Hydra::Works.generic_file? subject).to be_truthy
10
+ expect(subject).to be_works_generic_file
11
11
  end
12
12
  end
@@ -2,28 +2,17 @@ require 'spec_helper'
2
2
 
3
3
  describe Hydra::Works::GenericFile::Base do
4
4
 
5
- let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
6
- let(:generic_file2) { Hydra::Works::GenericFile::Base.create }
7
- let(:generic_file3) { Hydra::Works::GenericFile::Base.create }
8
-
9
- describe '#generic_files=' do
10
- it 'should aggregate generic_files' do
11
- generic_file1.generic_files = [generic_file2, generic_file3]
12
- generic_file1.save
13
- expect(generic_file1.generic_files).to eq [generic_file2, generic_file3]
14
- end
15
- end
5
+ let(:generic_file1) { Hydra::Works::GenericFile::Base.new }
16
6
 
17
7
  describe 'Related objects' do
18
- let(:object1) { Hydra::PCDM::Object.create }
8
+ let(:object1) { Hydra::PCDM::Object.new }
19
9
 
20
10
  before do
21
11
  generic_file1.related_objects = [object1]
22
- generic_file1.save
23
12
  end
24
13
 
25
14
  it 'persists' do
26
- expect(generic_file1.reload.related_objects).to eq [object1]
15
+ expect(generic_file1.related_objects).to eq [object1]
27
16
  end
28
17
  end
29
18
 
@@ -42,4 +31,202 @@ describe Hydra::Works::GenericFile::Base do
42
31
 
43
32
  it { is_expected.to eq [file1, file2] }
44
33
  end
34
+
35
+ describe 'add related object' do
36
+
37
+ let(:subject) { Hydra::Works::GenericFile::Base.new }
38
+
39
+ describe 'begin test' do
40
+
41
+ context 'with acceptable related objects' do
42
+ let(:object1) { Hydra::PCDM::Object.create }
43
+ let(:object2) { Hydra::PCDM::Object.new }
44
+ let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
45
+ let(:generic_work2) { Hydra::Works::GenericWork::Base.new }
46
+ let(:generic_file1) { Hydra::Works::GenericFile::Base.create }
47
+
48
+ it 'should add various types of related objects to generic_file' do
49
+ subject.related_objects << generic_work1
50
+ subject.related_objects << generic_file1
51
+ subject.related_objects << object1
52
+ subject.save
53
+ subject.reload
54
+ related_objects = subject.related_objects
55
+ expect( related_objects.include? generic_work1 ).to be true
56
+ expect( related_objects.include? generic_file1 ).to be true
57
+ expect( related_objects.include? object1 ).to be true
58
+ expect( related_objects.size ).to eq 3
59
+ end
60
+
61
+ context 'with files and generic_files' do
62
+ let(:file1) { subject.files.build }
63
+ let(:file2) { subject.files.build }
64
+
65
+ before do
66
+ subject.save
67
+ file1.content = "I'm a file"
68
+ file2.content = "I am too"
69
+ subject.related_objects << object1
70
+ end
71
+
72
+ it 'should add a related object to a generic_file with files and generic_files' do
73
+ subject.related_objects << object2
74
+ subject.save
75
+ subject.reload
76
+ related_objects = subject.related_objects
77
+ expect( related_objects.include? object1 ).to be true
78
+ expect( related_objects.include? object2 ).to be true
79
+ expect( related_objects.size ).to eq 2
80
+ end
81
+ end
82
+ end
83
+
84
+ context 'with unacceptable child related objects' do
85
+ let(:collection1) { Hydra::Works::Collection.new }
86
+ let(:pcdm_collection1) { Hydra::PCDM::Collection.new }
87
+ let(:pcdm_file1) { Hydra::PCDM::File.new }
88
+ let(:non_PCDM_object) { "I'm not a PCDM object" }
89
+ let(:af_base_object) { ActiveFedora::Base.new }
90
+
91
+ let(:error_message) { 'child_related_object must be a pcdm object' }
92
+
93
+ it 'should NOT aggregate Hydra::Works::Collection in related objects aggregation' do
94
+ expect{ subject.related_objects << collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::Works::Collection:.*> is not a PCDM object./)
95
+ end
96
+
97
+ it 'should NOT aggregate Hydra::PCDM::Collections in related objects aggregation' do
98
+ expect{ subject.related_objects << pcdm_collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::PCDM::Collection:.*> is not a PCDM object./)
99
+ end
100
+
101
+ it 'should NOT aggregate Hydra::PCDM::Files in related objects aggregation' do
102
+ expect{ subject.related_objects << pcdm_file1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got Hydra::PCDM::File.*/)
103
+ end
104
+
105
+ it 'should NOT aggregate non-PCDM objects in related objects aggregation' do
106
+ expect{ subject.related_objects << non_PCDM_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got String.*/)
107
+ end
108
+
109
+ it 'should NOT aggregate AF::Base objects in related objects aggregation' do
110
+ expect{ subject.related_objects << af_base_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* is not a PCDM object./)
111
+
112
+ end
113
+ end
114
+
115
+ context 'with invalid behaviors' do
116
+ let(:object1) { Hydra::PCDM::Object.new }
117
+ let(:object2) { Hydra::PCDM::Object.new }
118
+
119
+ it 'should NOT allow related objects to repeat' do
120
+ skip 'skipping this test because issue pcdm#92 needs to be addressed' do
121
+ subject.related_objects << object1
122
+ subject.related_objects << object2
123
+ subject.related_objects << object1
124
+ subject.save
125
+ subject.reload
126
+ related_objects = subject.related_objects
127
+ expect( related_objects.include? object1 ).to be true
128
+ expect( related_objects.include? object2 ).to be true
129
+ expect( related_objects.size ).to eq 2
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+
136
+ describe 'get related objects from generic file' do
137
+
138
+ subject { Hydra::Works::GenericFile::Base.new }
139
+
140
+ let(:object1) { Hydra::PCDM::Object.new }
141
+ let(:object2) { Hydra::PCDM::Object.new }
142
+
143
+ let(:generic_work1) { Hydra::Works::GenericWork::Base.new }
144
+ let(:generic_file1) { Hydra::Works::GenericFile::Base.new }
145
+
146
+ context 'with generic files' do
147
+ it 'should return empty array when only generic files are aggregated' do
148
+ expect( related_objects = subject.related_objects ).to eq []
149
+ end
150
+
151
+ it 'should return related objects' do
152
+ subject.related_objects << object2
153
+ expect( related_objects = subject.related_objects ).to eq [object2]
154
+ end
155
+
156
+ it 'should return related objects of various types' do
157
+ subject.related_objects << generic_work1
158
+ subject.related_objects << generic_file1
159
+ subject.related_objects << object1
160
+ subject.save
161
+ subject.reload
162
+ related_objects = subject.related_objects
163
+ expect( related_objects.include? object1 ).to be true
164
+ expect( related_objects.include? generic_work1 ).to be true
165
+ expect( related_objects.include? generic_file1 ).to be true
166
+ expect( related_objects.size ).to eq 3
167
+ end
168
+ end
169
+ end
170
+
171
+ describe 'remove related object from related object' do
172
+
173
+ subject { Hydra::Works::GenericFile::Base.new }
174
+
175
+ let(:related_object1) { Hydra::PCDM::Object.new }
176
+ let(:related_work2) { Hydra::Works::GenericWork::Base.new }
177
+ let(:related_file3) { Hydra::Works::GenericFile::Base.new }
178
+ let(:related_object4) { Hydra::PCDM::Object.new }
179
+ let(:related_work5) { Hydra::Works::GenericWork::Base.new }
180
+
181
+ let(:generic_file1) { Hydra::Works::GenericFile::Base.new }
182
+ let(:generic_file2) { Hydra::Works::GenericFile::Base.new }
183
+
184
+ context 'when multiple related objects' do
185
+ before do
186
+ subject.related_objects << related_object1
187
+ subject.related_objects << related_work2
188
+ subject.related_objects << related_file3
189
+ subject.related_objects << related_object4
190
+ subject.related_objects << related_work5
191
+ expect( related_ojects = subject.related_objects ).to eq [related_object1,related_work2,related_file3,related_object4,related_work5]
192
+
193
+ end
194
+
195
+ it 'should remove first related object' do
196
+ expect( subject.related_objects.delete related_object1 ).to eq [related_object1]
197
+ expect( related_objects = subject.related_objects).to eq [related_work2,related_file3,related_object4,related_work5]
198
+ end
199
+
200
+ it 'should remove last related object' do
201
+ expect( subject.related_objects.delete related_work5 ).to eq [related_work5]
202
+ expect( related_objects = subject.related_objects ).to eq [related_object1,related_work2,related_file3,related_object4]
203
+ end
204
+
205
+ it 'should remove middle related object' do
206
+ expect( subject.related_objects.delete related_file3 ).to eq [related_file3]
207
+ expect( related_objects = subject.related_objects ).to eq [related_object1,related_work2,related_object4,related_work5]
208
+ end
209
+ end
210
+
211
+ #Assuming this context not needed because unacceptable related objects
212
+ #can't be added.
213
+ #context 'with unacceptable related object' do
214
+
215
+ end
216
+
217
+ describe "should have parent work accessors" do
218
+ let(:generic_work1) { Hydra::Works::GenericWork::Base.create }
219
+ before do
220
+ generic_work1.generic_files << generic_file1
221
+ end
222
+
223
+ it 'should have parents' do
224
+ expect(generic_file1.parents).to eq [generic_work1]
225
+ end
226
+ it 'should have a parent work' do
227
+ expect(generic_file1.generic_works).to eq [generic_work1]
228
+ end
229
+ end
230
+
231
+
45
232
  end