ddr-models 2.7.3 → 2.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ddr/models/file_management.rb +4 -4
- data/lib/ddr/models/version.rb +1 -1
- data/spec/models/file_management_spec.rb +33 -23
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3c6181e57a1a67d5f374d1d83d5afa6e33d1962
|
4
|
+
data.tar.gz: 11ee5833bb3cb7730b30ed8e2ef38579de97ac59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e52d6d3b398d55289c9eb51d97fad7a08661849918e1077523ae770dbf8f77b261382befd8f7695f186981e9fba2c9dc40fc89039df701a3a9391473746cf8b0
|
7
|
+
data.tar.gz: 49ce6887894e3857da80afa8ba9f97bedb27a6b155405b64d8706e17d983d68d4f2086fd22ee51268d0d73e1a654dc60a9fa894609fe26d2ed1560d8178fcd2e
|
@@ -19,10 +19,10 @@ module Ddr::Models
|
|
19
19
|
# @param external [Boolean] Add file to external datastream.
|
20
20
|
# Not required for external datastream classes
|
21
21
|
# or datastream instances having controlGroup 'E'.
|
22
|
-
def add_file(file, dsid, mime_type: nil, external: false)
|
23
|
-
mime_type
|
24
|
-
source_path
|
25
|
-
original_filename
|
22
|
+
def add_file(file, dsid, mime_type: nil, external: false, original_filename: nil)
|
23
|
+
mime_type ||= Ddr::Utils.mime_type_for(file)
|
24
|
+
source_path = Ddr::Utils.file_path(file)
|
25
|
+
original_filename ||= Ddr::Utils.file_name(file)
|
26
26
|
file_to_add = FileToAdd.new(dsid, source_path, original_filename)
|
27
27
|
cache.with(file_to_add: file_to_add) do
|
28
28
|
run_callbacks(:add_file) do
|
data/lib/ddr/models/version.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
RSpec.shared_examples "a repository external file" do
|
2
|
-
it "
|
2
|
+
it "is owned by the effective user" do
|
3
3
|
expect(File.owned?(file_path)).to be true
|
4
4
|
end
|
5
|
-
it "
|
5
|
+
it "is readable by the effective user" do
|
6
6
|
expect(File.readable?(file_path)).to be true
|
7
7
|
end
|
8
|
-
it "
|
8
|
+
it "is writable by the effective user" do
|
9
9
|
expect(File.writable?(file_path)).to be true
|
10
10
|
end
|
11
|
-
it "
|
11
|
+
it "does not have the sticky bit set" do
|
12
12
|
expect(File.sticky?(file_path)).to be false
|
13
13
|
end
|
14
|
-
it "
|
14
|
+
it "has 644 mode" do
|
15
15
|
expect("%o" % File.world_readable?(file_path)).to eq "644"
|
16
16
|
end
|
17
17
|
end
|
@@ -24,51 +24,61 @@ module Ddr::Models
|
|
24
24
|
let(:xml_file) { fixture_file_upload("fits/image.xml", "text/xml") }
|
25
25
|
|
26
26
|
describe "#add_file" do
|
27
|
-
it "
|
27
|
+
it "runs a virus scan on the file" do
|
28
28
|
expect(object).to receive(:virus_scan)
|
29
29
|
object.add_file image_file, "content"
|
30
30
|
end
|
31
|
-
it "
|
31
|
+
it "calls add_file_datastream by default" do
|
32
32
|
expect(object).to receive(:add_file_datastream)
|
33
33
|
object.add_file image_file, "random_ds_1"
|
34
34
|
end
|
35
|
-
it "
|
35
|
+
it "calls add_file_datastream when dsid spec is managed" do
|
36
36
|
expect(object).to receive(:add_file_datastream)
|
37
37
|
object.add_file xml_file, "fits"
|
38
38
|
end
|
39
|
-
it "
|
39
|
+
it "calls add_external_file when dsid spec is external" do
|
40
40
|
expect(object).to receive(:add_external_file)
|
41
41
|
.with(image_file, "content", mime_type: "image/tiff")
|
42
42
|
object.add_file image_file, "content"
|
43
43
|
end
|
44
|
-
it "
|
44
|
+
it "calls add_external_file when :external => true option passed" do
|
45
45
|
expect(object).to receive(:add_external_file)
|
46
46
|
.with(image_file, "random_ds_2", mime_type: "image/tiff")
|
47
47
|
object.add_file image_file, "random_ds_2", external: true
|
48
48
|
end
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
context "original_filename" do
|
50
|
+
context "when dsid == 'content'" do
|
51
|
+
it "sets original_filename" do
|
52
|
+
expect { object.add_file image_file, "content" }
|
53
|
+
.to change(object, :original_filename).to("imageA.tif")
|
54
|
+
expect { object.add_file image_file, "content", original_filename: "foo.tif" }
|
55
|
+
.to change(object, :original_filename).to("foo.tif")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
context "when dsid != 'content'" do
|
59
|
+
it "does not set original_filename" do
|
60
|
+
expect { object.add_file xml_file, "fits" }
|
61
|
+
.not_to change(object, :original_filename)
|
62
|
+
expect { object.add_file xml_file, "fits", original_filename: "foo" }
|
63
|
+
.not_to change(object, :original_filename)
|
64
|
+
end
|
65
|
+
end
|
56
66
|
end
|
57
67
|
end
|
58
68
|
|
59
69
|
describe "#add_external_file" do
|
60
|
-
it "
|
70
|
+
it "calls add_external_datastream if no spec for dsid" do
|
61
71
|
expect(object).to receive(:add_external_datastream).with("random_ds_3").and_call_original
|
62
72
|
object.add_external_file(image_file, "random_ds_3")
|
63
73
|
end
|
64
|
-
it "
|
74
|
+
it "raises an exception if datastream is not external" do
|
65
75
|
expect { object.add_external_file(xml_file, "fits") }.to raise_error(ArgumentError)
|
66
76
|
end
|
67
|
-
it "
|
77
|
+
it "sets the mimeType" do
|
68
78
|
expect(object.content).to receive(:mimeType=).with("image/tiff")
|
69
79
|
object.add_external_file(image_file, "content", mime_type: "image/tiff")
|
70
80
|
end
|
71
|
-
it "
|
81
|
+
it "sets dsLocation to URI for generated file path by default" do
|
72
82
|
object.add_external_file(image_file, "content")
|
73
83
|
expect(object.content.dsLocation).not_to eq URI.escape("file:#{image_file.path}")
|
74
84
|
expect(object.content.dsLocation).not_to be_nil
|
@@ -83,7 +93,7 @@ module Ddr::Models
|
|
83
93
|
end
|
84
94
|
|
85
95
|
describe "#add_external_datastream" do
|
86
|
-
it "
|
96
|
+
it "returns a new external datastream" do
|
87
97
|
ds = object.add_external_datastream("random_ds_27")
|
88
98
|
expect(ds.controlGroup).to eq "E"
|
89
99
|
expect(object.datastreams["random_ds_27"]).to eq ds
|
@@ -100,7 +110,7 @@ module Ddr::Models
|
|
100
110
|
object.add_file(file2, "e_content_2", external: true)
|
101
111
|
object.save
|
102
112
|
end
|
103
|
-
it "
|
113
|
+
it "returns a list of file paths for all versions of all external datastreams for the object" do
|
104
114
|
paths = object.external_datastream_file_paths
|
105
115
|
expect(paths.size).to eq 2
|
106
116
|
paths.each do |path|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddr-models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.7.
|
4
|
+
version: 2.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Coble
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-04-
|
12
|
+
date: 2017-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -780,7 +780,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
780
780
|
version: '0'
|
781
781
|
requirements: []
|
782
782
|
rubyforge_project:
|
783
|
-
rubygems_version: 2.6.
|
783
|
+
rubygems_version: 2.6.8
|
784
784
|
signing_key:
|
785
785
|
specification_version: 4
|
786
786
|
summary: Models used in the Duke Digital Repository
|