rcap 2.4.1 → 2.7.3
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 +30 -29
- data/lib/rcap/base/alert.rb +208 -205
- data/lib/rcap/base/area.rb +95 -91
- data/lib/rcap/base/circle.rb +45 -34
- data/lib/rcap/base/event_code.rb +2 -0
- data/lib/rcap/base/geocode.rb +2 -0
- data/lib/rcap/base/info.rb +273 -272
- data/lib/rcap/base/parameter.rb +29 -28
- data/lib/rcap/base/point.rb +26 -24
- data/lib/rcap/base/polygon.rb +43 -35
- data/lib/rcap/base/resource.rb +65 -65
- data/lib/rcap/cap_1_0/alert.rb +85 -86
- data/lib/rcap/cap_1_0/area.rb +2 -2
- data/lib/rcap/cap_1_0/circle.rb +2 -1
- 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 -3
- data/lib/rcap/cap_1_0/parameter.rb +13 -13
- data/lib/rcap/cap_1_0/point.rb +2 -1
- data/lib/rcap/cap_1_0/polygon.rb +3 -3
- data/lib/rcap/cap_1_0/resource.rb +2 -3
- data/lib/rcap/cap_1_1/alert.rb +6 -6
- data/lib/rcap/cap_1_1/area.rb +2 -2
- data/lib/rcap/cap_1_1/circle.rb +2 -1
- 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 +125 -132
- data/lib/rcap/cap_1_1/parameter.rb +2 -3
- data/lib/rcap/cap_1_1/point.rb +2 -1
- data/lib/rcap/cap_1_1/polygon.rb +3 -3
- data/lib/rcap/cap_1_1/resource.rb +37 -38
- data/lib/rcap/cap_1_2/alert.rb +6 -6
- data/lib/rcap/cap_1_2/area.rb +2 -2
- data/lib/rcap/cap_1_2/circle.rb +2 -1
- 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 +120 -123
- data/lib/rcap/cap_1_2/parameter.rb +2 -3
- data/lib/rcap/cap_1_2/point.rb +2 -1
- data/lib/rcap/cap_1_2/polygon.rb +4 -4
- data/lib/rcap/cap_1_2/resource.rb +38 -38
- data/lib/rcap/config.rb +5 -3
- data/lib/rcap/custom_validators.rb +75 -78
- data/lib/rcap/extensions/array.rb +3 -1
- data/lib/rcap/extensions/date.rb +3 -1
- data/lib/rcap/extensions/date_time.rb +5 -2
- 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 +6 -4
- data/lib/rcap/extensions/time.rb +5 -3
- data/lib/rcap/formatters/yaml.rb +5 -0
- data/lib/rcap/info.rb +6 -5
- data/lib/rcap/utilities.rb +27 -30
- data/lib/rcap/validation.rb +22 -21
- data/lib/rcap/version.rb +3 -1
- data/rcap.gemspec +5 -5
- data/spec/alert_spec.rb +141 -141
- data/spec/cap_1_0/alert_spec.rb +92 -94
- data/spec/cap_1_0/area_spec.rb +86 -86
- data/spec/cap_1_0/circle_spec.rb +48 -39
- data/spec/cap_1_0/event_code_spec.rb +15 -15
- data/spec/cap_1_0/geocode_spec.rb +16 -16
- data/spec/cap_1_0/info_spec.rb +175 -177
- data/spec/cap_1_0/parameter_spec.rb +27 -27
- data/spec/cap_1_0/point_spec.rb +18 -18
- data/spec/cap_1_0/polygon_spec.rb +43 -41
- data/spec/cap_1_0/resource_spec.rb +63 -64
- data/spec/cap_1_1/alert_spec.rb +107 -109
- data/spec/cap_1_1/area_spec.rb +90 -90
- data/spec/cap_1_1/circle_spec.rb +43 -34
- data/spec/cap_1_1/event_code_spec.rb +15 -16
- data/spec/cap_1_1/geocode_spec.rb +16 -16
- data/spec/cap_1_1/info_spec.rb +194 -196
- data/spec/cap_1_1/parameter_spec.rb +17 -17
- data/spec/cap_1_1/point_spec.rb +18 -18
- data/spec/cap_1_1/polygon_spec.rb +43 -41
- data/spec/cap_1_1/resource_spec.rb +106 -107
- data/spec/cap_1_2/alert_spec.rb +98 -99
- data/spec/cap_1_2/area_spec.rb +90 -90
- data/spec/cap_1_2/circle_spec.rb +52 -43
- data/spec/cap_1_2/event_code_spec.rb +19 -20
- data/spec/cap_1_2/geocode_spec.rb +20 -20
- data/spec/cap_1_2/info_spec.rb +196 -198
- data/spec/cap_1_2/parameter_spec.rb +19 -19
- data/spec/cap_1_2/point_spec.rb +21 -21
- data/spec/cap_1_2/polygon_spec.rb +55 -47
- data/spec/cap_1_2/resource_spec.rb +96 -97
- data/spec/extensions_spec.rb +29 -29
- data/spec/info_spec.rb +15 -15
- data/spec/spec_helper.rb +3 -3
- data/spec/validations_spec.rb +73 -73
- metadata +12 -11
- data/lib/rcap/extensions/fixnum.rb +0 -5
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe(
|
4
|
-
context(
|
5
|
-
context(
|
6
|
-
before(
|
3
|
+
describe(RCAP::CAP_1_1::Parameter) do
|
4
|
+
context('when initialised') do
|
5
|
+
context('from XML') do
|
6
|
+
before(:each) do
|
7
7
|
|
8
8
|
@alert = RCAP::CAP_1_1::Alert.new do |alert|
|
9
9
|
alert.add_info.add_parameter do |parameter|
|
@@ -13,36 +13,36 @@ describe( RCAP::CAP_1_1::Parameter ) do
|
|
13
13
|
end
|
14
14
|
@original_parameter = @alert.infos.first.parameters.first
|
15
15
|
@xml_string = @alert.to_xml
|
16
|
-
@xml_document = REXML::Document.new(
|
17
|
-
@info_xml_element = RCAP.xpath_first(
|
18
|
-
@parameter_xml_element = RCAP.xpath_first(
|
19
|
-
@parameter = RCAP::CAP_1_1::Parameter.from_xml_element(
|
16
|
+
@xml_document = REXML::Document.new(@xml_string)
|
17
|
+
@info_xml_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
18
|
+
@parameter_xml_element = RCAP.xpath_first(@info_xml_element, RCAP::CAP_1_1::Parameter::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
19
|
+
@parameter = RCAP::CAP_1_1::Parameter.from_xml_element(@parameter_xml_element)
|
20
20
|
end
|
21
21
|
|
22
|
-
it(
|
22
|
+
it('should parse into the correct class') do
|
23
23
|
@parameter.class.should == RCAP::CAP_1_1::Parameter
|
24
24
|
end
|
25
25
|
|
26
|
-
it(
|
26
|
+
it('should parse the name correctly') do
|
27
27
|
@parameter.name.should == @original_parameter.name
|
28
28
|
end
|
29
29
|
|
30
|
-
it(
|
30
|
+
it('should parse the value correctly') do
|
31
31
|
@parameter.value.should == @original_parameter.value
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
context(
|
37
|
-
before(
|
36
|
+
context('when exported') do
|
37
|
+
before(:each) do
|
38
38
|
@parameter = RCAP::CAP_1_1::Parameter.new do |parameter|
|
39
|
-
|
40
|
-
|
39
|
+
parameter.name = 'name'
|
40
|
+
parameter.value = 'value'
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
context(
|
45
|
-
it(
|
44
|
+
context('to a hash') do
|
45
|
+
it('should export correctly') do
|
46
46
|
@parameter.to_h.should == { 'name' => 'value' }
|
47
47
|
end
|
48
48
|
end
|
data/spec/cap_1_1/point_spec.rb
CHANGED
@@ -1,50 +1,50 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe(
|
4
|
-
describe(
|
5
|
-
before(
|
3
|
+
describe(RCAP::CAP_1_1::Point) do
|
4
|
+
describe('is not valid if') do
|
5
|
+
before(:each) do
|
6
6
|
@point = RCAP::CAP_1_1::Point.new do |point|
|
7
7
|
point.lattitude = 0
|
8
8
|
point.longitude = 0
|
9
9
|
end
|
10
|
-
@point.should(
|
10
|
+
@point.should(be_valid)
|
11
11
|
end
|
12
12
|
|
13
|
-
it(
|
13
|
+
it('does not have a longitude defined') do
|
14
14
|
@point.longitude = nil
|
15
|
-
@point.should_not(
|
15
|
+
@point.should_not(be_valid)
|
16
16
|
end
|
17
17
|
|
18
|
-
it(
|
18
|
+
it('does not have a valid longitude') do
|
19
19
|
@point.longitude = RCAP::CAP_1_1::Point::MAX_LONGITUDE + 1
|
20
|
-
@point.should_not(
|
20
|
+
@point.should_not(be_valid)
|
21
21
|
@point.longitude = RCAP::CAP_1_1::Point::MIN_LONGITUDE - 1
|
22
|
-
@point.should_not(
|
22
|
+
@point.should_not(be_valid)
|
23
23
|
end
|
24
24
|
|
25
|
-
it(
|
25
|
+
it('does not have a lattitude defined') do
|
26
26
|
@point.lattitude = nil
|
27
|
-
@point.should_not(
|
27
|
+
@point.should_not(be_valid)
|
28
28
|
end
|
29
29
|
|
30
|
-
it(
|
30
|
+
it('does not have a valid lattitude') do
|
31
31
|
@point.lattitude = RCAP::CAP_1_1::Point::MAX_LATTITUDE + 1
|
32
|
-
@point.should_not(
|
32
|
+
@point.should_not(be_valid)
|
33
33
|
@point.lattitude = RCAP::CAP_1_1::Point::MIN_LATTITUDE - 1
|
34
|
-
@point.should_not(
|
34
|
+
@point.should_not(be_valid)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
context(
|
39
|
-
before(
|
38
|
+
context('when exported') do
|
39
|
+
before(:each) do
|
40
40
|
@point = RCAP::CAP_1_1::Point.new do |point|
|
41
41
|
point.lattitude = 1
|
42
42
|
point.longitude = 1
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
context(
|
47
|
-
it(
|
46
|
+
context('to hash') do
|
47
|
+
it('should export correctly') do
|
48
48
|
@point.to_h.should == { RCAP::CAP_1_1::Point::LATTITUDE_KEY => 1, RCAP::CAP_1_1::Point::LONGITUDE_KEY => 1 }
|
49
49
|
end
|
50
50
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe(
|
4
|
-
describe(
|
5
|
-
before(
|
3
|
+
describe(RCAP::CAP_1_1::Polygon) do
|
4
|
+
describe('is not valid if it') do
|
5
|
+
before(:each) do
|
6
6
|
@polygon = RCAP::CAP_1_1::Polygon.new do |polygon|
|
7
7
|
3.times do
|
8
8
|
polygon.add_point do |point|
|
@@ -10,24 +10,19 @@ 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
|
|
28
|
-
context(
|
29
|
-
context(
|
30
|
-
before(
|
23
|
+
context('on initialization') do
|
24
|
+
context('from XML') do
|
25
|
+
before(:each) do
|
31
26
|
@original_polygon = RCAP::CAP_1_1::Polygon.new do |polygon|
|
32
27
|
3.times do |i|
|
33
28
|
polygon.add_point do |point|
|
@@ -36,7 +31,7 @@ describe( RCAP::CAP_1_1::Polygon ) do
|
|
36
31
|
end
|
37
32
|
end
|
38
33
|
end
|
39
|
-
@empty_original_polygon = RCAP::CAP_1_1::Polygon.new
|
34
|
+
@empty_original_polygon = RCAP::CAP_1_1::Polygon.new
|
40
35
|
@alert = RCAP::CAP_1_1::Alert.new
|
41
36
|
@alert.add_info.add_area do |area|
|
42
37
|
area.add_polygon do |polygon|
|
@@ -50,29 +45,29 @@ describe( RCAP::CAP_1_1::Polygon ) do
|
|
50
45
|
area.add_polygon
|
51
46
|
end
|
52
47
|
@xml_string = @alert.to_xml
|
53
|
-
@xml_document = REXML::Document.new(
|
54
|
-
@info_element = RCAP.xpath_first(
|
55
|
-
@area_element = RCAP.xpath_first(
|
56
|
-
@polygon_element = RCAP.xpath_first(
|
57
|
-
@polygon = RCAP::CAP_1_1::Polygon.from_xml_element(
|
48
|
+
@xml_document = REXML::Document.new(@xml_string)
|
49
|
+
@info_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
50
|
+
@area_element = RCAP.xpath_first(@info_element, RCAP::CAP_1_1::Area::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
51
|
+
@polygon_element = RCAP.xpath_first(@area_element, RCAP::CAP_1_1::Polygon::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
52
|
+
@polygon = RCAP::CAP_1_1::Polygon.from_xml_element(@polygon_element)
|
58
53
|
end
|
59
54
|
|
60
|
-
it(
|
61
|
-
@polygon.points.zip(
|
55
|
+
it('should parse all the points') do
|
56
|
+
@polygon.points.zip(@original_polygon.points).each do |point, original_point|
|
62
57
|
point.lattitude.should == original_point.lattitude
|
63
58
|
point.longitude.should == original_point.longitude
|
64
59
|
end
|
65
60
|
end
|
66
61
|
|
67
62
|
it 'should allow empty polygon xml elements' do
|
68
|
-
empty_polygon_element = RCAP.xpath_match(
|
69
|
-
empty_polygon = RCAP::CAP_1_1::Polygon.from_xml_element(
|
63
|
+
empty_polygon_element = RCAP.xpath_match(@area_element, RCAP::CAP_1_1::Polygon::XPATH, RCAP::CAP_1_1::Alert::XMLNS)[1]
|
64
|
+
empty_polygon = RCAP::CAP_1_1::Polygon.from_xml_element(empty_polygon_element)
|
70
65
|
empty_polygon.should == @empty_original_polygon
|
71
66
|
end
|
72
67
|
end
|
73
68
|
|
74
|
-
context(
|
75
|
-
before(
|
69
|
+
context('from a hash') do
|
70
|
+
before(:each) do
|
76
71
|
@polygon = RCAP::CAP_1_1::Polygon.new do |polygon|
|
77
72
|
3.times do |i|
|
78
73
|
polygon.add_point do |point|
|
@@ -83,15 +78,15 @@ describe( RCAP::CAP_1_1::Polygon ) do
|
|
83
78
|
end
|
84
79
|
end
|
85
80
|
|
86
|
-
it(
|
87
|
-
@new_polygon = RCAP::CAP_1_1::Polygon.from_h(
|
81
|
+
it('should load all the points') do
|
82
|
+
@new_polygon = RCAP::CAP_1_1::Polygon.from_h(@polygon.to_h)
|
88
83
|
@new_polygon.points.should == @polygon.points
|
89
84
|
end
|
90
85
|
end
|
91
86
|
end
|
92
87
|
|
93
|
-
context(
|
94
|
-
before(
|
88
|
+
context('when exported') do
|
89
|
+
before(:each) do
|
95
90
|
@polygon = RCAP::CAP_1_1::Polygon.new do |polygon|
|
96
91
|
3.times do |i|
|
97
92
|
polygon.add_point do |point|
|
@@ -102,33 +97,40 @@ describe( RCAP::CAP_1_1::Polygon ) do
|
|
102
97
|
end
|
103
98
|
end
|
104
99
|
|
105
|
-
context(
|
106
|
-
it(
|
107
|
-
|
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
|
+
|
107
|
+
context('to a hash') do
|
108
|
+
it('should export correctly') do
|
109
|
+
@polygon.to_h.should == { RCAP::CAP_1_1::Polygon::POINTS_KEY => @polygon.points.map { |point| point.to_a } }
|
108
110
|
end
|
109
111
|
end
|
110
112
|
end
|
111
113
|
|
112
|
-
describe(
|
113
|
-
before(
|
114
|
+
describe('instance methods') do
|
115
|
+
before(:each) do
|
114
116
|
@polygon = RCAP::CAP_1_1::Polygon.new
|
115
117
|
end
|
116
118
|
|
117
|
-
describe(
|
118
|
-
before(
|
119
|
+
describe('#add_point') do
|
120
|
+
before(:each) do
|
119
121
|
@point = @polygon.add_point do |point|
|
120
122
|
point.lattitude = 1
|
121
123
|
point.longitude = 1
|
122
124
|
end
|
123
125
|
end
|
124
126
|
|
125
|
-
it(
|
127
|
+
it('should return a 1.1 Point') do
|
126
128
|
@point.class.should == RCAP::CAP_1_1::Point
|
127
129
|
@point.lattitude.should == 1
|
128
130
|
@point.longitude.should == 1
|
129
131
|
end
|
130
132
|
|
131
|
-
it(
|
133
|
+
it('should add a Point to the points attribute') do
|
132
134
|
@polygon.points.size.should == 1
|
133
135
|
end
|
134
136
|
end
|
@@ -1,237 +1,236 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe(
|
4
|
-
context(
|
5
|
-
before(
|
3
|
+
describe(RCAP::CAP_1_1::Resource) do
|
4
|
+
context('on initialisation') do
|
5
|
+
before(:each) do
|
6
6
|
@resource = RCAP::CAP_1_1::Resource.new
|
7
7
|
end
|
8
8
|
|
9
|
-
it(
|
10
|
-
it(
|
11
|
-
it(
|
12
|
-
it(
|
13
|
-
it(
|
14
|
-
it(
|
9
|
+
it('should have no mime_type') { @resource.mime_type.should(be_nil) }
|
10
|
+
it('should have no size') { @resource.size.should(be_nil) }
|
11
|
+
it('should have no uri') { @resource.uri.should(be_nil) }
|
12
|
+
it('should have no deref_uri') { @resource.deref_uri.should(be_nil) }
|
13
|
+
it('should have no digest') { @resource.digest.should(be_nil) }
|
14
|
+
it('should have no resource_desc') { @resource.resource_desc.should(be_nil) }
|
15
15
|
|
16
|
-
context(
|
17
|
-
before(
|
16
|
+
context('from XML') do
|
17
|
+
before(:each) do
|
18
18
|
@alert = RCAP::CAP_1_1::Alert.new
|
19
19
|
@alert.add_info.add_resource do |resource|
|
20
|
-
resource.resource_desc =
|
21
|
-
resource.uri =
|
20
|
+
resource.resource_desc = 'Image of incident'
|
21
|
+
resource.uri = 'http://capetown.gov.za/cap/resources/image.png'
|
22
22
|
resource.mime_type = 'image/png'
|
23
|
-
resource.deref_uri =
|
24
|
-
resource.size =
|
25
|
-
resource.digest =
|
23
|
+
resource.deref_uri = 'IMAGE DATA'
|
24
|
+
resource.size = 20_480
|
25
|
+
resource.digest = '2048'
|
26
26
|
end
|
27
27
|
@original_resource = @alert.infos.first.resources.first
|
28
28
|
@xml_string = @alert.to_xml
|
29
|
-
@xml_document = REXML::Document.new(
|
30
|
-
@info_element = RCAP.xpath_first(
|
31
|
-
@resource_element = RCAP.xpath_first(
|
32
|
-
@resource_element.should_not(
|
33
|
-
@resource = RCAP::CAP_1_1::Resource.from_xml_element(
|
29
|
+
@xml_document = REXML::Document.new(@xml_string)
|
30
|
+
@info_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
31
|
+
@resource_element = RCAP.xpath_first(@info_element, RCAP::CAP_1_1::Resource::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
32
|
+
@resource_element.should_not(be_nil)
|
33
|
+
@resource = RCAP::CAP_1_1::Resource.from_xml_element(@resource_element)
|
34
34
|
end
|
35
35
|
|
36
|
-
it(
|
36
|
+
it('should parse resource_desc correctly') do
|
37
37
|
@resource.resource_desc.should == @original_resource.resource_desc
|
38
38
|
end
|
39
39
|
|
40
|
-
it(
|
40
|
+
it('should parse uri correctly') do
|
41
41
|
@resource.uri.should == @original_resource.uri
|
42
42
|
end
|
43
43
|
|
44
|
-
it(
|
44
|
+
it('should parse mime_type correctly') do
|
45
45
|
@resource.mime_type.should == @original_resource.mime_type
|
46
46
|
end
|
47
47
|
|
48
|
-
it(
|
48
|
+
it('should parse deref_uri correctly') do
|
49
49
|
@resource.deref_uri.should == @original_resource.deref_uri
|
50
50
|
end
|
51
51
|
|
52
|
-
it(
|
52
|
+
it('should parse size correctly') do
|
53
53
|
@resource.size.should == @original_resource.size
|
54
54
|
end
|
55
55
|
|
56
|
-
it(
|
56
|
+
it('should parse digest correctly') do
|
57
57
|
@resource.digest.should == @original_resource.digest
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
before( :each ) do
|
61
|
+
context('from a hash') do
|
62
|
+
before(:each) do
|
64
63
|
@original_resource = RCAP::CAP_1_1::Resource.new do |resource|
|
65
|
-
resource.resource_desc =
|
66
|
-
resource.uri =
|
64
|
+
resource.resource_desc = 'Image of incident'
|
65
|
+
resource.uri = 'http://capetown.gov.za/cap/resources/image.png'
|
67
66
|
resource.mime_type = 'image/png'
|
68
|
-
resource.deref_uri =
|
69
|
-
resource.size =
|
70
|
-
resource.digest =
|
67
|
+
resource.deref_uri = 'IMAGE DATA'
|
68
|
+
resource.size = 20_480
|
69
|
+
resource.digest = '2048'
|
71
70
|
end
|
72
71
|
|
73
|
-
@resource = RCAP::CAP_1_1::Resource.from_h(
|
72
|
+
@resource = RCAP::CAP_1_1::Resource.from_h(@original_resource.to_h)
|
74
73
|
end
|
75
74
|
|
76
|
-
it(
|
75
|
+
it('should parse resource_desc correctly') do
|
77
76
|
@resource.resource_desc.should == @original_resource.resource_desc
|
78
77
|
end
|
79
78
|
|
80
|
-
it(
|
79
|
+
it('should parse uri correctly') do
|
81
80
|
@resource.uri.should == @original_resource.uri
|
82
81
|
end
|
83
82
|
|
84
|
-
it(
|
83
|
+
it('should parse mime_type correctly') do
|
85
84
|
@resource.mime_type.should == @original_resource.mime_type
|
86
85
|
end
|
87
86
|
|
88
|
-
it(
|
87
|
+
it('should parse deref_uri correctly') do
|
89
88
|
@resource.deref_uri.should == @original_resource.deref_uri
|
90
89
|
end
|
91
90
|
|
92
|
-
it(
|
91
|
+
it('should parse size correctly') do
|
93
92
|
@resource.size.should == @original_resource.size
|
94
93
|
end
|
95
94
|
|
96
|
-
it(
|
95
|
+
it('should parse digest correctly') do
|
97
96
|
@resource.digest.should == @original_resource.digest
|
98
97
|
end
|
99
98
|
end
|
100
99
|
|
101
|
-
context(
|
102
|
-
before(
|
100
|
+
context('from YAML') do
|
101
|
+
before(:each) do
|
103
102
|
@original_resource = RCAP::CAP_1_1::Resource.new do |resource|
|
104
|
-
resource.resource_desc =
|
105
|
-
resource.uri =
|
103
|
+
resource.resource_desc = 'Image of incident'
|
104
|
+
resource.uri = 'http://capetown.gov.za/cap/resources/image.png'
|
106
105
|
resource.mime_type = 'image/png'
|
107
|
-
resource.deref_uri =
|
108
|
-
resource.size =
|
109
|
-
resource.digest =
|
106
|
+
resource.deref_uri = 'IMAGE DATA'
|
107
|
+
resource.size = 20_480
|
108
|
+
resource.digest = '2048'
|
110
109
|
end
|
111
|
-
@resource = RCAP::CAP_1_1::Resource.from_yaml_data(
|
110
|
+
@resource = RCAP::CAP_1_1::Resource.from_yaml_data(YAML.load(@original_resource.to_yaml))
|
112
111
|
end
|
113
112
|
|
114
|
-
it(
|
113
|
+
it('should parse resource_desc correctly') do
|
115
114
|
@resource.resource_desc.should == @original_resource.resource_desc
|
116
115
|
end
|
117
116
|
|
118
|
-
it(
|
117
|
+
it('should parse uri correctly') do
|
119
118
|
@resource.uri.should == @original_resource.uri
|
120
119
|
end
|
121
120
|
|
122
|
-
it(
|
121
|
+
it('should parse mime_type correctly') do
|
123
122
|
@resource.mime_type.should == @original_resource.mime_type
|
124
123
|
end
|
125
124
|
|
126
|
-
it(
|
125
|
+
it('should parse deref_uri correctly') do
|
127
126
|
@resource.deref_uri.should == @original_resource.deref_uri
|
128
127
|
end
|
129
128
|
|
130
|
-
it(
|
129
|
+
it('should parse size correctly') do
|
131
130
|
@resource.size.should == @original_resource.size
|
132
131
|
end
|
133
132
|
|
134
|
-
it(
|
133
|
+
it('should parse digest correctly') do
|
135
134
|
@resource.digest.should == @original_resource.digest
|
136
135
|
end
|
137
136
|
end
|
138
137
|
end
|
139
138
|
|
140
|
-
context(
|
141
|
-
before(
|
139
|
+
context('when exported') do
|
140
|
+
before(:each) do
|
142
141
|
@resource = RCAP::CAP_1_1::Resource.new
|
143
|
-
@resource.resource_desc =
|
144
|
-
@resource.uri =
|
142
|
+
@resource.resource_desc = 'Image of incident'
|
143
|
+
@resource.uri = 'http://capetown.gov.za/cap/resources/image.png'
|
145
144
|
@resource.mime_type = 'image/png'
|
146
|
-
@resource.deref_uri =
|
147
|
-
@resource.size =
|
148
|
-
@resource.digest =
|
145
|
+
@resource.deref_uri = 'IMAGE DATA'
|
146
|
+
@resource.size = 20_480
|
147
|
+
@resource.digest = '2048'
|
149
148
|
end
|
150
149
|
|
151
|
-
context(
|
152
|
-
before(
|
150
|
+
context('to a hash') do
|
151
|
+
before(:each) do
|
153
152
|
@resource_hash = @resource.to_h
|
154
153
|
end
|
155
154
|
|
156
|
-
it(
|
157
|
-
@resource_hash[ RCAP::CAP_1_1::Resource::RESOURCE_DESC_KEY
|
155
|
+
it('should set the resource description') do
|
156
|
+
@resource_hash[ RCAP::CAP_1_1::Resource::RESOURCE_DESC_KEY].should == @resource.resource_desc
|
158
157
|
end
|
159
158
|
|
160
|
-
it(
|
161
|
-
@resource_hash[ RCAP::CAP_1_1::Resource::MIME_TYPE_KEY
|
159
|
+
it('should set the mime type') do
|
160
|
+
@resource_hash[ RCAP::CAP_1_1::Resource::MIME_TYPE_KEY].should == @resource.mime_type
|
162
161
|
end
|
163
162
|
|
164
|
-
it(
|
165
|
-
@resource_hash[ RCAP::CAP_1_1::Resource::SIZE_KEY
|
163
|
+
it('should set the size') do
|
164
|
+
@resource_hash[ RCAP::CAP_1_1::Resource::SIZE_KEY].should == @resource.size
|
166
165
|
end
|
167
166
|
|
168
|
-
it(
|
169
|
-
@resource_hash[ RCAP::CAP_1_1::Resource::URI_KEY
|
167
|
+
it('should set the URI') do
|
168
|
+
@resource_hash[ RCAP::CAP_1_1::Resource::URI_KEY].should == @resource.uri
|
170
169
|
end
|
171
170
|
|
172
|
-
it(
|
173
|
-
@resource_hash[ RCAP::CAP_1_1::Resource::DEREF_URI_KEY
|
171
|
+
it('should set the dereferenced URI') do
|
172
|
+
@resource_hash[ RCAP::CAP_1_1::Resource::DEREF_URI_KEY].should == @resource.deref_uri
|
174
173
|
end
|
175
174
|
|
176
|
-
it(
|
177
|
-
@resource_hash[ RCAP::CAP_1_1::Resource::DIGEST_KEY
|
175
|
+
it('should set the digest') do
|
176
|
+
@resource_hash[ RCAP::CAP_1_1::Resource::DIGEST_KEY].should == @resource.digest
|
178
177
|
end
|
179
178
|
end
|
180
179
|
|
181
|
-
context(
|
182
|
-
it(
|
183
|
-
lambda{ @resource_xml = @resource.to_xml }.should_not(
|
180
|
+
context('to xml') do
|
181
|
+
it('should be successful') do
|
182
|
+
lambda { @resource_xml = @resource.to_xml }.should_not(raise_exception)
|
184
183
|
end
|
185
184
|
end
|
186
185
|
end
|
187
186
|
|
188
|
-
context(
|
189
|
-
before(
|
187
|
+
context('which is valid') do
|
188
|
+
before(:each) do
|
190
189
|
@resource = RCAP::CAP_1_1::Resource.new do |resource|
|
191
190
|
resource.resource_desc = 'Resource Description'
|
192
191
|
end
|
193
|
-
@resource.should(
|
192
|
+
@resource.should(be_valid)
|
194
193
|
end
|
195
194
|
|
196
|
-
describe(
|
197
|
-
it(
|
195
|
+
describe('should not be valid if it') do
|
196
|
+
it('does not have a resource description (resource_desc)') do
|
198
197
|
@resource.resource_desc = nil
|
199
|
-
@resource.should_not(
|
198
|
+
@resource.should_not(be_valid)
|
200
199
|
end
|
201
200
|
end
|
202
201
|
end
|
203
202
|
|
204
|
-
context(
|
205
|
-
before(
|
203
|
+
context('with a non-rereferenced URI') do
|
204
|
+
before(:each) do
|
206
205
|
@resource = RCAP::CAP_1_1::Resource.new do |resource|
|
207
206
|
resource.resource_desc = 'Resource Description'
|
208
207
|
resource.mime_type = 'text/csv'
|
209
208
|
resource.uri = 'http://tempuri.org/resource.csv'
|
210
209
|
end
|
211
210
|
@content = "1,2\n3,4"
|
212
|
-
@encoded_content = Base64.encode64(
|
213
|
-
|
211
|
+
@encoded_content = Base64.encode64(@content)
|
212
|
+
expect(URI).to receive(:parse) { StringIO.new(@content) }
|
214
213
|
end
|
215
214
|
|
216
|
-
describe(
|
217
|
-
it(
|
218
|
-
lambda{ @resource.dereference_uri! }.should(
|
215
|
+
describe('#dereference_uri!') do
|
216
|
+
it('should fetch the content and store it in deref_uri as Base64 encoded content') do
|
217
|
+
lambda { @resource.dereference_uri! }.should(change(@resource, :deref_uri).to(@encoded_content))
|
219
218
|
end
|
220
219
|
|
221
|
-
it(
|
222
|
-
lambda{ @resource.dereference_uri! }.should(
|
220
|
+
it('should generate the correct SHA1 hash') do
|
221
|
+
lambda { @resource.dereference_uri! }.should(change(@resource, :digest).to(Digest::SHA1.hexdigest(@encoded_content)))
|
223
222
|
end
|
224
223
|
|
225
|
-
it(
|
226
|
-
lambda{ @resource.dereference_uri! }.should(
|
224
|
+
it('should set the size in bytes') do
|
225
|
+
lambda { @resource.dereference_uri! }.should(change(@resource, :size).to(@encoded_content.bytesize))
|
227
226
|
end
|
228
227
|
end
|
229
228
|
end
|
230
229
|
|
231
|
-
context(
|
232
|
-
before(
|
230
|
+
context('with a dereferenced URI') do
|
231
|
+
before(:each) do
|
233
232
|
@content = "1,2\n3,4"
|
234
|
-
@encoded_content = Base64.encode64(
|
233
|
+
@encoded_content = Base64.encode64(@content)
|
235
234
|
@resource = RCAP::CAP_1_1::Resource.new do |resource|
|
236
235
|
resource.resource_desc = 'Resource Description'
|
237
236
|
resource.mime_type = 'text/csv'
|
@@ -240,18 +239,18 @@ describe( RCAP::CAP_1_1::Resource ) do
|
|
240
239
|
end
|
241
240
|
end
|
242
241
|
|
243
|
-
describe(
|
244
|
-
it(
|
245
|
-
lambda{ @resource.calculate_hash_and_size }.should(
|
242
|
+
describe('#calculate_hash_and_size') do
|
243
|
+
it('should generate the correct SHA1 hash') do
|
244
|
+
lambda { @resource.calculate_hash_and_size }.should(change(@resource, :digest).to(Digest::SHA1.hexdigest(@encoded_content)))
|
246
245
|
end
|
247
246
|
|
248
|
-
it(
|
249
|
-
lambda{ @resource.calculate_hash_and_size }.should(
|
247
|
+
it('should set the size in bytes') do
|
248
|
+
lambda { @resource.calculate_hash_and_size }.should(change(@resource, :size).to(@encoded_content.bytesize))
|
250
249
|
end
|
251
250
|
end
|
252
251
|
|
253
|
-
describe(
|
254
|
-
it(
|
252
|
+
describe('#decoded_deref_uri') do
|
253
|
+
it('should return the original content') do
|
255
254
|
@resource.decoded_deref_uri.should == @content
|
256
255
|
end
|
257
256
|
end
|