hydra-works 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dccbd98c61c1d4f18a6638c637c52adb8414c39b
4
- data.tar.gz: 898863dcf45f52862fddebd401c31d31a7384ee2
3
+ metadata.gz: fc76ae65e10c75f045b933e2b8de237292821b2d
4
+ data.tar.gz: 20c76bd9fb5e0002a74f279efa932ab0685618e5
5
5
  SHA512:
6
- metadata.gz: 5b895ae5c78efa14c537173445f3d8b70304e4ff5462912839ffae55bb96162c867066b15c55d0315cd7de2146da6bcf911f27c3a7b2502fd0228a05bf532d80
7
- data.tar.gz: 526f699b440f37454b043a1e8127c93e42ff31a404ec9c487f0eeb15471feeda07abaf02aea2382e063360a25c06962a9d3bef79bc61107573ac6d8b74717838
6
+ metadata.gz: 7e97285baab41bb01e5ab16541057e6a50fee7630eb48daeb92eb8d7d64ef3cfd50878520533e1ee7e34fe6b5f74b8ad015b7756a99661aa9cd234bdbc0401e6
7
+ data.tar.gz: 35363e268e45beaf3331bd7976ad99b8a269850e8a51ef4c00380f98b6f9b8e9526fc3244a59ceb8f79fc0a51b9d36e3ebbe13bb3853f461d0396370a035b911
@@ -28,16 +28,6 @@ module Hydra::Works
28
28
  false
29
29
  end
30
30
 
31
- def file_format
32
- if mime_type.present? && format_label.present?
33
- "#{mime_type.split('/').last} (#{format_label.join(', ')})"
34
- elsif mime_type.present?
35
- mime_type.split('/').last
36
- elsif format_label.present?
37
- format_label
38
- end
39
- end
40
-
41
31
  module ClassMethods
42
32
  def image_mime_types
43
33
  ['image/png', 'image/jpeg', 'image/jpg', 'image/jp2', 'image/bmp', 'image/gif', 'image/tiff']
@@ -19,6 +19,8 @@ module Hydra::Works
19
19
  include Hydra::Works::Derivatives
20
20
  include Hydra::Works::MimeTypes
21
21
  include Hydra::Works::VersionedContent
22
+
23
+ before_destroy :remove_from_works
22
24
  end
23
25
 
24
26
  # @return [Boolean] whether this instance is a Hydra::Works Collection.
@@ -39,5 +41,15 @@ module Hydra::Works
39
41
  def in_works
40
42
  ordered_by.select { |parent| parent.class.included_modules.include?(Hydra::Works::WorkBehavior) }.to_a
41
43
  end
44
+
45
+ private
46
+
47
+ def remove_from_works
48
+ in_works.each do |parent|
49
+ parent.ordered_members.delete(self) # Delete the list node
50
+ parent.members.delete(self) # Delete the indirect container Proxy
51
+ parent.save! # record the changes to the ordered members
52
+ end
53
+ end
42
54
  end
43
55
  end
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module Works
3
- VERSION = '0.5.0'
3
+ VERSION = '0.6.0'
4
4
  end
5
5
  end
@@ -1,229 +1,87 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Hydra::Works::Collection do
4
- subject { described_class.new }
4
+ let(:collection) { described_class.new }
5
5
 
6
6
  let(:collection1) { described_class.new }
7
- let(:collection2) { described_class.new }
8
- let(:collection3) { described_class.new }
9
- let(:collection4) { described_class.new }
10
-
11
7
  let(:generic_work1) { Hydra::Works::GenericWork.new }
12
- let(:generic_work2) { Hydra::Works::GenericWork.new }
13
- let(:generic_work3) { Hydra::Works::GenericWork.new }
14
- let(:generic_work4) { Hydra::Works::GenericWork.new }
15
8
 
16
9
  describe '#collections' do
17
10
  it 'returns empty array when only works are aggregated' do
18
- subject.ordered_members << generic_work1
19
- subject.ordered_members << generic_work2
20
- expect(subject.collections).to eq []
11
+ collection.ordered_members << generic_work1
12
+ expect(collection.collections).to eq []
21
13
  end
