hydra-pcdm 0.2.0 → 0.3.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: a31e7e8302b6fa6566390c103c94e588199f2d50
4
- data.tar.gz: 35d89b527d58013dd4c4aa0477a59ac6a0235d56
3
+ metadata.gz: 6ddcd3f1a0e883fa81ac51d63cee4a16359b54c7
4
+ data.tar.gz: f569047389d44e967676fcc9fd6447536a3abbe7
5
5
  SHA512:
6
- metadata.gz: 95ea6fa959fb711e4ca1e5a32e92e3e834d42987c00232353111da00bd7a5a5fb50dcced29ff87e3f5d3bbd4e4a08373a1337bac8acb4e1ba37ca3134f5bc417
7
- data.tar.gz: 3549b065504e7bed1b1b8ecdbe941618b2000c73006b0cfe471e0250f79b5f4ec70ff9ea6dbbfb31d09ea73d32623378f71b13211071c29011eadc8ce89bc60a
6
+ metadata.gz: d409cb3d8f26a222cb90691d892bd24aed2451a323f238ad205d2843740b7023d461f539a8c44b20fd156d3a83e372b0e41e0fc705a28f88a6cb0ee2b1697153
7
+ data.tar.gz: 4dd1dcaf0e9cec180f14b35ebedc1bd10132ca1586eca54af825870c3333d3c7fc200ccd1e9d78c4392bec8b45c26c2c819ca1b0dbad2c34ba3975eadb6335b4
data/Gemfile CHANGED
@@ -8,5 +8,7 @@ group :development, :test do
8
8
  gem 'pry-byebug' unless ENV['CI']
9
9
  end
10
10
 
11
+ gem 'activefedora-aggregation', github: 'projecthydra-labs/activefedora-aggregation'
12
+
11
13
  # Specify your gem's dependencies in hydra-pcdm.gemspec
12
14
  gemspec
@@ -19,8 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_dependency 'active-fedora', '>= 9.4.1'
23
- spec.add_dependency 'activefedora-aggregation', '~> 0.4'
22
+ spec.add_dependency 'activefedora-aggregation', '~> 0.5'
24
23
  spec.add_dependency 'mime-types', '>= 1'
25
24
 
26
25
  spec.add_development_dependency 'bundler', '~> 1.6'
@@ -2,8 +2,10 @@ module Hydra::PCDM
2
2
  class CollectionIndexer < ObjectIndexer
3
3
  def generate_solr_document
4
4
  super.tap do |solr_doc|
5
- solr_doc['member_ids_ssim'] = object.member_ids
6
- solr_doc['collection_ids_ssim'] = object.collection_ids
5
+ solr_doc['member_ids_ssim'] ||= []
6
+ solr_doc['member_ids_ssim'] += object.member_ids
7
+ solr_doc['member_ids_ssim'].uniq!
8
+ solr_doc['collection_ids_ssim'] = object.ordered_collection_ids
7
9
  end
8
10
  end
9
11
  end
@@ -16,8 +16,6 @@ module Hydra::PCDM
16
16
  included do
17
17
  type Vocab::PCDMTerms.Collection
18
18
  include ::Hydra::PCDM::PcdmBehavior
19
-
20
- filters_association :members, as: :collections, condition: :pcdm_collection?
21
19
  end
22
20
 
23
21
  module ClassMethods
@@ -29,6 +27,22 @@ module Hydra::PCDM
29
27
  end
30
28
  end
31
29
 
30
+ def collections
31
+ members.select(&:pcdm_collection?)
32
+ end
33
+
34
+ def collection_ids
35
+ members.select(&:pcdm_collection?).map(&:id)
36
+ end
37
+
38
+ def ordered_collections
39
+ ordered_members.to_a.select(&:pcdm_collection?)
40
+ end
41
+
42
+ def ordered_collection_ids
43
+ ordered_collections.map(&:id)
44
+ end
45
+
32
46
  def pcdm_object?
33
47
  false
34
48
  end
@@ -39,17 +53,12 @@ module Hydra::PCDM
39
53
 
40
54
  def child_collections
41
55
  warn '[DEPRECATION] `child_collections` is deprecated in Hydra::PCDM. Please use `collections` instead. This has a target date for removal of 10-31-2015'
42
- collections
43
- end
44
-
45
- def child_collections=(new_collections)
46
- warn '[DEPRECATION] `child_collections=` is deprecated in Hydra::PCDM. Please use `collections=` instead. This has a target date for removal of 10-31-2015'
47
- self.collections = new_collections
56
+ ordered_collections
48
57
  end
49
58
 
50
59
  def child_collection_ids
51
60
  warn '[DEPRECATION] `child_collection_ids` is deprecated in Hydra::PCDM. Please use `collection_ids` instead. This has a target date for removal of 10-31-2015'
52
- collection_ids
61
+ ordered_collection_ids
53
62
  end
54
63
  end
55
64
  end
@@ -40,7 +40,7 @@ module Hydra::PCDM
40
40
  end
41
41
 
42
42
  def in_objects
43
- aggregated_by.select(&:pcdm_object?)
43
+ ordered_by.select(&:pcdm_object?).to_a
44
44
  end
