rcap 2.4.1 → 2.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +5 -5
  2. data/.ruby-version +1 -0
  3. data/CHANGELOG.md +18 -0
  4. data/README.md +1 -0
  5. data/lib/rcap.rb +3 -1
  6. data/lib/rcap/alert.rb +30 -29
  7. data/lib/rcap/base/alert.rb +208 -205
  8. data/lib/rcap/base/area.rb +95 -91
  9. data/lib/rcap/base/circle.rb +45 -34
  10. data/lib/rcap/base/event_code.rb +2 -0
  11. data/lib/rcap/base/geocode.rb +2 -0
  12. data/lib/rcap/base/info.rb +273 -272
  13. data/lib/rcap/base/parameter.rb +29 -28
  14. data/lib/rcap/base/point.rb +26 -24
  15. data/lib/rcap/base/polygon.rb +43 -35
  16. data/lib/rcap/base/resource.rb +65 -65
  17. data/lib/rcap/cap_1_0/alert.rb +85 -86
  18. data/lib/rcap/cap_1_0/area.rb +2 -2
  19. data/lib/rcap/cap_1_0/circle.rb +2 -1
  20. data/lib/rcap/cap_1_0/event_code.rb +3 -1
  21. data/lib/rcap/cap_1_0/geocode.rb +3 -1
  22. data/lib/rcap/cap_1_0/info.rb +3 -3
  23. data/lib/rcap/cap_1_0/parameter.rb +13 -13
  24. data/lib/rcap/cap_1_0/point.rb +2 -1
  25. data/lib/rcap/cap_1_0/polygon.rb +3 -3
  26. data/lib/rcap/cap_1_0/resource.rb +2 -3
  27. data/lib/rcap/cap_1_1/alert.rb +6 -6
  28. data/lib/rcap/cap_1_1/area.rb +2 -2
  29. data/lib/rcap/cap_1_1/circle.rb +2 -1
  30. data/lib/rcap/cap_1_1/event_code.rb +3 -1
  31. data/lib/rcap/cap_1_1/geocode.rb +3 -1
  32. data/lib/rcap/cap_1_1/info.rb +125 -132
  33. data/lib/rcap/cap_1_1/parameter.rb +2 -3
  34. data/lib/rcap/cap_1_1/point.rb +2 -1
  35. data/lib/rcap/cap_1_1/polygon.rb +3 -3
  36. data/lib/rcap/cap_1_1/resource.rb +37 -38
  37. data/lib/rcap/cap_1_2/alert.rb +6 -6
  38. data/lib/rcap/cap_1_2/area.rb +2 -2
  39. data/lib/rcap/cap_1_2/circle.rb +2 -1
  40. data/lib/rcap/cap_1_2/event_code.rb +3 -1
  41. data/lib/rcap/cap_1_2/geocode.rb +3 -1
  42. data/lib/rcap/cap_1_2/info.rb +120 -123
  43. data/lib/rcap/cap_1_2/parameter.rb +2 -3
  44. data/lib/rcap/cap_1_2/point.rb +2 -1
  45. data/lib/rcap/cap_1_2/polygon.rb +4 -4
  46. data/lib/rcap/cap_1_2/resource.rb +38 -38
  47. data/lib/rcap/config.rb +5 -3
  48. data/lib/rcap/custom_validators.rb +75 -78
  49. data/lib/rcap/extensions/array.rb +3 -1
  50. data/lib/rcap/extensions/date.rb +3 -1
  51. data/lib/rcap/extensions/date_time.rb +5 -2
  52. data/lib/rcap/extensions/float.rb +2 -0
  53. data/lib/rcap/extensions/integer.rb +7 -0
  54. data/lib/rcap/extensions/nil_class.rb +2 -0
  55. data/lib/rcap/extensions/string.rb +6 -4
  56. data/lib/rcap/extensions/time.rb +5 -3
  57. data/lib/rcap/formatters/yaml.rb +5 -0
  58. data/lib/rcap/info.rb +6 -5
  59. data/lib/rcap/utilities.rb +27 -30
  60. data/lib/rcap/validation.rb +22 -21
  61. data/lib/rcap/version.rb +3 -1
  62. data/rcap.gemspec +5 -5
  63. data/spec/alert_spec.rb +141 -141
  64. data/spec/cap_1_0/alert_spec.rb +92 -94
  65. data/spec/cap_1_0/area_spec.rb +86 -86
  66. data/spec/cap_1_0/circle_spec.rb +48 -39
  67. data/spec/cap_1_0/event_code_spec.rb +15 -15
  68. data/spec/cap_1_0/geocode_spec.rb +16 -16
  69. data/spec/cap_1_0/info_spec.rb +175 -177
  70. data/spec/cap_1_0/parameter_spec.rb +27 -27
  71. data/spec/cap_1_0/point_spec.rb +18 -18
  72. data/spec/cap_1_0/polygon_spec.rb +43 -41
  73. data/spec/cap_1_0/resource_spec.rb +63 -64
  74. data/spec/cap_1_1/alert_spec.rb +107 -109
  75. data/spec/cap_1_1/area_spec.rb +90 -90
  76. data/spec/cap_1_1/circle_spec.rb +43 -34
  77. data/spec/cap_1_1/event_code_spec.rb +15 -16
  78. data/spec/cap_1_1/geocode_spec.rb +16 -16
  79. data/spec/cap_1_1/info_spec.rb +194 -196
  80. data/spec/cap_1_1/parameter_spec.rb +17 -17
  81. data/spec/cap_1_1/point_spec.rb +18 -18
  82. data/spec/cap_1_1/polygon_spec.rb +43 -41
  83. data/spec/cap_1_1/resource_spec.rb +106 -107
  84. data/spec/cap_1_2/alert_spec.rb +98 -99
  85. data/spec/cap_1_2/area_spec.rb +90 -90
  86. data/spec/cap_1_2/circle_spec.rb +52 -43
  87. data/spec/cap_1_2/event_code_spec.rb +19 -20
  88. data/spec/cap_1_2/geocode_spec.rb +20 -20
  89. data/spec/cap_1_2/info_spec.rb +196 -198
  90. data/spec/cap_1_2/parameter_spec.rb +19 -19
  91. data/spec/cap_1_2/point_spec.rb +21 -21
  92. data/spec/cap_1_2/polygon_spec.rb +55 -47
  93. data/spec/cap_1_2/resource_spec.rb +96 -97
  94. data/spec/extensions_spec.rb +29 -29
  95. data/spec/info_spec.rb +15 -15
  96. data/spec/spec_helper.rb +3 -3
  97. data/spec/validations_spec.rb +73 -73
  98. metadata +12 -11
  99. data/lib/rcap/extensions/fixnum.rb +0 -5