22
14
 
23
15
  context 'with other collections & works' do
16
+ let(:collection2) { described_class.new }
24
17
  before do
25
- subject.ordered_members << collection1
26
- subject.ordered_members << collection2
27
- subject.ordered_members << generic_work1
28
- subject.ordered_members << generic_work2
18
+ collection.ordered_members << collection1
19
+ collection.ordered_members << collection2
20
+ collection.ordered_members << generic_work1
29
21
  end
30
22
 
31
23
  it 'returns only collections' do
32
- expect(subject.ordered_collections).to eq [collection1, collection2]
24
+ expect(collection.ordered_collections).to eq [collection1, collection2]
33
25
  end
34
26
  end
35
27
  end
36
28
 
37
29
  describe '#works' do
38
- it 'returns empty array when only collections are aggregated' do
39
- subject.ordered_members << collection1
40
- subject.ordered_members << collection2
41
- expect(subject.ordered_works). to eq []
30
+ subject { collection.works }
31
+ context "when only collections are aggregated" do
32
+ it 'returns empty array when only collections are aggregated' do
33
+ collection.ordered_members << collection1
34
+ expect(subject).to eq []
35
+ end
42
36
  end
43
37
 
44
38
  context 'with collections and generic works' do
39
+ let(:generic_work2) { Hydra::Works::GenericWork.new }
45
40
  before do
46
- subject.ordered_members << collection1
47
- subject.ordered_members << collection2
48
- subject.ordered_members << generic_work1
49
- subject.ordered_members << generic_work2
41
+ collection.ordered_members << collection1
42
+ collection.ordered_members << generic_work1
43
+ collection.ordered_members << generic_work2
50
44
  end
51
45
 
52
46
  it 'returns only generic works' do
53
- expect(subject.ordered_works). to eq [generic_work1, generic_work2]
47
+ expect(subject).to eq [generic_work1, generic_work2]
54
48
  end
55
49
  end
56
50
  end
57
51
 
58
- describe "#ordered_work_ids" do
59
- it "returns IDs of ordered works" do
60
- subject.ordered_members << generic_work1
61
- expect(subject.ordered_work_ids).to eq [generic_work1.id]
52
+ describe '#ordered_works' do
53
+ subject { collection.ordered_works }
54
+ context "when only collections are aggregated" do
55
+ it 'returns empty array when only collections are aggregated' do
56
+ collection.ordered_members << collection1
57
+ expect(subject).to eq []
58
+ end
62
59
  end
63
- end
64
-
65
- describe '#related_objects' do
66
- let(:generic_file1) { Hydra::Works::FileSet.new }
67
- let(:object1) { Hydra::PCDM::Object.new }
68
- let(:object2) { Hydra::PCDM::Object.new }
69
60
 
70
61
  context 'with collections and generic works' do
62
+ let(:generic_work2) { Hydra::Works::GenericWork.new }
71
63
  before do
72
- subject.ordered_members << collection1
73
- subject.ordered_members << collection2
74
- subject.ordered_members << generic_work1
75
- end
76
-
77
- it 'returns empty array when only collections and generic works are aggregated' do
78
- expect(subject.related_objects).to eq []
64
+ collection.ordered_members << collection1
65
+ collection.ordered_members << generic_work1
66
+ collection.ordered_members << generic_work2
79
67
  end
80
68
 