45
45
 
46
46
  def parent_objects
@@ -2,10 +2,11 @@ module Hydra::PCDM
2
2
  module PcdmBehavior
3
3
  extend ActiveSupport::Concern
4
4
  included do
5
- aggregates :members, predicate: Vocab::PCDMTerms.hasMember,
6
- class_name: 'ActiveFedora::Base',
7
- type_validator: type_validator
8
- filters_association :members, as: :objects, condition: :pcdm_object?
5
+ ordered_aggregation :members,
6
+ has_member_relation: Vocab::PCDMTerms.hasMember,
7
+ class_name: 'ActiveFedora::Base',
8
+ type_validator: type_validator,
9
+ through: :list_source
9
10
  indirectly_contains :related_objects, has_member_relation: RDF::Vocab::ORE.aggregates,
10
11
  inserted_content_relation: RDF::Vocab::ORE.proxyFor, class_name: 'ActiveFedora::Base',
11
12
  through: 'ActiveFedora::Aggregation::Proxy', foreign_key: :target,
@@ -23,16 +24,40 @@ module Hydra::PCDM
23
24
  end
24
25
 
25
26
  def member_of
26
- aggregated_by
27
+ ActiveFedora::Base.where(member_ids_ssim: id)
28
+ end
29
+
30
+ def member_ids
31
+ members.map(&:id)
32
+ end
33
+
34
+ def ordered_member_ids
35
+ ordered_member_proxies.map(&:target_id)
36
+ end
37
+
38
+ def objects
39
+ members.select(&:pcdm_object?)
40
+ end
41
+
42
+ def object_ids
43
+ members.select(&:pcdm_object?).map(&:id)
44
+ end
45
+
46
+ def ordered_objects
47
+ ordered_members.to_a.select(&:pcdm_object?)
48
+ end
49
+
50
+ def ordered_object_ids
51
+ ordered_objects.map(&:id)
27
52
  end
28
53
 
29
54
  def parents
30
- warn '[DEPRECATION] `parents` is deprecated in Hydra::PCDM. Please use `member_of` instead. This has a target date for removal of 10-31-2015'
31
- member_of
55
+ warn '[DEPRECATION] `parents` is deprecated in Hydra::PCDM. Please use `ordered_by` instead. This has a target date for removal of 10-31-2015'
56
+ ordered_by.to_a
32
57
  end
33
58
 
34
59
  def in_collections
35
- aggregated_by.select(&:pcdm_collection?)
60
+ member_of.select(&:pcdm_collection?).to_a
36
61
  end
37
62
 
38
63
  def parent_collections
@@ -59,12 +84,7 @@ module Hydra::PCDM
59
84
 
60
85
  def child_objects
61
86
  warn '[DEPRECATION] `child_objects` is deprecated in Hydra::PCDM. Please use `objects` instead. This has a target date for removal of 10-31-2015'
62
- objects
63
- end
64
-
65
- def child_objects=(new_objects)
66
- warn '[DEPRECATION] `child_objects=` is deprecated in Hydra::PCDM. Please use `objects=` instead. This has a target date for removal of 10-31-2015'
67
- self.objects = new_objects
87
+ ordered_objects
68
88
  end
69
89
 
70
90
  def child_object_ids
@@ -2,7 +2,10 @@ module Hydra::PCDM
2
2
  class ObjectIndexer < ActiveFedora::IndexingService
3
3
  def generate_solr_document
4
4
  super.tap do |solr_doc|
5
- solr_doc['object_ids_ssim'] = object.object_ids
5
+ solr_doc['member_ids_ssim'] ||= []
6
+ solr_doc['member_ids_ssim'] += object.member_ids
7
+ solr_doc['member_ids_ssim'].uniq!
8
+ solr_doc['object_ids_ssim'] = object.ordered_object_ids
6
9
  end
7
10
  end
8
11
  end
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module PCDM
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -8,8 +8,8 @@ describe Hydra::PCDM::CollectionIndexer do
8
8
  let(:indexer) { described_class.new(collection) }
9
9
 
10
10
  before do
11
- allow(collection).to receive(:collection_ids).and_return(collection_ids)
12
- allow(collection).to receive(:object_ids).and_return(object_ids)
11
+ allow(collection).to receive(:ordered_collection_ids).and_return(collection_ids)
12
+ allow(collection).to receive(:ordered_object_ids).and_return(object_ids)
13
13
  allow(collection).to receive(:member_ids).and_return(member_ids)
14
14
  end
15
15
 
@@ -10,33 +10,63 @@ describe Hydra::PCDM::Collection do
10
10
  let(:object2) { Hydra::PCDM::Object.new }
11
11
  let(:object3) { Hydra::PCDM::Object.new }
12
12
 
