rcap 2.5.0 → 2.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.ruby-version +1 -0
- data/CHANGELOG.md +18 -0
- data/README.md +1 -0
- data/lib/rcap.rb +3 -1
- data/lib/rcap/alert.rb +4 -2
- data/lib/rcap/base/alert.rb +70 -73
- data/lib/rcap/base/area.rb +19 -13
- data/lib/rcap/base/circle.rb +15 -4
- data/lib/rcap/base/event_code.rb +2 -0
- data/lib/rcap/base/geocode.rb +2 -0
- data/lib/rcap/base/info.rb +81 -75
- data/lib/rcap/base/parameter.rb +8 -6
- data/lib/rcap/base/point.rb +4 -2
- data/lib/rcap/base/polygon.rb +16 -8
- data/lib/rcap/base/resource.rb +13 -13
- data/lib/rcap/cap_1_0/alert.rb +36 -39
- data/lib/rcap/cap_1_0/area.rb +2 -0
- data/lib/rcap/cap_1_0/circle.rb +2 -0
- data/lib/rcap/cap_1_0/event_code.rb +3 -1
- data/lib/rcap/cap_1_0/geocode.rb +3 -1
- data/lib/rcap/cap_1_0/info.rb +3 -1
- data/lib/rcap/cap_1_0/parameter.rb +3 -2
- data/lib/rcap/cap_1_0/point.rb +2 -0
- data/lib/rcap/cap_1_0/polygon.rb +3 -1
- data/lib/rcap/cap_1_0/resource.rb +2 -0
- data/lib/rcap/cap_1_1/alert.rb +4 -2
- data/lib/rcap/cap_1_1/area.rb +2 -0
- data/lib/rcap/cap_1_1/circle.rb +2 -0
- data/lib/rcap/cap_1_1/event_code.rb +3 -1
- data/lib/rcap/cap_1_1/geocode.rb +3 -1
- data/lib/rcap/cap_1_1/info.rb +48 -46
- data/lib/rcap/cap_1_1/parameter.rb +2 -1
- data/lib/rcap/cap_1_1/point.rb +2 -0
- data/lib/rcap/cap_1_1/polygon.rb +3 -1
- data/lib/rcap/cap_1_1/resource.rb +12 -11
- data/lib/rcap/cap_1_2/alert.rb +4 -2
- data/lib/rcap/cap_1_2/area.rb +2 -0
- data/lib/rcap/cap_1_2/circle.rb +2 -0
- data/lib/rcap/cap_1_2/event_code.rb +3 -1
- data/lib/rcap/cap_1_2/geocode.rb +3 -1
- data/lib/rcap/cap_1_2/info.rb +55 -51
- data/lib/rcap/cap_1_2/parameter.rb +2 -1
- data/lib/rcap/cap_1_2/point.rb +2 -0
- data/lib/rcap/cap_1_2/polygon.rb +4 -2
- data/lib/rcap/cap_1_2/resource.rb +14 -12
- data/lib/rcap/config.rb +2 -0
- data/lib/rcap/custom_validators.rb +30 -27
- data/lib/rcap/extensions/array.rb +2 -0
- data/lib/rcap/extensions/date.rb +3 -1
- data/lib/rcap/extensions/date_time.rb +4 -1
- data/lib/rcap/extensions/float.rb +2 -0
- data/lib/rcap/extensions/integer.rb +7 -0
- data/lib/rcap/extensions/nil_class.rb +2 -0
- data/lib/rcap/extensions/string.rb +3 -1
- data/lib/rcap/extensions/time.rb +3 -0
- data/lib/rcap/formatters/yaml.rb +5 -0
- data/lib/rcap/info.rb +2 -0
- data/lib/rcap/utilities.rb +8 -10
- data/lib/rcap/validation.rb +19 -14
- data/lib/rcap/version.rb +3 -1
- data/rcap.gemspec +5 -5
- data/spec/alert_spec.rb +8 -9
- data/spec/cap_1_0/alert_spec.rb +4 -5
- data/spec/cap_1_0/area_spec.rb +7 -10
- data/spec/cap_1_0/circle_spec.rb +9 -0
- data/spec/cap_1_0/event_code_spec.rb +1 -1
- data/spec/cap_1_0/geocode_spec.rb +1 -1
- data/spec/cap_1_0/info_spec.rb +38 -38
- data/spec/cap_1_0/polygon_spec.rb +7 -5
- data/spec/cap_1_0/resource_spec.rb +6 -7
- data/spec/cap_1_1/alert_spec.rb +6 -7
- data/spec/cap_1_1/area_spec.rb +6 -8
- data/spec/cap_1_1/circle_spec.rb +9 -0
- data/spec/cap_1_1/info_spec.rb +26 -26
- data/spec/cap_1_1/parameter_spec.rb +1 -2
- data/spec/cap_1_1/polygon_spec.rb +12 -10
- data/spec/cap_1_1/resource_spec.rb +13 -13
- data/spec/cap_1_2/alert_spec.rb +7 -8
- data/spec/cap_1_2/area_spec.rb +6 -6
- data/spec/cap_1_2/circle_spec.rb +9 -0
- data/spec/cap_1_2/info_spec.rb +25 -26
- data/spec/cap_1_2/polygon_spec.rb +8 -0
- data/spec/cap_1_2/resource_spec.rb +13 -13
- data/spec/extensions_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- data/spec/validations_spec.rb +0 -1
- metadata +15 -15
- data/lib/rcap/extensions/fixnum.rb +0 -5
@@ -4,14 +4,13 @@ describe(RCAP::CAP_1_1::Parameter) do
|
|
4
4
|
context('when initialised') do
|
5
5
|
context('from XML') do
|
6
6
|
before(:each) do
|
7
|
-
|
8
7
|
@alert = RCAP::CAP_1_1::Alert.new do |alert|
|
9
8
|
alert.add_info.add_parameter do |parameter|
|
10
9
|
parameter.name = 'name'
|
11
10
|
parameter.value = 'value'
|
12
11
|
end
|
13
12
|
end
|
14
|
-
@original_parameter
|
13
|
+
@original_parameter = @alert.infos.first.parameters.first
|
15
14
|
@xml_string = @alert.to_xml
|
16
15
|
@xml_document = REXML::Document.new(@xml_string)
|
17
16
|
@info_xml_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
@@ -10,18 +10,13 @@ describe(RCAP::CAP_1_1::Polygon) do
|
|
10
10
|
point.longitude = 0
|
11
11
|
end
|
12
12
|
end
|
13
|
-
@polygon.should(be_valid)
|
14
|
-
end
|
15
|
-
|
16
|
-
it('does not have any points') do
|
17
|
-
@polygon.points.clear
|
18
|
-
@polygon.should_not(be_valid)
|
19
13
|
end
|
14
|
+
@polygon.should(be_valid)
|
15
|
+
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
17
|
+
it('does not have a valid collection of points') do
|
18
|
+
@polygon.points.first.lattitude = nil
|
19
|
+
@polygon.should_not(be_valid)
|
25
20
|
end
|
26
21
|
end
|
27
22
|
|
@@ -102,6 +97,13 @@ describe(RCAP::CAP_1_1::Polygon) do
|
|
102
97
|
end
|
103
98
|
end
|
104
99
|
|
100
|
+
context('to geojson') do
|
101
|
+
it('should be valid geojson') do
|
102
|
+
expected = '{"type":"Polygon","coordinates":[[[0,0],[1,1],[2,2]]]}'
|
103
|
+
expect(@polygon.to_geojson).to eq expected
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
105
107
|
context('to a hash') do
|
106
108
|
it('should export correctly') do
|
107
109
|
@polygon.to_h.should == { RCAP::CAP_1_1::Polygon::POINTS_KEY => @polygon.points.map { |point| point.to_a } }
|
@@ -153,33 +153,33 @@ describe(RCAP::CAP_1_1::Resource) do
|
|
153
153
|
end
|
154
154
|
|
155
155
|
it('should set the resource description') do
|
156
|
-
@resource_hash[
|
156
|
+
@resource_hash[RCAP::CAP_1_1::Resource::RESOURCE_DESC_KEY].should == @resource.resource_desc
|
157
157
|
end
|
158
158
|
|
159
159
|
it('should set the mime type') do
|
160
|
-
@resource_hash[
|
160
|
+
@resource_hash[RCAP::CAP_1_1::Resource::MIME_TYPE_KEY].should == @resource.mime_type
|
161
161
|
end
|
162
162
|
|
163
163
|
it('should set the size') do
|
164
|
-
@resource_hash[
|
164
|
+
@resource_hash[RCAP::CAP_1_1::Resource::SIZE_KEY].should == @resource.size
|
165
165
|
end
|
166
166
|
|
167
167
|
it('should set the URI') do
|
168
|
-
@resource_hash[
|
168
|
+
@resource_hash[RCAP::CAP_1_1::Resource::URI_KEY].should == @resource.uri
|
169
169
|
end
|
170
170
|
|
171
171
|
it('should set the dereferenced URI') do
|
172
|
-
@resource_hash[
|
172
|
+
@resource_hash[RCAP::CAP_1_1::Resource::DEREF_URI_KEY].should == @resource.deref_uri
|
173
173
|
end
|
174
174
|
|
175
175
|
it('should set the digest') do
|
176
|
-
@resource_hash[
|
176
|
+
@resource_hash[RCAP::CAP_1_1::Resource::DIGEST_KEY].should == @resource.digest
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
180
180
|
context('to xml') do
|
181
181
|
it('should be successful') do
|
182
|
-
|
182
|
+
-> { @resource_xml = @resource.to_xml }.should_not(raise_exception)
|
183
183
|
end
|
184
184
|
end
|
185
185
|
end
|
@@ -209,20 +209,20 @@ describe(RCAP::CAP_1_1::Resource) do
|
|
209
209
|
end
|
210
210
|
@content = "1,2\n3,4"
|
211
211
|
@encoded_content = Base64.encode64(@content)
|
212
|
-
|
212
|
+
expect(URI).to receive(:parse) { StringIO.new(@content) }
|
213
213
|
end
|
214
214
|
|
215
215
|
describe('#dereference_uri!') do
|
216
216
|
it('should fetch the content and store it in deref_uri as Base64 encoded content') do
|
217
|
-
|
217
|
+
-> { @resource.dereference_uri! }.should(change(@resource, :deref_uri).to(@encoded_content))
|
218
218
|
end
|
219
219
|
|
220
220
|
it('should generate the correct SHA1 hash') do
|
221
|
-
|
221
|
+
-> { @resource.dereference_uri! }.should(change(@resource, :digest).to(Digest::SHA1.hexdigest(@encoded_content)))
|
222
222
|
end
|
223
223
|
|
224
224
|
it('should set the size in bytes') do
|
225
|
-
|
225
|
+
-> { @resource.dereference_uri! }.should(change(@resource, :size).to(@encoded_content.bytesize))
|
226
226
|
end
|
227
227
|
end
|
228
228
|
end
|
@@ -241,11 +241,11 @@ describe(RCAP::CAP_1_1::Resource) do
|
|
241
241
|
|
242
242
|
describe('#calculate_hash_and_size') do
|
243
243
|
it('should generate the correct SHA1 hash') do
|
244
|
-
|
244
|
+
-> { @resource.calculate_hash_and_size }.should(change(@resource, :digest).to(Digest::SHA1.hexdigest(@encoded_content)))
|
245
245
|
end
|
246
246
|
|
247
247
|
it('should set the size in bytes') do
|
248
|
-
|
248
|
+
-> { @resource.calculate_hash_and_size }.should(change(@resource, :size).to(@encoded_content.bytesize))
|
249
249
|
end
|
250
250
|
end
|
251
251
|
|
data/spec/cap_1_2/alert_spec.rb
CHANGED
@@ -12,14 +12,14 @@ describe(RCAP::CAP_1_2::Alert) do
|
|
12
12
|
['Address 1', 'Address 2'].each do |address|
|
13
13
|
alert.addresses << address
|
14
14
|
end
|
15
|
-
%w
|
15
|
+
%w[Code1 Code2].each do |code|
|
16
16
|
alert.codes << code
|
17
17
|
end
|
18
|
-
alert.note
|
19
|
-
%w
|
18
|
+
alert.note = 'Note'
|
19
|
+
%w[Reference1 Reference2].each do |reference|
|
20
20
|
alert.references << reference
|
21
21
|
end
|
22
|
-
%w
|
22
|
+
%w[Incident1 Incident2].each do |incident|
|
23
23
|
alert.incidents << incident
|
24
24
|
end
|
25
25
|
2.times do
|
@@ -29,7 +29,7 @@ describe(RCAP::CAP_1_2::Alert) do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
context('on initialisation') do
|
32
|
-
before(:each)
|
32
|
+
before(:each) do
|
33
33
|
@alert = RCAP::CAP_1_2::Alert.new
|
34
34
|
end
|
35
35
|
|
@@ -77,7 +77,6 @@ describe(RCAP::CAP_1_2::Alert) do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it_should_behave_like('a successfully parsed CAP 1.2 alert')
|
80
|
-
|
81
80
|
end
|
82
81
|
|
83
82
|
context('from YAML') do
|
@@ -180,7 +179,7 @@ describe(RCAP::CAP_1_2::Alert) do
|
|
180
179
|
|
181
180
|
it('has in invalid info attribute') do
|
182
181
|
@info = RCAP::CAP_1_2::Info.new do |info|
|
183
|
-
info.event
|
182
|
+
info.event = 'Info Event'
|
184
183
|
info.categories << RCAP::CAP_1_2::Info::CATEGORY_GEO
|
185
184
|
info.urgency = RCAP::CAP_1_2::Info::URGENCY_IMMEDIATE
|
186
185
|
info.severity = RCAP::CAP_1_2::Info::SEVERITY_EXTREME
|
@@ -219,7 +218,7 @@ describe(RCAP::CAP_1_2::Alert) do
|
|
219
218
|
describe('#to_xml') do
|
220
219
|
context('with pretty_print = true') do
|
221
220
|
it('should not raise an exception') do
|
222
|
-
|
221
|
+
-> { @alert.to_xml(true) }.should_not(raise_exception)
|
223
222
|
end
|
224
223
|
end
|
225
224
|
end
|
data/spec/cap_1_2/area_spec.rb
CHANGED
@@ -108,27 +108,27 @@ describe(RCAP::CAP_1_2::Area) do
|
|
108
108
|
end
|
109
109
|
|
110
110
|
it('should export the area description correctly') do
|
111
|
-
@area_hash[
|
111
|
+
@area_hash[RCAP::CAP_1_2::Area::AREA_DESC_KEY].should == @area.area_desc
|
112
112
|
end
|
113
113
|
|
114
114
|
it('should export the altitude correctly') do
|
115
|
-
@area_hash[
|
115
|
+
@area_hash[RCAP::CAP_1_2::Area::ALTITUDE_KEY].should == @area.altitude
|
116
116
|
end
|
117
117
|
|
118
118
|
it('should set the ceiling correctly') do
|
119
|
-
@area_hash[
|
119
|
+
@area_hash[RCAP::CAP_1_2::Area::CEILING_KEY].should == @area.ceiling
|
120
120
|
end
|
121
121
|
|
122
122
|
it('should export the circles correctly') do
|
123
|
-
@area_hash[
|
123
|
+
@area_hash[RCAP::CAP_1_2::Area::CIRCLES_KEY].should == @area.circles.map { |circle| circle.to_a }
|
124
124
|
end
|
125
125
|
|
126
126
|
it('should export the geocodes correctly') do
|
127
|
-
@area_hash[
|
127
|
+
@area_hash[RCAP::CAP_1_2::Area::GEOCODES_KEY].should == @area.geocodes.map { |geocode| geocode.to_h }
|
128
128
|
end
|
129
129
|
|
130
130
|
it('should export the polygons correctly') do
|
131
|
-
@area_hash[
|
131
|
+
@area_hash[RCAP::CAP_1_2::Area::POLYGONS_KEY].should == @area.polygons.map { |polygon| polygon.to_h }
|
132
132
|
end
|
133
133
|
end
|
134
134
|
end
|
data/spec/cap_1_2/circle_spec.rb
CHANGED
@@ -93,6 +93,15 @@ describe(RCAP::CAP_1_2::Circle) do
|
|
93
93
|
@circle = RCAP::CAP_1_2::Circle.new(&@circle_builder)
|
94
94
|
end
|
95
95
|
|
96
|
+
context('to geojson') do
|
97
|
+
it('should be valid geojson') do
|
98
|
+
@circle.longitude = 5.6
|
99
|
+
expected = '{"type":"Feature","geometry":{"type":"Point",' \
|
100
|
+
'"coordinates":[5.6,0]},"properties":{"radius":1}}'
|
101
|
+
expect(@circle.to_geojson).to eq expected
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
96
105
|
context('to hash') do
|
97
106
|
it('should be correct') do
|
98
107
|
@circle.to_h.should == { 'radius' => 1, 'lattitude' => 0, 'longitude' => 0 }
|
data/spec/cap_1_2/info_spec.rb
CHANGED
@@ -2,7 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe(RCAP::CAP_1_2::Info) do
|
4
4
|
before(:each) do
|
5
|
-
|
6
5
|
@info_builder = lambda do |info|
|
7
6
|
info.categories << RCAP::CAP_1_2::Info::CATEGORY_GEO
|
8
7
|
info.categories << RCAP::CAP_1_2::Info::CATEGORY_FIRE
|
@@ -22,7 +21,7 @@ describe(RCAP::CAP_1_2::Info) do
|
|
22
21
|
info.instruction = 'Instruction'
|
23
22
|
info.web = 'http://website'
|
24
23
|
info.contact = 'contact@address'
|
25
|
-
[%w
|
24
|
+
[%w[name1 value1], %w[name2 value2]].each do |name, value|
|
26
25
|
info.add_event_code do |event_code|
|
27
26
|
event_code.name = name
|
28
27
|
event_code.value = value
|
@@ -34,14 +33,14 @@ describe(RCAP::CAP_1_2::Info) do
|
|
34
33
|
resource.mime_type = 'mime/type'
|
35
34
|
end
|
36
35
|
|
37
|
-
[%w
|
36
|
+
[%w[name1 value1], %w[name2 value2]].each do |name, value|
|
38
37
|
info.add_parameter do |parameter|
|
39
38
|
parameter.name = name
|
40
39
|
parameter.value = value
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
44
|
-
%w
|
43
|
+
%w[Area1 Area2].each do |area_desc|
|
45
44
|
info.add_area do |area|
|
46
45
|
area.area_desc = area_desc
|
47
46
|
end
|
@@ -273,7 +272,7 @@ describe(RCAP::CAP_1_2::Info) do
|
|
273
272
|
context('is not valid if it') do
|
274
273
|
before(:each) do
|
275
274
|
@info = RCAP::CAP_1_2::Info.new do |info|
|
276
|
-
info.event
|
275
|
+
info.event = 'Info Event'
|
277
276
|
info.categories << RCAP::CAP_1_2::Info::CATEGORY_GEO
|
278
277
|
info.urgency = RCAP::CAP_1_2::Info::URGENCY_IMMEDIATE
|
279
278
|
info.severity = RCAP::CAP_1_2::Info::SEVERITY_EXTREME
|
@@ -318,87 +317,87 @@ describe(RCAP::CAP_1_2::Info) do
|
|
318
317
|
end
|
319
318
|
|
320
319
|
it('should export the language correctly') do
|
321
|
-
@info_hash[
|
320
|
+
@info_hash[RCAP::CAP_1_2::Info::LANGUAGE_KEY].should == @info.language
|
322
321
|
end
|
323
322
|
|
324
323
|
it('should export the categories') do
|
325
|
-
@info_hash[
|
324
|
+
@info_hash[RCAP::CAP_1_2::Info::CATEGORIES_KEY].should == @info.categories
|
326
325
|
end
|
327
326
|
|
328
327
|
it('should export the event') do
|
329
|
-
@info_hash[
|
328
|
+
@info_hash[RCAP::CAP_1_2::Info::EVENT_KEY].should == @info.event
|
330
329
|
end
|
331
330
|
|
332
331
|
it('should export the response types') do
|
333
|
-
@info_hash[
|
332
|
+
@info_hash[RCAP::CAP_1_2::Info::RESPONSE_TYPES_KEY].should == @info.response_types
|
334
333
|
end
|
335
334
|
|
336
335
|
it('should export the urgency') do
|
337
|
-
@info_hash[
|
336
|
+
@info_hash[RCAP::CAP_1_2::Info:: URGENCY_KEY].should == @info.urgency
|
338
337
|
end
|
339
338
|
|
340
339
|
it('should export the severity') do
|
341
|
-
@info_hash[
|
340
|
+
@info_hash[RCAP::CAP_1_2::Info:: SEVERITY_KEY].should == @info.severity
|
342
341
|
end
|
343
342
|
|
344
343
|
it('should export the certainty') do
|
345
|
-
@info_hash[
|
344
|
+
@info_hash[RCAP::CAP_1_2::Info:: CERTAINTY_KEY].should == @info.certainty
|
346
345
|
end
|
347
346
|
|
348
347
|
it('should export the audience') do
|
349
|
-
@info_hash[
|
348
|
+
@info_hash[RCAP::CAP_1_2::Info:: AUDIENCE_KEY].should == @info.audience
|
350
349
|
end
|
351
350
|
|
352
351
|
it('should export the effective date') do
|
353
|
-
@info_hash[
|
352
|
+
@info_hash[RCAP::CAP_1_2::Info::EFFECTIVE_KEY].should == @info.effective.to_s_for_cap
|
354
353
|
end
|
355
354
|
|
356
355
|
it('should export the onset date') do
|
357
|
-
@info_hash[
|
356
|
+
@info_hash[RCAP::CAP_1_2::Info::ONSET_KEY].should == @info.onset.to_s_for_cap
|
358
357
|
end
|
359
358
|
|
360
359
|
it('should export the expires date') do
|
361
|
-
@info_hash[
|
360
|
+
@info_hash[RCAP::CAP_1_2::Info::EXPIRES_KEY].should == @info.expires.to_s_for_cap
|
362
361
|
end
|
363
362
|
|
364
363
|
it('should export the sender name') do
|
365
|
-
@info_hash[
|
364
|
+
@info_hash[RCAP::CAP_1_2::Info::SENDER_NAME_KEY].should == @info.sender_name
|
366
365
|
end
|
367
366
|
|
368
367
|
it('should export the headline') do
|
369
|
-
@info_hash[
|
368
|
+
@info_hash[RCAP::CAP_1_2::Info::HEADLINE_KEY].should == @info.headline
|
370
369
|
end
|
371
370
|
|
372
371
|
it('should export the description') do
|
373
|
-
@info_hash[
|
372
|
+
@info_hash[RCAP::CAP_1_2::Info::DESCRIPTION_KEY].should == @info.description
|
374
373
|
end
|
375
374
|
|
376
375
|
it('should export the instruction') do
|
377
|
-
@info_hash[
|
376
|
+
@info_hash[RCAP::CAP_1_2::Info::INSTRUCTION_KEY].should == @info.instruction
|
378
377
|
end
|
379
378
|
|
380
379
|
it('should export the web address ') do
|
381
|
-
@info_hash[
|
380
|
+
@info_hash[RCAP::CAP_1_2::Info::WEB_KEY].should == @info.web
|
382
381
|
end
|
383
382
|
|
384
383
|
it('should export the contact') do
|
385
|
-
@info_hash[
|
384
|
+
@info_hash[RCAP::CAP_1_2::Info::CONTACT_KEY].should == @info.contact
|
386
385
|
end
|
387
386
|
|
388
387
|
it('should export the event codes') do
|
389
|
-
@info_hash[
|
388
|
+
@info_hash[RCAP::CAP_1_2::Info::EVENT_CODES_KEY].should == @info.event_codes.map { |event_code| event_code.to_h }
|
390
389
|
end
|
391
390
|
|
392
391
|
it('should export the parameters ') do
|
393
|
-
@info_hash[
|
392
|
+
@info_hash[RCAP::CAP_1_2::Info::PARAMETERS_KEY].should == @info.parameters.map { |parameter| parameter.to_h }
|
394
393
|
end
|
395
394
|
|
396
395
|
it('should export the resources ') do
|
397
|
-
@info_hash[
|
396
|
+
@info_hash[RCAP::CAP_1_2::Info::RESOURCES_KEY].should == @info.resources.map { |resource| resource.to_h }
|
398
397
|
end
|
399
398
|
|
400
399
|
it('should export the areas') do
|
401
|
-
@info_hash[
|
400
|
+
@info_hash[RCAP::CAP_1_2::Info::AREAS_KEY].should == @info.areas.map { |area| area.to_h }
|
402
401
|
end
|
403
402
|
end
|
404
403
|
end
|
@@ -83,6 +83,14 @@ describe(RCAP::CAP_1_2::Polygon) do
|
|
83
83
|
@polygon = RCAP::CAP_1_2::Polygon.new(&@polygon_builder)
|
84
84
|
end
|
85
85
|
|
86
|
+
context('to geojson') do
|
87
|
+
it('should be valid geojson') do
|
88
|
+
expected = '{"type":"Polygon","coordinates":[[[0,0],[1,1],[2,2],' \
|
89
|
+
'[0,0]]]}'
|
90
|
+
expect(@polygon.to_geojson).to eq expected
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
86
94
|
context('to a hash') do
|
87
95
|
it('should export correctly') do
|
88
96
|
@polygon.to_h.should == { RCAP::CAP_1_2::Polygon::POINTS_KEY => @polygon.points.map { |point| point.to_a } }
|
@@ -107,33 +107,33 @@ describe(RCAP::CAP_1_2::Resource) do
|
|
107
107
|
end
|
108
108
|
|
109
109
|
it('should set the resource description') do
|
110
|
-
@resource_hash[
|
110
|
+
@resource_hash[RCAP::CAP_1_2::Resource::RESOURCE_DESC_KEY].should == @resource.resource_desc
|
111
111
|
end
|
112
112
|
|
113
113
|
it('should set the mime type') do
|
114
|
-
@resource_hash[
|
114
|
+
@resource_hash[RCAP::CAP_1_2::Resource::MIME_TYPE_KEY].should == @resource.mime_type
|
115
115
|
end
|
116
116
|
|
117
117
|
it('should set the size') do
|
118
|
-
@resource_hash[
|
118
|
+
@resource_hash[RCAP::CAP_1_2::Resource::SIZE_KEY].should == @resource.size
|
119
119
|
end
|
120
120
|
|
121
121
|
it('should set the URI') do
|
122
|
-
@resource_hash[
|
122
|
+
@resource_hash[RCAP::CAP_1_2::Resource::URI_KEY].should == @resource.uri
|
123
123
|
end
|
124
124
|
|
125
125
|
it('should set the dereferenced URI') do
|
126
|
-
@resource_hash[
|
126
|
+
@resource_hash[RCAP::CAP_1_2::Resource::DEREF_URI_KEY].should == @resource.deref_uri
|
127
127
|
end
|
128
128
|
|
129
129
|
it('should set the digest') do
|
130
|
-
@resource_hash[
|
130
|
+
@resource_hash[RCAP::CAP_1_2::Resource::DIGEST_KEY].should == @resource.digest
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
134
|
context('to xml') do
|
135
135
|
it('should be successful') do
|
136
|
-
|
136
|
+
-> { @resource_xml = @resource.to_xml }.should_not(raise_exception)
|
137
137
|
end
|
138
138
|
end
|
139
139
|
end
|
@@ -169,20 +169,20 @@ describe(RCAP::CAP_1_2::Resource) do
|
|
169
169
|
end
|
170
170
|
@content = "1,2\n3,4"
|
171
171
|
@encoded_content = Base64.encode64(@content)
|
172
|
-
|
172
|
+
expect(URI).to receive(:parse) { StringIO.new(@content) }
|
173
173
|
end
|
174
174
|
|
175
175
|
describe('calling dereference_uri!') do
|
176
176
|
it('should fetch the content and store it in deref_uri as Base64 encoded content') do
|
177
|
-
|
177
|
+
-> { @resource.dereference_uri! }.should(change(@resource, :deref_uri).to(@encoded_content))
|
178
178
|
end
|
179
179
|
|
180
180
|
it('should generate the correct SHA1 hash') do
|
181
|
-
|
181
|
+
-> { @resource.dereference_uri! }.should(change(@resource, :digest).to(Digest::SHA1.hexdigest(@encoded_content)))
|
182
182
|
end
|
183
183
|
|
184
184
|
it('should set the size in bytes') do
|
185
|
-
|
185
|
+
-> { @resource.dereference_uri! }.should(change(@resource, :size).to(@encoded_content.bytesize))
|
186
186
|
end
|
187
187
|
end
|
188
188
|
end
|
@@ -201,11 +201,11 @@ describe(RCAP::CAP_1_2::Resource) do
|
|
201
201
|
|
202
202
|
describe('#calculate_hash_and_size') do
|
203
203
|
it('should generate the correct SHA1 hash') do
|
204
|
-
|
204
|
+
-> { @resource.calculate_hash_and_size }.should(change(@resource, :digest).to(Digest::SHA1.hexdigest(@encoded_content)))
|
205
205
|
end
|
206
206
|
|
207
207
|
it('should set the size in bytes') do
|
208
|
-
|
208
|
+
-> { @resource.calculate_hash_and_size }.should(change(@resource, :size).to(@encoded_content.bytesize))
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|