81
- it 'returns only related objects' do
82
- subject.related_objects << object2
83
- expect(subject.related_objects).to eq [object2]
84
- end
85
-
86
- it 'returns related objects of various types' do
87
- subject.related_objects << generic_work2
88
- subject.related_objects << generic_file1
89
- subject.related_objects << object1
90
- subject.save
91
- subject.reload
92
- expect(subject.related_objects.include? object1).to be true
93
- expect(subject.related_objects.include? generic_work2).to be true
94
- expect(subject.related_objects.include? generic_file1).to be true
95
- expect(subject.related_objects.size).to eq 3
96
- end
97
- end
98
- end
99
-
100
- describe '#related_objects <<' do
101
- context 'with acceptable related objects' do
102
- let(:object1) { Hydra::PCDM::Object.new }
103
- let(:object2) { Hydra::PCDM::Object.new }
104
- let(:generic_file1) { Hydra::Works::FileSet.new }
105
-
106
- it 'adds various types of related objects to collection' do
107
- subject.related_objects << generic_work1
108
- subject.related_objects << generic_file1
109
- subject.related_objects << object1
110
- subject.save
111
- subject.reload
112
- expect(subject.related_objects.include? generic_work1).to be true
113
- expect(subject.related_objects.include? generic_file1).to be true
114
- expect(subject.related_objects.include? object1).to be true
115
- expect(subject.related_objects.size).to eq 3
116
- end
117
-
118
- context 'with collections and works' do
119
- before do
120
- subject.ordered_members << collection1
121
- subject.ordered_members << collection2
122
- subject.ordered_members << generic_work1
123
- subject.ordered_members << generic_work2
124
- subject.related_objects << object1
125
- end
126
-
127
- it 'adds a related object to collection with collections and works' do
128
- subject.related_objects << object2
129
- subject.save
130
- subject.reload
131
- expect(subject.related_objects.include? object1).to be true
132
- expect(subject.related_objects.include? object2).to be true
133
- expect(subject.related_objects.size).to eq 2
134
- end
135
- end
136
- end
137
-
138
- context 'with unacceptable child related objects' do
139
- let(:pcdm_collection1) { Hydra::PCDM::Collection.new }
140
- let(:pcdm_file1) { Hydra::PCDM::File.new }
141
- let(:non_PCDM_object) { "I'm not a PCDM object" }
142
- let(:af_base_object) { ActiveFedora::Base.new }
143
-
144
- it 'does not aggregate Hydra::Works::Collection in related objects aggregation' do
145
- expect { subject.related_objects << collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::Works::Collection:.*> is not a PCDM object./)
146
- end
147
-
148
- it 'does not aggregate Hydra::PCDM::Collections in related objects aggregation' do
149
- expect { subject.related_objects << pcdm_collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::PCDM::Collection:.* is not a PCDM object./)
150
- end
151
-
152
- it 'does not aggregate Hydra::PCDM::Files in related objects aggregation' do
153
- expect { subject.related_objects << pcdm_file1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got Hydra::PCDM::File.*/)
154
- end
155
-
156
- it 'does not aggregate non-PCDM objects in related objects aggregation' do
157
- expect { subject.related_objects << non_PCDM_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got String.*/)
158
- end
159
-
160
- it 'does not aggregate AF::Base objects in related objects aggregation' do
161
- expect { subject.related_objects << af_base_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* is not a PCDM object./)
162
- end
163
- end
164
-
165
- context 'with invalid behaviors' do
166
- let(:object1) { Hydra::PCDM::Object.new }
167
- let(:object2) { Hydra::PCDM::Object.new }
168
-
169
- it 'does not allow related objects to repeat' do
170
- skip 'skipping this test because issue pcdm#92 needs to be addressed' do
171
- subject.related_objects << object1
172
- subject.related_objects << object2
173
- subject.related_objects << object1
174
- related_objects = subject.related_objects
175
- expect(related_objects.include? object1).to be true
176
- expect(related_objects.include? object2).to be true
177
- expect(related_objects.size).to eq 2
178
- end
69
+ it 'returns only generic works' do
70
+ expect(subject).to eq [generic_work1, generic_work2]
179
71
  end
180
72
  end
181
73
  end
182
74
 