13
+ describe '#collections' do
14
+ it 'returns non-ordered collections' do
15
+ collection1.members += [collection2, collection3]
16
+ collection1.ordered_members << collection4
17
+
18
+ expect(collection1.collections).to eq [collection2, collection3, collection4]
19
+ expect(collection1.ordered_collections).to eq [collection4]
20
+ end
21
+ end
22
+
23
+ describe '#collection_ids' do
24
+ it 'returns IDs of non-ordered collections' do
25
+ collection1.members += [collection2, collection3]
26
+ collection1.ordered_members << collection4
27
+
28
+ expect(collection1.collection_ids).to eq [collection2.id, collection3.id, collection4.id]
29
+ end
30
+ end
31
+
32
+ describe '#objects' do
33
+ it 'returns non-ordered objects' do
34
+ collection1.members += [object1, object2]
35
+ collection1.ordered_members << object3
36
+
37
+ expect(collection1.objects).to eq [object1, object2, object3]
38
+ expect(collection1.ordered_objects).to eq [object3]
39
+ end
40
+ end
41
+
42
+ describe '#object_ids' do
43
+ it 'returns IDs of non-ordered objects' do
44
+ collection1.members += [object1, object2]
45
+ collection1.ordered_members << object3
46
+
47
+ expect(collection1.object_ids).to eq [object1.id, object2.id, object3.id]
48
+ end
49
+ end
50
+
13
51
  describe 'adding collections' do
14
52
  describe 'with acceptable inputs' do
15
53
  subject { described_class.new }
16
- it 'adds collections, sub-collections, and repeating collections' do
17
- subject.collections << collection1 # first add
18
- subject.collections << collection2 # second add to same collection
19
- subject.collections << collection1 # repeat a collection
20
- collection1.collections << collection3 # add sub-collection
21
- expect(subject.collections).to eq [collection1, collection2, collection1]
22
- expect(collection1.collections).to eq [collection3]
23
- end
24
54
  it 'adds an object to collection with collections and objects' do
25
- subject.members << collection1
26
- subject.members << collection2
27
- subject.members << object1
28
- subject.members << object2
29
- subject.members << collection3
30
- expect(subject.members).to eq [collection1, collection2, object1, object2, collection3]
31
- expect(subject.collections).to eq [collection1, collection2, collection3]
32
- expect(subject.objects).to eq [object1, object2]
55
+ subject.ordered_members << collection1
56
+ subject.ordered_members << collection2
57
+ subject.ordered_members << object1
58
+ subject.ordered_members << object2
59
+ subject.ordered_members << collection3
60
+ expect(subject.ordered_members).to eq [collection1, collection2, object1, object2, collection3]
61
+ expect(subject.ordered_collections).to eq [collection1, collection2, collection3]
62
+ expect(subject.ordered_objects).to eq [object1, object2]
33
63
  end
34
64
  end
35
65
 
36
66
  describe '#in_collection_ids' do
37
67
  it 'returns the IDs of the parent' do
38
- subject.members << object1
39
- subject.members << collection1
68
+ subject.ordered_members << object1
69
+ subject.ordered_members << collection1
40
70
  subject.save
41
71
  expect(object1.in_collection_ids).to eq [subject.id]
42
72
  expect(collection1.in_collection_ids).to eq [subject.id]
@@ -53,13 +83,13 @@ describe Hydra::PCDM::Collection do
53
83
  let(:kollection1) { Kollection.new }
54
84
 
55
85
  it 'accepts implementing collection as a child' do
56
- subject.collections << kollection1
57
- expect(subject.collections).to eq [kollection1]
86
+ subject.ordered_members << kollection1
87
+ expect(subject.ordered_collections).to eq [kollection1]
58
88
  end
59
89
 
60
90
  it 'accepts implementing collection as a parent' do
61
- kollection1.collections << collection1
62
- expect(kollection1.collections).to eq [collection1]
91
+ kollection1.ordered_members << collection1
92
+ expect(kollection1.ordered_collections).to eq [collection1]
63
93
  end
64
94
  end
65
95
 
@@ -72,13 +102,13 @@ describe Hydra::PCDM::Collection do
72
102
  let(:cullection1) { Cullection.new }
73
103
 
74
104
  it 'accepts extending collection as a child' do
75
- subject.collections << cullection1
76
- expect(subject.collections).to eq [cullection1]
105
+ subject.ordered_members << cullection1
106
+ expect(subject.ordered_collections).to eq [cullection1]
77
107
  end
78
108
 
79
109
  it 'accepts extending collection as a parent' do
80
- cullection1.collections << collection1
81
- expect(cullection1.collections).to eq [collection1]
110
+ cullection1.ordered_members << collection1
111
+ expect(cullection1.ordered_collections).to eq [collection1]
82
112
  end
83
113
  end
84
114
 
@@ -91,25 +121,23 @@ describe Hydra::PCDM::Collection do
91
121
  end
92
122
 
93
123
  context 'that are unacceptable child collections' do
