valkyrie 3.1.1 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/valkyrie/specs/shared_specs/queries.rb +48 -37
- data/lib/valkyrie/specs/shared_specs/storage_adapter.rb +16 -0
- data/lib/valkyrie/storage/fedora.rb +2 -1
- data/lib/valkyrie/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea9bed1186d59d54588f268cd3ab79a3b26a950e68f8f5147a8f670e97bfb8c2
|
4
|
+
data.tar.gz: f569c1c3f17d189dae8bfb2bdff83785c4802072020dd4789933629d2648e7f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2550a5c3815f64fdfb60fc2161bfadc6d92d046be6eff5221e522242520b820225fb44c7b2cad288abc5f4e8be3d8aa95d248f173858c42b8a49dcdd8cd668c
|
7
|
+
data.tar.gz: deb349e3cdecb013b1ad54f3a49addadbda41c2af2baea5e904597606d913e1b7a7dbb8f104f1929981ee4cd1a7bf4363599925af8262a3dfcb5cf655050c3e6
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# v3.1.2 2024-01-30
|
2
|
+
|
3
|
+
## Changes since last release
|
4
|
+
|
5
|
+
* Remove spec dependency on `ROOT_PATH` and favor `Valkyrie::Engine.root`
|
6
|
+
instead. Thus allowing downstream implementations to leverage the fixtures in
|
7
|
+
Valkyrie. ([jeremyf](https://github.com/jeremyf))
|
8
|
+
* make the shared query specs more flexible for testing four_flight adapter. ([orangewolf](https://github.com/orangewolf) and [jeremyf](https://github.com/jeremyf))
|
9
|
+
* Check for file size as well as length in shared StorageAdapter specs ([dlpierce](https://github.com/dlpierce))
|
10
|
+
|
11
|
+
Additional thanks to the following for code review and issue reports leading to this release:
|
12
|
+
|
13
|
+
* [dunn](https://github.com/dunn)
|
14
|
+
|
1
15
|
# v3.1.1 2023-10-05
|
2
16
|
|
3
17
|
## Changes since last release
|
@@ -1,4 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This shared example provides defaults (e.g. resource_class, second_resource_class, query_service,
|
4
|
+
# etc.) but allows for the downstream implementer to specify those values. See the various "unless
|
5
|
+
# defined?" sections of this code.
|
2
6
|
RSpec.shared_examples 'a Valkyrie query provider' do
|
3
7
|
before do
|
4
8
|
raise 'adapter must be set with `let(:adapter)`' unless
|
@@ -24,9 +28,11 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
24
28
|
Valkyrie::Specs.send(:remove_const, :SecondResource)
|
25
29
|
Valkyrie::Specs.send(:remove_const, :ThirdResource)
|
26
30
|
end
|
27
|
-
let(:resource_class) { Valkyrie::Specs::CustomResource }
|
31
|
+
let(:resource_class) { Valkyrie::Specs::CustomResource } unless defined? resource_class
|
32
|
+
let(:second_resource_class) { Valkyrie::Specs::SecondResource } unless defined? second_resource_class
|
33
|
+
let(:third_resource_class) { Valkyrie::Specs::ThirdResource } unless defined? third_resource_class
|
28
34
|
let(:query_service) { adapter.query_service } unless defined? query_service
|
29
|
-
let(:persister) { adapter.persister }
|
35
|
+
let(:persister) { adapter.persister } unless defined? persister
|
30
36
|
subject { adapter.query_service }
|
31
37
|
|
32
38
|
it { is_expected.to respond_to(:find_all).with(0).arguments }
|
@@ -53,17 +59,18 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
53
59
|
describe ".find_all_of_model" do
|
54
60
|
it "returns all of that model" do
|
55
61
|
persister.save(resource: resource_class.new)
|
56
|
-
resource2 = persister.save(resource:
|
62
|
+
resource2 = persister.save(resource: second_resource_class.new)
|
57
63
|
|
58
|
-
expect(query_service.find_all_of_model(model:
|
64
|
+
expect(query_service.find_all_of_model(model: second_resource_class).map(&:id)).to contain_exactly resource2.id
|
59
65
|
end
|
60
66
|
it "returns an empty array if there are none" do
|
61
|
-
expect(query_service.find_all_of_model(model:
|
67
|
+
expect(query_service.find_all_of_model(model: second_resource_class).to_a).to eq []
|
62
68
|
end
|
63
69
|
end
|
64
70
|
|
65
71
|
describe ".find_by" do
|
66
72
|
it "returns a resource by id or string representation of an id" do
|
73
|
+
before_find_by.call if defined? before_find_by
|
67
74
|
resource = persister.save(resource: resource_class.new)
|
68
75
|
|
69
76
|
found = query_service.find_by(id: resource.id)
|
@@ -86,6 +93,8 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
86
93
|
|
87
94
|
describe ".find_by_alternate_identifier" do
|
88
95
|
it "returns a resource by alternate identifier or string representation of an alternate identifier" do
|
96
|
+
before_find_by_alternate_identifier.call if defined? before_find_by_alternate_identifier
|
97
|
+
|
89
98
|
resource = resource_class.new
|
90
99
|
resource.alternate_ids = [Valkyrie::ID.new('p9s0xfj')]
|
91
100
|
resource = persister.save(resource: resource)
|
@@ -100,7 +109,7 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
100
109
|
end
|
101
110
|
|
102
111
|
it 'raises a Valkyrie::Persistence::ObjectNotFoundError when persisted objects do not have alternate_ids' do
|
103
|
-
persister.save(resource:
|
112
|
+
persister.save(resource: second_resource_class.new)
|
104
113
|
expect { query_service.find_by_alternate_identifier(alternate_identifier: Valkyrie::ID.new("123123123")) }.to raise_error ::Valkyrie::Persistence::ObjectNotFoundError
|
105
114
|
end
|
106
115
|
|
@@ -113,6 +122,8 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
113
122
|
end
|
114
123
|
|
115
124
|
it 'can have multiple alternate identifiers' do
|
125
|
+
before_find_by_alternate_identifier.call if defined? before_find_by_alternate_identifier
|
126
|
+
|
116
127
|
resource = resource_class.new
|
117
128
|
resource.alternate_ids = [Valkyrie::ID.new('p9s0xfj'), Valkyrie::ID.new('jks0xfj')]
|
118
129
|
resource = persister.save(resource: resource)
|
@@ -199,7 +210,7 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
199
210
|
end
|
200
211
|
|
201
212
|
context "when the model doesn't have member_ids" do
|
202
|
-
let(:parent) { persister.save(resource:
|
213
|
+
let(:parent) { persister.save(resource: second_resource_class.new) }
|
203
214
|
|
204
215
|
it "returns an empty array" do
|
205
216
|
expect(subject.to_a).to eq []
|
@@ -208,12 +219,12 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
208
219
|
end
|
209
220
|
|
210
221
|
context "filtering by model" do
|
211
|
-
subject { query_service.find_members(resource: parent, model:
|
222
|
+
subject { query_service.find_members(resource: parent, model: second_resource_class) }
|
212
223
|
|
213
224
|
context "when the object has members" do
|
214
|
-
let(:child1) { persister.save(resource:
|
225
|
+
let(:child1) { persister.save(resource: second_resource_class.new) }
|
215
226
|
let(:child2) { persister.save(resource: resource_class.new) }
|
216
|
-
let(:child3) { persister.save(resource:
|
227
|
+
let(:child3) { persister.save(resource: second_resource_class.new) }
|
217
228
|
let(:parent) { persister.save(resource: resource_class.new(member_ids: [child3.id, child2.id, child1.id])) }
|
218
229
|
|
219
230
|
it "returns all a resource's members in order" do
|
@@ -284,11 +295,11 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
284
295
|
|
285
296
|
context "filtering by model" do
|
286
297
|
context "when the object has related resources that match the filter" do
|
287
|
-
subject { query_service.find_references_by(resource: child1, property: :a_member_of, model:
|
288
|
-
let(:child1) { persister.save(resource:
|
289
|
-
let(:parent) { persister.save(resource:
|
298
|
+
subject { query_service.find_references_by(resource: child1, property: :a_member_of, model: second_resource_class) }
|
299
|
+
let(:child1) { persister.save(resource: third_resource_class.new(a_member_of: [parent3.id, parent2.id, parent.id])) }
|
300
|
+
let(:parent) { persister.save(resource: second_resource_class.new) }
|
290
301
|
let(:parent2) { persister.save(resource: Valkyrie::Specs::CustomResource.new) }
|
291
|
-
let(:parent3) { persister.save(resource:
|
302
|
+
let(:parent3) { persister.save(resource: second_resource_class.new) }
|
292
303
|
|
293
304
|
it "returns only resources with the relationship filtered to the specified model" do
|
294
305
|
expect(subject.map(&:id).to_a).to match_array [parent3.id, parent.id]
|
@@ -296,11 +307,11 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
296
307
|
end
|
297
308
|
|
298
309
|
context "when the object has ordered related resources that match the filter" do
|
299
|
-
subject { query_service.find_references_by(resource: child1, property: :an_ordered_member_of, model:
|
300
|
-
let(:child1) { persister.save(resource:
|
301
|
-
let(:parent) { persister.save(resource:
|
310
|
+
subject { query_service.find_references_by(resource: child1, property: :an_ordered_member_of, model: second_resource_class) }
|
311
|
+
let(:child1) { persister.save(resource: third_resource_class.new(an_ordered_member_of: [parent.id, parent3.id, parent2.id, parent.id])) }
|
312
|
+
let(:parent) { persister.save(resource: second_resource_class.new) }
|
302
313
|
let(:parent2) { persister.save(resource: Valkyrie::Specs::CustomResource.new) }
|
303
|
-
let(:parent3) { persister.save(resource:
|
314
|
+
let(:parent3) { persister.save(resource: second_resource_class.new) }
|
304
315
|
|
305
316
|
it "returns only resources with the relationship filtered to the specified model" do
|
306
317
|
expect(subject.map(&:id).to_a).to match_array [parent.id, parent3.id, parent.id]
|
@@ -308,8 +319,8 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
308
319
|
end
|
309
320
|
|
310
321
|
context "when there are no related resources that match the filter" do
|
311
|
-
subject { query_service.find_references_by(resource: child1, property: :a_member_of, model:
|
312
|
-
let(:child1) { persister.save(resource:
|
322
|
+
subject { query_service.find_references_by(resource: child1, property: :a_member_of, model: second_resource_class) }
|
323
|
+
let(:child1) { persister.save(resource: third_resource_class.new(a_member_of: [parent.id])) }
|
313
324
|
let(:parent) { persister.save(resource: Valkyrie::Specs::CustomResource.new) }
|
314
325
|
|
315
326
|
it "returns an empty array" do
|
@@ -323,18 +334,18 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
323
334
|
context "when the resource is saved" do
|
324
335
|
context "when the property is unordered" do
|
325
336
|
it "returns everything which references the given resource by the given property" do
|
326
|
-
parent = persister.save(resource:
|
327
|
-
parent2 = persister.save(resource:
|
337
|
+
parent = persister.save(resource: second_resource_class.new)
|
338
|
+
parent2 = persister.save(resource: second_resource_class.new)
|
328
339
|
child = persister.save(resource: resource_class.new(a_member_of: [parent.id]))
|
329
340
|
child2 = persister.save(resource: resource_class.new(a_member_of: [parent.id, parent2.id, parent.id]))
|
330
341
|
persister.save(resource: resource_class.new)
|
331
|
-
persister.save(resource:
|
342
|
+
persister.save(resource: second_resource_class.new)
|
332
343
|
|
333
344
|
expect(query_service.find_inverse_references_by(resource: parent, property: :a_member_of).map(&:id).to_a).to contain_exactly child.id, child2.id
|
334
345
|
end
|
335
346
|
|
336
347
|
it "returns an empty array if there are none" do
|
337
|
-
parent = persister.save(resource:
|
348
|
+
parent = persister.save(resource: second_resource_class.new)
|
338
349
|
|
339
350
|
expect(query_service.find_inverse_references_by(resource: parent, property: :a_member_of).to_a).to eq []
|
340
351
|
end
|
@@ -342,11 +353,11 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
342
353
|
|
343
354
|
context "when the property is ordered" do
|
344
355
|
it "returns everything which references the given resource by the given property" do
|
345
|
-
parent = persister.save(resource:
|
356
|
+
parent = persister.save(resource: second_resource_class.new)
|
346
357
|
child = persister.save(resource: resource_class.new(an_ordered_member_of: [parent.id]))
|
347
358
|
child2 = persister.save(resource: resource_class.new(an_ordered_member_of: [parent.id, parent.id]))
|
348
359
|
persister.save(resource: resource_class.new)
|
349
|
-
persister.save(resource:
|
360
|
+
persister.save(resource: second_resource_class.new)
|
350
361
|
|
351
362
|
expect(query_service.find_inverse_references_by(resource: parent, property: :an_ordered_member_of).map(&:id).to_a).to contain_exactly child.id, child2.id
|
352
363
|
end
|
@@ -383,12 +394,12 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
383
394
|
|
384
395
|
context "when id is passed instead of resource" do
|
385
396
|
it "returns everything which references the given resource by the given property" do
|
386
|
-
parent = persister.save(resource:
|
387
|
-
parent2 = persister.save(resource:
|
397
|
+
parent = persister.save(resource: second_resource_class.new)
|
398
|
+
parent2 = persister.save(resource: second_resource_class.new)
|
388
399
|
child = persister.save(resource: resource_class.new(a_member_of: [parent.id]))
|
389
400
|
child2 = persister.save(resource: resource_class.new(a_member_of: [parent.id, parent2.id, parent.id]))
|
390
401
|
persister.save(resource: resource_class.new)
|
391
|
-
persister.save(resource:
|
402
|
+
persister.save(resource: second_resource_class.new)
|
392
403
|
|
393
404
|
expect(query_service.find_inverse_references_by(id: parent.id, property: :a_member_of).map(&:id).to_a).to contain_exactly child.id, child2.id
|
394
405
|
end
|
@@ -412,11 +423,11 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
412
423
|
subject { query_service.find_inverse_references_by(resource: parent, property: :a_member_of, model: Valkyrie::Specs::CustomResource) }
|
413
424
|
|
414
425
|
context "when the object has related resources that match the filter" do
|
415
|
-
let(:parent) { persister.save(resource:
|
426
|
+
let(:parent) { persister.save(resource: second_resource_class.new) }
|
416
427
|
|
417
428
|
it "returns only resources with the relationship filtered to the specified model" do
|
418
429
|
child1 = persister.save(resource: Valkyrie::Specs::CustomResource.new(a_member_of: [parent.id]))
|
419
|
-
persister.save(resource:
|
430
|
+
persister.save(resource: third_resource_class.new(a_member_of: [parent.id]))
|
420
431
|
child3 = persister.save(resource: Valkyrie::Specs::CustomResource.new(a_member_of: [parent.id]))
|
421
432
|
|
422
433
|
expect(subject.map(&:id).to_a).to match_array [child3.id, child1.id]
|
@@ -424,10 +435,10 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
424
435
|
end
|
425
436
|
|
426
437
|
context "when there are no related resources that match the filter" do
|
427
|
-
let(:parent) { persister.save(resource:
|
438
|
+
let(:parent) { persister.save(resource: second_resource_class.new) }
|
428
439
|
|
429
440
|
it "returns an empty array" do
|
430
|
-
persister.save(resource:
|
441
|
+
persister.save(resource: third_resource_class.new(a_member_of: [parent.id]))
|
431
442
|
|
432
443
|
expect(subject.to_a).to eq []
|
433
444
|
end
|
@@ -460,7 +471,7 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
460
471
|
end
|
461
472
|
|
462
473
|
context "when the model doesn't have member_ids" do
|
463
|
-
let(:child1) { persister.save(resource:
|
474
|
+
let(:child1) { persister.save(resource: second_resource_class.new) }
|
464
475
|
|
465
476
|
it "returns an empty array if there are none" do
|
466
477
|
expect(query_service.find_parents(resource: child1).to_a).to eq []
|
@@ -540,9 +551,9 @@ RSpec.shared_examples 'a Valkyrie query provider' do
|
|
540
551
|
describe ".count_all_of_model" do
|
541
552
|
it "counts all of that model" do
|
542
553
|
persister.save(resource: resource_class.new)
|
543
|
-
persister.save(resource:
|
544
|
-
persister.save(resource:
|
545
|
-
expect(query_service.count_all_of_model(model:
|
554
|
+
persister.save(resource: second_resource_class.new)
|
555
|
+
persister.save(resource: second_resource_class.new)
|
556
|
+
expect(query_service.count_all_of_model(model: second_resource_class)).to eq(2)
|
546
557
|
end
|
547
558
|
end
|
548
559
|
end
|
@@ -35,6 +35,22 @@ RSpec.shared_examples 'a Valkyrie::StorageAdapter' do
|
|
35
35
|
expect(uploaded_file.valid?(digests: { sha1: sha1 })).to be true
|
36
36
|
end
|
37
37
|
|
38
|
+
it "can upload a ::File" do
|
39
|
+
# WebMock prevents the request from using send_request_with_body_stream as it can do IRL
|
40
|
+
WebMock.disable!
|
41
|
+
allow(storage_adapter).to receive(:file_mover).and_return(FileUtils.method(:cp))
|
42
|
+
File.open(Valkyrie::Engine.root.join("spec", "fixtures", "files", "tn_example.jpg")) do |io_file|
|
43
|
+
sha1 = Digest::SHA1.file(io_file).to_s
|
44
|
+
|
45
|
+
resource = Valkyrie::Specs::CustomResource.new(id: SecureRandom.uuid)
|
46
|
+
|
47
|
+
expect(uploaded_file = storage_adapter.upload(file: io_file, original_filename: 'foo.jpg', resource: resource, fake_upload_argument: true)).to be_kind_of Valkyrie::StorageAdapter::File
|
48
|
+
|
49
|
+
expect(uploaded_file.valid?(digests: { sha1: sha1 })).to be true
|
50
|
+
end
|
51
|
+
WebMock.enable!
|
52
|
+
end
|
53
|
+
|
38
54
|
it "doesn't leave a file handle open on upload/find_by" do
|
39
55
|
# No file handle left open from upload.
|
40
56
|
resource = Valkyrie::Specs::CustomResource.new(id: "testdiscovery")
|
@@ -106,7 +106,8 @@ module Valkyrie::Storage
|
|
106
106
|
connection.http.put do |request|
|
107
107
|
request.url fedora_uri
|
108
108
|
request.headers['Content-Type'] = content_type
|
109
|
-
|
109
|
+
io_size = (io.length if io.respond_to?(:length)) || (io.size if io.respond_to?(:size))
|
110
|
+
request.headers['Content-Length'] = io_size.to_s if io_size
|
110
111
|
request.headers['Content-Disposition'] = "attachment; filename=\"#{original_filename}\""
|
111
112
|
request.headers['digest'] = "#{sha1}=#{Digest::SHA1.file(io)}" if io.respond_to?(:to_str)
|
112
113
|
request.headers['link'] = "<http://www.w3.org/ns/ldp#NonRDFSource>; rel=\"type\""
|
data/lib/valkyrie/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valkyrie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trey Pendragon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-struct
|