@@ -1,47 +1,47 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe( RCAP::CAP_1_2::Parameter ) do
4
- before( :each ) do
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( 'when initialised' ) do
12
- context( 'from XML' ) do
13
- before( :each ) do
14
- @original_parameter = RCAP::CAP_1_2::Parameter.new( &@parameter_builder )
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( &@parameter_builder )
16
+ @alert.add_info.add_parameter(&@parameter_builder)
17
17
  @xml_string = @alert.to_xml
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 )
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( 'should parse into the correct class' ) do
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( 'should parse the name correctly' ) do
28
+ it('should parse the name correctly') do
29
29
  @parameter.name.should == @original_parameter.name
30
30
  end
31
31
 
32
- it( 'should parse the value correctly' ) do
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( 'when exported' ) do
39
- before( :each ) do
40
- @parameter = RCAP::CAP_1_2::Parameter.new( &@parameter_builder )
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( 'to a hash' ) do
44
- it( 'should export correctly' ) do
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
@@ -1,51 +1,51 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe( RCAP::CAP_1_2::Point ) do
4
- before( :each ) do
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( 'is not valid if' ) do
12
- before( :each ) do
13
- @point = RCAP::CAP_1_2::Point.new( &@point_constructor )
14
- @point.should( be_valid )
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( 'does not have a longitude defined' ) do
17
+ it('does not have a longitude defined') do
18
18
  @point.longitude = nil
19
- @point.should_not( be_valid )
19
+ @point.should_not(be_valid)
20
20
  end
21
21
 
22
- it( 'does not have a valid longitude' ) do
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( be_valid )
24
+ @point.should_not(be_valid)
25
25
  @point.longitude = RCAP::CAP_1_2::Point::MIN_LONGITUDE - 1
26
- @point.should_not( be_valid )
26
+ @point.should_not(be_valid)
27
27
  end
28
28
 
29
- it( 'does not have a lattitude defined' ) do
29
+ it('does not have a lattitude defined') do
30
30
  @point.lattitude = nil
31
- @point.should_not( be_valid )
31
+ @point.should_not(be_valid)
32
32
  end
33
33
 
34
- it( 'does not have a valid lattitude' ) do
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( be_valid )
36
+ @point.should_not(be_valid)
37
37
  @point.lattitude = RCAP::CAP_1_2::Point::MIN_LATTITUDE - 1
38
- @point.should_not( be_valid )
38
+ @point.should_not(be_valid)
39
39
  end