94
- let(:error_type1) { ArgumentError }
95
- let(:error_message1) { 'Hydra::PCDM::Object with ID: was expected to pcdm_collection?, but it was false' }
96
- let(:error_type2) { NoMethodError }
97
- let(:error_message2) { /undefined method `pcdm_collection\?' for .*/ }
124
+ let(:error_type1) { ActiveFedora::AssociationTypeMismatch }
125
+ let(:error_message1) { /ActiveFedora::Base\(#\d+\) expected, got String\(#[\d]+\)/ }
126
+ let(:error_type2) { ActiveFedora::AssociationTypeMismatch }
127
+ let(:error_message2) { /(<ActiveFedora::Base:[\d\s\w]{16}>|\s*) is not a PCDM object or collection./ }
128
+ let(:error_type3) { ActiveFedora::AssociationTypeMismatch }
129
+ let(:error_message3) { /ActiveFedora::Base\(#\d+\) expected, got Hydra::PCDM::File\(#[\d]+\)/ }
98
130
 
99
- it 'raises an error when trying to aggregate Hydra::PCDM::Objects in collections aggregation' do
100
- expect { collection1.collections << @object101 }.to raise_error(error_type1, error_message1)
131
+ it 'raises an error when trying to aggregate Hydra::PCDM::Files in members aggregation' do
132
+ expect { collection1.ordered_members << @file101 }.to raise_error(error_type3, error_message3)
101
133
  end
102
134
 
103
- it 'raises an error when trying to aggregate Hydra::PCDM::Files in collections aggregation' do
104
- expect { collection1.collections << @file101 }.to raise_error(error_type2, error_message2)
135
+ it 'raises an error when trying to aggregate non-PCDM objects in members aggregation' do
136
+ expect { collection1.ordered_members << @non_pcdm_object }.to raise_error(error_type1, error_message1)
105
137
  end
106
138
 
107
- it 'raises an error when trying to aggregate non-PCDM objects in collections aggregation' do
108
- expect { collection1.collections << @non_pcdm_object }.to raise_error(error_type2, error_message2)
109
- end
110
-
111
- it 'raises an error when trying to aggregate AF::Base objects in collections aggregation' do
112
- expect { collection1.collections << @af_base_object }.to raise_error(error_type2, error_message2)
139
+ it 'raises an error when trying to aggregate AF::Base objects in members aggregation' do
140
+ expect { collection1.ordered_members << @af_base_object }.to raise_error(error_type2, error_message2)
113
141
  end
114
142
  end
115
143
  end
@@ -120,35 +148,35 @@ describe Hydra::PCDM::Collection do
120
148
 
121
149
  context 'when the source collection is the same' do
122
150
  it 'raises an error' do
123
- expect { subject.collections << subject }.to raise_error(error_type, error_message)
151
+ expect { subject.ordered_members << subject }.to raise_error(error_type, error_message)
124
152
  end
125
153
  end
126
154
 
127
155
  before do
128
- subject.collections << collection1
156
+ subject.ordered_members << collection1
129
157
  end
130
158
 
131
159
  it 'raises and error' do
132
- expect { collection1.collections << subject }.to raise_error(error_type, error_message)
160
+ expect { collection1.ordered_members << subject }.to raise_error(error_type, error_message)
133
161
  end
134
162
 
135
163
  context 'with more ancestors' do
136
164
  before do
137
- collection1.collections << collection2
165
+ collection1.ordered_members << collection2
138
166
  end
139
167
 
140
168
  it 'raises an error' do
141
- expect { collection2.collections << subject }.to raise_error(error_type, error_message)
169
+ expect { collection2.ordered_members << subject }.to raise_error(error_type, error_message)
142
170
  end
143
171
 
144
172
  context 'with a more complicated example' do
145
173
  before do
146
- collection2.collections << collection3
174
+ collection2.ordered_members << collection3
147
175
  end
148
176
 
149
177
  it 'raises errors' do
150
- expect { collection3.collections << subject }.to raise_error(error_type, error_message)
151
- expect { collection3.collections << collection1 }.to raise_error(error_type, error_message)
178
+ expect { collection3.ordered_members << subject }.to raise_error(error_type, error_message)
179
+ expect { collection3.ordered_members << collection1 }.to raise_error(error_type, error_message)
152
180
  end
153
181
  end
154
182
  end
@@ -160,52 +188,52 @@ describe Hydra::PCDM::Collection do
160
188
 
161
189
  context 'when it is the only collection' do
162
190
  before do
163
- subject.members << collection1
164
- expect(subject.collections).to eq [collection1]
191
+ subject.ordered_members << collection1
192
+ expect(subject.ordered_collections).to eq [collection1]
165
193
  end
166
194
 
167
195
  it 'removes collection while changes are in memory' do
168
- expect(subject.members.delete collection1).to eq [collection1]
169
- expect(subject.collections).to eq []
196
+ subject.ordered_member_proxies.delete_at(0)
197
+ expect(subject.ordered_collections).to eq []
170
198
  end
171
199
 
172
200
  it 'removes collection only when objects and all changes are in memory' do
173
- subject.members << object1
174
- subject.members << object2
175
- expect(subject.members.delete collection1).to eq [collection1]
176
- expect(subject.collections).to eq []
177
- expect(subject.objects).to eq [object1, object2]
201
+ subject.ordered_members << object1
202
+ subject.ordered_members << object2
203
+ subject.ordered_member_proxies.delete_at(0)
204
+ expect(subject.ordered_collections).to eq []
205
+ expect(subject.ordered_objects).to eq [object1, object2]
178
206
  end
179
207
  end
180
208
 
181
209
  context 'when multiple collections' do
182
210
  before do
183
- subject.members << collection1
184
- subject.members << collection2
185
- subject.members << collection3
186
- expect(subject.collections).to eq [collection1, collection2, collection3]
211
+ subject.ordered_members << collection1
212
+ subject.ordered_members << collection2
213
+ subject.ordered_members << collection3
214
+ expect(subject.ordered_collections).to eq [collection1, collection2, collection3]
187
215
  end
188
216
 
189
217
  it 'removes first collection when changes are in memory' do
190
- expect(subject.members.delete collection1).to eq [collection1]
191
- expect(subject.collections).to eq [collection2, collection3]
218
+ subject.ordered_member_proxies.delete_at(0)
219
+ expect(subject.ordered_collections).to eq [collection2, collection3]
192
220
  end
193
221
 
194
222
  it 'removes last collection when changes are in memory' do
195
- expect(subject.members.delete collection3).to eq [collection3]
196
- expect(subject.collections).to eq [collection1, collection2]
223
+ subject.ordered_member_proxies.delete_at(2)
224
+ expect(subject.ordered_collections).to eq [collection1, collection2]
197
225
  end
198
226
 
199
227
  it 'removes middle collection when changes are in memory' do
200
- expect(subject.members.delete collection2).to eq [collection2]
201
- expect(subject.collections).to eq [collection1, collection3]
228
+ subject.ordered_member_proxies.delete_at(1)
229
+ expect(subject.ordered_collections).to eq [collection1, collection3]
202
230
  end
203
231
 
204
232
  it 'removes middle collection when changes are saved' do
205
- expect(subject.collections).to eq [collection1, collection2, collection3]
233
+ expect(subject.ordered_collections).to eq [collection1, collection2, collection3]
206
234
  subject.save
207
- expect(subject.members.delete collection2).to eq [collection2]
208
- expect(subject.collections).to eq [collection1, collection3]
235
+ subject.ordered_member_proxies.delete_at(1)
236
+ expect(subject.ordered_collections).to eq [collection1, collection3]
209
237
  end
210
238
  end
211
239
  context 'when collection is missing' do
@@ -214,14 +242,14 @@ describe Hydra::PCDM::Collection do
214
242
  end
215
243
 
216
244
  it 'and multiple sub-collections should return empty array when changes are in memory' do
217
- subject.members << collection1
218
- subject.members << collection3
245
+ subject.ordered_members << collection1
246
+ subject.ordered_members << collection3
219
247
  expect(subject.members.delete collection2).to eq []
220
248
  end
221
249
 
222
250
  it 'returns empty array when changes are saved' do
223
- subject.members << collection1
224
- subject.members << collection3
251
+ subject.ordered_members << collection1
252
+ subject.ordered_members << collection3
225
253
  subject.save
226
254
  expect(subject.members.delete collection2).to eq []
227
255
  end
@@ -231,19 +259,19 @@ describe Hydra::PCDM::Collection do
231
259
  describe 'adding objects' do
232
260
  context 'with acceptable inputs' do
233
261
  it 'adds objects, sub-collections, and repeating collections' do
234
- subject.objects << object1 # first add
235
- subject.objects << object2 # second add to same collection
236
- subject.objects << object1 # repeat an object
237
- expect(subject.objects).to eq [object1, object2, object1]
262
+ subject.ordered_members << object1 # first add
263
+ subject.ordered_members << object2 # second add to same collection
264
+ subject.ordered_members << object1 # repeat an object
265
+ expect(subject.ordered_members).to eq [object1, object2, object1]
238
266
  end
239
267
 
240
268
  context 'with collections and objects' do
241
269
  it 'adds an object to collection with collections and objects' do
242
- subject.objects << object1
243
- subject.collections << collection1
244
- subject.collections << collection2
245
- subject.objects << object2
246
- expect(subject.objects).to eq [object1, object2]
270
+ subject.ordered_members << object1
271
+ subject.ordered_members << collection1
272
+ subject.ordered_members << collection2
273
+ subject.ordered_members << object2
274
+ expect(subject.ordered_objects).to eq [object1, object2]
247
275
  end
248
276
  end
249
277
 
@@ -257,8 +285,8 @@ describe Hydra::PCDM::Collection do
257
285
  let(:ahbject1) { Ahbject.new }
258
286
 
259
287
  it 'accepts implementing object as a child' do
260
- subject.objects << ahbject1
261
- expect(subject.objects).to eq [ahbject1]
288
+ subject.ordered_members << ahbject1
289
+ expect(subject.ordered_objects).to eq [ahbject1]
262
290
  end
263
291
  end
264
292
 
@@ -271,168 +299,13 @@ describe Hydra::PCDM::Collection do
271
299
  let(:awbject1) { Awbject.new }
272
300
 
273
301
  it 'accepts extending object as a child' do
274
- subject.objects << awbject1
275
- expect(subject.objects).to eq [awbject1]
276
- end
277
- end
278
- end
279
-
280
- context 'with unacceptable inputs' do
281
- before(:all) do
282
- @file101 = Hydra::PCDM::File.new
283
- @non_pcdm_object = "I'm not a PCDM object"
284
- @af_base_object = ActiveFedora::Base.new
285
- end
286
-
287
- context 'with unacceptable objects' do
288
- let(:error_type1) { ArgumentError }
289
- let(:error_message1) { 'Hydra::PCDM::Collection with ID: was expected to pcdm_object?, but it was false' }
290
- let(:error_type2) { NoMethodError }
291
- let(:error_message2) { /undefined method `pcdm_object\?' for .*/ }
292
-
293
- it 'raises an error when trying to aggregate Hydra::PCDM::Collection in objects aggregation' do
294
- expect { collection1.objects << collection2 }.to raise_error(error_type1, error_message1)
295
- end
296
-
297
- it 'raises an error when trying to aggregate Hydra::PCDM::Files in objects aggregation' do
298
- expect { collection1.objects << @file101 }.to raise_error(error_type2, error_message2)
299
- end
300
-
301
- it 'raises an error when trying to aggregate non-PCDM objects in objects aggregation' do
302
- expect { collection1.objects << @non_pcdm_object }.to raise_error(error_type2, error_message2)
303
- end
304
-
305
- it 'raises an error when trying to aggregate AF::Base objects in objects aggregation' do
306
- expect { collection1.objects << @af_base_object }.to raise_error(error_type2, error_message2)
302
+ subject.ordered_members << awbject1
303
+ expect(subject.ordered_objects).to eq [awbject1]
307
304
  end
308
305
  end
309
306
  end
310
307
  end
311
308
 
312
- describe 'removing objects' do
313
- context 'when it is the only object' do
314
- before do
315
- subject.objects << object1
316
- expect(subject.objects).to eq [object1]
317
- end
318
-
319
- it 'removes object while changes are in memory' do
320
- expect(subject.objects.delete object1).to eq [object1]
321
- expect(subject.objects).to eq []
322
- end
323
-
324
- it 'removes object only when collections and all changes are in memory' do
325
- subject.collections << collection1
326
- subject.collections << collection2
327
- expect(subject.objects.delete object1).to eq [object1]
328
- expect(subject.objects).to eq []
329
- expect(subject.collections).to eq [collection1, collection2]
330
- end
331
- end
332
-
333
- context 'when multiple objects' do
334
- let(:object3) { Hydra::PCDM::Object.new }
335
-
336
- before do
337
- subject.objects << object1
338
- subject.objects << object2
339
- subject.objects << object3
340
- expect(subject.objects).to eq [object1, object2, object3]
341
- end
342
-
343
- it 'removes first object when changes are in memory' do
344
- expect(subject.objects.delete object1).to eq [object1]
345
- expect(subject.objects).to eq [object2, object3]
346
- end
347
-
348
- it 'removes middle object when changes are in memory' do
349
- expect(subject.objects.delete object2).to eq [object2]
350
- expect(subject.objects).to eq [object1, object3]
351
- end
352
-
353
- it 'removes last object when changes are in memory' do
354
- expect(subject.objects.delete object3).to eq [object3]
355
- expect(subject.objects).to eq [object1, object2]
356
- end
357
- it 'removes middle object when changes are saved' do
358
- expect(subject.objects.delete object2).to eq [object2]
359
- expect(subject.objects).to eq [object1, object3]
360
- subject.save
361
- expect(subject.reload.objects).to eq [object1, object3]
362
- end
363
- end
364
-
365
- context 'when object repeats' do
366
- let(:object3) { Hydra::PCDM::Object.new }
367
- let(:object4) { Hydra::PCDM::Object.new }
368
- let(:object5) { Hydra::PCDM::Object.new }
369
-
370
- before do
371
- subject.objects << object1
372
- subject.objects << object2
373
- subject.objects << object3
374
- subject.objects << object2
375
- subject.objects << object4
376
- subject.objects << object2
377
- subject.objects << object5
378
- expect(subject.objects).to eq [object1, object2, object3, object2, object4, object2, object5]
379
- end
380
-
381
- # TODO: pending implementation of multiple objects
382
-
383
- it 'removes first occurrence when changes in memory' do
384
- expect(subject.objects.delete object2).to eq [object2]
385
- expect(subject.objects).to eq [object1, object3, object4, object5]
386
- end
387
-
388
- it 'removes last occurrence when changes in memory' do
389
- skip('pending resolution of AF-agg 46 and PCDM 102') do
390
- expect(subject.objects.delete object2, -1).to eq object2
391
- expect(subject.objects).to eq [object1, object2, object3, object2, object4, object5]
392
- end
393
- end
394
-
395
- it 'removes nth occurrence when changes in memory' do
396
- skip('pending resolution of AF-agg 46 and PCDM 102') do
397
- expect(subject.objects.delete object2, 2).to eq object2
398
- expect(subject.objects).to eq [object1, object2, object3, object4, object2, object5]
399
- end
400
- end
401
- it 'removes nth occurrence when changes are saved' do
402
- skip('pending resolution of AF-agg 46 and PCDM 102') do
403
- expect(subject.objects).to eq [object1, object2, object3, object2, object4, object2, object5]
404
- subject.save
405
- expect(subject.reload.objects).to eq [object1, object2, object3, object2, object4, object2, object5]
406
-
407
- expect(subject.objects.delete object2, 2).to eq object2
408
- subject.save
409
- expect(subject.reload.objects).to eq [object1, object2, object3, object4, object2, object5]
410
- end
411
- end
412
- end
413
-
414
- context 'when object is missing' do
415
- let(:object3) { Hydra::PCDM::Object.new }
416
-
417
- it 'and 0 objects in collection should return empty array' do
418
- expect(subject.objects.delete object1).to eq []
419
- end
420
-
421
- it 'and multiple objects in collection should return empty array when changes are in memory' do
422
- subject.objects << object1
423
- subject.objects << object2
424
- expect(subject.objects.delete object3).to eq []
425
- end
426
-
427
- it 'returns empty array when changes are saved' do
428
- subject.objects << object1
429
- subject.objects << object2
430
- subject.save
431
- expect(subject.reload.objects.delete object3).to eq []
432
- end
433
- end
434
- end
435
-
436
309
  describe 'add related objects' do
437
310
  context 'with acceptable collections' do
438
311
  it 'adds objects to the related object set' do
@@ -529,14 +402,14 @@ describe Hydra::PCDM::Collection do
529
402
  end
530
403
 
531
404
  it 'removes related object only when objects & collections and all changes are in memory' do
532
- subject.collections << collection1
533
- subject.collections << collection2
534
- subject.objects << object3
535
- subject.objects << object2
405
+ subject.ordered_members << collection1
406
+ subject.ordered_members << collection2
407
+ subject.ordered_members << object3
408
+ subject.ordered_members << object2
536
409
  expect(subject.related_objects.delete object1).to eq [object1]
537
410
  expect(subject.related_objects).to eq []
538
- expect(subject.collections).to eq [collection1, collection2]
539
- expect(subject.objects).to eq [object3, object2]
411
+ expect(subject.ordered_collections).to eq [collection1, collection2]
412
+ expect(subject.ordered_objects).to eq [object3, object2]
540
413
  end
541
414
  end
542
415
 
@@ -581,10 +454,10 @@ describe Hydra::PCDM::Collection do
581
454
  end
582
455
 
583
456
  it 'returns empty array when 0 related objects, but has collections and objects and changes in memory' do
584
- subject.members << collection1
585
- subject.members << collection2
586
- subject.members << object1
587
- subject.members << object2
457
+ subject.ordered_members << collection1
458
+ subject.ordered_members << collection2
459
+ subject.ordered_members << object1
460
+ subject.ordered_members << object2
588
461
  expect(subject.related_objects.delete object1).to eq []
589
462
  end
590
463
 
@@ -625,67 +498,13 @@ describe Hydra::PCDM::Collection do
625
498
  end
626
499
  end
627
500
 
628
- describe '#collections=' do
629
- it 'aggregates collections' do
630
- collection1.collections = [collection2, collection3]
631
- expect(collection1.collections).to eq [collection2, collection3]
632
- end
633
- end
634
-
635
- describe '#collections<<' do
636
- before do
637
- collection1.collections = [collection2]
638
- end
639
- it 'aggregates collections' do
640
- collection1.collections << collection3
641
- expect(collection1.collections).to eq [collection2, collection3]
642
- end
643
- end
644
-
645
- describe '#collections+=' do
646
- before do
647
- collection1.collections = [collection2]
648
- end
649
- it 'aggregates collections' do
650
- collection1.collections += [collection3, collection4]
651
- expect(collection1.collections).to eq [collection2, collection3, collection4]
652
- end
653
- end
654
-
655
- describe '#objects=' do
656
- it 'aggregates objects' do
657
- collection1.objects = [object1, object2]
658
- expect(collection1.objects).to eq [object1, object2]
659
- end
660
- end
661
-
662
- describe '#objects<<' do
663
- before do
664
- collection1.objects = [object1]
665
- end
666
- it 'appends object to aggregated objects' do
667
- collection1.objects << object2
668
- expect(collection1.objects).to eq [object1, object2]
669
- end
670
- end
671
-
672
- describe '#objects+=' do
673
- before do
674
- collection1.objects = [object1]
675
- end
676
- it 'appends object to aggregated objects' do
677
- collection1.objects += [object2, object3]
678
- expect(collection1.objects).to eq [object1, object2, object3]
679
- end
680
- end
681
-
682
- describe '#collection_ids' do
501
+ describe '#ordered_collection_ids' do
683
502
  let(:child1) { described_class.new(id: '1') }
684
503
  let(:child2) { described_class.new(id: '2') }
685
504
  let(:object) { described_class.new }
686
- before { object.collections = [child1, child2] }
505
+ before { object.ordered_members = [child1, child2] }
687
506
 
688
- subject { object.collection_ids }
507
+ subject { object.ordered_collection_ids }
689
508
 
690
509
  it { is_expected.to eq %w(1 2) }
691
510
  end
@@ -694,31 +513,31 @@ describe Hydra::PCDM::Collection do
694
513
  subject { described_class.new }
695
514
 
696
515
  it 'returns empty array when no members' do
697
- expect(subject.collections).to eq []
698
- expect(subject.objects).to eq []
516
+ expect(subject.ordered_collections).to eq []
517
+ expect(subject.ordered_objects).to eq []
699
518
  end
700
519
 
701
520
  it 'collections should return empty array when only objects are aggregated' do
702
- subject.members << object1
703
- subject.members << object2
704
- expect(subject.collections).to eq []
521
+ subject.ordered_members << object1
522
+ subject.ordered_members << object2
523
+ expect(subject.ordered_collections).to eq []
705
524
  end
706
525
 
707
526
  it 'objects should return empty array when only collections are aggregated' do
708
- subject.members << collection1
709
- subject.members << collection2
710
- expect(subject.objects).to eq []
527
+ subject.ordered_members << collection1
528
+ subject.ordered_members << collection2
529
+ expect(subject.ordered_objects).to eq []
711
530
  end
712
531
 
713
532
  context 'should only contain members of the correct type' do
714
533
  it 'returns only collections' do
715
- subject.collections << collection1
716
- subject.members << collection2
717
- subject.objects << object1
718
- subject.members << object2
719
- expect(subject.collections).to eq [collection1, collection2]
720
- expect(subject.objects).to eq [object1, object2]
721
- expect(subject.members).to eq [collection1, collection2, object1, object2]
534
+ subject.ordered_members << collection1
535
+ subject.ordered_members << collection2
536
+ subject.ordered_members << object1
537
+ subject.ordered_members << object2
538
+ expect(subject.ordered_collections).to eq [collection1, collection2]
539
+ expect(subject.ordered_objects).to eq [object1, object2]
540
+ expect(subject.ordered_members).to eq [collection1, collection2, object1, object2]
722
541
  end
723
542
  end
724
543
  end
@@ -730,20 +549,17 @@ describe Hydra::PCDM::Collection do
730
549
  @collection1 = described_class.new
731
550
  @collection2 = described_class.new
732
551
  @collection = described_class.new
733
- @collection1.collections << @collection
734
- @collection2.collections << @collection
735
- allow(@collection).to receive(:id).and_return('banana')
736
- proxies = [
737
- build_proxy(container: @collection1),
738
- build_proxy(container: @collection2)
739
- ]
740
- allow(ActiveFedora::Aggregation::Proxy).to receive(:where).with(proxyFor_ssim: @collection.id).and_return(proxies)
552
+ @collection1.members << @collection
553
+ @collection2.members << @collection
554
+ @collection.save
555
+ @collection1.save!
556
+ @collection2.save!
741
557
  end
742
558
 
743
559
  describe 'member_of' do
744
560
  subject { @collection.member_of }
745
561
  it 'finds all nodes that aggregate the object with hasMember' do
746
- expect(subject).to include(@collection1, @collection2)
562
+ expect(subject.to_a).to include(@collection1, @collection2)
747
563
  expect(subject.count).to eq 2
748
564
  end
749
565
  end
@@ -755,9 +571,6 @@ describe Hydra::PCDM::Collection do
755
571
  expect(subject.count).to eq 2
756
572
  end
757
573
  end
758
- def build_proxy(container:)
759
- instance_double(ActiveFedora::Aggregation::Proxy, container: container)
760
- end
761
574
  end
762
575
 
763
576
  describe '.indexer' do
@@ -803,16 +616,20 @@ describe Hydra::PCDM::Collection do
803
616
 
804
617
  describe 'make sure deprecated methods still work' do
805
618
  it 'deprecated methods should pass' do
806
- expect(collection1.child_collections = [collection2]).to eq [collection2]
807
- expect(collection1.child_collections << collection3).to eq [collection2, collection3]
808
- expect(collection1.child_collections += [collection4]).to eq [collection2, collection3, collection4]
809
- expect(collection1.child_objects = [object1]).to eq [object1]
810
- expect(collection1.child_objects << object2).to eq [object1, object2]
811
- expect(collection1.child_objects += [object3]).to eq [object1, object2, object3]
619
+ expect(collection1.ordered_members = [collection2]).to eq [collection2]
620
+ expect(collection1.ordered_members << collection3).to eq [collection2, collection3]
621
+ expect(collection1.ordered_members += [collection4]).to eq [collection2, collection3, collection4]
622
+ expect(collection1.ordered_members << object1).to eq [collection2, collection3, collection4, object1]
623
+ expect(collection1.ordered_members << object2).to eq [collection2, collection3, collection4, object1, object2]
624
+ expect(collection1.ordered_members += [object3]).to eq [collection2, collection3, collection4, object1, object2, object3]
812
625
  collection1.save # required until issue AF-Agg-75 is fixed
813
626
  expect(collection2.parent_collections).to eq [collection1]
814
627
  expect(collection2.parents).to eq [collection1]
815
628
  expect(collection2.parent_collection_ids).to eq [collection1.id]
629
+ expect(collection1.child_objects).to eq [object1, object2, object3]
630
+ expect(collection1.child_object_ids).to eq [object1.id, object2.id, object3.id]
631
+ expect(collection1.child_collections).to eq [collection2, collection3, collection4]
632
+ expect(collection1.child_collection_ids).to eq [collection2.id, collection3.id, collection4.id]
816
633
  end
817
634
  end
818
635
  end