rcap-rails-generators 1.3
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::Geocode ) do
|
4
|
+
context( 'when initialised' ) do
|
5
|
+
context( 'from XML' ) do
|
6
|
+
before( :each ) do
|
7
|
+
@original_geocode = RCAP::Geocode.new( :name => 'name', :value => 'value' )
|
8
|
+
@alert = RCAP::Alert.new( :infos => RCAP::Info.new( :areas => RCAP::Area.new( :geocodes => @original_geocode )))
|
9
|
+
@xml_string = @alert.to_xml
|
10
|
+
@xml_document = REXML::Document.new( @xml_string )
|
11
|
+
@info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::Info::XPATH )
|
12
|
+
@area_xml_element = RCAP.xpath_first( @info_xml_element, RCAP::Area::XPATH )
|
13
|
+
@geocode_xml_element = RCAP.xpath_first( @area_xml_element, RCAP::Geocode::XPATH )
|
14
|
+
@geocode = RCAP::Geocode.from_xml_element( @geocode_xml_element )
|
15
|
+
end
|
16
|
+
|
17
|
+
it( 'should parse the name correctly' ) do
|
18
|
+
@geocode.name.should == @original_geocode.name
|
19
|
+
end
|
20
|
+
|
21
|
+
it( 'should parse the value correctly' ) do
|
22
|
+
@geocode.value.should == @original_geocode.value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context( 'when exported' ) do
|
28
|
+
before( :each ) do
|
29
|
+
@geocode = RCAP::Geocode.new( :name => 'name', :value => 'value' )
|
30
|
+
end
|
31
|
+
|
32
|
+
context( 'to a hash' ) do
|
33
|
+
it( 'should export correctly' ) do
|
34
|
+
@geocode.to_h.should == { 'name' => 'value' }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/info_spec.rb
ADDED
@@ -0,0 +1,270 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::Info ) do
|
4
|
+
context( 'on initialisation' ) do
|
5
|
+
before( :each ) do
|
6
|
+
@info = RCAP::Info.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it( 'should have a default language of en-US' ) { @info.language.should == 'en-US' }
|
10
|
+
it( 'should have no categories' ) { @info.categories.should( be_empty )}
|
11
|
+
it( 'should have no event' ) { @info.event.should( be_nil )}
|
12
|
+
it( 'should have no response types' ) { @info.response_types.should( be_empty )}
|
13
|
+
it( 'should have no urgency' ) { @info.urgency.should( be_nil )}
|
14
|
+
it( 'should have no severity' ) { @info.severity.should( be_nil )}
|
15
|
+
it( 'should have no certainty' ) { @info.certainty.should( be_nil )}
|
16
|
+
it( 'should have no audience' ) { @info.audience.should( be_nil )}
|
17
|
+
it( 'should have no event_codes' ) { @info.event_codes.should( be_empty )}
|
18
|
+
it( 'should have no effective datetime' ) { @info.effective.should( be_nil )}
|
19
|
+
it( 'should have no onset datetime' ) { @info.onset.should( be_nil )}
|
20
|
+
it( 'should have no expires datetime' ) { @info.expires.should( be_nil )}
|
21
|
+
it( 'should have no sender name ' ) { @info.sender_name.should( be_nil )}
|
22
|
+
it( 'should have no headline' ) { @info.headline.should( be_nil )}
|
23
|
+
it( 'should have no description' ) { @info.description.should( be_nil )}
|
24
|
+
it( 'should have no instruction' ) { @info.instruction.should( be_nil )}
|
25
|
+
it( 'should have no web' ) { @info.web.should( be_nil )}
|
26
|
+
it( 'should have no contact' ) { @info.contact.should( be_nil )}
|
27
|
+
it( 'should have no parameters' ) { @info.parameters.should( be_empty )}
|
28
|
+
|
29
|
+
shared_examples_for( 'it can parse into an Info object' ) do
|
30
|
+
it( 'should parse categories correctly' ){ @info .categories.should == @original_info.categories }
|
31
|
+
it( 'should parse event correctly' ){ @info .event.should == @original_info.event }
|
32
|
+
it( 'should parse response_types correctly' ){ @info .response_types.should == @original_info.response_types }
|
33
|
+
it( 'should parse urgency correctly' ){ @info .urgency.should == @original_info.urgency }
|
34
|
+
it( 'should parse severity correctly' ){ @info .severity.should == @original_info.severity }
|
35
|
+
it( 'should parse certainty correctly' ){ @info .certainty.should == @original_info.certainty }
|
36
|
+
it( 'should parse audience correctly' ){ @info .audience.should == @original_info.audience }
|
37
|
+
it( 'should parse effective correctly' ){ @info .effective.should( be_close( @original_info.effective, Rational( 1, 86400 )))}
|
38
|
+
it( 'should parse onset correctly' ){ @info .onset.should( be_close( @original_info.onset, Rational( 1, 86400 )))}
|
39
|
+
it( 'should parse expires correctly' ){ @info .expires.should( be_close( @original_info.expires, Rational( 1, 86400 )))}
|
40
|
+
it( 'should parse sender_name correctly' ){ @info .sender_name.should == @original_info.sender_name }
|
41
|
+
it( 'should parse headline correctly' ){ @info .headline.should == @original_info.headline }
|
42
|
+
it( 'should parse description correctly' ){ @info .description.should == @original_info.description }
|
43
|
+
it( 'should parse instruction correctly' ){ @info .instruction.should == @original_info.instruction }
|
44
|
+
it( 'should parse web correctly' ){ @info .web.should == @original_info.web }
|
45
|
+
it( 'should parse contact correctly' ){ @info .contact.should == @original_info.contact }
|
46
|
+
it( 'should parse event_codes correctly' ){ @info .event_codes.should == @original_info.event_codes }
|
47
|
+
it( 'should parse parameters correctly' ){ @info .parameters.should == @original_info.parameters }
|
48
|
+
it( 'should parse resources correctly' ){ @info .resources.should == @original_info.resources }
|
49
|
+
it( 'should parse areas correctly' ){ @info .areas.should == @original_info.areas }
|
50
|
+
end
|
51
|
+
|
52
|
+
context( 'from XML' ) do
|
53
|
+
before( :each ) do
|
54
|
+
@original_info = RCAP::Info.new( :categories => [ RCAP::Info::CATEGORY_GEO, RCAP::Info::CATEGORY_FIRE ],
|
55
|
+
:event => 'Event Description',
|
56
|
+
:response_types => [ RCAP::Info::RESPONSE_TYPE_MONITOR, RCAP::Info::RESPONSE_TYPE_ASSESS ],
|
57
|
+
:urgency => RCAP::Info::URGENCY_IMMEDIATE,
|
58
|
+
:severity => RCAP::Info::SEVERITY_EXTREME,
|
59
|
+
:certainty => RCAP::Info::CERTAINTY_OBSERVED,
|
60
|
+
:audience => 'Audience',
|
61
|
+
:effective => DateTime.now,
|
62
|
+
:onset => DateTime.now + 1,
|
63
|
+
:expires => DateTime.now + 2,
|
64
|
+
:sender_name => 'Sender Name',
|
65
|
+
:headline => 'Headline',
|
66
|
+
:description => 'Description',
|
67
|
+
:instruction => 'Instruction',
|
68
|
+
:web => 'http://website',
|
69
|
+
:contact => 'contact@address',
|
70
|
+
:event_codes => [ RCAP::EventCode.new( :name => 'name1', :value => 'value1' ),
|
71
|
+
RCAP::EventCode.new( :name => 'name2', :value => 'value2' )],
|
72
|
+
:parameters => [ RCAP::Parameter.new( :name => 'name1', :value => 'value1' ),
|
73
|
+
RCAP::Parameter.new( :name => 'name2', :value => 'value2' )],
|
74
|
+
:areas => [ RCAP::Area.new( :area_desc => 'Area1' ),
|
75
|
+
RCAP::Area.new( :area_desc => 'Area2' )]
|
76
|
+
)
|
77
|
+
@alert = RCAP::Alert.new( :infos => @original_info )
|
78
|
+
@xml_string = @alert.to_xml
|
79
|
+
@xml_document = REXML::Document.new( @xml_string )
|
80
|
+
@info = RCAP::Info.from_xml_element( RCAP.xpath_first( @xml_document.root, RCAP::Info::XPATH ))
|
81
|
+
end
|
82
|
+
|
83
|
+
it_should_behave_like( "it can parse into an Info object" )
|
84
|
+
end
|
85
|
+
|
86
|
+
context( 'from a hash' ) do
|
87
|
+
before( :each ) do
|
88
|
+
@original_info = RCAP::Info.new( :categories => [ RCAP::Info::CATEGORY_GEO, RCAP::Info::CATEGORY_FIRE ],
|
89
|
+
:event => 'Event Description',
|
90
|
+
:response_types => [ RCAP::Info::RESPONSE_TYPE_MONITOR, RCAP::Info::RESPONSE_TYPE_ASSESS ],
|
91
|
+
:urgency => RCAP::Info::URGENCY_IMMEDIATE,
|
92
|
+
:severity => RCAP::Info::SEVERITY_EXTREME,
|
93
|
+
:certainty => RCAP::Info::CERTAINTY_OBSERVED,
|
94
|
+
:audience => 'Audience',
|
95
|
+
:effective => DateTime.now,
|
96
|
+
:onset => DateTime.now + 1,
|
97
|
+
:expires => DateTime.now + 2,
|
98
|
+
:sender_name => 'Sender Name',
|
99
|
+
:headline => 'Headline',
|
100
|
+
:description => 'Description',
|
101
|
+
:instruction => 'Instruction',
|
102
|
+
:web => 'http://website',
|
103
|
+
:contact => 'contact@address',
|
104
|
+
:event_codes => [ RCAP::EventCode.new( :name => 'name1', :value => 'value1' ),
|
105
|
+
RCAP::EventCode.new( :name => 'name2', :value => 'value2' )],
|
106
|
+
:parameters => [ RCAP::Parameter.new( :name => 'name1', :value => 'value1' ),
|
107
|
+
RCAP::Parameter.new( :name => 'name2', :value => 'value2' )],
|
108
|
+
:areas => [ RCAP::Area.new( :area_desc => 'Area1' ),
|
109
|
+
RCAP::Area.new( :area_desc => 'Area2' )]
|
110
|
+
)
|
111
|
+
@info = RCAP::Info.from_h( @original_info.to_h )
|
112
|
+
end
|
113
|
+
it_should_behave_like( "it can parse into an Info object" )
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context( 'is not valid if it' ) do
|
118
|
+
before( :each ) do
|
119
|
+
@info = RCAP::Info.new( :event => 'Info Event',
|
120
|
+
:categories => RCAP::Info::CATEGORY_GEO,
|
121
|
+
:urgency => RCAP::Info::URGENCY_IMMEDIATE,
|
122
|
+
:severity => RCAP::Info::SEVERITY_EXTREME,
|
123
|
+
:certainty => RCAP::Info::CERTAINTY_OBSERVED )
|
124
|
+
@info.valid?
|
125
|
+
puts @info.errors.full_messages
|
126
|
+
@info.should( be_valid )
|
127
|
+
end
|
128
|
+
|
129
|
+
it( 'does not have an event' ) do
|
130
|
+
@info.event = nil
|
131
|
+
@info.should_not( be_valid )
|
132
|
+
end
|
133
|
+
|
134
|
+
it( 'does not have categories' ) do
|
135
|
+
@info.categories.clear
|
136
|
+
@info.should_not( be_valid )
|
137
|
+
end
|
138
|
+
|
139
|
+
it( 'does not have an urgency' ) do
|
140
|
+
@info.urgency = nil
|
141
|
+
@info.should_not( be_valid )
|
142
|
+
end
|
143
|
+
|
144
|
+
it( 'does not have an severity' ) do
|
145
|
+
@info.severity = nil
|
146
|
+
@info.should_not( be_valid )
|
147
|
+
end
|
148
|
+
|
149
|
+
it( 'does not have an certainty' ) do
|
150
|
+
@info.certainty = nil
|
151
|
+
@info.should_not( be_valid )
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
describe( 'when exported' ) do
|
157
|
+
context( 'to hash' ) do
|
158
|
+
before( :each ) do
|
159
|
+
@info = RCAP::Info.new( :categories => [ RCAP::Info::CATEGORY_GEO, RCAP::Info::CATEGORY_FIRE ],
|
160
|
+
:event => 'Event Description',
|
161
|
+
:response_types => [ RCAP::Info::RESPONSE_TYPE_MONITOR, RCAP::Info::RESPONSE_TYPE_ASSESS ],
|
162
|
+
:urgency => RCAP::Info::URGENCY_IMMEDIATE,
|
163
|
+
:severity => RCAP::Info::SEVERITY_EXTREME,
|
164
|
+
:certainty => RCAP::Info::CERTAINTY_OBSERVED,
|
165
|
+
:audience => 'Audience',
|
166
|
+
:effective => DateTime.now,
|
167
|
+
:onset => DateTime.now + 1,
|
168
|
+
:expires => DateTime.now + 2,
|
169
|
+
:sender_name => 'Sender Name',
|
170
|
+
:headline => 'Headline',
|
171
|
+
:description => 'Description',
|
172
|
+
:instruction => 'Instruction',
|
173
|
+
:web => 'http://website',
|
174
|
+
:contact => 'contact@address',
|
175
|
+
:resources => [ RCAP::Resource.new( :resource_desc => 'Resource Description', :uri => 'http://tempuri.org/resource' )],
|
176
|
+
:event_codes => [ RCAP::EventCode.new( :name => 'name1', :value => 'value1' ),
|
177
|
+
RCAP::EventCode.new( :name => 'name2', :value => 'value2' )],
|
178
|
+
:parameters => [ RCAP::Parameter.new( :name => 'name1', :value => 'value1' ),
|
179
|
+
RCAP::Parameter.new( :name => 'name2', :value => 'value2' )],
|
180
|
+
:areas => [ RCAP::Area.new( :area_desc => 'Area1' ),
|
181
|
+
RCAP::Area.new( :area_desc => 'Area2' )])
|
182
|
+
@info_hash = @info.to_h
|
183
|
+
end
|
184
|
+
|
185
|
+
it( 'should export the language correctly' ) do
|
186
|
+
@info_hash[ RCAP::Info::LANGUAGE_KEY ].should == @info.language
|
187
|
+
end
|
188
|
+
|
189
|
+
it( 'should export the categories' ) do
|
190
|
+
@info_hash[ RCAP::Info::CATEGORIES_KEY ].should == @info.categories
|
191
|
+
end
|
192
|
+
|
193
|
+
it( 'should export the event' ) do
|
194
|
+
@info_hash[ RCAP::Info::EVENT_KEY ].should == @info.event
|
195
|
+
end
|
196
|
+
|
197
|
+
it( 'should export the response types' ) do
|
198
|
+
@info_hash[ RCAP::Info::RESPONSE_TYPES_KEY ].should == @info.response_types
|
199
|
+
end
|
200
|
+
|
201
|
+
it( 'should export the urgency' ) do
|
202
|
+
@info_hash[ RCAP::Info:: URGENCY_KEY ].should == @info.urgency
|
203
|
+
end
|
204
|
+
|
205
|
+
it( 'should export the severity' ) do
|
206
|
+
@info_hash[ RCAP::Info:: SEVERITY_KEY ].should == @info.severity
|
207
|
+
end
|
208
|
+
|
209
|
+
it( 'should export the certainty' ) do
|
210
|
+
@info_hash[ RCAP::Info:: CERTAINTY_KEY ].should == @info.certainty
|
211
|
+
end
|
212
|
+
|
213
|
+
it( 'should export the audience' ) do
|
214
|
+
@info_hash[ RCAP::Info:: AUDIENCE_KEY ].should == @info.audience
|
215
|
+
end
|
216
|
+
|
217
|
+
it( 'should export the effective date' ) do
|
218
|
+
@info_hash[ RCAP::Info::EFFECTIVE_KEY ].should == @info.effective.to_s_for_cap
|
219
|
+
end
|
220
|
+
|
221
|
+
it( 'should export the onset date' ) do
|
222
|
+
@info_hash[ RCAP::Info::ONSET_KEY ].should == @info.onset.to_s_for_cap
|
223
|
+
end
|
224
|
+
|
225
|
+
it( 'should export the expires date' ) do
|
226
|
+
@info_hash[ RCAP::Info::EXPIRES_KEY ].should == @info.expires.to_s_for_cap
|
227
|
+
end
|
228
|
+
|
229
|
+
it( 'should export the sender name' ) do
|
230
|
+
@info_hash[ RCAP::Info::SENDER_NAME_KEY ].should == @info.sender_name
|
231
|
+
end
|
232
|
+
|
233
|
+
it( 'should export the headline' ) do
|
234
|
+
@info_hash[ RCAP::Info::HEADLINE_KEY ].should == @info.headline
|
235
|
+
end
|
236
|
+
|
237
|
+
it( 'should export the description' ) do
|
238
|
+
@info_hash[ RCAP::Info::DESCRIPTION_KEY ].should == @info.description
|
239
|
+
end
|
240
|
+
|
241
|
+
it( 'should export the instruction' ) do
|
242
|
+
@info_hash[ RCAP::Info::INSTRUCTION_KEY ].should == @info.instruction
|
243
|
+
end
|
244
|
+
|
245
|
+
it( 'should export the web address ' ) do
|
246
|
+
@info_hash[ RCAP::Info::WEB_KEY ].should == @info.web
|
247
|
+
end
|
248
|
+
|
249
|
+
it( 'should export the contact' ) do
|
250
|
+
@info_hash[ RCAP::Info::CONTACT_KEY ].should == @info.contact
|
251
|
+
end
|
252
|
+
|
253
|
+
it( 'should export the event codes' ) do
|
254
|
+
@info_hash[ RCAP::Info::EVENT_CODES_KEY ].should == @info.event_codes.map{ |event_code| event_code.to_h }
|
255
|
+
end
|
256
|
+
|
257
|
+
it( 'should export the parameters ' ) do
|
258
|
+
@info_hash[ RCAP::Info::PARAMETERS_KEY ].should == @info.parameters.map{ |parameter| parameter.to_h }
|
259
|
+
end
|
260
|
+
|
261
|
+
it( 'should export the resources ' ) do
|
262
|
+
@info_hash[ RCAP::Info::RESOURCES_KEY ].should == @info.resources.map{ |resource| resource.to_h }
|
263
|
+
end
|
264
|
+
|
265
|
+
it( 'should export the areas' ) do
|
266
|
+
@info_hash[ RCAP::Info::AREAS_KEY ].should == @info.areas.map{ |area| area.to_h }
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
data/spec/point_spec.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::Point ) do
|
4
|
+
describe( 'is not valid if' ) do
|
5
|
+
before( :each ) do
|
6
|
+
@point = RCAP::Point.new( :lattitude => 0, :longitude => 0 )
|
7
|
+
@point.should( be_valid )
|
8
|
+
end
|
9
|
+
|
10
|
+
it( 'does not have a longitude defined' ) do
|
11
|
+
@point.longitude = nil
|
12
|
+
@point.should_not( be_valid )
|
13
|
+
end
|
14
|
+
|
15
|
+
it( 'does not have a valid longitude' ) do
|
16
|
+
@point.longitude = RCAP::Point::MAX_LONGITUDE + 1
|
17
|
+
@point.should_not( be_valid )
|
18
|
+
@point.longitude = RCAP::Point::MIN_LONGITUDE - 1
|
19
|
+
@point.should_not( be_valid )
|
20
|
+
end
|
21
|
+
|
22
|
+
it( 'does not have a lattitude defined' ) do
|
23
|
+
@point.lattitude = nil
|
24
|
+
@point.should_not( be_valid )
|
25
|
+
end
|
26
|
+
|
27
|
+
it( 'does not have a valid lattitude' ) do
|
28
|
+
@point.lattitude = RCAP::Point::MAX_LATTITUDE + 1
|
29
|
+
@point.should_not( be_valid )
|
30
|
+
@point.lattitude = RCAP::Point::MIN_LATTITUDE - 1
|
31
|
+
@point.should_not( be_valid )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context( 'when exported' ) do
|
36
|
+
before( :each ) do
|
37
|
+
@point = RCAP::Point.new( :lattitude => 1, :longitude => 1 )
|
38
|
+
end
|
39
|
+
|
40
|
+
context( 'to hash' ) do
|
41
|
+
it( 'should export correctly' ) do
|
42
|
+
@point.to_h.should == { RCAP::Point::LATTITUDE_KEY => 1, RCAP::Point::LONGITUDE_KEY => 1 }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::Polygon ) do
|
4
|
+
describe( 'is not valid if it' ) do
|
5
|
+
before( :each ) do
|
6
|
+
@polygon = RCAP::Polygon.new
|
7
|
+
3.times do
|
8
|
+
@polygon.points << RCAP::Point.new( :lattitude => 0, :longitude => 0 )
|
9
|
+
end
|
10
|
+
@polygon.should( be_valid )
|
11
|
+
end
|
12
|
+
|
13
|
+
it( 'does not have any points' ) do
|
14
|
+
@polygon.points.clear
|
15
|
+
@polygon.should_not( be_valid )
|
16
|
+
end
|
17
|
+
|
18
|
+
it( 'does not have a valid collection of points' ) do
|
19
|
+
@polygon.points.first.lattitude = nil
|
20
|
+
@polygon.should_not( be_valid )
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context( 'on initialization' ) do
|
25
|
+
context( 'from XML' ) do
|
26
|
+
before( :each ) do
|
27
|
+
@original_polygon = RCAP::Polygon.new( :points => Array.new(3){|i| RCAP::Point.new( :lattitude => i, :longitude => i )})
|
28
|
+
@alert = RCAP::Alert.new( :infos => RCAP::Info.new( :areas => RCAP::Area.new( :polygons => @original_polygon )))
|
29
|
+
@xml_string = @alert.to_xml
|
30
|
+
@xml_document = REXML::Document.new( @xml_string )
|
31
|
+
@info_element = RCAP.xpath_first( @xml_document.root, RCAP::Info::XPATH )
|
32
|
+
@area_element = RCAP.xpath_first( @info_element, RCAP::Area::XPATH )
|
33
|
+
@polygon_element = RCAP.xpath_first( @area_element, RCAP::Polygon::XPATH )
|
34
|
+
@polygon = RCAP::Polygon.from_xml_element( @polygon_element )
|
35
|
+
end
|
36
|
+
|
37
|
+
it( 'should parse all the points' ) do
|
38
|
+
@polygon.points.zip( @original_polygon.points ).each do |point, original_point|
|
39
|
+
point.lattitude.should == original_point.lattitude
|
40
|
+
point.longitude.should == original_point.longitude
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context( 'from a hash' ) do
|
46
|
+
before( :each ) do
|
47
|
+
@polygon = RCAP::Polygon.new( :points => Array.new(3){|i| RCAP::Point.new( :lattitude => i, :longitude => i )})
|
48
|
+
end
|
49
|
+
|
50
|
+
it( 'should load all the points' ) do
|
51
|
+
@new_polygon = RCAP::Polygon.from_h( @polygon.to_h )
|
52
|
+
@new_polygon.points.should == @polygon.points
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context( 'when exported' ) do
|
58
|
+
before( :each ) do
|
59
|
+
@polygon = RCAP::Polygon.new( :points => Array.new(3){|i| RCAP::Point.new( :lattitude => i, :longitude => i )})
|
60
|
+
end
|
61
|
+
|
62
|
+
context( 'to a hash' ) do
|
63
|
+
it( 'should export correctly' ) do
|
64
|
+
@polygon.to_h.should == { RCAP::Polygon::POINTS_KEY => @polygon.points.map{ |point| point.to_h }}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::Resource ) do
|
4
|
+
context( 'on initialisation' ) do
|
5
|
+
before( :each ) do
|
6
|
+
@resource = RCAP::Resource.new
|
7
|
+
end
|
8
|
+
|
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
|
+
|
16
|
+
context( 'from XML' ) do
|
17
|
+
before( :each ) do
|
18
|
+
@original_resource = RCAP::Resource.new
|
19
|
+
@original_resource.resource_desc = "Image of incident"
|
20
|
+
@original_resource.uri = "http://capetown.gov.za/cap/resources/image.png"
|
21
|
+
@original_resource.mime_type = 'image/png'
|
22
|
+
@original_resource.deref_uri = "IMAGE DATA"
|
23
|
+
@original_resource.size = "20480"
|
24
|
+
@original_resource.digest = "2048"
|
25
|
+
|
26
|
+
@alert = RCAP::Alert.new( :infos => RCAP::Info.new( :resources => @original_resource ))
|
27
|
+
@xml_string = @alert.to_xml
|
28
|
+
@xml_document = REXML::Document.new( @xml_string )
|
29
|
+
@info_element = RCAP.xpath_first( @xml_document.root, RCAP::Info::XPATH )
|
30
|
+
@resource_element = RCAP.xpath_first( @info_element, RCAP::Resource::XPATH )
|
31
|
+
@resource_element.should_not( be_nil )
|
32
|
+
@resource = RCAP::Resource.from_xml_element( @resource_element )
|
33
|
+
end
|
34
|
+
|
35
|
+
it( 'should parse resource_desc correctly' ) do
|
36
|
+
@resource.resource_desc.should == @original_resource.resource_desc
|
37
|
+
end
|
38
|
+
|
39
|
+
it( 'should parse uri correctly' ) do
|
40
|
+
@resource.uri.should == @original_resource.uri
|
41
|
+
end
|
42
|
+
|
43
|
+
it( 'should parse mime_type correctly' ) do
|
44
|
+
@resource.mime_type.should == @original_resource.mime_type
|
45
|
+
end
|
46
|
+
|
47
|
+
it( 'should parse deref_uri correctly' ) do
|
48
|
+
@resource.deref_uri.should == @original_resource.deref_uri
|
49
|
+
end
|
50
|
+
|
51
|
+
it( 'should parse size correctly' ) do
|
52
|
+
@resource.size.should == @original_resource.size
|
53
|
+
end
|
54
|
+
|
55
|
+
it( 'should parse digest correctly' ) do
|
56
|
+
@resource.digest.should == @original_resource.digest
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
context( 'from a hash' ) do
|
62
|
+
before( :each ) do
|
63
|
+
@original_resource = RCAP::Resource.new
|
64
|
+
@original_resource.resource_desc = "Image of incident"
|
65
|
+
@original_resource.uri = "http://capetown.gov.za/cap/resources/image.png"
|
66
|
+
@original_resource.mime_type = 'image/png'
|
67
|
+
@original_resource.deref_uri = "IMAGE DATA"
|
68
|
+
@original_resource.size = "20480"
|
69
|
+
@original_resource.digest = "2048"
|
70
|
+
|
71
|
+
@resource = RCAP::Resource.from_h( @original_resource.to_h )
|
72
|
+
end
|
73
|
+
|
74
|
+
it( 'should parse resource_desc correctly' ) do
|
75
|
+
@resource.resource_desc.should == @original_resource.resource_desc
|
76
|
+
end
|
77
|
+
|
78
|
+
it( 'should parse uri correctly' ) do
|
79
|
+
@resource.uri.should == @original_resource.uri
|
80
|
+
end
|
81
|
+
|
82
|
+
it( 'should parse mime_type correctly' ) do
|
83
|
+
@resource.mime_type.should == @original_resource.mime_type
|
84
|
+
end
|
85
|
+
|
86
|
+
it( 'should parse deref_uri correctly' ) do
|
87
|
+
@resource.deref_uri.should == @original_resource.deref_uri
|
88
|
+
end
|
89
|
+
|
90
|
+
it( 'should parse size correctly' ) do
|
91
|
+
@resource.size.should == @original_resource.size
|
92
|
+
end
|
93
|
+
|
94
|
+
it( 'should parse digest correctly' ) do
|
95
|
+
@resource.digest.should == @original_resource.digest
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
context( 'when exported' ) do
|
102
|
+
before( :each ) do
|
103
|
+
@resource = RCAP::Resource.new
|
104
|
+
@resource.resource_desc = "Image of incident"
|
105
|
+
@resource.uri = "http://capetown.gov.za/cap/resources/image.png"
|
106
|
+
@resource.mime_type = 'image/png'
|
107
|
+
@resource.deref_uri = "IMAGE DATA"
|
108
|
+
@resource.size = "20480"
|
109
|
+
@resource.digest = "2048"
|
110
|
+
end
|
111
|
+
|
112
|
+
context( 'to a hash' ) do
|
113
|
+
before( :each ) do
|
114
|
+
@resource_hash = @resource.to_h
|
115
|
+
end
|
116
|
+
|
117
|
+
it( 'should set the resource description' ) do
|
118
|
+
@resource_hash[ RCAP::Resource::RESOURCE_DESC_KEY ].should == @resource.resource_desc
|
119
|
+
end
|
120
|
+
|
121
|
+
it( 'should set the mime type' ) do
|
122
|
+
@resource_hash[ RCAP::Resource::MIME_TYPE_KEY ].should == @resource.mime_type
|
123
|
+
end
|
124
|
+
|
125
|
+
it( 'should set the size' ) do
|
126
|
+
@resource_hash[ RCAP::Resource::SIZE_KEY ].should == @resource.size
|
127
|
+
end
|
128
|
+
|
129
|
+
it( 'should set the URI' ) do
|
130
|
+
@resource_hash[ RCAP::Resource::URI_KEY ].should == @resource.uri
|
131
|
+
end
|
132
|
+
|
133
|
+
it( 'should set the dereferenced URI' ) do
|
134
|
+
@resource_hash[ RCAP::Resource::DEREF_URI_KEY ].should == @resource.deref_uri
|
135
|
+
end
|
136
|
+
|
137
|
+
it( 'should set the digest' ) do
|
138
|
+
@resource_hash[ RCAP::Resource::DIGEST_KEY ].should == @resource.digest
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context( 'which is valid' ) do
|
144
|
+
before( :each ) do
|
145
|
+
@resource = RCAP::Resource.new( :resource_desc => 'Resource Description' )
|
146
|
+
@resource.should( be_valid )
|
147
|
+
end
|
148
|
+
|
149
|
+
describe( 'should not be valid if it' ) do
|
150
|
+
it( 'does not have a resource description (resource_desc)' ) do
|
151
|
+
@resource.resource_desc = nil
|
152
|
+
@resource.should_not( be_valid )
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|