datacite-mapping 0.2.4 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +27 -11
- data/.ruby-version +1 -1
- data/CHANGES.md +25 -0
- data/Gemfile +2 -0
- data/LICENSE.md +1 -1
- data/README.md +10 -5
- data/Rakefile +5 -3
- data/datacite-mapping.gemspec +10 -9
- data/examples/reading.rb +1 -1
- data/examples/writing.rb +1 -0
- data/lib/datacite/mapping/affiliation.rb +44 -0
- data/lib/datacite/mapping/alternate_identifier.rb +6 -2
- data/lib/datacite/mapping/contributor.rb +35 -7
- data/lib/datacite/mapping/contributor_name.rb +42 -0
- data/lib/datacite/mapping/creator.rb +43 -9
- data/lib/datacite/mapping/creator_name.rb +42 -0
- data/lib/datacite/mapping/date.rb +17 -5
- data/lib/datacite/mapping/date_value.rb +10 -2
- data/lib/datacite/mapping/description.rb +10 -4
- data/lib/datacite/mapping/empty_filtering_nodes.rb +3 -0
- data/lib/datacite/mapping/funding_reference.rb +31 -10
- data/lib/datacite/mapping/geo_location.rb +8 -1
- data/lib/datacite/mapping/geo_location_box.rb +17 -10
- data/lib/datacite/mapping/geo_location_node.rb +12 -8
- data/lib/datacite/mapping/geo_location_point.rb +11 -6
- data/lib/datacite/mapping/geo_location_polygon.rb +13 -2
- data/lib/datacite/mapping/identifier.rb +18 -14
- data/lib/datacite/mapping/module_info.rb +5 -3
- data/lib/datacite/mapping/name_identifier.rb +12 -6
- data/lib/datacite/mapping/name_type.rb +18 -0
- data/lib/datacite/mapping/namespace_extensions.rb +2 -0
- data/lib/datacite/mapping/publisher.rb +42 -0
- data/lib/datacite/mapping/read_only_nodes.rb +9 -3
- data/lib/datacite/mapping/related_identifier.rb +43 -4
- data/lib/datacite/mapping/resource.rb +37 -21
- data/lib/datacite/mapping/resource_type.rb +7 -1
- data/lib/datacite/mapping/rights.rb +35 -6
- data/lib/datacite/mapping/subject.rb +7 -4
- data/lib/datacite/mapping/title.rb +7 -4
- data/lib/datacite/mapping.rb +3 -1
- data/spec/.rubocop.yml +3 -0
- data/spec/data/datacite4/{datacite-example-Box_dateCollected_DataCollector-v4.0.xml → datacite-example-Box_dateCollected_DataCollector-v4.xml} +9 -11
- data/spec/data/datacite4/{datacite-example-GeoLocation-v4.0.xml → datacite-example-GeoLocation-v4.xml} +11 -10
- data/spec/data/datacite4/{datacite-example-HasMetadata-v4.0.xml → datacite-example-HasMetadata-v4.xml} +18 -13
- data/spec/data/datacite4/{datacite-example-ResearchGroup_Methods-v4.0.xml → datacite-example-ResearchGroup_Methods-v4.xml} +14 -12
- data/spec/data/datacite4/{datacite-example-ResourceTypeGeneral_Collection-v4.0.xml → datacite-example-ResourceTypeGeneral_Collection-v4.xml} +9 -9
- data/spec/data/datacite4/datacite-example-affiliation-v4.xml +114 -0
- data/spec/data/datacite4/{datacite-example-complicated-v4.0.xml → datacite-example-complicated-v4.xml} +14 -11
- data/spec/data/datacite4/datacite-example-datapaper-v4.xml +32 -0
- data/spec/data/datacite4/{datacite-example-dataset-v4.0.xml → datacite-example-dataset-v4.xml} +20 -14
- data/spec/data/datacite4/datacite-example-full-v4.xml +114 -0
- data/spec/data/datacite4/{datacite-example-fundingReference-v.4.0.xml → datacite-example-fundingReference-v4.xml} +16 -13
- data/spec/data/datacite4/datacite-example-polygon-advanced-v4.xml +141 -0
- data/spec/data/datacite4/datacite-example-polygon-v4.xml +161 -0
- data/spec/data/datacite4/{datacite-example-relationTypeIsIdenticalTo-v4.0.xml → datacite-example-relationTypeIsIdenticalTo-v4.xml} +17 -17
- data/spec/data/datacite4/datacite-example-software-v4.xml +66 -0
- data/spec/data/datacite4/{datacite-example-video-v4.0.xml → datacite-example-video-v4.xml} +7 -7
- data/spec/data/datacite4/{datacite-example-workflow-v4.0.xml → datacite-example-workflow-v4.xml} +13 -11
- data/spec/data/datacite4/metadata.xsd +102 -57
- data/spec/rspec_custom_matchers.rb +11 -8
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/datacite/mapping/alternate_identifier_spec.rb +2 -0
- data/spec/unit/datacite/mapping/contributor_spec.rb +9 -1
- data/spec/unit/datacite/mapping/creator_spec.rb +11 -3
- data/spec/unit/datacite/mapping/date_spec.rb +2 -0
- data/spec/unit/datacite/mapping/date_value_spec.rb +2 -0
- data/spec/unit/datacite/mapping/description_spec.rb +2 -0
- data/spec/unit/datacite/mapping/funding_reference_spec.rb +13 -1
- data/spec/unit/datacite/mapping/geo_location_box_spec.rb +2 -0
- data/spec/unit/datacite/mapping/geo_location_point_spec.rb +2 -0
- data/spec/unit/datacite/mapping/geo_location_polygon_spec.rb +22 -20
- data/spec/unit/datacite/mapping/geo_location_spec.rb +24 -22
- data/spec/unit/datacite/mapping/identifier_spec.rb +8 -6
- data/spec/unit/datacite/mapping/name_identifier_spec.rb +2 -0
- data/spec/unit/datacite/mapping/related_identifier_spec.rb +2 -0
- data/spec/unit/datacite/mapping/resource_spec.rb +34 -33
- data/spec/unit/datacite/mapping/rights_spec.rb +3 -14
- data/spec/unit/datacite/mapping/subject_spec.rb +2 -0
- data/spec/unit/datacite/mapping/title_spec.rb +2 -0
- metadata +74 -60
- data/spec/data/datacite4/datacite-example-full-v4.0.xml +0 -71
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Datacite
|
@@ -45,11 +47,11 @@ module Datacite
|
|
45
47
|
end
|
46
48
|
it 'accepts a polygon' do
|
47
49
|
polygon = GeoLocationPolygon.new(points: [
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
GeoLocationPoint.new(47.61, -122.33),
|
51
|
+
GeoLocationPoint.new(-33.45, -122.33),
|
52
|
+
GeoLocationPoint.new(47.61, -70.67),
|
53
|
+
GeoLocationPoint.new(47.61, -122.33)
|
54
|
+
])
|
53
55
|
loc = GeoLocation.new(polygon: polygon)
|
54
56
|
expect(loc.polygon).to eq(polygon)
|
55
57
|
end
|
@@ -106,11 +108,11 @@ module Datacite
|
|
106
108
|
describe '#polygon=' do
|
107
109
|
it 'sets the polygon' do
|
108
110
|
polygon = GeoLocationPolygon.new(points: [
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
111
|
+
GeoLocationPoint.new(47.61, -122.33),
|
112
|
+
GeoLocationPoint.new(-33.45, -122.33),
|
113
|
+
GeoLocationPoint.new(47.61, -70.67),
|
114
|
+
GeoLocationPoint.new(47.61, -122.33)
|
115
|
+
])
|
114
116
|
loc = GeoLocation.new
|
115
117
|
loc.polygon = polygon
|
116
118
|
expect(loc.polygon).to eq(polygon)
|
@@ -168,11 +170,11 @@ module Datacite
|
|
168
170
|
expect(loc.place).to eq('Atlantic Ocean')
|
169
171
|
actual_polygon = loc.polygon
|
170
172
|
expected_polygon = GeoLocationPolygon.new(points: [
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
173
|
+
GeoLocationPoint.new(31.233, -67.302),
|
174
|
+
GeoLocationPoint.new(-68.211, -71.032),
|
175
|
+
GeoLocationPoint.new(42.893, 41.09),
|
176
|
+
GeoLocationPoint.new(31.233, -67.302)
|
177
|
+
])
|
176
178
|
expect(actual_polygon).to eq(expected_polygon)
|
177
179
|
end
|
178
180
|
|
@@ -196,12 +198,12 @@ module Datacite
|
|
196
198
|
point: GeoLocationPoint.new(31.233, -67.302),
|
197
199
|
box: GeoLocationBox.new(41.09, -71.032, 42.893, -68.211),
|
198
200
|
place: 'Atlantic Ocean',
|
199
|
-
polygon:
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
201
|
+
polygon: GeoLocationPolygon.new(points: [
|
202
|
+
GeoLocationPoint.new(-67.302, 31.233),
|
203
|
+
GeoLocationPoint.new(-71.032, -68.211),
|
204
|
+
GeoLocationPoint.new(41.09, 42.893),
|
205
|
+
GeoLocationPoint.new(-67.302, 31.233)
|
206
|
+
])
|
205
207
|
)
|
206
208
|
end
|
207
209
|
|
@@ -257,7 +259,7 @@ module Datacite
|
|
257
259
|
|
258
260
|
it 'writes DC3 in XSD-defined order: point, box, place' do
|
259
261
|
actual_xml = loc.save_to_xml(mapping: :datacite_3)
|
260
|
-
expected_order = %w
|
262
|
+
expected_order = %w[geoLocationPoint geoLocationBox geoLocationPlace]
|
261
263
|
actual_order = actual_xml.children.map(&:name)
|
262
264
|
expect(actual_order).to eq(expected_order)
|
263
265
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Datacite
|
@@ -21,13 +23,13 @@ module Datacite
|
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'disallows bad DOIs' do
|
24
|
-
bad_dois = %w
|
26
|
+
bad_dois = %w[
|
25
27
|
20.14749/1407399495
|
26
28
|
11.14749/1407399495
|
27
29
|
10./1407399495
|
28
30
|
10.14749\1407399495
|
29
31
|
10.14749/
|
30
|
-
|
32
|
+
]
|
31
33
|
bad_dois.each do |doi|
|
32
34
|
expect { Identifier.new(value: doi) }.to raise_error(ArgumentError)
|
33
35
|
end
|
@@ -71,13 +73,13 @@ module Datacite
|
|
71
73
|
end
|
72
74
|
|
73
75
|
it 'raises ArgumentError if it is passed a bad DOI' do
|
74
|
-
bad_dois = %w
|
76
|
+
bad_dois = %w[
|
75
77
|
20.14749/1407399495
|
76
78
|
11.14749/1407399495
|
77
79
|
10./1407399495
|
78
80
|
10.14749\1407399495
|
79
81
|
10.14749/
|
80
|
-
|
82
|
+
]
|
81
83
|
bad_dois.each do |doi|
|
82
84
|
expect { Identifier.from_doi(doi) }.to raise_error do |e|
|
83
85
|
expect(e).to be_an(ArgumentError)
|
@@ -95,13 +97,13 @@ module Datacite
|
|
95
97
|
end
|
96
98
|
it 'disallows bad DOIs' do
|
97
99
|
id = Identifier.allocate
|
98
|
-
bad_dois = %w
|
100
|
+
bad_dois = %w[
|
99
101
|
20.14749/1407399495
|
100
102
|
11.14749/1407399495
|
101
103
|
10./1407399495
|
102
104
|
10.14749\1407399495
|
103
105
|
10.14749/
|
104
|
-
|
106
|
+
]
|
105
107
|
bad_dois.each do |doi|
|
106
108
|
expect { id.value = doi }.to raise_error(ArgumentError)
|
107
109
|
expect(id.value).to be_nil
|
@@ -1,5 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
4
|
+
require 'tmpdir'
|
3
5
|
|
4
6
|
module Datacite
|
5
7
|
module Mapping
|
@@ -119,9 +121,9 @@ module Datacite
|
|
119
121
|
resource = Resource.new(args)
|
120
122
|
expect(resource.creator_affiliations)
|
121
123
|
.to eq([
|
122
|
-
|
123
|
-
|
124
|
-
|
124
|
+
['United Artists', 'Metro-Goldwyn-Mayer'],
|
125
|
+
['Gaumont Buena Vista International', '20th Century Fox']
|
126
|
+
])
|
125
127
|
end
|
126
128
|
end
|
127
129
|
end
|
@@ -171,32 +173,31 @@ module Datacite
|
|
171
173
|
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
172
174
|
end
|
173
175
|
it 'requires a non-blank publisher' do
|
174
|
-
|
175
|
-
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
176
|
+
expect { Publisher.new(value: ' ') }.to raise_error(ArgumentError)
|
176
177
|
end
|
177
178
|
it 'can be initialized' do
|
178
179
|
resource = Resource.new(args)
|
179
|
-
expect(resource.publisher).to eq(publisher)
|
180
|
+
expect(resource.publisher.value).to eq(publisher)
|
180
181
|
end
|
181
182
|
it 'can be set' do
|
182
183
|
new_publisher = 'University of California'
|
183
184
|
resource = Resource.new(args)
|
184
185
|
resource.publisher = new_publisher
|
185
|
-
expect(resource.publisher).to eq(new_publisher)
|
186
|
+
expect(resource.publisher.value).to eq(new_publisher)
|
186
187
|
end
|
187
188
|
it 'strips on initialization' do
|
188
|
-
args[:publisher] = '
|
189
|
+
args[:publisher] = Publisher.new(value: '
|
189
190
|
University of California
|
190
|
-
|
191
|
+
')
|
191
192
|
resource = Resource.new(args)
|
192
|
-
expect(resource.publisher).to eq('University of California')
|
193
|
+
expect(resource.publisher.value).to eq('University of California')
|
193
194
|
end
|
194
195
|
it 'strips on set' do
|
195
196
|
resource = Resource.new(args)
|
196
|
-
resource.publisher = '
|
197
|
+
resource.publisher = Publisher.new(value: '
|
197
198
|
University of California
|
198
|
-
|
199
|
-
expect(resource.publisher).to eq('University of California')
|
199
|
+
')
|
200
|
+
expect(resource.publisher.value).to eq('University of California')
|
200
201
|
end
|
201
202
|
end
|
202
203
|
|
@@ -228,7 +229,7 @@ module Datacite
|
|
228
229
|
it 'converts strings to integers' do
|
229
230
|
new_pub_year = 1963
|
230
231
|
resource = Resource.new(args)
|
231
|
-
resource.publication_year =
|
232
|
+
resource.publication_year = new_pub_year.to_s
|
232
233
|
expect(resource.publication_year).to eq(new_pub_year)
|
233
234
|
end
|
234
235
|
end
|
@@ -426,7 +427,8 @@ module Datacite
|
|
426
427
|
scheme_uri: URI('http://iatistandard.org/201/codelists/OrganisationIdentifier/'),
|
427
428
|
value: 'GR-9¾'
|
428
429
|
),
|
429
|
-
type: ContributorType::FUNDER
|
430
|
+
type: ContributorType::FUNDER
|
431
|
+
)
|
430
432
|
@resource.contributors << @funder
|
431
433
|
end
|
432
434
|
|
@@ -465,7 +467,7 @@ module Datacite
|
|
465
467
|
describe 'dates:' do
|
466
468
|
it 'can be initialized' do
|
467
469
|
dates = [
|
468
|
-
Date.new(value: DateTime.new(1914, 8, 4, 11,
|
470
|
+
Date.new(value: DateTime.new(1914, 8, 4, 11, 0o1, 6.0123, '+1'), type: DateType::AVAILABLE),
|
469
471
|
Date.new(value: '1914-08-04T11:01:06.0123+01:00', type: DateType::AVAILABLE)
|
470
472
|
]
|
471
473
|
args[:dates] = dates
|
@@ -483,7 +485,7 @@ module Datacite
|
|
483
485
|
it 'can be set' do
|
484
486
|
resource = Resource.new(args)
|
485
487
|
dates = [
|
486
|
-
Date.new(value: DateTime.new(1914, 8, 4, 11,
|
488
|
+
Date.new(value: DateTime.new(1914, 8, 4, 11, 0o1, 6.0123, '+1'), type: DateType::AVAILABLE),
|
487
489
|
Date.new(value: '1914-08-04T11:01:06.0123+01:00', type: DateType::AVAILABLE)
|
488
490
|
]
|
489
491
|
resource.dates = dates
|
@@ -625,7 +627,7 @@ module Datacite
|
|
625
627
|
|
626
628
|
describe 'sizes:' do
|
627
629
|
it 'can be initialized' do
|
628
|
-
sizes = %w
|
630
|
+
sizes = %w[48K 128K]
|
629
631
|
args[:sizes] = sizes
|
630
632
|
resource = Resource.new(args)
|
631
633
|
expect(resource.sizes).to eq(sizes)
|
@@ -639,7 +641,7 @@ module Datacite
|
|
639
641
|
|
640
642
|
describe '#sizes=' do
|
641
643
|
it 'can be set' do
|
642
|
-
sizes = %w
|
644
|
+
sizes = %w[48K 128K]
|
643
645
|
resource = Resource.new(args)
|
644
646
|
resource.sizes = sizes
|
645
647
|
expect(resource.sizes).to eq(sizes)
|
@@ -660,7 +662,7 @@ module Datacite
|
|
660
662
|
|
661
663
|
describe 'formats:' do
|
662
664
|
it 'can be initialized' do
|
663
|
-
formats = %w
|
665
|
+
formats = %w[D64 DSK]
|
664
666
|
args[:formats] = formats
|
665
667
|
resource = Resource.new(args)
|
666
668
|
expect(resource.formats).to eq(formats)
|
@@ -674,7 +676,7 @@ module Datacite
|
|
674
676
|
|
675
677
|
describe '#formats=' do
|
676
678
|
it 'can be set' do
|
677
|
-
formats = %w
|
679
|
+
formats = %w[D64 DSK]
|
678
680
|
resource = Resource.new(args)
|
679
681
|
resource.formats = formats
|
680
682
|
expect(resource.formats).to eq(formats)
|
@@ -918,7 +920,7 @@ module Datacite
|
|
918
920
|
end
|
919
921
|
|
920
922
|
def parse_file(xml_text, basename)
|
921
|
-
|
923
|
+
Resource.parse_xml(xml_text)
|
922
924
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
923
925
|
warn "Error parsing #{basename}: #{e}"
|
924
926
|
File.open("tmp/#{basename}-xml_text.xml", 'w') { |t| t.write(xml_text) }
|
@@ -929,7 +931,7 @@ module Datacite
|
|
929
931
|
def write_xml(resource, basename, options)
|
930
932
|
# Workaround for Dash 1 datacite.xml with missing DOI
|
931
933
|
resource.identifier = Identifier.from_doi('10.5555/12345678') unless resource.identifier
|
932
|
-
|
934
|
+
resource.write_xml(options)
|
933
935
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
934
936
|
warn "Error writing #{basename}: #{e}"
|
935
937
|
raise
|
@@ -940,7 +942,7 @@ module Datacite
|
|
940
942
|
r1 = r0.gsub(%r{<br\s+/>}, '<br/>') # entity-de-escape <br/> tags
|
941
943
|
# r2 = r1.gsub(%r{<(?!br)[^>]+/>}, '') # remove empty tags
|
942
944
|
r2 = r1
|
943
|
-
r3 = r2.gsub(/<resource (xmlns:xsi="[^"]+")\s+(xsi:schemaLocation="[^"]+")>/,
|
945
|
+
r3 = r2.gsub(/<resource (xmlns:xsi="[^"]+")\s+(xsi:schemaLocation="[^"]+")>/, '<resource \\2 \\1 xmlns="http://datacite.org/schema/kernel-3">') # fix missing namespace
|
944
946
|
r4 = r3.gsub(%r{(<identifier[^>]+>)\s*([^ ]+)\s*(</identifier>)}, '\\1\\2\\3') # trim identifiers
|
945
947
|
r5 = r4.gsub(%r{<([^>]+tude)>([0-9.-]+?)(0?)0+</\1>}, '<\\1>\\2\\3</\\1>') # strip trailing coordinate zeroes
|
946
948
|
r6 = r5.gsub(%r{<(geoLocation[^>]+)>[^<]+</\1>}) { |loc| loc.gsub(/([0-9\-]+\.[0-9]+?)0+([^0-9])/, '\\1\\2') } # strip trailing coordinate zeroes
|
@@ -984,11 +986,10 @@ module Datacite
|
|
984
986
|
actual_xml = write_xml(resource, basename, options)
|
985
987
|
expected_xml.gsub!(/(<resource[^>]+>)\s+(<creators>)/, "\\1\n <identifier identifierType=\"DOI\">10.5555/12345678</identifier>\n \\2") if fix_dash1
|
986
988
|
begin
|
987
|
-
# actual_xml = actual_xml.gsub(''', "'")
|
988
989
|
expect(actual_xml).to be_xml(expected_xml)
|
989
990
|
rescue Exception # rubocop:disable Lint/RescueException
|
990
|
-
File.open("tmp/#{basename}-expected.xml", 'w') { |t| t.write(expected_xml) }
|
991
|
-
File.open("tmp/#{basename}-actual.xml", 'w') { |t| t.write(actual_xml) }
|
991
|
+
File.open("/tmp/#{basename}-expected.xml", 'w') { |t| t.write(expected_xml) }
|
992
|
+
File.open("/tmp/#{basename}-actual.xml", 'w') { |t| t.write(actual_xml) }
|
992
993
|
raise
|
993
994
|
end
|
994
995
|
end
|
@@ -1017,7 +1018,7 @@ module Datacite
|
|
1017
1018
|
matches = warnings_including(substring)
|
1018
1019
|
found_count = matches.size
|
1019
1020
|
msg = "expected #{count} warnings including '#{substring}', found #{found_count}"
|
1020
|
-
msg
|
1021
|
+
msg += ": #{matches}" if include_matches
|
1021
1022
|
expect(found_count).to eq(count), msg
|
1022
1023
|
end
|
1023
1024
|
|
@@ -1025,7 +1026,7 @@ module Datacite
|
|
1025
1026
|
matches = REXML::XPath.match(rexml, xpath)
|
1026
1027
|
found_count = matches.size
|
1027
1028
|
msg = "expected #{count} matches for XPath '#{xpath}', found #{found_count}"
|
1028
|
-
msg
|
1029
|
+
msg += ": #{matches}" if include_matches
|
1029
1030
|
expect(found_count).to eq(count), msg
|
1030
1031
|
end
|
1031
1032
|
|
@@ -1033,7 +1034,7 @@ module Datacite
|
|
1033
1034
|
@warnings = []
|
1034
1035
|
allow(ReadOnlyNodes).to receive(:warn) do |w|
|
1035
1036
|
warnings << w
|
1036
|
-
Kernel.warn(w) # for debugging
|
1037
|
+
# Kernel.warn(w) # for debugging
|
1037
1038
|
end
|
1038
1039
|
|
1039
1040
|
xml = File.read('spec/data/datacite-4-synthetic.xml')
|
@@ -1051,7 +1052,7 @@ module Datacite
|
|
1051
1052
|
end
|
1052
1053
|
|
1053
1054
|
it 'warns about givenNames and familyNames' do
|
1054
|
-
name_tags = %w
|
1055
|
+
name_tags = %w[givenName familyName]
|
1055
1056
|
name_tags.each do |tag|
|
1056
1057
|
expect_matches("//#{tag}", 0, true)
|
1057
1058
|
expect_warning(tag, 1)
|
@@ -1151,7 +1152,7 @@ module Datacite
|
|
1151
1152
|
|
1152
1153
|
describe '#save_to_file' do
|
1153
1154
|
it 'saves to a file' do
|
1154
|
-
xml_text =
|
1155
|
+
xml_text = File.read('spec/data/datacite4/datacite-example-full-v4.xml')
|
1155
1156
|
resource = Resource.parse_xml(xml_text)
|
1156
1157
|
Dir.mktmpdir('resource_spec') do |dir|
|
1157
1158
|
path = "#{dir}/resource.xml"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Datacite
|
@@ -12,9 +14,6 @@ module Datacite
|
|
12
14
|
rights = Rights.new(value: 'CC0 1.0 Universal', uri: URI('http://creativecommons.org/publicdomain/zero/1.0/'))
|
13
15
|
expect(rights.uri).to eq(URI('http://creativecommons.org/publicdomain/zero/1.0/'))
|
14
16
|
end
|
15
|
-
it 'requires a value' do
|
16
|
-
expect { Rights.new(uri: URI('http://creativecommons.org/publicdomain/zero/1.0/')) }.to raise_error(ArgumentError)
|
17
|
-
end
|
18
17
|
end
|
19
18
|
|
20
19
|
describe '#value=' do
|
@@ -23,16 +22,6 @@ module Datacite
|
|
23
22
|
rights.value = 'CC0 1.0 Universal'
|
24
23
|
expect(rights.value).to eq('CC0 1.0 Universal')
|
25
24
|
end
|
26
|
-
it 'requires a value' do
|
27
|
-
rights = Rights.new(value: 'CC0 1.0 Universal')
|
28
|
-
expect { rights.value = nil }.to raise_error(ArgumentError)
|
29
|
-
expect(rights.value).to eq('CC0 1.0 Universal')
|
30
|
-
end
|
31
|
-
it 'requires a non-empty value' do
|
32
|
-
rights = Rights.new(value: 'CC0 1.0 Universal')
|
33
|
-
expect { rights.value = '' }.to raise_error(ArgumentError)
|
34
|
-
expect(rights.value).to eq('CC0 1.0 Universal')
|
35
|
-
end
|
36
25
|
end
|
37
26
|
|
38
27
|
describe '#uri=' do
|
@@ -80,7 +69,7 @@ module Datacite
|
|
80
69
|
expected_xml = '<rights rightsURI="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International (CC BY 4.0)</rights>'
|
81
70
|
expect(rights.save_to_xml).to be_xml(expected_xml)
|
82
71
|
|
83
|
-
[
|
72
|
+
%i[CC_ZERO CC_BY].each do |c|
|
84
73
|
r = Rights.const_get(c)
|
85
74
|
puts "#{c.to_s.downcase.gsub('_zero', '0')}:"
|
86
75
|
puts " uri: #{r.uri}"
|