183
- describe '#related_objects.delete' do
184
- let(:related_object1) { Hydra::PCDM::Object.new }
185
- let(:related_work2) { Hydra::Works::GenericWork.new }
186
- let(:related_file3) { Hydra::Works::FileSet.new }
187
- let(:related_object4) { Hydra::PCDM::Object.new }
188
- let(:related_work5) { Hydra::Works::GenericWork.new }
189
-
190
- context 'when multiple related objects' do
191
- before do
192
- subject.related_objects << related_object1
193
- subject.related_objects << related_work2
194
- subject.members << collection2
195
- subject.members << generic_work1
196
- subject.related_objects << related_file3
197
- subject.related_objects << related_object4
198
- subject.members << collection1
199
- subject.related_objects << related_work5
200
- expect(subject.related_objects).to eq [related_object1, related_work2, related_file3, related_object4, related_work5]
201
- end
202
-
203
- it 'removes first related object' do
204
- expect(subject.related_objects.delete related_object1).to eq [related_object1]
205
- expect(subject.related_objects).to eq [related_work2, related_file3, related_object4, related_work5]
206
- expect(subject.collections).to eq [collection2, collection1]
207
- expect(subject.works). to eq [generic_work1]
208
- end
209
-
210
- it 'removes last related object' do
211
- expect(subject.related_objects.delete related_work5).to eq [related_work5]
212
- expect(subject.related_objects).to eq [related_object1, related_work2, related_file3, related_object4]
213
- expect(subject.collections).to eq [collection2, collection1]
214
- expect(subject.works). to eq [generic_work1]
215
- end
216
-
217
- it 'removes middle related object' do
218
- expect(subject.related_objects.delete related_file3).to eq [related_file3]
219
- expect(subject.related_objects).to eq [related_object1, related_work2, related_object4, related_work5]
220
- expect(subject.collections).to eq [collection2, collection1]
221
- expect(subject.works). to eq [generic_work1]
222
- end
75
+ describe "#ordered_work_ids" do
76
+ subject { collection.ordered_work_ids }
77
+ it "returns IDs of ordered works" do
78
+ collection.ordered_members << generic_work1
79
+ expect(subject).to eq [generic_work1.id]
223
80
  end
224
81
  end
225
82
 
226
- describe 'Related objects' do
83
+ describe '#related_objects' do
84
+ subject { collection.related_objects }
227
85
  let(:object) { Hydra::PCDM::Object.new }
228
86
  let(:collection) { described_class.new }
229
87
 
@@ -231,22 +89,16 @@ describe Hydra::Works::Collection do
231
89
  collection.related_objects = [object]
232
90
  end
233
91
 
234
- it 'persists' do
235
- expect(collection.related_objects).to eq [object]
236
- end
92
+ it { is_expected.to eq [object] }
237
93
  end
238
94
 
239
- describe 'should have parent collection accessors' do
95
+ describe "#in_collections" do
240
96
  before do
241
- collection1.ordered_members << collection2
97
+ collection1.ordered_members << collection
242
98
  collection1.save
243
99
  end
244
100
 
245
- it 'has parents' do
246
- expect(collection2.member_of).to eq [collection1]
247
- end
248
- it 'has a parent collection' do
249
- expect(collection2.in_collections).to eq [collection1]
250
- end
101
+ subject { collection.in_collections }
102
+ it { is_expected.to eq [collection1] }
251
103
  end
252
104
  end
@@ -53,22 +53,4 @@ describe Hydra::Works::MimeTypes do
53
53
  expect(subject.collection?).to be false
54
54
  end
55
55
  end
56
-
57
- describe '#file_format?' do
58
- it 'handles both mime and format_label' do
59
- allow(subject).to receive(:mime_type).and_return('image/png')
60
- allow(subject).to receive(:format_label).and_return(['Portable Network Graphics'])
61
- expect(subject.file_format).to eq 'png (Portable Network Graphics)'
62
- end
63
- it 'handles just mime type' do
64
- allow(subject).to receive(:mime_type).and_return('image/png')
65
- allow(subject).to receive(:format_label).and_return([])
66
- expect(subject.file_format).to eq 'png'
67
- end
68
- it 'handles just format_label' do
69
- allow(subject).to receive(:mime_type).and_return('')
70
- allow(subject).to receive(:format_label).and_return(['Portable Network Graphics'])
71
- expect(subject.file_format).to eq ['Portable Network Graphics']
72
- end
73
- end
74
56
  end