40
40
  end
41
41
 
42
- context( 'when exported' ) do
43
- before( :each ) do
44
- @point = RCAP::CAP_1_2::Point.new( &@point_constructor )
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( 'to hash' ) do
48
- it( 'should export correctly' ) do
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( RCAP::CAP_1_2::Polygon ) do
4
- before( :each ) do
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( '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 )
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( 'hass less than 4 points' ) do
21
+ it('hass less than 4 points') do
22
22
  @polygon.points.pop
23
- @polygon.should_not( be_valid )
23
+ @polygon.should_not(be_valid)
24
24
  end
25
25
 
26
- it( 'does not have the first and last points equal' ) do
26
+ it('does not have the first and last points equal') do
27
27
  @polygon.points.last.lattitude = 1
28
- @polygon.should_not( be_valid )
28
+ @polygon.should_not(be_valid)
29
29
  end
30
30
 
31
- it( 'does not have a valid collection of points' ) do
31
+ it('does not have a valid collection of points') do
32
32
  @polygon.points.first.lattitude = nil
33
- @polygon.should_not( be_valid )
33
+ @polygon.should_not(be_valid)
34
34
  end
35
35
  end
36
36
 
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()
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( &@polygon_builder )
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( @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 )
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( 'should parse all the points' ) do
56
- @polygon.points.zip( @original_polygon.points ).each do |point, original_point|
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( @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 )
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( 'from a hash' ) do
70
- before( :each ) do
71
- @polygon = RCAP::CAP_1_2::Polygon.new( &@polygon_builder )
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( 'should load all the points' ) do
75
- @new_polygon = RCAP::CAP_1_2::Polygon.from_h( @polygon.to_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( 'when exported' ) do
82
- before( :each ) do
83
- @polygon = RCAP::CAP_1_2::Polygon.new( &@polygon_builder )
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( 'to a hash' ) do
87
- it( 'should export correctly' ) do
88
- @polygon.to_h.should == { RCAP::CAP_1_2::Polygon::POINTS_KEY => @polygon.points.map{ |point| point.to_a }}
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( 'instance methods' ) do
94
- before( :each ) do
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( '#add_point' ) do
99
- before( :each ) do
106
+ describe('#add_point') do
107
+ before(:each) do
100
108
  @point = @polygon.add_point do |point|
101
- point.lattitude = 1
102
- point.longitude = 1
109
+ point.lattitude = 1
110
+ point.longitude = 1
103
111
  end
104
112
  end
105
113
 
106
- it( 'should return a 1.2 Point' ) do
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( 'should add a Point to the points attribute' ) do
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( RCAP::CAP_1_2::Resource ) do
4
- before( :each ) do
3
+ describe(RCAP::CAP_1_2::Resource) do
4
+ before(:each) do
5
5
  @resource_builder = lambda do |resource|
6
- resource.resource_desc = "Image of incident"
7
- resource.uri = "http://capetown.gov.za/cap/resources/image.png"
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 = "IMAGE DATA"
10
- resource.size = 20480
11
- resource.digest = "2048"
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( 'on initialisation' ) do
16
- before( :each ) do
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( '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 )}
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( 'from XML' ) do
28
- before( :each ) do
29
- @original_resource = RCAP::CAP_1_2::Resource.new( &@resource_builder )
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( &@resource_builder )
32
+ @alert.add_info.add_resource(&@resource_builder)
33
33
  @xml_string = @alert.to_xml
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 )
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( 'should parse resource_desc correctly' ) do
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( 'should parse uri correctly' ) do
45
+ it('should parse uri correctly') do
46
46
  @resource.uri.should == @original_resource.uri
47
47
  end
48
48
 
49
- it( 'should parse mime_type correctly' ) do
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( 'should parse deref_uri correctly' ) do
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( 'should parse size correctly' ) do
57
+ it('should parse size correctly') do
58
58
  @resource.size.should == @original_resource.size
59
59
  end
60
60
 
61
- it( 'should parse digest correctly' ) do
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
- context( 'from a hash' ) do
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( 'should parse resource_desc correctly' ) do
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( 'should parse uri correctly' ) do
77
+ it('should parse uri correctly') do
79
78
  @resource.uri.should == @original_resource.uri
80
79
  end
81
80
 
82
- it( 'should parse mime_type correctly' ) do
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( 'should parse deref_uri correctly' ) do
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( 'should parse size correctly' ) do
89
+ it('should parse size correctly') do
91
90
  @resource.size.should == @original_resource.size
92
91
  end
93
92
 
94
- it( 'should parse digest correctly' ) do
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( 'when exported' ) do
101
- before( :each ) do
102
- @resource = RCAP::CAP_1_2::Resource.new( &@resource_builder )
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( 'to a hash' ) do
106
- before( :each ) do
104
+ context('to a hash') do
105
+ before(:each) do
107
106
  @resource_hash = @resource.to_h
108
107
  end
109
108
 
110
- it( 'should set the resource description' ) do
111
- @resource_hash[ RCAP::CAP_1_2::Resource::RESOURCE_DESC_KEY ].should == @resource.resource_desc
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( 'should set the mime type' ) do
115
- @resource_hash[ RCAP::CAP_1_2::Resource::MIME_TYPE_KEY ].should == @resource.mime_type
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( 'should set the size' ) do
119
- @resource_hash[ RCAP::CAP_1_2::Resource::SIZE_KEY ].should == @resource.size
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( 'should set the URI' ) do
123
- @resource_hash[ RCAP::CAP_1_2::Resource::URI_KEY ].should == @resource.uri
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( 'should set the dereferenced URI' ) do
127
- @resource_hash[ RCAP::CAP_1_2::Resource::DEREF_URI_KEY ].should == @resource.deref_uri
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( 'should set the digest' ) do
131
- @resource_hash[ RCAP::CAP_1_2::Resource::DIGEST_KEY ].should == @resource.digest
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( 'to xml' ) do
136
- it( 'should be successful' ) do
137
- lambda{ @resource_xml = @resource.to_xml }.should_not( raise_exception )
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( 'which is valid' ) do
143
- before( :each ) do
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( be_valid )
147
+ @resource.should(be_valid)
149
148
  end
150
149
 
151
- describe( 'should not be valid if it' ) do
152
- it( 'does not have a resource description (resource_desc)' ) do
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( be_valid )
153
+ @resource.should_not(be_valid)
155
154
  end
156
155
 
157
- it( 'does not have a MIME type' ) do
156
+ it('does not have a MIME type') do
158
157
  @resource.mime_type = nil
159
- @resource.should_not( be_valid )
158
+ @resource.should_not(be_valid)
160
159
  end
161
160
  end
162
161
  end
163
162
 
164
- context( 'with a non-rereferenced URI' ) do
165
- before( :each ) do
163
+ context('with a non-rereferenced URI') do
164
+ before(:each) do
166
165
  @resource = RCAP::CAP_1_2::Resource.new do |resource|
167
- resource.resource_desc = 'Resource Description'
168
- resource.mime_type = 'text/csv'
169
- resource.uri = 'http://tempuri.org/resource.csv'
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( @content )
173
- stub_request( :get, @resource.uri ).to_return( :status => 200, :body => @content )
171
+ @encoded_content = Base64.encode64(@content)
172
+ expect(URI).to receive(:parse) { StringIO.new(@content) }
174
173
  end
175
174
 
176
- describe( 'calling dereference_uri!' ) do
177
- it( 'should fetch the content and store it in deref_uri as Base64 encoded content' ) do
178
- lambda{ @resource.dereference_uri! }.should( change( @resource, :deref_uri ).to( @encoded_content ))
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( 'should generate the correct SHA1 hash' ) do
182
- lambda{ @resource.dereference_uri! }.should( change( @resource, :digest ).to( Digest::SHA1.hexdigest( @encoded_content )))
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( 'should set the size in bytes' ) do
186
- lambda{ @resource.dereference_uri! }.should( change( @resource, :size ).to( @encoded_content.bytesize ))
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( 'with a dereferenced URI' ) do
192
- before( :each ) do
190
+ context('with a dereferenced URI') do
191
+ before(:each) do
193
192
  @content = "1,2\n3,4"
194
- @encoded_content = Base64.encode64( @content )
193
+ @encoded_content = Base64.encode64(@content)
195
194
  @resource = RCAP::CAP_1_2::Resource.new do |resource|
196
- resource.resource_desc = 'Resource Description'
197
- resource.mime_type = 'text/csv'
198
- resource.uri = 'http://tempuri.org/resource.csv'
199
- resource.deref_uri = @encoded_content
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( '#calculate_hash_and_size' ) do
204
- it( 'should generate the correct SHA1 hash' ) do
205
- lambda{ @resource.calculate_hash_and_size }.should( change( @resource, :digest ).to( Digest::SHA1.hexdigest( @encoded_content )))
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( 'should set the size in bytes' ) do
209
- lambda{ @resource.calculate_hash_and_size }.should( change( @resource, :size ).to( @encoded_content.bytesize ))
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( '#decoded_deref_uri' ) do
214
- it( 'should return the original content' ) do
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