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.
- checksums.yaml +7 -0
- data/.gitignore +42 -0
- data/.rubocop.yml +28 -0
- data/.ruby-version +1 -0
- data/.travis.yml +2 -0
- data/.yardopts +2 -0
- data/CHANGES.md +3 -0
- data/Gemfile +3 -0
- data/LICENSE.md +22 -0
- data/README.md +168 -0
- data/Rakefile +49 -0
- data/datacite-mapping.gemspec +37 -0
- data/examples/reading.rb +75 -0
- data/examples/writing.rb +49 -0
- data/lib/datacite/mapping.rb +36 -0
- data/lib/datacite/mapping/alternate_identifier.rb +45 -0
- data/lib/datacite/mapping/contributor.rb +125 -0
- data/lib/datacite/mapping/creator.rb +48 -0
- data/lib/datacite/mapping/date.rb +153 -0
- data/lib/datacite/mapping/description.rb +121 -0
- data/lib/datacite/mapping/geo_location.rb +49 -0
- data/lib/datacite/mapping/geo_location_box.rb +137 -0
- data/lib/datacite/mapping/geo_location_point.rb +102 -0
- data/lib/datacite/mapping/identifier.rb +45 -0
- data/lib/datacite/mapping/module_info.rb +12 -0
- data/lib/datacite/mapping/name_identifier.rb +48 -0
- data/lib/datacite/mapping/related_identifier.rb +209 -0
- data/lib/datacite/mapping/resource.rb +201 -0
- data/lib/datacite/mapping/resource_type.rb +83 -0
- data/lib/datacite/mapping/rights.rb +36 -0
- data/lib/datacite/mapping/subject.rb +55 -0
- data/lib/datacite/mapping/title.rb +69 -0
- data/spec/.rubocop.yml +7 -0
- data/spec/data/resource.xml +61 -0
- data/spec/rspec_custom_matchers.rb +69 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/unit/datacite/mapping/alternate_identifier_spec.rb +60 -0
- data/spec/unit/datacite/mapping/contributor_spec.rb +129 -0
- data/spec/unit/datacite/mapping/creator_spec.rb +125 -0
- data/spec/unit/datacite/mapping/date_spec.rb +246 -0
- data/spec/unit/datacite/mapping/description_spec.rb +89 -0
- data/spec/unit/datacite/mapping/geo_location_box_spec.rb +241 -0
- data/spec/unit/datacite/mapping/geo_location_point_spec.rb +148 -0
- data/spec/unit/datacite/mapping/geo_location_spec.rb +116 -0
- data/spec/unit/datacite/mapping/identifier_spec.rb +75 -0
- data/spec/unit/datacite/mapping/name_identifier_spec.rb +89 -0
- data/spec/unit/datacite/mapping/related_identifier_spec.rb +157 -0
- data/spec/unit/datacite/mapping/resource_spec.rb +727 -0
- data/spec/unit/datacite/mapping/resource_type_spec.rb +69 -0
- data/spec/unit/datacite/mapping/rights_spec.rb +78 -0
- data/spec/unit/datacite/mapping/subject_spec.rb +108 -0
- data/spec/unit/datacite/mapping/title_spec.rb +113 -0
- metadata +262 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Datacite
|
4
|
+
module Mapping
|
5
|
+
describe Description do
|
6
|
+
describe '#load_from_xml' do
|
7
|
+
it 'reads XML' do
|
8
|
+
xml_text = '<description xml:lang="en-us" descriptionType="Abstract">
|
9
|
+
XML example of all DataCite Metadata Schema v3.1 properties.
|
10
|
+
</description>'
|
11
|
+
xml = REXML::Document.new(xml_text).root
|
12
|
+
desc = Description.load_from_xml(xml)
|
13
|
+
|
14
|
+
expected_lang = 'en-us'
|
15
|
+
expected_type = DescriptionType::ABSTRACT
|
16
|
+
expected_value = 'XML example of all DataCite Metadata Schema v3.1 properties.'
|
17
|
+
|
18
|
+
expect(desc.language).to eq(expected_lang)
|
19
|
+
expect(desc.type).to eq(expected_type)
|
20
|
+
expect(desc.value.strip).to eq(expected_value)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'handles escaped HTML' do
|
24
|
+
xml_text = '<description xml:lang="en-us" descriptionType="Abstract">
|
25
|
+
<p>This is HTML text</p><p><small>despite the advice in the standard</small></p>
|
26
|
+
</description>'
|
27
|
+
xml = REXML::Document.new(xml_text).root
|
28
|
+
desc = Description.load_from_xml(xml)
|
29
|
+
|
30
|
+
expected_value = '<p>This is HTML text</p><p><small>despite the advice in the standard</small></p>'
|
31
|
+
expect(desc.value).to eq(expected_value)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'strips extra whitespace' do
|
35
|
+
xml_text = '<description xml:lang="en-us" descriptionType="Abstract">
|
36
|
+
This is the value
|
37
|
+
</description>'
|
38
|
+
xml = REXML::Document.new(xml_text).root
|
39
|
+
desc = Description.load_from_xml(xml)
|
40
|
+
expect(desc.value).to eq('This is the value')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'allows un-escaped <br/> and <br></br> tags' do
|
44
|
+
xml_text = '<description descriptionType="Abstract">
|
45
|
+
I am an <br></br> abstract <br/> full <br/> of <br/>s
|
46
|
+
</description>'
|
47
|
+
xml = REXML::Document.new(xml_text).root
|
48
|
+
desc = Description.load_from_xml(xml)
|
49
|
+
expected_value = 'I am an <br/> abstract <br/> full <br/> of <br/>s'
|
50
|
+
expect(desc.value.strip).to eq(expected_value)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#save_to_xml' do
|
55
|
+
it 'writes XML' do
|
56
|
+
desc = Description.new(language: 'en-us', type: DescriptionType::ABSTRACT, value: 'foo')
|
57
|
+
expected_xml = '<description xml:lang="en-us" descriptionType="Abstract">foo</description>'
|
58
|
+
expect(desc.save_to_xml).to be_xml(expected_xml)
|
59
|
+
end
|
60
|
+
it 'escapes HTML' do
|
61
|
+
desc = Description.new(type: DescriptionType::ABSTRACT, value: '<p>This is HTML text</p>')
|
62
|
+
expected_xml = '<description xml:lang="en" descriptionType="Abstract"><p>This is HTML text</p></description>'
|
63
|
+
expect(desc.save_to_xml).to be_xml(expected_xml)
|
64
|
+
end
|
65
|
+
it 'preserves <br/> and <br></br> tags' do
|
66
|
+
desc = Description.new(type: DescriptionType::ABSTRACT, value: '<br/> <br/> abstract <br></br> full <br /> of <br> </br>s')
|
67
|
+
expected_xml = '<description xml:lang="en" descriptionType="Abstract"><br/> &lt;br/&gt; abstract <br/> full <br/> of <br/>s</description>'
|
68
|
+
expect(desc.save_to_xml).to be_xml(expected_xml)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'round-trips to XML' do
|
73
|
+
xml_text = '<description xml:lang="en-us" descriptionType="Abstract">foo</description>'
|
74
|
+
xml = REXML::Document.new(xml_text).root
|
75
|
+
desc = Description.load_from_xml(xml)
|
76
|
+
expect(desc.save_to_xml).to be_xml(xml_text)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'un-escapes <br/> tags when round-tripping' do
|
80
|
+
xml_text = '<description xml:lang="en-us" descriptionType="Abstract"><br/> <br/> abstract <br></br> full <br /> of <br> </br>s</description>'
|
81
|
+
xml = REXML::Document.new(xml_text).root
|
82
|
+
desc = Description.load_from_xml(xml)
|
83
|
+
expected_xml = '<description xml:lang="en-us" descriptionType="Abstract"><br/> <br/> abstract <br></br> full <br /> of <br> </br>s</description>'
|
84
|
+
expect(desc.save_to_xml).to be_xml(expected_xml)
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,241 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Datacite
|
4
|
+
module Mapping
|
5
|
+
describe GeoLocationBox do
|
6
|
+
describe '#initialize' do
|
7
|
+
it 'accepts a lat/long/lat/long quad' do
|
8
|
+
box = GeoLocationBox.new(-33.45, -122.33, 47.61, -70.67)
|
9
|
+
expect(box.south_latitude).to eq(-33.45)
|
10
|
+
expect(box.west_longitude).to eq(-122.33)
|
11
|
+
expect(box.north_latitude).to eq(47.61)
|
12
|
+
expect(box.east_longitude).to eq(-70.67)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'accepts a quad with flipped east/west coordinates' do
|
16
|
+
box = GeoLocationBox.new(-33.45, -70.67, 47.61, -122.33)
|
17
|
+
expect(box.south_latitude).to eq(-33.45)
|
18
|
+
expect(box.west_longitude).to eq(-122.33)
|
19
|
+
expect(box.north_latitude).to eq(47.61)
|
20
|
+
expect(box.east_longitude).to eq(-70.67)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'accepts a quad with flipped north/south coordinates' do
|
24
|
+
box = GeoLocationBox.new(47.61, -122.33, -33.45, -70.67)
|
25
|
+
expect(box.south_latitude).to eq(-33.45)
|
26
|
+
expect(box.west_longitude).to eq(-122.33)
|
27
|
+
expect(box.north_latitude).to eq(47.61)
|
28
|
+
expect(box.east_longitude).to eq(-70.67)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'accepts :south_latitude, :west_longitude, :north_latitude, :east_longitude' do
|
32
|
+
box = GeoLocationBox.new(
|
33
|
+
south_latitude: -33.45,
|
34
|
+
west_longitude: -122.33,
|
35
|
+
north_latitude: 47.61,
|
36
|
+
east_longitude: -70.67
|
37
|
+
)
|
38
|
+
expect(box.south_latitude).to eq(-33.45)
|
39
|
+
expect(box.west_longitude).to eq(-122.33)
|
40
|
+
expect(box.north_latitude).to eq(47.61)
|
41
|
+
expect(box.east_longitude).to eq(-70.67)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'requires all four coordinates with hash arguments' do
|
45
|
+
all_args = {
|
46
|
+
south_latitude: -33.45,
|
47
|
+
west_longitude: -122.33,
|
48
|
+
north_latitude: 47.61,
|
49
|
+
east_longitude: -70.67
|
50
|
+
}
|
51
|
+
all_args.each_key do |k|
|
52
|
+
bad_args = all_args.select { |k2, _v2| k2 == k }
|
53
|
+
expect { GeoLocationBox.new(bad_args) }.to raise_error(ArgumentError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'requires all four coordinates with array arguments' do
|
58
|
+
expect { GeoLocationBox.new(-33.45, -122.33, 47.61) }.to raise_error(ArgumentError)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'rejects extra array arguments' do
|
62
|
+
expect { GeoLocationBox.new(-33.45, -122.33, 47.61, -70.67, -33.45) }.to raise_error(ArgumentError)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'rejects extra hash arguments' do
|
66
|
+
expect do
|
67
|
+
GeoLocationBox.new(
|
68
|
+
south_latitude: -33.45,
|
69
|
+
west_longitude: -122.33,
|
70
|
+
north_latitude: 47.61,
|
71
|
+
east_longitude: -70.67,
|
72
|
+
latitude: 47.61,
|
73
|
+
longitude: -122.33
|
74
|
+
)
|
75
|
+
end.to raise_error(ArgumentError)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#south_latitude=' do
|
80
|
+
it 'sets the south_latitude' do
|
81
|
+
box = GeoLocationBox.allocate
|
82
|
+
box.south_latitude = 47.61
|
83
|
+
expect(box.south_latitude).to eq(47.61)
|
84
|
+
end
|
85
|
+
it 'requires a value' do
|
86
|
+
box = GeoLocationBox.allocate
|
87
|
+
expect { box.south_latitude = nil }.to raise_error(ArgumentError)
|
88
|
+
end
|
89
|
+
it 'rejects bad values' do
|
90
|
+
box = GeoLocationBox.allocate
|
91
|
+
expect { box.south_latitude = 91 }.to raise_error(ArgumentError)
|
92
|
+
expect { box.south_latitude = -91 }.to raise_error(ArgumentError)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '#west_longitude=' do
|
97
|
+
it 'sets the west_longitude' do
|
98
|
+
box = GeoLocationBox.allocate
|
99
|
+
box.west_longitude = 47.61
|
100
|
+
expect(box.west_longitude).to eq(47.61)
|
101
|
+
end
|
102
|
+
it 'requires a value' do
|
103
|
+
box = GeoLocationBox.allocate
|
104
|
+
expect { box.west_longitude = nil }.to raise_error(ArgumentError)
|
105
|
+
end
|
106
|
+
it 'rejects bad values' do
|
107
|
+
box = GeoLocationBox.allocate
|
108
|
+
expect { box.west_longitude = 181 }.to raise_error(ArgumentError)
|
109
|
+
expect { box.west_longitude = -181 }.to raise_error(ArgumentError)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '#north_latitude=' do
|
114
|
+
it 'sets the north_latitude' do
|
115
|
+
box = GeoLocationBox.allocate
|
116
|
+
box.north_latitude = 47.61
|
117
|
+
expect(box.north_latitude).to eq(47.61)
|
118
|
+
end
|
119
|
+
it 'requires a value' do
|
120
|
+
box = GeoLocationBox.allocate
|
121
|
+
expect { box.north_latitude = nil }.to raise_error(ArgumentError)
|
122
|
+
end
|
123
|
+
it 'rejects bad values' do
|
124
|
+
box = GeoLocationBox.allocate
|
125
|
+
expect { box.north_latitude = 91 }.to raise_error(ArgumentError)
|
126
|
+
expect { box.north_latitude = -91 }.to raise_error(ArgumentError)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe '#east_longitude=' do
|
131
|
+
it 'sets the east_longitude' do
|
132
|
+
box = GeoLocationBox.allocate
|
133
|
+
box.east_longitude = 47.61
|
134
|
+
expect(box.east_longitude).to eq(47.61)
|
135
|
+
end
|
136
|
+
it 'requires a value' do
|
137
|
+
box = GeoLocationBox.allocate
|
138
|
+
expect { box.east_longitude = nil }.to raise_error(ArgumentError)
|
139
|
+
end
|
140
|
+
it 'rejects bad values' do
|
141
|
+
box = GeoLocationBox.allocate
|
142
|
+
expect { box.east_longitude = 181 }.to raise_error(ArgumentError)
|
143
|
+
expect { box.east_longitude = -181 }.to raise_error(ArgumentError)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe '#==' do
|
148
|
+
it 'reports equal values as equal' do
|
149
|
+
box1 = GeoLocationBox.new(-33.45, -122.33, 47.61, -70.67)
|
150
|
+
box2 = GeoLocationBox.new(
|
151
|
+
south_latitude: -33.45,
|
152
|
+
west_longitude: -122.33,
|
153
|
+
north_latitude: 47.61,
|
154
|
+
east_longitude: -70.67
|
155
|
+
)
|
156
|
+
expect(box1).to eq(box2)
|
157
|
+
expect(box2).to eq(box1)
|
158
|
+
end
|
159
|
+
it 'reports unequal values as unequal' do
|
160
|
+
box1 = GeoLocationBox.new(-47.61, -70.67, -33.45, 122.33)
|
161
|
+
box2 = GeoLocationBox.new(
|
162
|
+
south_latitude: -33.45,
|
163
|
+
west_longitude: -122.33,
|
164
|
+
north_latitude: 47.61,
|
165
|
+
east_longitude: -70.67
|
166
|
+
)
|
167
|
+
expect(box1).not_to eq(box2)
|
168
|
+
expect(box2).not_to eq(box1)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe '#hash' do
|
173
|
+
it 'reports equal values as having equal hashes' do
|
174
|
+
box1 = GeoLocationBox.new(-33.45, -122.33, 47.61, -70.67)
|
175
|
+
box2 = GeoLocationBox.new(
|
176
|
+
south_latitude: -33.45,
|
177
|
+
west_longitude: -122.33,
|
178
|
+
north_latitude: 47.61,
|
179
|
+
east_longitude: -70.67
|
180
|
+
)
|
181
|
+
expect(box1.hash).to eq(box2.hash)
|
182
|
+
expect(box2.hash).to eq(box1.hash)
|
183
|
+
end
|
184
|
+
it 'reports unequal values as having unequal hashes' do
|
185
|
+
box1 = GeoLocationBox.new(-47.61, -70.67, -33.45, 122.33)
|
186
|
+
box2 = GeoLocationBox.new(
|
187
|
+
south_latitude: -33.45,
|
188
|
+
west_longitude: -122.33,
|
189
|
+
north_latitude: 47.61,
|
190
|
+
east_longitude: -70.67
|
191
|
+
)
|
192
|
+
expect(box1.hash).not_to eq(box2.hash)
|
193
|
+
expect(box2.hash).not_to eq(box1.hash)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe '#to_s' do
|
198
|
+
it 'returns the coordinates' do
|
199
|
+
box = GeoLocationBox.new(-33.45, -122.33, 47.61, -70.67)
|
200
|
+
expect(box.to_s).to eq('-33.45 -122.33 47.61 -70.67')
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
describe GeoLocationBoxNode do
|
206
|
+
|
207
|
+
class SomeElement
|
208
|
+
include XML::Mapping
|
209
|
+
end
|
210
|
+
|
211
|
+
describe '#to_value' do
|
212
|
+
it 'parses the value' do
|
213
|
+
xml_text = '-33.45 -122.33 47.61 -70.67'
|
214
|
+
node = GeoLocationBoxNode.new(SomeElement, :box, 'box')
|
215
|
+
expected_box = GeoLocationBox.new(-33.45, -122.33, 47.61, -70.67)
|
216
|
+
expect(node.to_value(xml_text)).to eq(expected_box)
|
217
|
+
end
|
218
|
+
it 'deals with flipped east/west coordinates' do
|
219
|
+
xml_text = '-33.45 -70.67 47.61 -122.33'
|
220
|
+
node = GeoLocationBoxNode.new(SomeElement, :box, 'box')
|
221
|
+
expected_box = GeoLocationBox.new(-33.45, -122.33, 47.61, -70.67)
|
222
|
+
expect(node.to_value(xml_text)).to eq(expected_box)
|
223
|
+
end
|
224
|
+
it 'deals with flipped north/south coordinates' do
|
225
|
+
xml_text = '47.61 -122.33 -33.45 -70.67'
|
226
|
+
node = GeoLocationBoxNode.new(SomeElement, :box, 'box')
|
227
|
+
expected_box = GeoLocationBox.new(-33.45, -122.33, 47.61, -70.67)
|
228
|
+
expect(node.to_value(xml_text)).to eq(expected_box)
|
229
|
+
end
|
230
|
+
it 'deals with weird whitespace' do
|
231
|
+
node = GeoLocationBoxNode.new(SomeElement, :box, 'box')
|
232
|
+
xml_text = %(
|
233
|
+
-33.45 -122.33\t47.61 -70.67
|
234
|
+
)
|
235
|
+
expected = GeoLocationBox.new(-33.45, -122.33, 47.61, -70.67)
|
236
|
+
expect(node.to_value(xml_text)).to eq(expected)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Datacite
|
4
|
+
module Mapping
|
5
|
+
describe GeoLocationPoint do
|
6
|
+
describe '#initialize' do
|
7
|
+
it 'accepts a lat/long pair' do
|
8
|
+
point = GeoLocationPoint.new(47.61, -122.33)
|
9
|
+
expect(point.latitude).to eq(47.61)
|
10
|
+
expect(point.longitude).to eq(-122.33)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'accepts :latitude and :longitude' do
|
14
|
+
point = GeoLocationPoint.new(latitude: 47.61, longitude: -122.33)
|
15
|
+
expect(point.latitude).to eq(47.61)
|
16
|
+
expect(point.longitude).to eq(-122.33)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'requires both latitude and longitude' do
|
20
|
+
expect { GeoLocationPoint.new(47.61) }.to raise_error(ArgumentError)
|
21
|
+
expect { GeoLocationPoint.new(latitude: 47.61) }.to raise_error(ArgumentError)
|
22
|
+
expect { GeoLocationPoint.new(longitude: -122.33) }.to raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'rejects extra array arguments' do
|
26
|
+
expect { GeoLocationPoint.new(47.61, -122.33, -70.67) }.to raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'rejects extra hash arguments' do
|
30
|
+
expect { GeoLocationPoint.new(latitude: 47.61, longitude: -122.33, south_latitude: -70.67) }.to raise_error(ArgumentError)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'rejects bad values' do
|
34
|
+
expect { GeoLocationPoint.new(91, -122.33) }.to raise_error(ArgumentError)
|
35
|
+
expect { GeoLocationPoint.new(-91, -122.33) }.to raise_error(ArgumentError)
|
36
|
+
expect { GeoLocationPoint.new(47.61, 181) }.to raise_error(ArgumentError)
|
37
|
+
expect { GeoLocationPoint.new(47.61, -181) }.to raise_error(ArgumentError)
|
38
|
+
expect { GeoLocationPoint.new(latitude: 91, longitude: -122.33) }.to raise_error(ArgumentError)
|
39
|
+
expect { GeoLocationPoint.new(latitude: -91, longitude: -122.33) }.to raise_error(ArgumentError)
|
40
|
+
expect { GeoLocationPoint.new(latitude: 47.61, longitude: 181) }.to raise_error(ArgumentError)
|
41
|
+
expect { GeoLocationPoint.new(latitude: 47.61, longitude: -181) }.to raise_error(ArgumentError)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#latitude=' do
|
46
|
+
it 'sets the latitude' do
|
47
|
+
point = GeoLocationPoint.allocate
|
48
|
+
point.latitude = 47.61
|
49
|
+
expect(point.latitude).to eq(47.61)
|
50
|
+
end
|
51
|
+
it 'requires a value' do
|
52
|
+
point = GeoLocationPoint.allocate
|
53
|
+
expect { point.latitude = nil }.to raise_error(ArgumentError)
|
54
|
+
end
|
55
|
+
it 'rejects bad values' do
|
56
|
+
point = GeoLocationPoint.allocate
|
57
|
+
expect { point.latitude = 91 }.to raise_error(ArgumentError)
|
58
|
+
expect { point.latitude = -91 }.to raise_error(ArgumentError)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#longitude=' do
|
63
|
+
it 'sets the longitude' do
|
64
|
+
point = GeoLocationPoint.allocate
|
65
|
+
point.longitude = 47.61
|
66
|
+
expect(point.longitude).to eq(47.61)
|
67
|
+
end
|
68
|
+
it 'requires a value' do
|
69
|
+
point = GeoLocationPoint.allocate
|
70
|
+
expect { point.longitude = nil }.to raise_error(ArgumentError)
|
71
|
+
end
|
72
|
+
it 'rejects bad values' do
|
73
|
+
point = GeoLocationPoint.allocate
|
74
|
+
expect { point.longitude = 181 }.to raise_error(ArgumentError)
|
75
|
+
expect { point.longitude = -181 }.to raise_error(ArgumentError)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#==' do
|
80
|
+
it 'reports equal values as equal' do
|
81
|
+
point1 = GeoLocationPoint.new(-33.45, -122.33)
|
82
|
+
point2 = GeoLocationPoint.new(
|
83
|
+
latitude: -33.45,
|
84
|
+
longitude: -122.33
|
85
|
+
)
|
86
|
+
expect(point1).to eq(point2)
|
87
|
+
expect(point2).to eq(point1)
|
88
|
+
end
|
89
|
+
it 'reports unequal values as unequal' do
|
90
|
+
point1 = GeoLocationPoint.new(-47.61, -70.67)
|
91
|
+
point2 = GeoLocationPoint.new(-33.45, -122.33)
|
92
|
+
expect(point1).not_to eq(point2)
|
93
|
+
expect(point2).not_to eq(point1)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#hash' do
|
98
|
+
it 'reports equal values as having equal hashes' do
|
99
|
+
point1 = GeoLocationPoint.new(-33.45, -122.33)
|
100
|
+
point2 = GeoLocationPoint.new(
|
101
|
+
latitude: -33.45,
|
102
|
+
longitude: -122.33
|
103
|
+
)
|
104
|
+
expect(point1.hash).to eq(point2.hash)
|
105
|
+
expect(point2.hash).to eq(point1.hash)
|
106
|
+
end
|
107
|
+
it 'reports unequal values as having unequal hashes' do
|
108
|
+
point1 = GeoLocationPoint.new(-47.61, -70.67)
|
109
|
+
point2 = GeoLocationPoint.new(-33.45, -122.33)
|
110
|
+
expect(point1.hash).not_to eq(point2.hash)
|
111
|
+
expect(point2.hash).not_to eq(point1.hash)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#to_s' do
|
116
|
+
it 'returns the coordinates' do
|
117
|
+
point = GeoLocationPoint.new(-33.45, -122.33)
|
118
|
+
expect(point.to_s).to eq('-33.45 -122.33')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe GeoLocationPointNode do
|
124
|
+
|
125
|
+
class SomeElement
|
126
|
+
include XML::Mapping
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#to_value' do
|
130
|
+
it 'parses the value' do
|
131
|
+
node = GeoLocationPointNode.new(SomeElement, :point, 'point')
|
132
|
+
xml_text = '-33.45 -122.33'
|
133
|
+
expected = GeoLocationPoint.new(-33.45, -122.33)
|
134
|
+
expect(node.to_value(xml_text)).to eq(expected)
|
135
|
+
end
|
136
|
+
it 'deals with weird whitespace' do
|
137
|
+
node = GeoLocationPointNode.new(SomeElement, :point, 'point')
|
138
|
+
xml_text = %(
|
139
|
+
-33.45\t-122.33
|
140
|
+
)
|
141
|
+
expected = GeoLocationPoint.new(-33.45, -122.33)
|
142
|
+
expect(node.to_value(xml_text)).to eq(expected)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
end
|