rcap 2.4.1 → 2.7.3
Sign up to get free protection for your applications and to get access to all the features.
- 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,47 +1,47 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe(
|
4
|
-
before(
|
3
|
+
describe(RCAP::CAP_1_2::Parameter) do
|
4
|
+
before(:each) do
|
5
5
|
@parameter_builder = lambda do |parameter|
|
6
6
|
parameter.name = 'name'
|
7
7
|
parameter.value = 'value'
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
context(
|
12
|
-
context(
|
13
|
-
before(
|
14
|
-
@original_parameter = RCAP::CAP_1_2::Parameter.new(
|
11
|
+
context('when initialised') do
|
12
|
+
context('from XML') do
|
13
|
+
before(:each) do
|
14
|
+
@original_parameter = RCAP::CAP_1_2::Parameter.new(&@parameter_builder)
|
15
15
|
@alert = RCAP::CAP_1_2::Alert.new
|
16
|
-
@alert.add_info.add_parameter(
|
16
|
+
@alert.add_info.add_parameter(&@parameter_builder)
|
17
17
|
@xml_string = @alert.to_xml
|
18
|
-
@xml_document = REXML::Document.new(
|
19
|
-
@info_xml_element = RCAP.xpath_first(
|
20
|
-
@parameter_xml_element = RCAP.xpath_first(
|
21
|
-
@parameter = RCAP::CAP_1_2::Parameter.from_xml_element(
|
18
|
+
@xml_document = REXML::Document.new(@xml_string)
|
19
|
+
@info_xml_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_2::Info::XPATH, RCAP::CAP_1_2::Alert::XMLNS)
|
20
|
+
@parameter_xml_element = RCAP.xpath_first(@info_xml_element, RCAP::CAP_1_2::Parameter::XPATH, RCAP::CAP_1_2::Alert::XMLNS)
|
21
|
+
@parameter = RCAP::CAP_1_2::Parameter.from_xml_element(@parameter_xml_element)
|
22
22
|
end
|
23
23
|
|
24
|
-
it(
|
24
|
+
it('should parse into the correct class') do
|
25
25
|
@parameter.class.should == RCAP::CAP_1_2::Parameter
|
26
26
|
end
|
27
27
|
|
28
|
-
it(
|
28
|
+
it('should parse the name correctly') do
|
29
29
|
@parameter.name.should == @original_parameter.name
|
30
30
|
end
|
31
31
|
|
32
|
-
it(
|
32
|
+
it('should parse the value correctly') do
|
33
33
|
@parameter.value.should == @original_parameter.value
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
context(
|
39
|
-
before(
|
40
|
-
@parameter = RCAP::CAP_1_2::Parameter.new(
|
38
|
+
context('when exported') do
|
39
|
+
before(:each) do
|
40
|
+
@parameter = RCAP::CAP_1_2::Parameter.new(&@parameter_builder)
|
41
41
|
end
|
42
42
|
|
43
|
-
context(
|
44
|
-
it(
|
43
|
+
context('to a hash') do
|
44
|
+
it('should export correctly') do
|
45
45
|
@parameter.to_h.should == { 'name' => 'value' }
|
46
46
|
end
|
47
47
|
end
|
data/spec/cap_1_2/point_spec.rb
CHANGED
@@ -1,51 +1,51 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe(
|
4
|
-
before(
|
3
|
+
describe(RCAP::CAP_1_2::Point) do
|
4
|
+
before(:each) do
|
5
5
|
@point_constructor = lambda do |point|
|
6
6
|
point.lattitude = 0
|
7
7
|
point.longitude = 0
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
describe(
|
12
|
-
before(
|
13
|
-
@point = RCAP::CAP_1_2::Point.new(
|
14
|
-
@point.should(
|
11
|
+
describe('is not valid if') do
|
12
|
+
before(:each) do
|
13
|
+
@point = RCAP::CAP_1_2::Point.new(&@point_constructor)
|
14
|
+
@point.should(be_valid)
|
15
15
|
end
|
16
16
|
|
17
|
-
it(
|
17
|
+
it('does not have a longitude defined') do
|
18
18
|
@point.longitude = nil
|
19
|
-
@point.should_not(
|
19
|
+
@point.should_not(be_valid)
|
20
20
|
end
|
21
21
|
|
22
|
-
it(
|
22
|
+
it('does not have a valid longitude') do
|
23
23
|
@point.longitude = RCAP::CAP_1_2::Point::MAX_LONGITUDE + 1
|
24
|
-
@point.should_not(
|
24
|
+
@point.should_not(be_valid)
|
25
25
|
@point.longitude = RCAP::CAP_1_2::Point::MIN_LONGITUDE - 1
|
26
|
-
@point.should_not(
|
26
|
+
@point.should_not(be_valid)
|
27
27
|
end
|
28
28
|
|
29
|
-
it(
|
29
|
+
it('does not have a lattitude defined') do
|
30
30
|
@point.lattitude = nil
|
31
|
-
@point.should_not(
|
31
|
+
@point.should_not(be_valid)
|
32
32
|
end
|
33
33
|
|
34
|
-
it(
|
34
|
+
it('does not have a valid lattitude') do
|
35
35
|
@point.lattitude = RCAP::CAP_1_2::Point::MAX_LATTITUDE + 1
|
36
|
-
@point.should_not(
|
36
|
+
@point.should_not(be_valid)
|
37
37
|
@point.lattitude = RCAP::CAP_1_2::Point::MIN_LATTITUDE - 1
|
38
|
-
@point.should_not(
|
38
|
+
@point.should_not(be_valid)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
context(
|
43
|
-
before(
|
44
|
-
@point = RCAP::CAP_1_2::Point.new(
|
42
|
+
context('when exported') do
|
43
|
+
before(:each) do
|
44
|
+
@point = RCAP::CAP_1_2::Point.new(&@point_constructor)
|
45
45
|
end
|
46
46
|
|
47
|
-
context(
|
48
|
-
it(
|
47
|
+
context('to hash') do
|
48
|
+
it('should export correctly') do
|
49
49
|
@point.to_h.should == { RCAP::CAP_1_2::Point::LATTITUDE_KEY => 0, RCAP::CAP_1_2::Point::LONGITUDE_KEY => 0 }
|
50
50
|
end
|
51
51
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe(
|
4
|
-
before(
|
3
|
+
describe(RCAP::CAP_1_2::Polygon) do
|
4
|
+
before(:each) do
|
5
5
|
@polygon_builder = lambda do |polygon|
|
6
|
-
[0,1,2,0].each do |coordinate|
|
6
|
+
[0, 1, 2, 0].each do |coordinate|
|
7
7
|
polygon.add_point do |point|
|
8
8
|
point.lattitude = coordinate
|
9
9
|
point.longitude = coordinate
|
@@ -12,104 +12,112 @@ describe( RCAP::CAP_1_2::Polygon ) do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
describe(
|
16
|
-
before(
|
17
|
-
@polygon = RCAP::CAP_1_2::Polygon.new(
|
18
|
-
@polygon.should(
|
15
|
+
describe('is not valid if it') do
|
16
|
+
before(:each) do
|
17
|
+
@polygon = RCAP::CAP_1_2::Polygon.new(&@polygon_builder)
|
18
|
+
@polygon.should(be_valid)
|
19
19
|
end
|
20
20
|
|
21
|
-
it(
|
21
|
+
it('hass less than 4 points') do
|
22
22
|
@polygon.points.pop
|
23
|
-
@polygon.should_not(
|
23
|
+
@polygon.should_not(be_valid)
|
24
24
|
end
|
25
25
|
|
26
|
-
it(
|
26
|
+
it('does not have the first and last points equal') do
|
27
27
|
@polygon.points.last.lattitude = 1
|
28
|
-
@polygon.should_not(
|
28
|
+
@polygon.should_not(be_valid)
|
29
29
|
end
|
30
30
|
|
31
|
-
it(
|
31
|
+
it('does not have a valid collection of points') do
|
32
32
|
@polygon.points.first.lattitude = nil
|
33
|
-
@polygon.should_not(
|
33
|
+
@polygon.should_not(be_valid)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
context(
|
38
|
-
context(
|
39
|
-
before(
|
40
|
-
@original_polygon = RCAP::CAP_1_2::Polygon.new(
|
41
|
-
@empty_original_polygon = RCAP::CAP_1_2::Polygon.new
|
37
|
+
context('on initialization') do
|
38
|
+
context('from XML') do
|
39
|
+
before(:each) do
|
40
|
+
@original_polygon = RCAP::CAP_1_2::Polygon.new(&@polygon_builder)
|
41
|
+
@empty_original_polygon = RCAP::CAP_1_2::Polygon.new
|
42
42
|
@alert = RCAP::CAP_1_2::Alert.new
|
43
43
|
@alert.add_info.add_area do |area|
|
44
|
-
area.add_polygon(
|
44
|
+
area.add_polygon(&@polygon_builder)
|
45
45
|
area.add_polygon
|
46
46
|
end
|
47
47
|
@xml_string = @alert.to_xml
|
48
|
-
@xml_document = REXML::Document.new(
|
49
|
-
@info_element = RCAP.xpath_first(
|
50
|
-
@area_element = RCAP.xpath_first(
|
51
|
-
@polygon_element = RCAP.xpath_first(
|
52
|
-
@polygon = RCAP::CAP_1_2::Polygon.from_xml_element(
|
48
|
+
@xml_document = REXML::Document.new(@xml_string)
|
49
|
+
@info_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_2::Info::XPATH, RCAP::CAP_1_2::Alert::XMLNS)
|
50
|
+
@area_element = RCAP.xpath_first(@info_element, RCAP::CAP_1_2::Area::XPATH, RCAP::CAP_1_2::Alert::XMLNS)
|
51
|
+
@polygon_element = RCAP.xpath_first(@area_element, RCAP::CAP_1_2::Polygon::XPATH, RCAP::CAP_1_2::Alert::XMLNS)
|
52
|
+
@polygon = RCAP::CAP_1_2::Polygon.from_xml_element(@polygon_element)
|
53
53
|
end
|
54
54
|
|
55
|
-
it(
|
56
|
-
@polygon.points.zip(
|
55
|
+
it('should parse all the points') do
|
56
|
+
@polygon.points.zip(@original_polygon.points).each do |point, original_point|
|
57
57
|
point.lattitude.should == original_point.lattitude
|
58
58
|
point.longitude.should == original_point.longitude
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should allow empty polygon xml elements' do
|
63
|
-
empty_polygon_element = RCAP.xpath_match(
|
64
|
-
empty_polygon = RCAP::CAP_1_2::Polygon.from_xml_element(
|
63
|
+
empty_polygon_element = RCAP.xpath_match(@area_element, RCAP::CAP_1_2::Polygon::XPATH, RCAP::CAP_1_2::Alert::XMLNS)[1]
|
64
|
+
empty_polygon = RCAP::CAP_1_2::Polygon.from_xml_element(empty_polygon_element)
|
65
65
|
empty_polygon.should == @empty_original_polygon
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
context(
|
70
|
-
before(
|
71
|
-
@polygon = RCAP::CAP_1_2::Polygon.new(
|
69
|
+
context('from a hash') do
|
70
|
+
before(:each) do
|
71
|
+
@polygon = RCAP::CAP_1_2::Polygon.new(&@polygon_builder)
|
72
72
|
end
|
73
73
|
|
74
|
-
it(
|
75
|
-
@new_polygon = RCAP::CAP_1_2::Polygon.from_h(
|
74
|
+
it('should load all the points') do
|
75
|
+
@new_polygon = RCAP::CAP_1_2::Polygon.from_h(@polygon.to_h)
|
76
76
|
@new_polygon.points.should == @polygon.points
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
context(
|
82
|
-
before(
|
83
|
-
@polygon = RCAP::CAP_1_2::Polygon.new(
|
81
|
+
context('when exported') do
|
82
|
+
before(:each) do
|
83
|
+
@polygon = RCAP::CAP_1_2::Polygon.new(&@polygon_builder)
|
84
84
|
end
|
85
85
|
|
86
|
-
context(
|
87
|
-
it(
|
88
|
-
|
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
|
+
|
94
|
+
context('to a hash') do
|
95
|
+
it('should export correctly') do
|
96
|
+
@polygon.to_h.should == { RCAP::CAP_1_2::Polygon::POINTS_KEY => @polygon.points.map { |point| point.to_a } }
|
89
97
|
end
|
90
98
|
end
|
91
99
|
end
|
92
100
|
|
93
|
-
describe(
|
94
|
-
before(
|
101
|
+
describe('instance methods') do
|
102
|
+
before(:each) do
|
95
103
|
@polygon = RCAP::CAP_1_2::Polygon.new
|
96
104
|
end
|
97
105
|
|
98
|
-
describe(
|
99
|
-
before(
|
106
|
+
describe('#add_point') do
|
107
|
+
before(:each) do
|
100
108
|
@point = @polygon.add_point do |point|
|
101
|
-
|
102
|
-
|
109
|
+
point.lattitude = 1
|
110
|
+
point.longitude = 1
|
103
111
|
end
|
104
112
|
end
|
105
113
|
|
106
|
-
it(
|
114
|
+
it('should return a 1.2 Point') do
|
107
115
|
@point.class.should == RCAP::CAP_1_2::Point
|
108
116
|
@point.lattitude.should == 1
|
109
117
|
@point.longitude.should == 1
|
110
118
|
end
|
111
119
|
|
112
|
-
it(
|
120
|
+
it('should add a Point to the points attribute') do
|
113
121
|
@polygon.points.size.should == 1
|
114
122
|
end
|
115
123
|
end
|
@@ -1,217 +1,216 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe(
|
4
|
-
before(
|
3
|
+
describe(RCAP::CAP_1_2::Resource) do
|
4
|
+
before(:each) do
|
5
5
|
@resource_builder = lambda do |resource|
|
6
|
-
resource.resource_desc =
|
7
|
-
resource.uri =
|
6
|
+
resource.resource_desc = 'Image of incident'
|
7
|
+
resource.uri = 'http://capetown.gov.za/cap/resources/image.png'
|
8
8
|
resource.mime_type = 'image/png'
|
9
|
-
resource.deref_uri =
|
10
|
-
resource.size =
|
11
|
-
resource.digest =
|
9
|
+
resource.deref_uri = 'IMAGE DATA'
|
10
|
+
resource.size = 20_480
|
11
|
+
resource.digest = '2048'
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
context(
|
16
|
-
before(
|
15
|
+
context('on initialisation') do
|
16
|
+
before(:each) do
|
17
17
|
@resource = RCAP::CAP_1_2::Resource.new
|
18
18
|
end
|
19
19
|
|
20
|
-
it(
|
21
|
-
it(
|
22
|
-
it(
|
23
|
-
it(
|
24
|
-
it(
|
25
|
-
it(
|
20
|
+
it('should have no mime_type') { @resource.mime_type.should(be_nil) }
|
21
|
+
it('should have no size') { @resource.size.should(be_nil) }
|
22
|
+
it('should have no uri') { @resource.uri.should(be_nil) }
|
23
|
+
it('should have no deref_uri') { @resource.deref_uri.should(be_nil) }
|
24
|
+
it('should have no digest') { @resource.digest.should(be_nil) }
|
25
|
+
it('should have no resource_desc') { @resource.resource_desc.should(be_nil) }
|
26
26
|
|
27
|
-
context(
|
28
|
-
before(
|
29
|
-
@original_resource = RCAP::CAP_1_2::Resource.new(
|
27
|
+
context('from XML') do
|
28
|
+
before(:each) do
|
29
|
+
@original_resource = RCAP::CAP_1_2::Resource.new(&@resource_builder)
|
30
30
|
|
31
31
|
@alert = RCAP::CAP_1_2::Alert.new
|
32
|
-
@alert.add_info.add_resource(
|
32
|
+
@alert.add_info.add_resource(&@resource_builder)
|
33
33
|
@xml_string = @alert.to_xml
|
34
|
-
@xml_document = REXML::Document.new(
|
35
|
-
@info_element = RCAP.xpath_first(
|
36
|
-
@resource_element = RCAP.xpath_first(
|
37
|
-
@resource_element.should_not(
|
38
|
-
@resource = RCAP::CAP_1_2::Resource.from_xml_element(
|
34
|
+
@xml_document = REXML::Document.new(@xml_string)
|
35
|
+
@info_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_2::Info::XPATH, RCAP::CAP_1_2::Alert::XMLNS)
|
36
|
+
@resource_element = RCAP.xpath_first(@info_element, RCAP::CAP_1_2::Resource::XPATH, RCAP::CAP_1_2::Alert::XMLNS)
|
37
|
+
@resource_element.should_not(be_nil)
|
38
|
+
@resource = RCAP::CAP_1_2::Resource.from_xml_element(@resource_element)
|
39
39
|
end
|
40
40
|
|
41
|
-
it(
|
41
|
+
it('should parse resource_desc correctly') do
|
42
42
|
@resource.resource_desc.should == @original_resource.resource_desc
|
43
43
|
end
|
44
44
|
|
45
|
-
it(
|
45
|
+
it('should parse uri correctly') do
|
46
46
|
@resource.uri.should == @original_resource.uri
|
47
47
|
end
|
48
48
|
|
49
|
-
it(
|
49
|
+
it('should parse mime_type correctly') do
|
50
50
|
@resource.mime_type.should == @original_resource.mime_type
|
51
51
|
end
|
52
52
|
|
53
|
-
it(
|
53
|
+
it('should parse deref_uri correctly') do
|
54
54
|
@resource.deref_uri.should == @original_resource.deref_uri
|
55
55
|
end
|
56
56
|
|
57
|
-
it(
|
57
|
+
it('should parse size correctly') do
|
58
58
|
@resource.size.should == @original_resource.size
|
59
59
|
end
|
60
60
|
|
61
|
-
it(
|
61
|
+
it('should parse digest correctly') do
|
62
62
|
@resource.digest.should == @original_resource.digest
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
context('from a hash') do
|
67
|
+
before(:each) do
|
68
|
+
@original_resource = RCAP::CAP_1_2::Resource.new(&@resource_builder)
|
66
69
|
|
67
|
-
|
68
|
-
before( :each ) do
|
69
|
-
@original_resource = RCAP::CAP_1_2::Resource.new( &@resource_builder )
|
70
|
-
|
71
|
-
@resource = RCAP::CAP_1_2::Resource.from_h( @original_resource.to_h )
|
70
|
+
@resource = RCAP::CAP_1_2::Resource.from_h(@original_resource.to_h)
|
72
71
|
end
|
73
72
|
|
74
|
-
it(
|
73
|
+
it('should parse resource_desc correctly') do
|
75
74
|
@resource.resource_desc.should == @original_resource.resource_desc
|
76
75
|
end
|
77
76
|
|
78
|
-
it(
|
77
|
+
it('should parse uri correctly') do
|
79
78
|
@resource.uri.should == @original_resource.uri
|
80
79
|
end
|
81
80
|
|
82
|
-
it(
|
81
|
+
it('should parse mime_type correctly') do
|
83
82
|
@resource.mime_type.should == @original_resource.mime_type
|
84
83
|
end
|
85
84
|
|
86
|
-
it(
|
85
|
+
it('should parse deref_uri correctly') do
|
87
86
|
@resource.deref_uri.should == @original_resource.deref_uri
|
88
87
|
end
|
89
88
|
|
90
|
-
it(
|
89
|
+
it('should parse size correctly') do
|
91
90
|
@resource.size.should == @original_resource.size
|
92
91
|
end
|
93
92
|
|
94
|
-
it(
|
93
|
+
it('should parse digest correctly') do
|
95
94
|
@resource.digest.should == @original_resource.digest
|
96
95
|
end
|
97
96
|
end
|
98
97
|
end
|
99
98
|
|
100
|
-
context(
|
101
|
-
before(
|
102
|
-
@resource = RCAP::CAP_1_2::Resource.new(
|
99
|
+
context('when exported') do
|
100
|
+
before(:each) do
|
101
|
+
@resource = RCAP::CAP_1_2::Resource.new(&@resource_builder)
|
103
102
|
end
|
104
103
|
|
105
|
-
context(
|
106
|
-
before(
|
104
|
+
context('to a hash') do
|
105
|
+
before(:each) do
|
107
106
|
@resource_hash = @resource.to_h
|
108
107
|
end
|
109
108
|
|
110
|
-
it(
|
111
|
-
@resource_hash[ RCAP::CAP_1_2::Resource::RESOURCE_DESC_KEY
|
109
|
+
it('should set the resource description') do
|
110
|
+
@resource_hash[ RCAP::CAP_1_2::Resource::RESOURCE_DESC_KEY].should == @resource.resource_desc
|
112
111
|
end
|
113
112
|
|
114
|
-
it(
|
115
|
-
@resource_hash[ RCAP::CAP_1_2::Resource::MIME_TYPE_KEY
|
113
|
+
it('should set the mime type') do
|
114
|
+
@resource_hash[ RCAP::CAP_1_2::Resource::MIME_TYPE_KEY].should == @resource.mime_type
|
116
115
|
end
|
117
116
|
|
118
|
-
it(
|
119
|
-
@resource_hash[ RCAP::CAP_1_2::Resource::SIZE_KEY
|
117
|
+
it('should set the size') do
|
118
|
+
@resource_hash[ RCAP::CAP_1_2::Resource::SIZE_KEY].should == @resource.size
|
120
119
|
end
|
121
120
|
|
122
|
-
it(
|
123
|
-
@resource_hash[ RCAP::CAP_1_2::Resource::URI_KEY
|
121
|
+
it('should set the URI') do
|
122
|
+
@resource_hash[ RCAP::CAP_1_2::Resource::URI_KEY].should == @resource.uri
|
124
123
|
end
|
125
124
|
|
126
|
-
it(
|
127
|
-
@resource_hash[ RCAP::CAP_1_2::Resource::DEREF_URI_KEY
|
125
|
+
it('should set the dereferenced URI') do
|
126
|
+
@resource_hash[ RCAP::CAP_1_2::Resource::DEREF_URI_KEY].should == @resource.deref_uri
|
128
127
|
end
|
129
128
|
|
130
|
-
it(
|
131
|
-
@resource_hash[ RCAP::CAP_1_2::Resource::DIGEST_KEY
|
129
|
+
it('should set the digest') do
|
130
|
+
@resource_hash[ RCAP::CAP_1_2::Resource::DIGEST_KEY].should == @resource.digest
|
132
131
|
end
|
133
132
|
end
|
134
133
|
|
135
|
-
context(
|
136
|
-
it(
|
137
|
-
lambda{ @resource_xml = @resource.to_xml }.should_not(
|
134
|
+
context('to xml') do
|
135
|
+
it('should be successful') do
|
136
|
+
lambda { @resource_xml = @resource.to_xml }.should_not(raise_exception)
|
138
137
|
end
|
139
138
|
end
|
140
139
|
end
|
141
140
|
|
142
|
-
context(
|
143
|
-
before(
|
141
|
+
context('which is valid') do
|
142
|
+
before(:each) do
|
144
143
|
@resource = RCAP::CAP_1_2::Resource.new do |resource|
|
145
144
|
resource.resource_desc = 'Resource Description'
|
146
145
|
resource.mime_type = 'text/csv'
|
147
146
|
end
|
148
|
-
@resource.should(
|
147
|
+
@resource.should(be_valid)
|
149
148
|
end
|
150
149
|
|
151
|
-
describe(
|
152
|
-
it(
|
150
|
+
describe('should not be valid if it') do
|
151
|
+
it('does not have a resource description (resource_desc)') do
|
153
152
|
@resource.resource_desc = nil
|
154
|
-
@resource.should_not(
|
153
|
+
@resource.should_not(be_valid)
|
155
154
|
end
|
156
155
|
|
157
|
-
it(
|
156
|
+
it('does not have a MIME type') do
|
158
157
|
@resource.mime_type = nil
|
159
|
-
@resource.should_not(
|
158
|
+
@resource.should_not(be_valid)
|
160
159
|
end
|
161
160
|
end
|
162
161
|
end
|
163
162
|
|
164
|
-
context(
|
165
|
-
before(
|
163
|
+
context('with a non-rereferenced URI') do
|
164
|
+
before(:each) do
|
166
165
|
@resource = RCAP::CAP_1_2::Resource.new do |resource|
|
167
|
-
|
168
|
-
|
169
|
-
|
166
|
+
resource.resource_desc = 'Resource Description'
|
167
|
+
resource.mime_type = 'text/csv'
|
168
|
+
resource.uri = 'http://tempuri.org/resource.csv'
|
170
169
|
end
|
171
170
|
@content = "1,2\n3,4"
|
172
|
-
@encoded_content = Base64.encode64(
|
173
|
-
|
171
|
+
@encoded_content = Base64.encode64(@content)
|
172
|
+
expect(URI).to receive(:parse) { StringIO.new(@content) }
|
174
173
|
end
|
175
174
|
|
176
|
-
describe(
|
177
|
-
it(
|
178
|
-
lambda{ @resource.dereference_uri! }.should(
|
175
|
+
describe('calling dereference_uri!') do
|
176
|
+
it('should fetch the content and store it in deref_uri as Base64 encoded content') do
|
177
|
+
lambda { @resource.dereference_uri! }.should(change(@resource, :deref_uri).to(@encoded_content))
|
179
178
|
end
|
180
179
|
|
181
|
-
it(
|
182
|
-
lambda{ @resource.dereference_uri! }.should(
|
180
|
+
it('should generate the correct SHA1 hash') do
|
181
|
+
lambda { @resource.dereference_uri! }.should(change(@resource, :digest).to(Digest::SHA1.hexdigest(@encoded_content)))
|
183
182
|
end
|
184
183
|
|
185
|
-
it(
|
186
|
-
lambda{ @resource.dereference_uri! }.should(
|
184
|
+
it('should set the size in bytes') do
|
185
|
+
lambda { @resource.dereference_uri! }.should(change(@resource, :size).to(@encoded_content.bytesize))
|
187
186
|
end
|
188
187
|
end
|
189
188
|
end
|
190
189
|
|
191
|
-
context(
|
192
|
-
before(
|
190
|
+
context('with a dereferenced URI') do
|
191
|
+
before(:each) do
|
193
192
|
@content = "1,2\n3,4"
|
194
|
-
@encoded_content = Base64.encode64(
|
193
|
+
@encoded_content = Base64.encode64(@content)
|
195
194
|
@resource = RCAP::CAP_1_2::Resource.new do |resource|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
195
|
+
resource.resource_desc = 'Resource Description'
|
196
|
+
resource.mime_type = 'text/csv'
|
197
|
+
resource.uri = 'http://tempuri.org/resource.csv'
|
198
|
+
resource.deref_uri = @encoded_content
|
200
199
|
end
|
201
200
|
end
|
202
201
|
|
203
|
-
describe(
|
204
|
-
it(
|
205
|
-
lambda{ @resource.calculate_hash_and_size }.should(
|
202
|
+
describe('#calculate_hash_and_size') do
|
203
|
+
it('should generate the correct SHA1 hash') do
|
204
|
+
lambda { @resource.calculate_hash_and_size }.should(change(@resource, :digest).to(Digest::SHA1.hexdigest(@encoded_content)))
|
206
205
|
end
|
207
206
|
|
208
|
-
it(
|
209
|
-
lambda{ @resource.calculate_hash_and_size }.should(
|
207
|
+
it('should set the size in bytes') do
|
208
|
+
lambda { @resource.calculate_hash_and_size }.should(change(@resource, :size).to(@encoded_content.bytesize))
|
210
209
|
end
|
211
210
|
end
|
212
211
|
|
213
|
-
describe(
|
214
|
-
it(
|
212
|
+
describe('#decoded_deref_uri') do
|
213
|
+
it('should return the original content') do
|
215
214
|
@resource.decoded_deref_uri.should == @content
|
216
215
|
end
|
217
216
|
end
|