@@ -1,223 +1,57 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Hydra::Works::FileSet do
4
- let(:generic_file1) { described_class.new }
4
+ let(:file_set) { described_class.new }
5
5
 
6
6
  describe 'Related objects' do
7
7
  let(:object1) { Hydra::PCDM::Object.new }
8
8
 
9
9
  before do
10
- generic_file1.related_objects = [object1]
10
+ file_set.related_objects = [object1]
11
11
  end
12
12
 
13
13
  it 'persists' do
14
- expect(generic_file1.related_objects).to eq [object1]
14
+ expect(file_set.related_objects).to eq [object1]
15
15
  end
16
16
  end
17
17
 
18
18
  describe '#files' do
19
- let(:object) { described_class.create }
20
- let(:file1) { object.files.build }
21
- let(:file2) { object.files.build }
19
+ let(:file1) { file_set.files.build }
20
+ let(:file2) { file_set.files.build }
22
21
 
23
22
  before do
23
+ file_set.save!
24
24
  file1.content = "I'm a file"
25
25
  file2.content = 'I am too'
26
- object.save!
26
+ file_set.save!
27
27
  end
28
28
 
29
- subject { described_class.find(object.id).files }
29
+ subject { described_class.find(file_set.id).files }
30
30
 
31
31
  it { is_expected.to eq [file1, file2] }
32
32
  end
33
33
 
