stash-wrapper 0.1.9 → 0.1.10
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/.gitignore +1 -1
- data/CHANGES.md +14 -0
- data/lib/stash/wrapper/embargo.rb +18 -5
- data/lib/stash/wrapper/identifier.rb +2 -0
- data/lib/stash/wrapper/inventory.rb +11 -1
- data/lib/stash/wrapper/license.rb +12 -2
- data/lib/stash/wrapper/module_info.rb +1 -1
- data/lib/stash/wrapper/size.rb +1 -0
- data/lib/stash/wrapper/stash_administrative.rb +6 -1
- data/lib/stash/wrapper/stash_wrapper.rb +2 -0
- data/lib/stash/wrapper/version.rb +2 -0
- data/spec/data/wrapper/wrapper-2.xml +2 -2
- data/spec/unit/stash/wrapper/embargo_spec.rb +77 -0
- data/spec/unit/stash/wrapper/identifier_spec.rb +63 -0
- data/spec/unit/stash/wrapper/inventory_spec.rb +75 -0
- data/spec/unit/stash/wrapper/license_spec.rb +70 -0
- data/spec/unit/stash/wrapper/size_spec.rb +36 -0
- data/spec/unit/stash/wrapper/stash_administrative_spec.rb +38 -8
- data/spec/unit/stash/wrapper/stash_file_spec.rb +35 -0
- data/spec/unit/stash/wrapper/stash_wrapper_spec.rb +53 -2
- data/spec/unit/stash/wrapper/version_spec.rb +68 -0
- data/stash-wrapper.gemspec +2 -2
- metadata +17 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ae3ee08a179c12c58921b916cd4643494a7c6c1
|
4
|
+
data.tar.gz: 1ef85936f7f0b4f460ad92828764bf444d548e0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 856c79ec10de00d0e8184d6c83040ef7e166986e94981a3b93f88117250f3bf0c9c22363a5c6514c76cc6b19f5058707e7e7dbd159e9681050fa28e17eae754a
|
7
|
+
data.tar.gz: b9839d55c2cba560b6c65c652dadadc4d1582d43396582a75bf5b1fda39249c4e4a14e56ee1f19e4d0d056b9f12f2a4136b777b986df44c3d6200219f4b9893c
|
data/.gitignore
CHANGED
data/CHANGES.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# 0.1.10 (next)
|
2
|
+
|
3
|
+
- Added convenience constant `License::CC_ZERO` for the
|
4
|
+
[CC0](https://creativecommons.org/publicdomain/zero/1.0/legalcode) public domain declaration
|
5
|
+
- Allow `License` to take a string as a `uri` parameter, so long as that string is a valid URI
|
6
|
+
- Validate parameters for:
|
7
|
+
- `StashWrapper`
|
8
|
+
- `StashAdministrative` (fixes issue #2)
|
9
|
+
- `Embargo`
|
10
|
+
- `Identifier`
|
11
|
+
- `Inventory`
|
12
|
+
- `Size`
|
13
|
+
- `Version`
|
14
|
+
|
1
15
|
# 0.1.9 (18 May 2016)
|
2
16
|
|
3
17
|
- Update to XML::MappingExtensions 0.4.1
|
@@ -18,11 +18,15 @@ module Stash
|
|
18
18
|
# @param period [String] The embargo period
|
19
19
|
# @param start_date [Date] The embargo start date
|
20
20
|
# @param end_date [Date] The embargo end date
|
21
|
-
def initialize(type:, period:, start_date:, end_date:)
|
21
|
+
def initialize(type:, period:, start_date:, end_date:) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
22
|
+
fail ArgumentError, "Specified type does not appear to be an EmbargoType: #{type || 'nil'}" unless type && type.is_a?(EmbargoType)
|
23
|
+
fail ArgumentError, "Specified embargo period does not appear to be a non-empty string: #{period.inspect}" if period.to_s.strip.empty?
|
24
|
+
fail ArgumentError, "Specified start date does not appear to be a date: #{start_date || 'nil'}" unless start_date && start_date.respond_to?(:iso8601)
|
25
|
+
fail ArgumentError, "Specified end date does not appear to be a date: #{end_date || 'nil'}" unless end_date && end_date.respond_to?(:iso8601)
|
26
|
+
|
22
27
|
self.type = type
|
23
|
-
self.period = period
|
24
|
-
self.start_date = start_date
|
25
|
-
self.end_date = end_date
|
28
|
+
self.period = period.to_s
|
29
|
+
self.start_date, self.end_date = valid_range(start_date, end_date)
|
26
30
|
end
|
27
31
|
|
28
32
|
# Creates a new `Embargo` instance of type {EmbargoType::NONE} with the current date as start and end.
|
@@ -31,7 +35,16 @@ module Stash
|
|
31
35
|
today = Date.today
|
32
36
|
new(type: EmbargoType::NONE, period: EmbargoType::NONE.value, start_date: today, end_date: today)
|
33
37
|
end
|
34
|
-
end
|
35
38
|
|
39
|
+
private
|
40
|
+
|
41
|
+
def valid_range(start_date, end_date)
|
42
|
+
if start_date > end_date
|
43
|
+
fail RangeError, "start_date #{start_date} must be <= end_date #{end_date}"
|
44
|
+
else
|
45
|
+
[start_date.to_date, end_date.to_date]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
36
49
|
end
|
37
50
|
end
|
@@ -12,6 +12,8 @@ module Stash
|
|
12
12
|
|
13
13
|
# Creates a new {Identifier}
|
14
14
|
def initialize(type:, value:)
|
15
|
+
fail ArgumentError, "Identifier type does not appear to be an IdentifierType: #{type || 'nil'}" unless type && type.is_a?(IdentifierType)
|
16
|
+
fail ArgumentError, "Identifier value does not appear to be a non-empty string: #{value.inspect}" if value.to_s.strip.empty?
|
15
17
|
self.type = type
|
16
18
|
self.value = value
|
17
19
|
end
|
@@ -14,9 +14,19 @@ module Stash
|
|
14
14
|
# creates a new {Inventory} object
|
15
15
|
# @param files [List<StashFile>] The inventory of files
|
16
16
|
def initialize(files:)
|
17
|
-
self.files = files
|
17
|
+
self.files = valid_file_array(files)
|
18
18
|
self.num_files = files.size
|
19
19
|
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def valid_file_array(files)
|
24
|
+
fail ArgumentError, "specified file list does not appear to be an array of StashFiles: #{files.inspect}" unless files.is_a?(Array)
|
25
|
+
files.each_with_index do |f, i|
|
26
|
+
fail ArgumentError, "files[#{i}] does not appear to be a StashFile: #{f.inspect}" unless f.is_a?(StashFile)
|
27
|
+
end
|
28
|
+
files
|
29
|
+
end
|
20
30
|
end
|
21
31
|
end
|
22
32
|
end
|
@@ -12,10 +12,13 @@ module Stash
|
|
12
12
|
|
13
13
|
# Creates a new {License} object
|
14
14
|
# @param name [String] The license name
|
15
|
-
# @param uri [URI] The license URI
|
15
|
+
# @param uri [URI, String] The license URI
|
16
|
+
# @raise [URI::InvalidURIError] if `uri` is a string that is not a valid URI
|
16
17
|
def initialize(name:, uri:)
|
18
|
+
fail ArgumentError, "License name does not appear to be a non-empty string: #{name.inspect}" if name.to_s.strip.empty?
|
19
|
+
fail ArgumentError, 'No uri provided' unless uri
|
17
20
|
self.name = name
|
18
|
-
self.uri = uri
|
21
|
+
self.uri = ::XML::MappingExtensions.to_uri(uri)
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
@@ -25,6 +28,13 @@ module Stash
|
|
25
28
|
name: 'Creative Commons Attribution 4.0 International (CC-BY)',
|
26
29
|
uri: URI('https://creativecommons.org/licenses/by/4.0/legalcode')
|
27
30
|
)
|
31
|
+
|
32
|
+
# Convenience instance for the [CC0](https://creativecommons.org/publicdomain/zero/1.0/legalcode)
|
33
|
+
# public domain declaration
|
34
|
+
CC_ZERO = License.new(
|
35
|
+
name: 'CC0 1.0 Universal (CC0 1.0) Public Domain Dedication',
|
36
|
+
uri: URI('https://creativecommons.org/publicdomain/zero/1.0/legalcode')
|
37
|
+
)
|
28
38
|
end
|
29
39
|
end
|
30
40
|
end
|
data/lib/stash/wrapper/size.rb
CHANGED
@@ -14,6 +14,7 @@ module Stash
|
|
14
14
|
# Creates a new {Size}
|
15
15
|
# @param bytes [Integer] the size in bytes
|
16
16
|
def initialize(bytes:)
|
17
|
+
fail ArgumentError, "specified file size does not appear to be an integer byte count: #{bytes || 'nil'}" unless bytes.respond_to?(:to_i) && bytes.to_i == bytes
|
17
18
|
self.size = bytes
|
18
19
|
self.unit = SizeUnit::BYTE
|
19
20
|
end
|
@@ -22,7 +22,12 @@ module Stash
|
|
22
22
|
# is supplied, it will default to an embargo of type {EmbargoType::NONE}
|
23
23
|
# with the current date as start and end.
|
24
24
|
# @param inventory [Inventory, nil] the (optional) file inventory
|
25
|
-
def initialize(version:, license:, embargo: nil, inventory: nil)
|
25
|
+
def initialize(version:, license:, embargo: nil, inventory: nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
26
|
+
fail ArgumentError, "version does not appear to be a Version object: #{version || 'nil'}" unless version.is_a?(Version)
|
27
|
+
fail ArgumentError, "license does not appear to be a License object: #{license || 'nil'}" unless license.is_a?(License)
|
28
|
+
fail ArgumentError, "embargo does not appear to be an Embargo object: #{embargo || 'nil'}" if embargo unless embargo.is_a?(Embargo)
|
29
|
+
fail ArgumentError, "inventory does not appear to be an Inventory object: #{inventory || 'nil'}" if inventory unless inventory.is_a?(Inventory)
|
30
|
+
|
26
31
|
self.version = version
|
27
32
|
self.license = license
|
28
33
|
self.embargo = embargo || Embargo.none
|
@@ -36,6 +36,8 @@ module Stash
|
|
36
36
|
# @param descriptive_elements [Array<REXML::Element>] the encapsulated
|
37
37
|
# XML metadata
|
38
38
|
def initialize(identifier:, version:, license:, embargo: nil, inventory: nil, descriptive_elements:) # rubocop:disable Metrics/ParameterLists
|
39
|
+
fail ArgumentError, "identifier does not appear to be an Identifier object: #{identifier || 'nil'}" unless identifier.is_a?(Identifier)
|
40
|
+
|
39
41
|
self.identifier = identifier
|
40
42
|
self.stash_administrative = StashAdministrative.new(
|
41
43
|
version: version,
|
@@ -15,6 +15,8 @@ module Stash
|
|
15
15
|
# @param date [Date] the date the new version was created
|
16
16
|
# @param note [String, nil] the (optional) version note
|
17
17
|
def initialize(number:, date:, note: nil)
|
18
|
+
fail ArgumentError, "specified version number does not appear to be an integer: #{number || 'nil'}" unless number.respond_to?(:to_i) && number.to_i == number
|
19
|
+
fail ArgumentError, "date does not appear to be a Date object: #{date || 'nil'}" unless date.respond_to?(:iso8601)
|
18
20
|
self.version_number = number
|
19
21
|
self.date = date
|
20
22
|
self.note = note
|
@@ -16,8 +16,8 @@
|
|
16
16
|
<st:embargo>
|
17
17
|
<st:type>download</st:type>
|
18
18
|
<st:period>1 year</st:period>
|
19
|
-
<st:start>
|
20
|
-
<st:end>
|
19
|
+
<st:start>2013-08-18Z</st:start>
|
20
|
+
<st:end>2014-08-18Z</st:end>
|
21
21
|
</st:embargo>
|
22
22
|
<st:inventory num_files="10">
|
23
23
|
<st:file>
|
@@ -3,6 +3,83 @@ require 'spec_helper'
|
|
3
3
|
module Stash
|
4
4
|
module Wrapper
|
5
5
|
describe Embargo do
|
6
|
+
describe '#initialize' do
|
7
|
+
|
8
|
+
attr_reader :params
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@params = {
|
12
|
+
type: EmbargoType::DOWNLOAD,
|
13
|
+
period: 'a year and a day',
|
14
|
+
start_date: Date.new(2015, 1, 1),
|
15
|
+
end_date: Date.new(2016, 1, 1)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'sets values from parameters' do
|
20
|
+
type = params[:type]
|
21
|
+
period = params[:period]
|
22
|
+
start_date = params[:start_date]
|
23
|
+
end_date = params[:end_date]
|
24
|
+
embargo = Embargo.new(params)
|
25
|
+
expect(embargo.type).to eq(type)
|
26
|
+
expect(embargo.period).to eq(period)
|
27
|
+
expect(embargo.start_date).to eq(start_date)
|
28
|
+
expect(embargo.end_date).to eq(end_date)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'rejects a nil type' do
|
32
|
+
params[:type] = nil
|
33
|
+
expect { Embargo.new(params) }.to raise_error(ArgumentError)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'rejects a string type' do
|
37
|
+
params[:type] = 'download'
|
38
|
+
expect { Embargo.new(params) }.to raise_error(ArgumentError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'rejects a nil period' do
|
42
|
+
params[:period] = nil
|
43
|
+
expect { Embargo.new(params) }.to raise_error(ArgumentError)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'rejects an empty period' do
|
47
|
+
params[:period] = ''
|
48
|
+
expect { Embargo.new(params) }.to raise_error(ArgumentError)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'rejects a blank period' do
|
52
|
+
params[:period] = ' '
|
53
|
+
expect { Embargo.new(params) }.to raise_error(ArgumentError)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'rejects a nil start date' do
|
57
|
+
params[:start_date] = nil
|
58
|
+
expect { Embargo.new(params) }.to raise_error(ArgumentError)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'rejects a string start date' do
|
62
|
+
params[:start_date] = '2015-01-01'
|
63
|
+
expect { Embargo.new(params) }.to raise_error(ArgumentError)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'rejects a nil end date' do
|
67
|
+
params[:end_date] = nil
|
68
|
+
expect { Embargo.new(params) }.to raise_error(ArgumentError)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'rejects a string end date' do
|
72
|
+
params[:end_date] = '2016-01-01'
|
73
|
+
expect { Embargo.new(params) }.to raise_error(ArgumentError)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'rejects an invalid date range' do
|
77
|
+
params[:start_date] = Date.new(2016, 1, 1)
|
78
|
+
params[:end_date] = Date.new(2015, 12, 31)
|
79
|
+
expect { Embargo.new(params) }.to raise_error(RangeError)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
6
83
|
describe 'none' do
|
7
84
|
it "returns a no-embargo #{Embargo}" do
|
8
85
|
embargo = Embargo.none
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Stash
|
4
|
+
module Wrapper
|
5
|
+
describe Identifier do
|
6
|
+
describe '#initialize' do
|
7
|
+
attr_accessor :params
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@params = {
|
11
|
+
type: IdentifierType::DOI,
|
12
|
+
value: '10.14749/1407399498'
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets fields from parameters' do
|
17
|
+
type = params[:type]
|
18
|
+
value = params[:value]
|
19
|
+
id = Identifier.new(params)
|
20
|
+
expect(id.type).to eq(type)
|
21
|
+
expect(id.value).to eq(value)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'requires a type' do
|
25
|
+
params.delete(:type)
|
26
|
+
expect { Identifier.new(params) }.to raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'rejects a nil type' do
|
30
|
+
params[:type] = nil
|
31
|
+
expect { Identifier.new(params) }.to raise_error(ArgumentError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'rejects a string type' do
|
35
|
+
params[:type] = 'ARK'
|
36
|
+
expect { Identifier.new(params) }.to raise_error(ArgumentError)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'requires a value' do
|
40
|
+
params.delete(:value)
|
41
|
+
expect { Identifier.new(params) }.to raise_error(ArgumentError)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'rejects a nil value' do
|
45
|
+
params[:value] = nil
|
46
|
+
expect { Identifier.new(params) }.to raise_error(ArgumentError)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'rejects an empty value' do
|
50
|
+
params[:value] = ''
|
51
|
+
expect { Identifier.new(params) }.to raise_error(ArgumentError)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'rejects a blank value' do
|
55
|
+
params[:value] = ' '
|
56
|
+
expect { Identifier.new(params) }.to raise_error(ArgumentError)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Stash
|
4
|
+
module Wrapper
|
5
|
+
describe Inventory do
|
6
|
+
describe '#initialize' do
|
7
|
+
attr_reader :params
|
8
|
+
before(:each) do
|
9
|
+
@params = {
|
10
|
+
files: [
|
11
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.dat', size_bytes: 12_345, mime_type: 'text/plain'),
|
12
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.csv', size_bytes: 67_890, mime_type: 'text/csv'),
|
13
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.sas7bdat', size_bytes: 123_456, mime_type: 'application/x-sas-data')
|
14
|
+
]
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'sets the file list' do
|
19
|
+
files = params[:files]
|
20
|
+
inv = Inventory.new(params)
|
21
|
+
expect(inv.files).to eq(files)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sets the file count' do
|
25
|
+
files = params[:files]
|
26
|
+
inv = Inventory.new(params)
|
27
|
+
expect(inv.num_files).to eq(files.size)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'accepts an empty list' do
|
31
|
+
params[:files] = []
|
32
|
+
inv = Inventory.new(params)
|
33
|
+
expect(inv.files).to eq([])
|
34
|
+
expect(inv.num_files).to eq(0)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'rejects single files' do
|
38
|
+
params[:files] = params[:files][0]
|
39
|
+
expect { Inventory.new(params) }.to raise_error(ArgumentError)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'rejects strings' do
|
43
|
+
params[:files] = 'HSRC_MasterSampleII.dat'
|
44
|
+
expect { Inventory.new(params) }.to raise_error(ArgumentError)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'rejects File objects' do
|
48
|
+
File.new('spec/data/wrapper/wrapper-2-payload.xml') do |f|
|
49
|
+
params[:files] = f
|
50
|
+
expect { Inventory.new(params) }.to raise_error(ArgumentError)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'rejects arrays of strings' do
|
55
|
+
params[:files] = params[:files].map(&:pathname)
|
56
|
+
expect { Inventory.new(params) }.to raise_error(ArgumentError)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'rejects arrays of File objects' do
|
60
|
+
files = [
|
61
|
+
File.new('spec/data/wrapper/wrapper-1.xml'),
|
62
|
+
File.new('spec/data/wrapper/wrapper-1.xml')
|
63
|
+
]
|
64
|
+
begin
|
65
|
+
params[:files] = files
|
66
|
+
expect { Inventory.new(params) }.to raise_error(ArgumentError)
|
67
|
+
ensure
|
68
|
+
files.each(&:close)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Stash
|
4
|
+
module Wrapper
|
5
|
+
describe License do
|
6
|
+
describe '#initialize' do
|
7
|
+
|
8
|
+
attr_reader :params
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@params = {
|
12
|
+
name: 'Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)',
|
13
|
+
uri: URI('http://creativecommons.org/licenses/by-sa/4.0/legalcode')
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'sets attributes from parameters' do
|
18
|
+
name = params[:name]
|
19
|
+
uri = params[:uri]
|
20
|
+
lic = License.new(params)
|
21
|
+
expect(lic.name).to eq(name)
|
22
|
+
expect(lic.uri).to eq(uri)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'requires a name' do
|
26
|
+
params.delete(:name)
|
27
|
+
expect { License.new(params) }.to raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'rejects a nil name' do
|
31
|
+
params[:name] = nil
|
32
|
+
expect { License.new(params) }.to raise_error(ArgumentError)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'rejects an empty name' do
|
36
|
+
params[:name] = ''
|
37
|
+
expect { License.new(params) }.to raise_error(ArgumentError)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'rejects a blank name' do
|
41
|
+
params[:name] = ' '
|
42
|
+
expect { License.new(params) }.to raise_error(ArgumentError)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'requires a uri' do
|
46
|
+
params.delete(:uri)
|
47
|
+
expect { License.new(params) }.to raise_error(ArgumentError)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'accepts a string URI' do
|
51
|
+
url = 'http://example.org/'
|
52
|
+
params[:uri] = url
|
53
|
+
lic = License.new(params)
|
54
|
+
expect(lic.uri).to eq(URI(url))
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'rejects a nil uri' do
|
58
|
+
params[:uri] = nil
|
59
|
+
expect { License.new(params) }.to raise_error(ArgumentError)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'rejects an invalid uri' do
|
63
|
+
params[:uri] = 'I am not a URI'
|
64
|
+
expect { License.new(params) }.to raise_error(URI::InvalidURIError)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Stash
|
4
|
+
module Wrapper
|
5
|
+
describe Size do
|
6
|
+
describe '#initialize' do
|
7
|
+
attr_accessor :params
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@params = { bytes: 12_345 }
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'sets fields from parameters' do
|
14
|
+
size = Size.new(params)
|
15
|
+
expect(size.size).to eq(12_345)
|
16
|
+
expect(size.unit).to eq(SizeUnit::BYTE)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'rejects a nil byte count' do
|
20
|
+
params.delete(:bytes)
|
21
|
+
expect { Size.new(params) }.to raise_error(ArgumentError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'rejects a non-integer byte count' do
|
25
|
+
params[:bytes] = 1.1
|
26
|
+
expect { Size.new(params) }.to raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'rejects a non-numeric byte count' do
|
30
|
+
params[:bytes] = '1'
|
31
|
+
expect { Size.new(params) }.to raise_error(ArgumentError)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -3,16 +3,23 @@ require 'spec_helper'
|
|
3
3
|
module Stash
|
4
4
|
module Wrapper
|
5
5
|
describe StashAdministrative do
|
6
|
+
|
7
|
+
attr_reader :params
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@params = {
|
11
|
+
version: Version.new(number: 1, date: Date.new(2013, 8, 18), note: 'Sample wrapped Datacite document'),
|
12
|
+
license: License::CC_BY,
|
13
|
+
inventory: Inventory.new(
|
14
|
+
files: [
|
15
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.dat', size_bytes: 12_345, mime_type: 'text/plain')
|
16
|
+
])
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
6
20
|
describe '#initialize' do
|
7
21
|
it 'defaults to no embargo' do
|
8
|
-
admin = StashAdministrative.new(
|
9
|
-
version: Version.new(number: 1, date: Date.new(2013, 8, 18), note: 'Sample wrapped Datacite document'),
|
10
|
-
license: License::CC_BY,
|
11
|
-
inventory: Inventory.new(
|
12
|
-
files: [
|
13
|
-
StashFile.new(pathname: 'HSRC_MasterSampleII.dat', size_bytes: 12_345, mime_type: 'text/plain')
|
14
|
-
])
|
15
|
-
)
|
22
|
+
admin = StashAdministrative.new(params)
|
16
23
|
embargo = admin.embargo
|
17
24
|
expect(embargo).to be_an(Embargo)
|
18
25
|
expect(embargo.type).to eq(EmbargoType::NONE)
|
@@ -21,6 +28,29 @@ module Stash
|
|
21
28
|
expect(embargo.start_date).to eq(today)
|
22
29
|
expect(embargo.end_date).to eq(today)
|
23
30
|
end
|
31
|
+
|
32
|
+
it 'requires a version' do
|
33
|
+
params.delete(:version)
|
34
|
+
expect { StashAdministrative.new(params) }.to raise_error(ArgumentError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'requires a valid version' do
|
38
|
+
params[:version] = 1
|
39
|
+
expect { StashAdministrative.new(params) }.to raise_error(ArgumentError)
|
40
|
+
|
41
|
+
params[:version] = '1'
|
42
|
+
expect { StashAdministrative.new(params) }.to raise_error(ArgumentError)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'requires a license' do
|
46
|
+
params.delete(:license)
|
47
|
+
expect { StashAdministrative.new(params) }.to raise_error(ArgumentError)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'requires a valid license' do
|
51
|
+
params[:license] = 'CC-BY'
|
52
|
+
expect { StashAdministrative.new(params) }.to raise_error(ArgumentError)
|
53
|
+
end
|
24
54
|
end
|
25
55
|
end
|
26
56
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Stash
|
4
|
+
module Wrapper
|
5
|
+
describe StashFile do
|
6
|
+
describe '#initialize' do
|
7
|
+
attr_reader :params
|
8
|
+
before(:each) do
|
9
|
+
@params = {
|
10
|
+
pathname: 'foo.txt',
|
11
|
+
size_bytes: 12_345,
|
12
|
+
mime_type: 'text/plain'
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets attributes from parameters'
|
17
|
+
|
18
|
+
it 'requires a pathname'
|
19
|
+
it 'rejects a nil pathname'
|
20
|
+
it 'rejects an empty pathname'
|
21
|
+
it 'rejects a blank pathname'
|
22
|
+
|
23
|
+
it 'requires size_bytes'
|
24
|
+
it 'rejects a nil size_bytes'
|
25
|
+
it 'rejects a non-integer size_bytes'
|
26
|
+
it 'rejects a non-numeric size_bytes'
|
27
|
+
|
28
|
+
it 'accepts a standard MIME type'
|
29
|
+
it 'accepts a non-standard MIME type'
|
30
|
+
it 'fails if mime_type isn\'t a MIME type'
|
31
|
+
it 'parses a nil mime-type as nil'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -109,6 +109,57 @@ module Stash
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
+
describe '#initialize' do
|
113
|
+
|
114
|
+
attr_reader :params
|
115
|
+
|
116
|
+
before(:each) do
|
117
|
+
@params = {
|
118
|
+
identifier: Identifier.new(type: IdentifierType::DOI, value: '10.14749/1407399498'),
|
119
|
+
version: Version.new(number: 1, date: Date.new(2013, 8, 18), note: 'Sample wrapped Datacite document'),
|
120
|
+
license: License::CC_BY,
|
121
|
+
inventory: Inventory.new(
|
122
|
+
files: [
|
123
|
+
StashFile.new(pathname: 'HSRC_MasterSampleII.dat', size_bytes: 12_345, mime_type: 'text/plain')
|
124
|
+
]),
|
125
|
+
descriptive_elements: []
|
126
|
+
}
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'requires an identifier' do
|
130
|
+
params.delete(:identifier)
|
131
|
+
expect { StashWrapper.new(params) }.to raise_error(ArgumentError)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'requires a valid identifier' do
|
135
|
+
params[:identifier] = 'doi:10.14749/1407399498'
|
136
|
+
expect { StashWrapper.new(params) }.to raise_error(ArgumentError)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'requires a version' do
|
140
|
+
params.delete(:version)
|
141
|
+
expect { StashWrapper.new(params) }.to raise_error(ArgumentError)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'requires a valid version' do
|
145
|
+
params[:version] = 1
|
146
|
+
expect { StashWrapper.new(params) }.to raise_error(ArgumentError)
|
147
|
+
|
148
|
+
params[:version] = '1'
|
149
|
+
expect { StashWrapper.new(params) }.to raise_error(ArgumentError)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'requires a license' do
|
153
|
+
params.delete(:license)
|
154
|
+
expect { StashWrapper.new(params) }.to raise_error(ArgumentError)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'requires a valid license' do
|
158
|
+
params[:license] = 'CC-BY'
|
159
|
+
expect { StashWrapper.new(params) }.to raise_error(ArgumentError)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
112
163
|
describe 'convenience accessors' do
|
113
164
|
it 'evades the law of Demeter' do
|
114
165
|
data = File.read('spec/data/wrapper/wrapper-1.xml')
|
@@ -193,7 +244,7 @@ module Stash
|
|
193
244
|
identifier: Identifier.new(type: IdentifierType::DOI, value: '10.14749/1407399498'),
|
194
245
|
version: Version.new(number: 1, date: Date.new(2013, 8, 18), note: 'Sample wrapped Datacite document'),
|
195
246
|
license: License::CC_BY,
|
196
|
-
embargo: Embargo.new(type: EmbargoType::DOWNLOAD, period: '1 year', start_date: Date.new(
|
247
|
+
embargo: Embargo.new(type: EmbargoType::DOWNLOAD, period: '1 year', start_date: Date.new(2013, 8, 18), end_date: Date.new(2014, 8, 18)),
|
197
248
|
inventory: Inventory.new(
|
198
249
|
files: [
|
199
250
|
StashFile.new(pathname: 'HSRC_MasterSampleII.dat', size_bytes: 12_345, mime_type: 'text/plain')
|
@@ -252,7 +303,7 @@ module Stash
|
|
252
303
|
identifier: Identifier.new(type: IdentifierType::DOI, value: '10.14749/1407399498'),
|
253
304
|
version: Version.new(number: 1, date: Date.new(2013, 8, 18), note: 'Sample wrapped Datacite document'),
|
254
305
|
license: License::CC_BY,
|
255
|
-
embargo: Embargo.new(type: EmbargoType::DOWNLOAD, period: '1 year', start_date: Date.new(
|
306
|
+
embargo: Embargo.new(type: EmbargoType::DOWNLOAD, period: '1 year', start_date: Date.new(2013, 8, 18), end_date: Date.new(2014, 8, 18)),
|
256
307
|
inventory: Inventory.new(
|
257
308
|
files: [
|
258
309
|
StashFile.new(pathname: 'HSRC_MasterSampleII.dat', size_bytes: 12_345, mime_type: 'text/plain'),
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Stash
|
4
|
+
module Wrapper
|
5
|
+
describe Version do
|
6
|
+
describe '#initialize' do
|
7
|
+
attr_reader :params
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@params = {
|
11
|
+
number: 1,
|
12
|
+
date: Date.today,
|
13
|
+
note: 'I am a note'
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'sets fields from arguments' do
|
18
|
+
number = params[:number]
|
19
|
+
date = params[:date]
|
20
|
+
note = params[:note]
|
21
|
+
version = Version.new(params)
|
22
|
+
expect(version.version_number).to eq(number)
|
23
|
+
expect(version.date).to eq(date)
|
24
|
+
expect(version.note).to eq(note)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'accepts a nil note' do
|
28
|
+
params.delete(:note)
|
29
|
+
version = Version.new(params)
|
30
|
+
expect(version.note).to be_nil
|
31
|
+
|
32
|
+
params[:note] = nil
|
33
|
+
version = Version.new(params)
|
34
|
+
expect(version.note).to be_nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'accepts a DateTime as the date' do
|
38
|
+
date = DateTime.new(2001, 2, 3, 4, 5, 6)
|
39
|
+
params[:date] = date
|
40
|
+
version = Version.new(params)
|
41
|
+
expect(version.date).to eq(date)
|
42
|
+
xml = version.write_xml
|
43
|
+
expect(xml).to include('<date>2001-02-03Z</date>')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'rejects a nil number' do
|
47
|
+
params.delete(:number)
|
48
|
+
expect { Version.new(params) }.to raise_error(ArgumentError)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'rejects a non-integer number' do
|
52
|
+
params[:number] = 1.1
|
53
|
+
expect { Version.new(params) }.to raise_error(ArgumentError)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'rejects a non-numeric number' do
|
57
|
+
params[:number] = '1'
|
58
|
+
expect { Version.new(params) }.to raise_error(ArgumentError)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'rejects a non-date or -datetime' do
|
62
|
+
params[:date] = '2016-06-01'
|
63
|
+
expect { Version.new(params) }.to raise_error(ArgumentError)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/stash-wrapper.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
17
|
origin = `git config --get remote.origin.url`.chomp
|
18
|
-
origin_uri = origin.start_with?('http') ? URI(origin) : URI(origin.
|
18
|
+
origin_uri = origin.start_with?('http') ? URI(origin) : URI(origin.gsub(%r{git@([^:]+)(.com|.org)[^\/]+}, 'http://\1\2'))
|
19
19
|
spec.homepage = URI::HTTP.build(host: origin_uri.host, path: origin_uri.path.chomp('.git')).to_s
|
20
20
|
|
21
21
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.require_paths = ['lib']
|
26
26
|
|
27
27
|
spec.add_dependency 'typesafe_enum', '~> 0.1', '>= 0.1.7'
|
28
|
-
spec.add_dependency 'xml-mapping_extensions', '~> 0.4', '>= 0.4.
|
28
|
+
spec.add_dependency 'xml-mapping_extensions', '~> 0.4', '>= 0.4.2'
|
29
29
|
|
30
30
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
31
31
|
spec.add_development_dependency 'equivalent-xml', '~> 0.6.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stash-wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Moles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typesafe_enum
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: '0.4'
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 0.4.
|
42
|
+
version: 0.4.2
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: '0.4'
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: 0.4.
|
52
|
+
version: 0.4.2
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: bundler
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -206,10 +206,16 @@ files:
|
|
206
206
|
- spec/rspec_custom_matchers.rb
|
207
207
|
- spec/spec_helper.rb
|
208
208
|
- spec/unit/stash/wrapper/embargo_spec.rb
|
209
|
+
- spec/unit/stash/wrapper/identifier_spec.rb
|
210
|
+
- spec/unit/stash/wrapper/inventory_spec.rb
|
211
|
+
- spec/unit/stash/wrapper/license_spec.rb
|
212
|
+
- spec/unit/stash/wrapper/size_spec.rb
|
209
213
|
- spec/unit/stash/wrapper/stash_administrative_spec.rb
|
214
|
+
- spec/unit/stash/wrapper/stash_file_spec.rb
|
210
215
|
- spec/unit/stash/wrapper/stash_wrapper_spec.rb
|
216
|
+
- spec/unit/stash/wrapper/version_spec.rb
|
211
217
|
- stash-wrapper.gemspec
|
212
|
-
homepage: http://github.com/
|
218
|
+
homepage: http://github.com/stash-wrapper
|
213
219
|
licenses:
|
214
220
|
- MIT
|
215
221
|
metadata: {}
|
@@ -244,6 +250,12 @@ test_files:
|
|
244
250
|
- spec/rspec_custom_matchers.rb
|
245
251
|
- spec/spec_helper.rb
|
246
252
|
- spec/unit/stash/wrapper/embargo_spec.rb
|
253
|
+
- spec/unit/stash/wrapper/identifier_spec.rb
|
254
|
+
- spec/unit/stash/wrapper/inventory_spec.rb
|
255
|
+
- spec/unit/stash/wrapper/license_spec.rb
|
256
|
+
- spec/unit/stash/wrapper/size_spec.rb
|
247
257
|
- spec/unit/stash/wrapper/stash_administrative_spec.rb
|
258
|
+
- spec/unit/stash/wrapper/stash_file_spec.rb
|
248
259
|
- spec/unit/stash/wrapper/stash_wrapper_spec.rb
|
260
|
+
- spec/unit/stash/wrapper/version_spec.rb
|
249
261
|
has_rdoc:
|