datacite-mapping 0.1.0

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.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +42 -0
  3. data/.rubocop.yml +28 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +2 -0
  6. data/.yardopts +2 -0
  7. data/CHANGES.md +3 -0
  8. data/Gemfile +3 -0
  9. data/LICENSE.md +22 -0
  10. data/README.md +168 -0
  11. data/Rakefile +49 -0
  12. data/datacite-mapping.gemspec +37 -0
  13. data/examples/reading.rb +75 -0
  14. data/examples/writing.rb +49 -0
  15. data/lib/datacite/mapping.rb +36 -0
  16. data/lib/datacite/mapping/alternate_identifier.rb +45 -0
  17. data/lib/datacite/mapping/contributor.rb +125 -0
  18. data/lib/datacite/mapping/creator.rb +48 -0
  19. data/lib/datacite/mapping/date.rb +153 -0
  20. data/lib/datacite/mapping/description.rb +121 -0
  21. data/lib/datacite/mapping/geo_location.rb +49 -0
  22. data/lib/datacite/mapping/geo_location_box.rb +137 -0
  23. data/lib/datacite/mapping/geo_location_point.rb +102 -0
  24. data/lib/datacite/mapping/identifier.rb +45 -0
  25. data/lib/datacite/mapping/module_info.rb +12 -0
  26. data/lib/datacite/mapping/name_identifier.rb +48 -0
  27. data/lib/datacite/mapping/related_identifier.rb +209 -0
  28. data/lib/datacite/mapping/resource.rb +201 -0
  29. data/lib/datacite/mapping/resource_type.rb +83 -0
  30. data/lib/datacite/mapping/rights.rb +36 -0
  31. data/lib/datacite/mapping/subject.rb +55 -0
  32. data/lib/datacite/mapping/title.rb +69 -0
  33. data/spec/.rubocop.yml +7 -0
  34. data/spec/data/resource.xml +61 -0
  35. data/spec/rspec_custom_matchers.rb +69 -0
  36. data/spec/spec_helper.rb +31 -0
  37. data/spec/unit/datacite/mapping/alternate_identifier_spec.rb +60 -0
  38. data/spec/unit/datacite/mapping/contributor_spec.rb +129 -0
  39. data/spec/unit/datacite/mapping/creator_spec.rb +125 -0
  40. data/spec/unit/datacite/mapping/date_spec.rb +246 -0
  41. data/spec/unit/datacite/mapping/description_spec.rb +89 -0
  42. data/spec/unit/datacite/mapping/geo_location_box_spec.rb +241 -0
  43. data/spec/unit/datacite/mapping/geo_location_point_spec.rb +148 -0
  44. data/spec/unit/datacite/mapping/geo_location_spec.rb +116 -0
  45. data/spec/unit/datacite/mapping/identifier_spec.rb +75 -0
  46. data/spec/unit/datacite/mapping/name_identifier_spec.rb +89 -0
  47. data/spec/unit/datacite/mapping/related_identifier_spec.rb +157 -0
  48. data/spec/unit/datacite/mapping/resource_spec.rb +727 -0
  49. data/spec/unit/datacite/mapping/resource_type_spec.rb +69 -0
  50. data/spec/unit/datacite/mapping/rights_spec.rb +78 -0
  51. data/spec/unit/datacite/mapping/subject_spec.rb +108 -0
  52. data/spec/unit/datacite/mapping/title_spec.rb +113 -0
  53. metadata +262 -0
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ module Datacite
4
+ module Mapping
5
+
6
+ describe Contributor do
7
+ describe '#initialize' do
8
+ it 'sets the contributor name' do
9
+ contributor = Contributor.new(name: 'Hedy Lamarr', type: ContributorType::RESEARCHER)
10
+ expect(contributor.name).to eq('Hedy Lamarr')
11
+ end
12
+
13
+ it 'sets the identifier' do
14
+ id = NameIdentifier.new(scheme: 'ISNI', scheme_uri: URI('http://isni.org/'), value: '0000-0001-1690-159X')
15
+ contributor = Contributor.new(name: 'Hedy Lamarr', identifier: id, type: ContributorType::RESEARCHER)
16
+ expect(contributor.identifier).to eq(id)
17
+ end
18
+
19
+ it 'sets affiliations' do
20
+ affiliations = ['United Artists', 'Metro-Goldwyn-Mayer']
21
+ contributor = Contributor.new(name: 'Hedy Lamarr', affiliations: affiliations, type: ContributorType::RESEARCHER)
22
+ expect(contributor.affiliations).to eq(affiliations)
23
+ end
24
+
25
+ it 'sets the contributor type' do
26
+ ContributorType.each do |t|
27
+ contributor = Contributor.new(name: 'Hedy Lamarr', type: t)
28
+ expect(contributor.type).to eq(t)
29
+ end
30
+ end
31
+
32
+ it 'requires a contributor name' do
33
+ expect { Contributor.new(type: ContributorType::RESEARCHER) }.to raise_error(ArgumentError)
34
+ end
35
+
36
+ it 'requires a contributor type' do
37
+ expect { Contributor.new(name: 'Hedy Lamarr') }.to raise_error(ArgumentError)
38
+ end
39
+
40
+ it 'defaults to a nil identifier' do
41
+ contributor = Contributor.new(name: 'Hedy Lamarr', type: ContributorType::RESEARCHER)
42
+ expect(contributor.identifier).to be_nil
43
+ end
44
+
45
+ it 'defaults to an empty affiliation array' do
46
+ contributor = Contributor.new(name: 'Hedy Lamarr', type: ContributorType::RESEARCHER)
47
+ expect(contributor.affiliations).to eq([])
48
+ end
49
+
50
+ end
51
+
52
+ describe '#name=' do
53
+ it 'sets the name' do
54
+ contrib = Contributor.allocate
55
+ contrib.name = 'Hershlag, Natalie'
56
+ expect(contrib.name).to eq('Hershlag, Natalie')
57
+ end
58
+ it 'rejects nil' do
59
+ contrib = Contributor.new(name: 'Hershlag, Natalie', type: ContributorType::PROJECT_MEMBER)
60
+ expect { contrib.name = nil }.to raise_error(ArgumentError)
61
+ expect(contrib.name).to eq('Hershlag, Natalie')
62
+ end
63
+ it 'rejects empty' do
64
+ contrib = Contributor.new(name: 'Hershlag, Natalie', type: ContributorType::PROJECT_MEMBER)
65
+ expect { contrib.name = '' }.to raise_error(ArgumentError)
66
+ expect(contrib.name).to eq('Hershlag, Natalie')
67
+ end
68
+ end
69
+
70
+ describe '#type=' do
71
+ it 'sets the type' do
72
+ contrib = Contributor.allocate
73
+ contrib.type = ContributorType::PROJECT_MEMBER
74
+ expect(contrib.type).to eq(ContributorType::PROJECT_MEMBER)
75
+ end
76
+ it 'rejects nil' do
77
+ contrib = Contributor.new(name: 'Hershlag, Natalie', type: ContributorType::PROJECT_MEMBER)
78
+ expect { contrib.type = nil }.to raise_error(ArgumentError)
79
+ expect(contrib.type).to eq(ContributorType::PROJECT_MEMBER)
80
+ end
81
+ end
82
+
83
+ describe '#load_from_xml' do
84
+ it 'parses XML' do
85
+ xml_text = '<contributor contributorType="ProjectMember">
86
+ <contributorName>Hershlag, Natalie</contributorName>
87
+ <nameIdentifier schemeURI="http://isni.org/" nameIdentifierScheme="ISNI">0000-0001-0907-8419</nameIdentifier>
88
+ <affiliation>Gaumont Buena Vista International</affiliation>
89
+ <affiliation>20th Century Fox</affiliation>
90
+ </contributor>'
91
+ xml = REXML::Document.new(xml_text).root
92
+ contributor = Contributor.load_from_xml(xml)
93
+ expect(contributor.name).to eq('Hershlag, Natalie')
94
+ expect(contributor.affiliations).to eq(['Gaumont Buena Vista International', '20th Century Fox'])
95
+ id = contributor.identifier
96
+ expect(id.scheme).to eq('ISNI')
97
+ expect(id.scheme_uri).to eq(URI('http://isni.org'))
98
+ expect(id.value).to eq('0000-0001-0907-8419')
99
+ expect(contributor.type).to eq(ContributorType::PROJECT_MEMBER)
100
+
101
+ end
102
+
103
+ it 'defaults to an empty affiliation array' do
104
+ xml_text = '<contributor contributorType="Researcher">
105
+ <contributorName>Hedy Lamarr</contributorName>
106
+ <nameIdentifier schemeURI="http://isni.org/" nameIdentifierScheme="ISNI">0000-0001-1690-159X</nameIdentifier>
107
+ </contributor>'
108
+ xml = REXML::Document.new(xml_text).root
109
+ contributor = Contributor.load_from_xml(xml)
110
+ expect(contributor.affiliations).to eq([])
111
+ end
112
+ end
113
+
114
+ describe '#save_to_xml' do
115
+ it 'writes XML' do
116
+ id = NameIdentifier.new(scheme: 'ISNI', scheme_uri: URI('http://isni.org/'), value: '0000-0001-1690-159X')
117
+ contributor = Contributor.new(name: 'Hedy Lamarr', type: ContributorType::RESEARCHER, identifier: id, affiliations: ['United Artists', 'Metro-Goldwyn-Mayer'])
118
+ expected_xml = '<contributor contributorType="Researcher">
119
+ <contributorName>Hedy Lamarr</contributorName>
120
+ <nameIdentifier schemeURI="http://isni.org/" nameIdentifierScheme="ISNI">0000-0001-1690-159X</nameIdentifier>
121
+ <affiliation>United Artists</affiliation>
122
+ <affiliation>Metro-Goldwyn-Mayer</affiliation>
123
+ </contributor>'
124
+ expect(contributor.save_to_xml).to be_xml(expected_xml)
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+
3
+ module Datacite
4
+ module Mapping
5
+ describe Creator do
6
+
7
+ describe '#initialize' do
8
+ it 'sets the creator name' do
9
+ creator = Creator.new(name: 'Hedy Lamarr')
10
+ expect(creator.name).to eq('Hedy Lamarr')
11
+ end
12
+
13
+ it 'sets the identifier' do
14
+ id = NameIdentifier.new(scheme: 'ISNI', scheme_uri: URI('http://isni.org/'), value: '0000-0001-1690-159X')
15
+ creator = Creator.new(name: 'Hedy Lamarr', identifier: id)
16
+ expect(creator.identifier).to eq(id)
17
+ end
18
+
19
+ it 'sets affiliations' do
20
+ creator = Creator.new(name: 'Hedy Lamarr', affiliations: ['United Artists', 'Metro-Goldwyn-Mayer'])
21
+ expect(creator.affiliations).to eq(['United Artists', 'Metro-Goldwyn-Mayer'])
22
+ end
23
+
24
+ it 'defaults to an empty affiliation array' do
25
+ creator = Creator.new(name: 'Hedy Lamarr')
26
+ expect(creator.affiliations).to eq([])
27
+ end
28
+ end
29
+
30
+ describe '#name=' do
31
+ it 'sets the name' do
32
+ creator = Creator.allocate
33
+ creator.name = 'Hedy Lamarr'
34
+ expect(creator.name).to eq('Hedy Lamarr')
35
+ end
36
+ it 'rejects nil' do
37
+ creator = Creator.new(name: 'Hedy Lamarr')
38
+ expect { creator.name = nil }.to raise_error(ArgumentError)
39
+ expect(creator.name).to eq('Hedy Lamarr')
40
+ end
41
+ it 'rejects empty' do
42
+ creator = Creator.new(name: 'Hedy Lamarr')
43
+ expect { creator.name = '' }.to raise_error(ArgumentError)
44
+ expect(creator.name).to eq('Hedy Lamarr')
45
+ end
46
+ end
47
+
48
+ describe '#identifier=' do
49
+ it 'sets the identifier' do
50
+ creator = Creator.new(name: 'Hedy Lamarr')
51
+ identifier = NameIdentifier.new(scheme: 'ISNI', scheme_uri: URI('http://isni.org/'), value: '0000-0001-1690-159X')
52
+ creator.identifier = identifier
53
+ expect(creator.identifier).to eq(identifier)
54
+ end
55
+ it 'allows nil' do
56
+ creator = Creator.new(name: 'Hedy Lamarr', identifier: NameIdentifier.new(scheme: 'ISNI', scheme_uri: URI('http://isni.org/'), value: '0000-0001-1690-159X'))
57
+ creator.identifier = nil
58
+ expect(creator.identifier).to be_nil
59
+ end
60
+ end
61
+
62
+ describe '#affiliation=' do
63
+ it 'sets affiliations' do
64
+ creator = Creator.allocate
65
+ affiliations = ['United Artists', 'Metro-Goldwyn-Mayer']
66
+ creator.affiliations = affiliations
67
+ expect(creator.affiliations).to eq(affiliations)
68
+ end
69
+ it 'treats nil as empty' do
70
+ creator = Creator.new(name: 'Hedy Lamarr', affiliations: ['United Artists', 'Metro-Goldwyn-Mayer'])
71
+ creator.affiliations = nil
72
+ expect(creator.affiliations).to eq([])
73
+ end
74
+ it 'accepts an empty array' do
75
+ creator = Creator.new(name: 'Hedy Lamarr', affiliations: ['United Artists', 'Metro-Goldwyn-Mayer'])
76
+ creator.affiliations = []
77
+ expect(creator.affiliations).to eq([])
78
+ end
79
+ end
80
+
81
+ describe '#load_from_xml' do
82
+ it 'parses XML' do
83
+ xml_text = '<creator>
84
+ <creatorName>Hedy Lamarr</creatorName>
85
+ <nameIdentifier schemeURI="http://isni.org/" nameIdentifierScheme="ISNI">0000-0001-1690-159X</nameIdentifier>
86
+ <affiliation>United Artists</affiliation>
87
+ <affiliation>Metro-Goldwyn-Mayer</affiliation>
88
+ </creator>'
89
+ xml = REXML::Document.new(xml_text).root
90
+ creator = Creator.load_from_xml(xml)
91
+ expect(creator.name).to eq('Hedy Lamarr')
92
+ expect(creator.affiliations).to eq(['United Artists', 'Metro-Goldwyn-Mayer'])
93
+ id = creator.identifier
94
+ expect(id.scheme).to eq('ISNI')
95
+ expect(id.scheme_uri).to eq(URI('http://isni.org'))
96
+ expect(id.value).to eq('0000-0001-1690-159X')
97
+ end
98
+
99
+ it 'defaults to an empty affiliation array' do
100
+ xml_text = '<creator>
101
+ <creatorName>Hedy Lamarr</creatorName>
102
+ <nameIdentifier schemeURI="http://isni.org/" nameIdentifierScheme="ISNI">0000-0001-1690-159X</nameIdentifier>
103
+ </creator>'
104
+ xml = REXML::Document.new(xml_text).root
105
+ creator = Creator.load_from_xml(xml)
106
+ expect(creator.affiliations).to eq([])
107
+ end
108
+ end
109
+
110
+ describe '#save_to_xml' do
111
+ it 'writes XML' do
112
+ id = NameIdentifier.new(scheme: 'ISNI', scheme_uri: URI('http://isni.org/'), value: '0000-0001-1690-159X')
113
+ creator = Creator.new(name: 'Hedy Lamarr', identifier: id, affiliations: ['United Artists', 'Metro-Goldwyn-Mayer'])
114
+ expected_xml = '<creator>
115
+ <creatorName>Hedy Lamarr</creatorName>
116
+ <nameIdentifier schemeURI="http://isni.org/" nameIdentifierScheme="ISNI">0000-0001-1690-159X</nameIdentifier>
117
+ <affiliation>United Artists</affiliation>
118
+ <affiliation>Metro-Goldwyn-Mayer</affiliation>
119
+ </creator>'
120
+ expect(creator.save_to_xml).to be_xml(expected_xml)
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,246 @@
1
+ require 'spec_helper'
2
+
3
+ module Datacite
4
+ module Mapping
5
+ describe Date do
6
+
7
+ before(:each) do
8
+ @values = {}
9
+ @values[:with_date_time] = DateTime.new(1914, 8, 4, 11, 01, 6.0123, '+1')
10
+ @values[:with_date] = ::Date.new(1914, 8, 4)
11
+ @values[:with_year] = 1914
12
+ @values[:with_year_str] = '1914'
13
+ @values[:with_year_month] = '1914-08'
14
+ @values[:iso8601] = '1914-08-04T11:01+01:00'
15
+ @values[:iso8601_secs] = '1914-08-04T11:01:06+01:00'
16
+ @values[:iso8601_frac] = '1914-08-04T11:01:06.0123+01:00'
17
+ @dates = @values.map { |format, v| [format, Date.new(type: DateType::AVAILABLE, value: v)] }.to_h
18
+ end
19
+
20
+ describe '#initialize' do
21
+ it 'accepts a DateTime' do
22
+ d = @dates[:with_date_time]
23
+ expect(d).to be_a(Date)
24
+ expect(d.value).not_to be_nil
25
+ end
26
+
27
+ it 'accepts a Date' do
28
+ d = @dates[:with_date]
29
+ expect(d).to be_a(Date)
30
+ expect(d.value).not_to be_nil
31
+ end
32
+
33
+ it 'accepts a year as an integer' do
34
+ d = @dates[:with_year]
35
+ expect(d).to be_a(Date)
36
+ expect(d.value).not_to be_nil
37
+ end
38
+
39
+ it 'accepts a year as a string' do
40
+ d = @dates[:with_year_str]
41
+ expect(d).to be_a(Date)
42
+ expect(d.value).not_to be_nil
43
+ end
44
+
45
+ it 'accepts a year-month string' do
46
+ d = @dates[:with_year_month]
47
+ expect(d).to be_a(Date)
48
+ expect(d.value).not_to be_nil
49
+ end
50
+
51
+ it 'accepts an ISO 8601 date string with hours and minutes' do
52
+ d = @dates[:iso8601]
53
+ expect(d).to be_a(Date)
54
+ expect(d.value).not_to be_nil
55
+ end
56
+
57
+ it 'accepts an ISO 8601 date string with hours, minutes, and seconds' do
58
+ d = @dates[:iso8601_secs]
59
+ expect(d).to be_a(Date)
60
+ expect(d.value).not_to be_nil
61
+ end
62
+
63
+ it 'accepts an ISO 8601 date string with hours, minutes, seconds, and fractional seconds' do
64
+ d = @dates[:iso8601_frac]
65
+ expect(d).to be_a(Date)
66
+ expect(d.value).not_to be_nil
67
+ end
68
+
69
+ it 'rejects invalid dates' do
70
+ expect { Date.new(value: 'elvis') }.to raise_error(ArgumentError)
71
+ end
72
+
73
+ it 'rejects nil' do
74
+ expect { Date.new(value: nil) }.to raise_error(ArgumentError)
75
+ end
76
+ end
77
+
78
+ describe 'value=' do
79
+ it 'accepts all date formats' do
80
+ @values.each_value do |v|
81
+ d = Date.allocate
82
+ d.value = v
83
+ expect(d.value).not_to be_nil, "Expected non-nil value for #{v}, got nil"
84
+ end
85
+ end
86
+
87
+ it 'supports RKMS-ISO8601 date ranges'
88
+
89
+ it 'rejects invalid dates' do
90
+ d = Date.new(value: 1914, type: DateType::AVAILABLE)
91
+ old_value = d.value
92
+ expect { d.value = 'elvis' }.to raise_error(ArgumentError)
93
+ expect(d.value).to eq(old_value)
94
+ end
95
+
96
+ it 'rejects nil' do
97
+ d = Date.new(value: 1914, type: DateType::AVAILABLE)
98
+ old_value = d.value
99
+ expect { d.value = nil }.to raise_error(ArgumentError)
100
+ expect(d.value).to eq(old_value)
101
+ end
102
+ end
103
+
104
+ describe 'type=' do
105
+ it 'sets the type' do
106
+ d = Date.allocate
107
+ d.type = DateType::COLLECTED
108
+ expect(d.type).to eq(DateType::COLLECTED)
109
+ end
110
+
111
+ it 'rejects nil' do
112
+ d = Date.new(value: 1914, type: DateType::COLLECTED)
113
+ expect { d.type = nil }.to raise_error(ArgumentError)
114
+ expect(d.type).to eq(DateType::COLLECTED)
115
+ end
116
+ end
117
+
118
+ describe 'value' do
119
+ it 'returns a string for a DateTime' do
120
+ expect(@dates[:with_date_time].value).to eq(@values[:with_date_time].iso8601)
121
+ end
122
+ it 'returns a string for a Date' do
123
+ expect(@dates[:with_date].value).to eq(@values[:with_date].iso8601)
124
+ end
125
+ it 'returns a string for a year as an integer' do
126
+ expect(@dates[:with_year].value).to eq(@values[:with_year].to_s)
127
+ end
128
+ it 'returns a string for a year as a string' do
129
+ expect(@dates[:with_year_str].value).to eq(@values[:with_year_str])
130
+ end
131
+ it 'returns a string for a year-month string' do
132
+ expect(@dates[:with_year_month].value).to eq(@values[:with_year_month])
133
+ end
134
+ it 'preserves an ISO 8601 date string with hours and minutes' do
135
+ expect(@dates[:iso8601].value).to eq(@values[:iso8601])
136
+ end
137
+ it 'preserves an ISO 8601 date string with hours, minutes, and seconds' do
138
+ expect(@dates[:iso8601_secs].value).to eq(@values[:iso8601_secs])
139
+ end
140
+ it 'preserves an ISO 8601 date string with hours, minutes, seconds, and fractional seconds' do
141
+ expect(@dates[:iso8601_frac].value).to eq(@values[:iso8601_frac])
142
+ end
143
+ end
144
+
145
+ describe 'year' do
146
+ it 'returns the year for all date formats' do
147
+ @dates.each_value do |d|
148
+ expect(d.year).to eq(1914)
149
+ end
150
+ end
151
+ end
152
+
153
+ describe 'month' do
154
+ it 'returns the month for all date formats that have it' do
155
+ expected = 8
156
+ @dates.each_pair do |format, d|
157
+ if [:with_year, :with_year_str].include?(format)
158
+ expect(d.month).to be_nil
159
+ else
160
+ expect(d.month).to eq(expected), "expected #{expected}, got #{d.month} for :#{format} (#{d.value})"
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ describe 'day' do
167
+ it 'returns the day for all date formats that have it' do
168
+ expected = 4
169
+ @dates.each_pair do |format, d|
170
+ if [:with_year, :with_year_str, :with_year_month].include?(format)
171
+ expect(d.day).to be_nil
172
+ else
173
+ expect(d.day).to eq(expected), "expected #{expected}, got #{d.day} for :#{format} (#{d.value})"
174
+ end
175
+ end
176
+ end
177
+ end
178
+
179
+ describe 'hour' do
180
+ it 'returns the hour for all formats that have it' do
181
+ expected = 11
182
+ @dates.each_pair do |format, d|
183
+ if [:with_date, :with_year, :with_year_str, :with_year_month].include?(format)
184
+ expect(d.hour).to be_nil, "expected nil, got #{d.hour} for :#{format} (#{d.value})"
185
+ else
186
+ expect(d.hour).to eq(expected), "expected #{expected}, got #{d.hour} for :#{format} (#{d.value})"
187
+ end
188
+ end
189
+ end
190
+ end
191
+
192
+ describe 'minute' do
193
+ it 'returns the minutes for all formats that have it' do
194
+ expected = 1
195
+ @dates.each_pair do |format, d|
196
+ if [:with_date, :with_year, :with_year_str, :with_year_month].include?(format)
197
+ expect(d.minute).to be_nil, "expected nil, got #{d.hour} for :#{format} (#{d.value})"
198
+ else
199
+ expect(d.minute).to eq(expected), "expected #{expected}, got #{d.minute} for :#{format} (#{d.value})"
200
+ end
201
+ end
202
+ end
203
+ end
204
+
205
+ describe 'sec' do
206
+ it 'returns the seconds for all formats that have it' do
207
+ expected = 6
208
+ @dates.each_pair do |format, d|
209
+ if [:with_date, :with_year, :with_year_str, :with_year_month].include?(format)
210
+ expect(d.sec).to be_nil, "expected nil, got #{d.hour} for :#{format} (#{d.value})"
211
+ elsif format == :iso8601
212
+ expect(d.sec).to eq(0)
213
+ else
214
+ expect(d.sec).to eq(expected), "expected #{expected}, got #{d.sec} for :#{format} (#{d.value})"
215
+ end
216
+ end
217
+ end
218
+ end
219
+
220
+ describe 'nsec' do
221
+ it 'returns the nanoseconds for all formats that have it' do
222
+ expected = 12_300_000
223
+ @dates.each_pair do |format, d|
224
+ if [:with_date, :with_year, :with_year_str, :with_year_month].include?(format)
225
+ expect(d.nsec).to be_nil, "expected nil, got #{d.hour} for :#{format} (#{d.value})"
226
+ elsif [:iso8601, :iso8601_secs].include?(format)
227
+ expect(d.nsec).to eq(0)
228
+ else
229
+ expect(d.nsec).to eq(expected), "expected #{expected}, got #{d.nsec} for :#{format} (#{d.value})"
230
+ end
231
+ end
232
+ end
233
+ end
234
+
235
+ describe '#save_to_xml' do
236
+ it 'writes XML' do
237
+ d = Date.new(value: '1914-08-04T11:01:06.0123+01:00', type: DateType::AVAILABLE)
238
+ expected_xml = '<date dateType="Available">1914-08-04T11:01:06.0123+01:00</date>'
239
+ expect(d.save_to_xml).to be_xml(expected_xml)
240
+ end
241
+ end
242
+
243
+ describe '#load_from_xml'
244
+ end
245
+ end
246
+ end