34
- describe 'add related object' do
35
- let(:subject) { described_class.new }
36
-
37
- describe 'begin test' do
38
- context 'with acceptable related objects' do
39
- let(:object1) { Hydra::PCDM::Object.create }
40
- let(:object2) { Hydra::PCDM::Object.new }
41
- let(:generic_work1) { Hydra::Works::GenericWork.create }
42
- let(:generic_work2) { Hydra::Works::GenericWork.new }
43
- let(:generic_file1) { described_class.create }
44
-
45
- it 'adds various types of related objects to generic_file' do
46
- subject.related_objects << generic_work1
47
- subject.related_objects << generic_file1
48
- subject.related_objects << object1
49
- subject.save
50
- subject.reload
51
- related_objects = subject.related_objects
52
- expect(related_objects.include? generic_work1).to be true
53
- expect(related_objects.include? generic_file1).to be true
54
- expect(related_objects.include? object1).to be true
55
- expect(related_objects.size).to eq 3
56
- end
57
-
58
- context 'with files and generic_files' do
59
- let(:file1) { subject.files.build }
60
- let(:file2) { subject.files.build }
61
-
62
- before do
63
- subject.save
64
- file1.content = "I'm a file"
65
- file2.content = 'I am too'
66
- subject.related_objects << object1
67
- end
68
-
69
- it 'adds a related object to a generic_file with files and generic_files' do
70
- subject.related_objects << object2
71
- subject.save
72
- subject.reload
73
- related_objects = subject.related_objects
74
- expect(related_objects.include? object1).to be true
75
- expect(related_objects.include? object2).to be true
76
- expect(related_objects.size).to eq 2
77
- end
78
- end
79
- end
80
-
81
- context 'with unacceptable child related objects' do
82
- let(:collection1) { Hydra::Works::Collection.new }
83
- let(:pcdm_collection1) { Hydra::PCDM::Collection.new }
84
- let(:pcdm_file1) { Hydra::PCDM::File.new }
85
- let(:non_PCDM_object) { "I'm not a PCDM object" }
86
- let(:af_base_object) { ActiveFedora::Base.new }
87
-
88
- let(:error_message) { 'child_related_object must be a pcdm object' }
89
-
90
- it 'does not aggregate Hydra::Works::Collection in related objects aggregation' do
91
- expect { subject.related_objects << collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::Works::Collection:.*> is not a PCDM object./)
92
- end
93
-
94
- it 'does not aggregate Hydra::PCDM::Collections in related objects aggregation' do
95
- expect { subject.related_objects << pcdm_collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::PCDM::Collection:.*> is not a PCDM object./)
96
- end
97
-
98
- it 'does not aggregate Hydra::PCDM::Files in related objects aggregation' do
99
- expect { subject.related_objects << pcdm_file1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got Hydra::PCDM::File.*/)
100
- end
101
-
102
- it 'does not aggregate non-PCDM objects in related objects aggregation' do
103
- expect { subject.related_objects << non_PCDM_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got String.*/)
104
- end
105
-
106
- it 'does not aggregate AF::Base objects in related objects aggregation' do
107
- expect { subject.related_objects << af_base_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* is not a PCDM object./)
108
- end
109
- end
110
-
111
- context 'with invalid behaviors' do
112
- let(:object1) { Hydra::PCDM::Object.new }
113
- let(:object2) { Hydra::PCDM::Object.new }
114
-
115
- it 'does not allow related objects to repeat' do
116
- skip 'skipping this test because issue pcdm#92 needs to be addressed' do
117
- subject.related_objects << object1
118
- subject.related_objects << object2
119
- subject.related_objects << object1
120
- subject.save
121
- subject.reload
122
- related_objects = subject.related_objects
123
- expect(related_objects.include? object1).to be true
124
- expect(related_objects.include? object2).to be true
125
- expect(related_objects.size).to eq 2
126
- end
127
- end
128
- end
129
- end
130
- end
131
-
132
- describe 'get related objects from generic file' do
133
- subject { described_class.new }
134
-
135
- let(:object1) { Hydra::PCDM::Object.new }
136
- let(:object2) { Hydra::PCDM::Object.new }
137
-
138
- let(:generic_work1) { Hydra::Works::GenericWork.new }
139
- let(:generic_file1) { described_class.new }
140
-
141
- context 'with generic files' do
142
- it 'returns empty array when only generic files are aggregated' do
143
- expect(subject.related_objects).to eq []
144
- end
145
-
146
- it 'returns related objects' do
147
- subject.related_objects << object2
148
- expect(subject.related_objects).to eq [object2]
149
- end
150
-
151
- it 'returns related objects of various types' do
152
- subject.related_objects << generic_work1
153
- subject.related_objects << generic_file1
154
- subject.related_objects << object1
155
- subject.save
156
- subject.reload
157
- related_objects = subject.related_objects
158
- expect(related_objects.include? object1).to be true
159
- expect(related_objects.include? generic_work1).to be true
160
- expect(related_objects.include? generic_file1).to be true
161
- expect(related_objects.size).to eq 3
162
- end
163
- end
164
- end
165
-
166
- describe 'remove related object from related object' do
167
- subject { described_class.new }
168
-
169
- let(:related_object1) { Hydra::PCDM::Object.new }
170
- let(:related_work2) { Hydra::Works::GenericWork.new }
171
- let(:related_file3) { described_class.new }
172
- let(:related_object4) { Hydra::PCDM::Object.new }
173
- let(:related_work5) { Hydra::Works::GenericWork.new }
174
-
175
- let(:generic_file1) { described_class.new }
176
- let(:generic_file2) { described_class.new }
177
-
178
- context 'when multiple related objects' do
179
- before do
180
- subject.related_objects << related_object1
181
- subject.related_objects << related_work2
182
- subject.related_objects << related_file3
183
- subject.related_objects << related_object4
184
- subject.related_objects << related_work5
185
- expect(subject.related_objects).to eq [related_object1, related_work2, related_file3, related_object4, related_work5]
186
- end
187
-
188
- it 'removes first related object' do
189
- expect(subject.related_objects.delete related_object1).to eq [related_object1]
190
- expect(subject.related_objects).to eq [related_work2, related_file3, related_object4, related_work5]
191
- end
192
-
193
- it 'removes last related object' do
194
- expect(subject.related_objects.delete related_work5).to eq [related_work5]
195
- expect(subject.related_objects).to eq [related_object1, related_work2, related_file3, related_object4]
196
- end
197
-
198
- it 'removes middle related object' do
199
- expect(subject.related_objects.delete related_file3).to eq [related_file3]
200
- expect(subject.related_objects).to eq [related_object1, related_work2, related_object4, related_work5]
201
- end
34
+ describe '#in_works' do
35
+ subject { file_set.in_works }
36
+ let(:generic_work) { Hydra::Works::GenericWork.create }
37
+ before do
38
+ generic_work.ordered_members << file_set
39
+ generic_work.save
202
40
  end
