rcap-rails-generators 1.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.
- data/CHANGELOG.rdoc +25 -0
- data/README.rdoc +248 -0
- data/lib/generators/rcap/migrations/migrations_generator.rb +38 -0
- data/lib/generators/rcap/migrations/templates/alerts_migration.rb +27 -0
- data/lib/generators/rcap/migrations/templates/areas_migration.rb +14 -0
- data/lib/generators/rcap/migrations/templates/infos_migration.rb +33 -0
- data/lib/generators/rcap/migrations/templates/resources_migration.rb +14 -0
- data/lib/generators/rcap/models/models_generator.rb +33 -0
- data/lib/generators/rcap/models/templates/models/alert.rb +365 -0
- data/lib/generators/rcap/models/templates/models/area.rb +156 -0
- data/lib/generators/rcap/models/templates/models/circle.rb +76 -0
- data/lib/generators/rcap/models/templates/models/event_code.rb +20 -0
- data/lib/generators/rcap/models/templates/models/geocode.rb +20 -0
- data/lib/generators/rcap/models/templates/models/info.rb +452 -0
- data/lib/generators/rcap/models/templates/models/parameter.rb +64 -0
- data/lib/generators/rcap/models/templates/models/point.rb +51 -0
- data/lib/generators/rcap/models/templates/models/polygon.rb +75 -0
- data/lib/generators/rcap/models/templates/models/resource.rb +143 -0
- data/lib/generators/rcap/models/templates/modules/rcap.rb +5 -0
- data/lib/generators/rcap/models/templates/modules/validations.rb +116 -0
- data/spec/alert_spec.rb +195 -0
- data/spec/area_spec.rb +179 -0
- data/spec/circle_spec.rb +88 -0
- data/spec/geocode_spec.rb +38 -0
- data/spec/info_spec.rb +270 -0
- data/spec/point_spec.rb +46 -0
- data/spec/polygon_spec.rb +68 -0
- data/spec/resource_spec.rb +156 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/utilities_spec.rb +57 -0
- data/spec/validations_spec.rb +95 -0
- metadata +155 -0
data/spec/alert_spec.rb
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::Alert ) do
|
4
|
+
context( 'on initialisation' ) do
|
5
|
+
before( :each ) do
|
6
|
+
@alert = RCAP::Alert.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it( 'should have a default identifier' ){ @alert.identifier.should_not( be_nil )}
|
10
|
+
it( 'should not have a sender' ){ @alert.sender.should( be_nil )}
|
11
|
+
it( 'should have a default sent time' ){ @alert.sent.should_not( be_nil )}
|
12
|
+
it( 'should not have a status' ){ @alert.status.should( be_nil )}
|
13
|
+
it( 'should not have a scope' ){ @alert.scope.should( be_nil )}
|
14
|
+
it( 'should not have a source'){ @alert.source.should( be_nil )}
|
15
|
+
it( 'should not have a restriction'){ @alert.restriction.should( be_nil )}
|
16
|
+
it( 'should not have any addresses' ){ @alert.addresses.should( be_empty )}
|
17
|
+
it( 'should not have a code' ){ @alert.code.should( be_nil )}
|
18
|
+
it( 'should not have a note' ){ @alert.note.should( be_nil )}
|
19
|
+
it( 'should not have any references' ){ @alert.references.should( be_empty )}
|
20
|
+
it( 'should not have any incidents' ){ @alert.incidents.should( be_empty )}
|
21
|
+
it( 'should not have any infos' ){ @alert.infos.should( be_empty )}
|
22
|
+
|
23
|
+
shared_examples_for( "a successfully parsed alert" ) do
|
24
|
+
it( 'should parse identifier correctly' ) { @alert.identifier.should == @original_alert.identifier }
|
25
|
+
it( 'should parse sender correctly' ) { @alert.sender.should == @original_alert.sender }
|
26
|
+
it( 'should parse sent correctly' ) { @alert.sent.should( be_close( @original_alert.sent, Rational( 1, 86400 )))}
|
27
|
+
it( 'should parse status correctly' ) { @alert.status.should == @original_alert.status }
|
28
|
+
it( 'should parse msg_type correctly' ) { @alert.msg_type.should == @original_alert.msg_type }
|
29
|
+
it( 'should parse source correctly' ) { @alert.source.should == @original_alert.source }
|
30
|
+
it( 'should parse scope correctly' ) { @alert.scope.should == @original_alert.scope }
|
31
|
+
it( 'should parse restriction correctly' ){ @alert.restriction.should == @original_alert.restriction }
|
32
|
+
it( 'should parse addresses correctly' ) { @alert.addresses.should == @original_alert.addresses }
|
33
|
+
it( 'should parse code correctly' ) { @alert.code.should == @original_alert.code }
|
34
|
+
it( 'should parse note correctly' ) { @alert.note.should == @original_alert.note }
|
35
|
+
it( 'should parse references correctly' ) { @alert.references.should == @original_alert.references }
|
36
|
+
it( 'should parse incidents correctly' ) { @alert.incidents.should == @original_alert.incidents }
|
37
|
+
it( 'should parse infos correctly' ) do
|
38
|
+
@alert.infos.size.should == @original_alert.infos.size
|
39
|
+
@alert.infos.each{ |info| info.class.should == RCAP::Info }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context( 'from XML' ) do
|
44
|
+
before( :each ) do
|
45
|
+
@original_alert = RCAP::Alert.new( :sender => 'Sender',
|
46
|
+
:status => RCAP::Alert::STATUS_TEST,
|
47
|
+
:scope => RCAP::Alert::SCOPE_PUBLIC,
|
48
|
+
:source => 'Source',
|
49
|
+
:restriction => 'No Restriction',
|
50
|
+
:addresses => [ 'Address 1', 'Address 2'],
|
51
|
+
:code => 'Code',
|
52
|
+
:note => 'Note',
|
53
|
+
:references => [ RCAP::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::Alert.new( :sender => 'Sender2' ).to_reference ],
|
54
|
+
:incidents => [ 'Incident1', 'Incident2' ],
|
55
|
+
:infos => [ RCAP::Info.new, RCAP::Info.new ])
|
56
|
+
@xml_string = @original_alert.to_xml
|
57
|
+
@xml_document = REXML::Document.new( @xml_string )
|
58
|
+
@alert_element = @xml_document.root
|
59
|
+
@alert = RCAP::Alert.from_xml_element( @alert_element )
|
60
|
+
end
|
61
|
+
|
62
|
+
it_should_behave_like( "a successfully parsed alert" )
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
context( 'from YAML' ) do
|
67
|
+
before( :each ) do
|
68
|
+
@original_alert = RCAP::Alert.new( :sender => 'Sender',
|
69
|
+
:status => RCAP::Alert::STATUS_TEST,
|
70
|
+
:scope => RCAP::Alert::SCOPE_PUBLIC,
|
71
|
+
:source => 'Source',
|
72
|
+
:restriction => 'No Restriction',
|
73
|
+
:addresses => [ 'Address 1', 'Address 2'],
|
74
|
+
:code => 'Code',
|
75
|
+
:note => 'Note',
|
76
|
+
:references => [ RCAP::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::Alert.new( :sender => 'Sender2' ).to_reference ],
|
77
|
+
:incidents => [ 'Incident1', 'Incident2' ],
|
78
|
+
:infos => [ RCAP::Info.new, RCAP::Info.new ])
|
79
|
+
@yaml_string = @original_alert.to_yaml
|
80
|
+
@alert = RCAP::Alert.from_yaml( @yaml_string )
|
81
|
+
end
|
82
|
+
|
83
|
+
it_should_behave_like( "a successfully parsed alert" )
|
84
|
+
end
|
85
|
+
|
86
|
+
context( 'from a hash' ) do
|
87
|
+
before( :each ) do
|
88
|
+
@original_alert = RCAP::Alert.new( :sender => 'Sender',
|
89
|
+
:status => RCAP::Alert::STATUS_TEST,
|
90
|
+
:scope => RCAP::Alert::SCOPE_PUBLIC,
|
91
|
+
:source => 'Source',
|
92
|
+
:restriction => 'No Restriction',
|
93
|
+
:addresses => [ 'Address 1', 'Address 2'],
|
94
|
+
:code => 'Code',
|
95
|
+
:note => 'Note',
|
96
|
+
:references => [ RCAP::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::Alert.new( :sender => 'Sender2' ).to_reference ],
|
97
|
+
:incidents => [ 'Incident1', 'Incident2' ],
|
98
|
+
:infos => [ RCAP::Info.new, RCAP::Info.new ])
|
99
|
+
@alert = RCAP::Alert.from_h( @original_alert.to_h )
|
100
|
+
end
|
101
|
+
|
102
|
+
it_should_behave_like( "a successfully parsed alert" )
|
103
|
+
end
|
104
|
+
|
105
|
+
context( 'from JSON' ) do
|
106
|
+
before( :each ) do
|
107
|
+
@original_alert = RCAP::Alert.new( :sender => 'Sender',
|
108
|
+
:status => RCAP::Alert::STATUS_TEST,
|
109
|
+
:scope => RCAP::Alert::SCOPE_PUBLIC,
|
110
|
+
:source => 'Source',
|
111
|
+
:restriction => 'No Restriction',
|
112
|
+
:addresses => [ 'Address 1', 'Address 2'],
|
113
|
+
:code => 'Code',
|
114
|
+
:note => 'Note',
|
115
|
+
:references => [ RCAP::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::Alert.new( :sender => 'Sender2' ).to_reference ],
|
116
|
+
:incidents => [ 'Incident1', 'Incident2' ],
|
117
|
+
:infos => [ RCAP::Info.new, RCAP::Info.new ])
|
118
|
+
@alert = RCAP::Alert.from_json( @original_alert.to_json )
|
119
|
+
end
|
120
|
+
|
121
|
+
it_should_behave_like( "a successfully parsed alert" )
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe( 'is not valid if it' ) do
|
126
|
+
before( :each ) do
|
127
|
+
@alert = RCAP::Alert.new( :sender => "cap@tempuri.org",
|
128
|
+
:status => RCAP::Alert::STATUS_TEST,
|
129
|
+
:msg_type => RCAP::Alert::MSG_TYPE_ALERT,
|
130
|
+
:scope => RCAP::Alert::SCOPE_PUBLIC )
|
131
|
+
@alert.should( be_valid )
|
132
|
+
end
|
133
|
+
|
134
|
+
it( 'does not have a identifier' ) do
|
135
|
+
@alert.identifier = nil
|
136
|
+
@alert.should_not( be_valid )
|
137
|
+
end
|
138
|
+
|
139
|
+
it( 'does not have a sender' ) do
|
140
|
+
@alert.sender = nil
|
141
|
+
@alert.should_not( be_valid )
|
142
|
+
end
|
143
|
+
|
144
|
+
it( 'does not have a sent time (sent)' ) do
|
145
|
+
@alert.sent = nil
|
146
|
+
@alert.should_not( be_valid )
|
147
|
+
end
|
148
|
+
|
149
|
+
it( 'does not have a status' ) do
|
150
|
+
@alert.status = nil
|
151
|
+
@alert.should_not( be_valid )
|
152
|
+
end
|
153
|
+
|
154
|
+
it( 'does not have a message type (msg_type)' ) do
|
155
|
+
@alert.msg_type = nil
|
156
|
+
@alert.should_not( be_valid )
|
157
|
+
end
|
158
|
+
|
159
|
+
it( 'does not have a scope' ) do
|
160
|
+
@alert.scope = nil
|
161
|
+
@alert.should_not( be_valid )
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
it( 'does not have a valid status' ) do
|
166
|
+
@alert.status = 'incorrect value'
|
167
|
+
@alert.should_not( be_valid )
|
168
|
+
end
|
169
|
+
|
170
|
+
it( 'does not have a valid message type msg_type' ) do
|
171
|
+
@alert.msg_type = 'incorrect value'
|
172
|
+
@alert.should_not( be_valid )
|
173
|
+
end
|
174
|
+
|
175
|
+
it( 'does not have a valid scope' ) do
|
176
|
+
@alert.scope = 'incorrect value'
|
177
|
+
@alert.should_not( be_valid )
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
context( 'has an info element and it' ) do
|
182
|
+
it( 'is not valid' ) do
|
183
|
+
@info = RCAP::Info.new( :event => 'Info Event',
|
184
|
+
:categories => RCAP::Info::CATEGORY_GEO,
|
185
|
+
:urgency => RCAP::Info::URGENCY_IMMEDIATE,
|
186
|
+
:severity => RCAP::Info::SEVERITY_EXTREME,
|
187
|
+
:certainty => RCAP::Info::CERTAINTY_OBSERVED )
|
188
|
+
@info.event = nil
|
189
|
+
@alert.infos << @info
|
190
|
+
@info.should_not( be_valid )
|
191
|
+
@alert.should_not( be_valid )
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
data/spec/area_spec.rb
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::Area ) do
|
4
|
+
context( 'on initialisation' ) do
|
5
|
+
before( :each ) do
|
6
|
+
@area = RCAP::Area.new
|
7
|
+
end
|
8
|
+
|
9
|
+
# Atomic
|
10
|
+
it( 'should not have a area_desc' ){ @area.area_desc.should( be_nil )}
|
11
|
+
it( 'should not have a altitude' ){ @area.altitude.should( be_nil )}
|
12
|
+
it( 'should not have a ceiling' ){ @area.ceiling.should( be_nil )}
|
13
|
+
|
14
|
+
# Group
|
15
|
+
it( 'should have an empty polygons' ){ @area.polygons.should( be_empty )}
|
16
|
+
it( 'should have an empty circles' ){ @area.circles.should( be_empty )}
|
17
|
+
it( 'should have an empty geocodes' ){ @area.geocodes.should( be_empty )}
|
18
|
+
|
19
|
+
shared_examples_for( "it can parse into an Area object" ) do
|
20
|
+
it( 'should parse the area_desc correctly' ) do
|
21
|
+
@area.area_desc.should == @original_area.area_desc
|
22
|
+
end
|
23
|
+
|
24
|
+
it( 'should parse the altitude correctly' ) do
|
25
|
+
@area.altitude.should == @original_area.altitude
|
26
|
+
end
|
27
|
+
|
28
|
+
it( 'should parse the ceiling correctly' ) do
|
29
|
+
@area.ceiling.should == @original_area.ceiling
|
30
|
+
end
|
31
|
+
|
32
|
+
it( 'should parse the circles correctly' ) do
|
33
|
+
@area.circles.should == @original_area.circles
|
34
|
+
end
|
35
|
+
|
36
|
+
it( 'should parse the geocodes correctly' ) do
|
37
|
+
@area.geocodes.should == @original_area.geocodes
|
38
|
+
end
|
39
|
+
|
40
|
+
it( 'should parse the polygons correctly' ) do
|
41
|
+
@area.polygons.should == @original_area.polygons
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context( 'from XML' ) do
|
46
|
+
before( :each ) do
|
47
|
+
@original_area = RCAP::Area.new( :area_desc => 'Area Description',
|
48
|
+
:altitude => 100,
|
49
|
+
:ceiling => 200,
|
50
|
+
:circles => RCAP::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
|
51
|
+
:geocodes => RCAP::Geocode.new( :name => 'name', :value => 'value' ),
|
52
|
+
:polygons => RCAP::Polygon.new( :points => RCAP::Point.new( :lattitude =>1, :longitude => 1 )))
|
53
|
+
|
54
|
+
@alert = RCAP::Alert.new( :infos => RCAP::Info.new( :areas => @original_area ))
|
55
|
+
@xml_string = @alert.to_xml
|
56
|
+
@xml_document = REXML::Document.new( @xml_string )
|
57
|
+
@info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::Info::XPATH )
|
58
|
+
@area_xml_element = RCAP.xpath_first( @info_xml_element, RCAP::Area::XPATH )
|
59
|
+
@area = RCAP::Area.from_xml_element( @area_xml_element )
|
60
|
+
end
|
61
|
+
|
62
|
+
it_should_behave_like( "it can parse into an Area object" )
|
63
|
+
end
|
64
|
+
|
65
|
+
context( 'from a hash' ) do
|
66
|
+
before( :each ) do
|
67
|
+
@original_area = RCAP::Area.new( :area_desc => 'Area Description',
|
68
|
+
:altitude => 100,
|
69
|
+
:ceiling => 200,
|
70
|
+
:circles => RCAP::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
|
71
|
+
:geocodes => RCAP::Geocode.new( :name => 'name', :value => 'value' ),
|
72
|
+
:polygons => RCAP::Polygon.new( :points => RCAP::Point.new( :lattitude =>1, :longitude => 1 )))
|
73
|
+
|
74
|
+
@area = RCAP::Area.from_h( @original_area.to_h )
|
75
|
+
end
|
76
|
+
|
77
|
+
it_should_behave_like( "it can parse into an Area object" )
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context( 'when exported' ) do
|
82
|
+
before( :each ) do
|
83
|
+
@area = RCAP::Area.new( :area_desc => 'Area Description',
|
84
|
+
:altitude => 100,
|
85
|
+
:ceiling => 200,
|
86
|
+
:circles => RCAP::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
|
87
|
+
:geocodes => RCAP::Geocode.new( :name => 'name', :value => 'value' ),
|
88
|
+
:polygons => RCAP::Polygon.new( :points => RCAP::Point.new( :lattitude =>1, :longitude => 1 )))
|
89
|
+
end
|
90
|
+
context( 'to a hash' ) do
|
91
|
+
before( :each ) do
|
92
|
+
@area_hash = @area.to_h
|
93
|
+
end
|
94
|
+
|
95
|
+
it( 'should export the area description correctly' ) do
|
96
|
+
@area_hash[ RCAP::Area::AREA_DESC_KEY ].should == @area.area_desc
|
97
|
+
end
|
98
|
+
|
99
|
+
it( 'should export the altitude correctly' ) do
|
100
|
+
@area_hash[ RCAP::Area::ALTITUDE_KEY ].should == @area.altitude
|
101
|
+
end
|
102
|
+
|
103
|
+
it( 'should set the ceiling correctly' ) do
|
104
|
+
@area_hash[ RCAP::Area::CEILING_KEY ].should == @area.ceiling
|
105
|
+
end
|
106
|
+
|
107
|
+
it( 'should export the circles correctly' ) do
|
108
|
+
@area_hash[ RCAP::Area::CIRCLES_KEY ].should == @area.circles.map{ |circle| circle.to_h }
|
109
|
+
end
|
110
|
+
|
111
|
+
it( 'should export the geocodes correctly' ) do
|
112
|
+
@area_hash[ RCAP::Area::GEOCODES_KEY ].should == @area.geocodes.map{ |geocode| geocode.to_h }
|
113
|
+
end
|
114
|
+
|
115
|
+
it( 'should export the polygons correctly' ) do
|
116
|
+
@area_hash[ RCAP::Area::POLYGONS_KEY ].should == @area.polygons.map{ |polygon| polygon.to_h }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context( 'is not valid if' ) do
|
122
|
+
before( :each ) do
|
123
|
+
@area = RCAP::Area.new( :area_desc => "Cape Town Metropole" )
|
124
|
+
@area.should( be_valid )
|
125
|
+
end
|
126
|
+
|
127
|
+
it( 'does not have an area descrtiption (area_desc)') do
|
128
|
+
@area.area_desc = nil
|
129
|
+
@area.should_not( be_valid )
|
130
|
+
end
|
131
|
+
|
132
|
+
it( 'has a ceiling defined but no altitude' ) do
|
133
|
+
@area.ceiling = 1
|
134
|
+
@area.altitude = nil
|
135
|
+
@area.should_not( be_valid )
|
136
|
+
end
|
137
|
+
|
138
|
+
context( 'it contains circles and it' ) do
|
139
|
+
before( :each ) do
|
140
|
+
@area.circles << RCAP::Circle.new( :lattitude => 0, :longitude => 0, :radius => 1)
|
141
|
+
@area.should( be_valid )
|
142
|
+
end
|
143
|
+
|
144
|
+
it( 'has an invalid circle' ) do
|
145
|
+
@area.circles.first.lattitude = nil
|
146
|
+
@area.should_not( be_valid )
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context( 'it contains polygons and it' ) do
|
151
|
+
before( :each ) do
|
152
|
+
@polygon = RCAP::Polygon.new
|
153
|
+
@polygon.points.push( RCAP::Point.new( :lattitude => 0, :longitude => 0 ),
|
154
|
+
RCAP::Point.new( :lattitude => 0, :longitude => 1 ),
|
155
|
+
RCAP::Point.new( :lattitude => 1, :longitude => 0 ))
|
156
|
+
@area.polygons << @polygon
|
157
|
+
@area.should( be_valid )
|
158
|
+
end
|
159
|
+
|
160
|
+
it( 'has an invalid polygon' ) do
|
161
|
+
@polygon.points.first.lattitude = nil
|
162
|
+
@area.should_not( be_valid )
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context( 'it contains geocodes and it' ) do
|
167
|
+
before( :each ) do
|
168
|
+
@geocode = RCAP::Geocode.new( :name => 'foo', :value => 'bar' )
|
169
|
+
@area.geocodes << @geocode
|
170
|
+
@area.should( be_valid )
|
171
|
+
end
|
172
|
+
|
173
|
+
it( 'has an invalid geocode' ) do
|
174
|
+
@geocode.value = nil
|
175
|
+
@area.should_not( be_valid )
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
data/spec/circle_spec.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::Circle ) do
|
4
|
+
describe( 'should not be valid if' ) do
|
5
|
+
before( :each ) do
|
6
|
+
@circle = RCAP::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 1 )
|
7
|
+
@circle.should( be_valid )
|
8
|
+
end
|
9
|
+
|
10
|
+
it( 'does not have a lattitude defined' ) do
|
11
|
+
@circle.lattitude = nil
|
12
|
+
@circle.should_not( be_valid )
|
13
|
+
end
|
14
|
+
|
15
|
+
it( 'does not have a longitude defined' ) do
|
16
|
+
@circle.longitude = nil
|
17
|
+
@circle.should_not( be_valid )
|
18
|
+
end
|
19
|
+
|
20
|
+
it( 'does not have a radius defined' ) do
|
21
|
+
@circle.radius = nil
|
22
|
+
@circle.should_not( be_valid )
|
23
|
+
end
|
24
|
+
|
25
|
+
it( 'does not have a numeric radius' ) do
|
26
|
+
@circle.radius = "not a number"
|
27
|
+
@circle.should_not( be_valid )
|
28
|
+
end
|
29
|
+
|
30
|
+
it( 'does not have a positive radius' ) do
|
31
|
+
@circle.radius = -1
|
32
|
+
@circle.should_not( be_valid )
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context( 'on initialisation' ) do
|
37
|
+
context( 'from XML' ) do
|
38
|
+
before( :each ) do
|
39
|
+
@original_circle = RCAP::Circle.new( :radius => 10.5,
|
40
|
+
:lattitude => 30, :longitude => 60 )
|
41
|
+
@alert = RCAP::Alert.new( :infos => RCAP::Info.new( :areas => RCAP::Area.new( :circles => @original_circle )))
|
42
|
+
@xml_string = @alert.to_xml
|
43
|
+
@xml_document = REXML::Document.new( @xml_string )
|
44
|
+
@info_element = RCAP.xpath_first( @xml_document.root, RCAP::Info::XPATH )
|
45
|
+
@area_element = RCAP.xpath_first( @info_element, RCAP::Area::XPATH )
|
46
|
+
@circle_element = RCAP.xpath_first( @area_element, RCAP::Circle::XPATH )
|
47
|
+
@circle = RCAP::Circle.from_xml_element( @circle_element )
|
48
|
+
end
|
49
|
+
|
50
|
+
it( 'should parse the radius correctly' ) do
|
51
|
+
@circle.radius.should == @original_circle.radius
|
52
|
+
end
|
53
|
+
|
54
|
+
it( 'should parse the lattitude and longitude correctly' ) do
|
55
|
+
@circle.lattitude.should == @original_circle.lattitude
|
56
|
+
@circle.longitude.should == @original_circle.longitude
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context( 'from a hash' ) do
|
61
|
+
before( :each ) do
|
62
|
+
@original_circle = RCAP::Circle.new( :radius => 10.5, :lattitude => 30, :longitude => 60 )
|
63
|
+
@circle = RCAP::Circle.from_h( @original_circle.to_h )
|
64
|
+
end
|
65
|
+
|
66
|
+
it( 'should set the radius correctly' ) do
|
67
|
+
@circle.radius.should == @original_circle.radius
|
68
|
+
end
|
69
|
+
|
70
|
+
it( 'should parse the lattitude and longitude correctly' ) do
|
71
|
+
@circle.lattitude.should == @original_circle.lattitude
|
72
|
+
@circle.longitude.should == @original_circle.longitude
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context( 'when exported' ) do
|
78
|
+
before( :each ) do
|
79
|
+
@circle = RCAP::Circle.new( :radius => 10.5, :lattitude => 30, :longitude => 60 )
|
80
|
+
end
|
81
|
+
|
82
|
+
context( 'to hash' ) do
|
83
|
+
it( 'should be correct' ) do
|
84
|
+
@circle.to_h.should == { 'radius' => 10.5, 'lattitude' => 30, 'longitude' => 60 }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|