203
41
 
204
- # Assuming this context not needed because unacceptable related objects
205
- # can't be added.
206
- # context 'with unacceptable related object' do
42
+ it { is_expected.to eq [generic_work] }
207
43
  end
208
44
 
209
- describe 'should have parent work accessors' do
210
- let(:generic_work1) { Hydra::Works::GenericWork.create }
45
+ describe '#destroy' do
46
+ let(:generic_work) { Hydra::Works::GenericWork.create }
211
47
  before do
212
- generic_work1.ordered_members << generic_file1
213
- generic_work1.save
48
+ generic_work.ordered_members << file_set
49
+ generic_work.save
214
50
  end
215
51
 
216
- it 'has parents' do
217
- expect(generic_file1.member_of).to eq [generic_work1]
218
- end
219
- it 'has a parent work' do
220
- expect(generic_file1.in_works).to eq [generic_work1]
52
+ it "Removes the proxy, the list_node and the FileSet" do
53
+ expect { file_set.destroy }.to change { ActiveFedora::Aggregation::Proxy.count }.by(-1)
54
+ .and change { generic_work.reload.ordered_member_proxies.to_a.length }.by(-1)
221
55
  end
222
56
  end
223
57
  end
@@ -207,153 +207,6 @@ describe Hydra::Works::GenericWork do
207
207
  end
208
208
  end
209
209
 
210
- describe '#related_objects' do
211
- context 'with acceptable related objects' do
212
- it 'adds various types of related objects to generic_work' do
213
- subject.related_objects << generic_work1
214
- subject.related_objects << file_set1
215
- subject.related_objects << object1
216
- subject.save
217
- subject.reload
218
- expect(subject.related_objects.include? generic_work1).to be true
219
- expect(subject.related_objects.include? file_set1).to be true
220
- expect(subject.related_objects.include? object1).to be true
221
- expect(subject.related_objects.size).to eq 3
222
- end
223
-
224
- context 'with works and file_sets' do
225
- before do
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
230
- subject.related_objects << object1
231
- end
232
-
233
- it 'adds a related object to file_set with works and file_sets' do
234
- subject.related_objects << object2
235
- subject.save
236
- subject.reload
237
- expect(subject.related_objects.include? object1).to be true
238
- expect(subject.related_objects.include? object2).to be true
239
- expect(subject.related_objects.size).to eq 2
240
- end
241
- end
242
- end
243
-
244
- context 'with unacceptable child related objects' do
245
- let(:collection1) { Hydra::Works::Collection.new }
246
- let(:pcdm_collection1) { Hydra::PCDM::Collection.new }
247
- let(:pcdm_file1) { Hydra::PCDM::File.new }
248
- let(:non_PCDM_object) { "I'm not a PCDM object" }
249
- let(:af_base_object) { ActiveFedora::Base.new }
250
-
251
- let(:error_message) { 'child_related_object must be a pcdm object' }
252
-
253
- it 'does not aggregate Hydra::Works::Collection in related objects aggregation' do
254
- expect { subject.related_objects << collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::Works::Collection:.*> is not a PCDM object./)
255
- end
256
-
257
- it 'does not aggregate Hydra::PCDM::Collections in related objects aggregation' do
258
- expect { subject.related_objects << pcdm_collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::PCDM::Collection:.*> is not a PCDM object./)
259
- end
260
-
261
- it 'does not aggregate Hydra::PCDM::Files in related objects aggregation' do
262
- expect { subject.related_objects << pcdm_file1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got Hydra::PCDM::File.*/)
263
- end
264
-
265
- it 'does not aggregate non-PCDM objects in related objects aggregation' do
266
- expect { subject.related_objects << non_PCDM_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got String.*/)
267
- end
268
-
269
- it 'does not aggregate AF::Base objects in related objects aggregation' do
270
- expect { subject.related_objects << af_base_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base:.*> is not a PCDM object./)
271
- end
272
- end
273
-
274
- context 'with invalid bahaviors' do
275
- it 'does not allow related objects to repeat' do
276
- skip 'skipping this test because issue pcdm#92 needs to be addressed' do
277
- subject.related_objects << object1
278
- subject.related_objects << object2
279
- subject.related_objects << object1
280
- expect(subject.related_objects.include? object1).to be true
281
- expect(subject.related_objects.include? object2).to be true
282
- expect(subject.related_objects.size).to eq 2
283
- end
284
- end
285
- end
286
- end
287
-
288
- describe '#related_objects <<' do
289
- context 'with file sets and works' do
290
- before do
291
- subject.ordered_members << generic_work1
292
- subject.ordered_members << generic_work1
293
- subject.ordered_members << file_set1
294
- end
295
-
296
- it 'returns empty array when only generic files and generic works are aggregated' do
297
- expect(subject.related_objects).to eq []
298
- end
299
-
300
- it 'returns only related objects' do
301
- subject.related_objects << object2
302
- expect(subject.related_objects).to eq [object2]
303
- end
304
-
305
- it 'returns related objects of various types' do
306
- subject.related_objects << generic_work2
307
- subject.related_objects << file_set1
308
- subject.related_objects << object1
309
- expect(subject.related_objects).to eq [generic_work2, file_set1, object1]
310
- expect(subject.related_objects.size).to eq 3
311
- end
312
- end
313
- end
314
-
315
- describe '#related_objects.delete' do
316
- context 'when multiple related objects' do
317
- let(:related_object1) { Hydra::PCDM::Object.new }
318
- let(:related_work2) { described_class.new }
319
- let(:related_file3) { Hydra::Works::FileSet.new }
320
- let(:related_object4) { Hydra::PCDM::Object.new }
321
- let(:related_work5) { described_class.new }
322
- before do
323
- subject.related_objects << related_object1
324
- subject.related_objects << related_work2
325
- subject.ordered_members << generic_work2
326
- subject.ordered_members << file_set1
327
- subject.related_objects << related_file3
328
- subject.related_objects << related_object4
329
- subject.ordered_members << generic_work1
330
- subject.related_objects << related_work5
331
- expect(subject.related_objects).to eq [related_object1, related_work2, related_file3, related_object4, related_work5]
332
- end
333
-
334
- it 'removes first related object' do
335
- expect(subject.related_objects.delete related_object1).to eq [related_object1]
336
- expect(subject.related_objects).to eq [related_work2, related_file3, related_object4, related_work5]
337
- expect(subject.ordered_works).to eq [generic_work2, generic_work1]
338
- expect(subject.ordered_file_sets).to eq [file_set1]
339
- end
340
-
341
- it 'removes last related object' do
342
- expect(subject.related_objects.delete related_work5).to eq [related_work5]
343
- expect(subject.related_objects).to eq [related_object1, related_work2, related_file3, related_object4]
344
- expect(subject.ordered_works).to eq [generic_work2, generic_work1]
345
- expect(subject.ordered_file_sets).to eq [file_set1]
346
- end
347
-
348
- it 'removes middle related object' do
349
- expect(subject.related_objects.delete related_file3).to eq [related_file3]
350
- expect(subject.related_objects).to eq [related_object1, related_work2, related_object4, related_work5]
351
- expect(subject.ordered_works).to eq [generic_work2, generic_work1]
352
- expect(subject.ordered_file_sets).to eq [file_set1]
353
- end
354
- end
355
- end
356
-
357
210
  describe 'should have parent work and collection accessors' do
358
211
  let(:collection1) { Hydra::Works::Collection.new }
359
212
  before do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-works
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-30 00:00:00.000000000 Z
11
+ date: 2015-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hydra-pcdm