ratis 3.1.0 → 3.1.1

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.
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ratis::LandmarkCategory do
4
+
5
+ before do
6
+ stub_atis_request.to_return( atis_response 'Getcategories', '1.1', '0', <<-BODY )
7
+ <Types>
8
+ <Typeinfo>
9
+ <Type>AIRPORT</Type>
10
+ <Description>AIRPT</Description>
11
+ </Typeinfo>
12
+ <Typeinfo>
13
+ <Type>CASINO</Type>
14
+ <Description>CAS</Description>
15
+ </Typeinfo>
16
+ <Typeinfo>
17
+ <Type>CEMETARIES</Type>
18
+ <Description>CEM</Description>
19
+ </Typeinfo>
20
+ </Types>
21
+ BODY
22
+
23
+ @landmark_categories = Ratis::LandmarkCategory.all
24
+ end
25
+
26
+ it 'only makes one request' do
27
+ an_atis_request.should have_been_made.times 1
28
+ end
29
+
30
+ it 'requests the correct SOAP action' do
31
+ an_atis_request_for('Getcategories').should have_been_made
32
+ end
33
+
34
+ it 'should return all landmark categories' do
35
+ @landmark_categories.should have(3).items
36
+
37
+ @landmark_categories[0].type.should eql 'AIRPORT'
38
+ @landmark_categories[0].description.should eql 'AIRPT'
39
+ @landmark_categories[1].type.should eql 'CASINO'
40
+ @landmark_categories[1].description.should eql 'CAS'
41
+ @landmark_categories[2].type.should eql 'CEMETARIES'
42
+ @landmark_categories[2].description.should eql 'CEM'
43
+ end
44
+
45
+ end
46
+
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ratis::Landmark do
4
+
5
+ before do
6
+ stub_atis_request.to_return( atis_response 'Getlandmarks', '1.4', '0', <<-BODY )
7
+ <Landmarks>
8
+ <Landmark>
9
+ <Id>5007</Id>
10
+ <Verbose>FALCON FIELD AIRPORT</Verbose>
11
+ <Location>4800 E. FALCON DR.</Location>
12
+ <Area>ME</Area>
13
+ <Latitude>33.456119</Latitude>
14
+ <Longitude>-111.728010</Longitude>
15
+ <Locality>N</Locality>
16
+ <Type>AIRPT</Type>
17
+ <Map_level>3</Map_level>
18
+ <Notes> Hours of Operation: </Notes>
19
+ <Zipcode>85215</Zipcode>
20
+ </Landmark>
21
+ <Landmark>
22
+ <Id>5009</Id>
23
+ <Verbose>SKY HARBOR AIRPORT TERMINAL 4 WB</Verbose>
24
+ <Location>3700 E SKY HARBOR BLVD</Location>
25
+ <Area>PH</Area>
26
+ <Latitude>33.434520</Latitude>
27
+ <Longitude>-111.996145</Longitude>
28
+ <Locality>N</Locality>
29
+ <Type>AIRPT</Type>
30
+ <Map_level>3</Map_level>
31
+ <Notes> Hours of Operation: !!!!!!!!24 hours</Notes>
32
+ <Zipcode>99999</Zipcode>
33
+ </Landmark>
34
+ </Landmarks>
35
+ BODY
36
+
37
+ @landmarks = Ratis::Landmark.where :type => :all
38
+ end
39
+
40
+ it 'only makes one request' do
41
+ an_atis_request.should have_been_made.times 1
42
+ end
43
+
44
+ it 'requests the correct SOAP action' do
45
+ an_atis_request_for('Getlandmarks', 'Type' => 'ALL').should have_been_made
46
+ end
47
+
48
+ it 'should return all landmarks' do
49
+ @landmarks.should have(2).items
50
+
51
+ @landmarks[0].type.should eql 'AIRPT'
52
+ @landmarks[0].verbose.should eql 'FALCON FIELD AIRPORT'
53
+ @landmarks[0].location.should eql '4800 E. FALCON DR.'
54
+ @landmarks[0].locality.should eql 'N'
55
+
56
+ @landmarks[1].type.should eql 'AIRPT'
57
+ @landmarks[1].verbose.should eql 'SKY HARBOR AIRPORT TERMINAL 4 WB'
58
+ @landmarks[1].location.should eql '3700 E SKY HARBOR BLVD'
59
+ @landmarks[1].locality.should eql 'N'
60
+ end
61
+
62
+ end
63
+
@@ -0,0 +1,207 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ratis::Location do
4
+
5
+ describe 'Intersection or Stop' do
6
+ pending 'needs implementation'
7
+ end
8
+
9
+ describe 'Landmark' do
10
+
11
+ before do
12
+ stub_atis_request.to_return( atis_response 'Locate', '1.12', 'ok', <<-BODY )
13
+ <Projection>SP</Projection>
14
+ <Locationtype>L</Locationtype>
15
+ <Location>
16
+ <Name>CENTRAL STATION</Name>
17
+ <Area>Phoenix</Area>
18
+ <Areacode>PH</Areacode>
19
+ <Region>1</Region>
20
+ <Zipname></Zipname>
21
+ <Latitude>33.452082</Latitude>
22
+ <Longitude>-112.074374</Longitude>
23
+ <Landmarkid>7234</Landmarkid>
24
+ <Islocality>N</Islocality>
25
+ </Location>
26
+ BODY
27
+
28
+ @locations = Ratis::Location.where :location => "Central Station", :media => 'a', :max_answers => 3
29
+ @first_location = @locations.first
30
+ end
31
+
32
+ describe '#where' do
33
+
34
+ it 'only makes one request' do
35
+ an_atis_request.should have_been_made.times 1
36
+ end
37
+
38
+ it 'requests the correct SOAP action' do
39
+ an_atis_request_for('Locate', 'Location' => 'Central Station', 'Media' => 'A', 'Maxanswers' => '3').should have_been_made
40
+ end
41
+
42
+ it 'returns the single locations' do
43
+ @locations.should have(1).item
44
+ end
45
+
46
+ it 'parses out fields correctly' do
47
+ @first_location.name.should eql 'CENTRAL STATION'
48
+ @first_location.area.should eql 'Phoenix'
49
+ @first_location.response.should eql 'ok'
50
+ @first_location.areacode.should eql 'PH'
51
+ @first_location.latitude.should eql '33.452082'
52
+ @first_location.longitude.should eql '-112.074374'
53
+ @first_location.landmark_id.should eql '7234'
54
+ @first_location.address.should eql ''
55
+ @first_location.startaddr.should eql ''
56
+ @first_location.endaddr.should eql ''
57
+ @first_location.address_string.should eql 'CENTRAL STATION (in Phoenix)'
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ describe 'Address with house number match' do
65
+ pending 'needs implementation'
66
+ end
67
+
68
+ describe 'Address without house number match' do
69
+
70
+ before do
71
+ stub_atis_request.to_return( atis_response 'Locate', '1.12', 'ambig', <<-BODY )
72
+ <Locationtype>A</Locationtype>
73
+ <Projection>SP</Projection>
74
+ <Location>
75
+ <Name>W PENNSYLVANIA AVE</Name>
76
+ <Area>Youngtown</Area>
77
+ <Areacode>YG</Areacode>
78
+ <Region>1</Region>
79
+ <Zipname>85363 - Youngtown</Zipname>
80
+ <Latitude>33.5811205</Latitude>
81
+ <Longitude>-112.2989325</Longitude>
82
+ <Landmarkid>0</Landmarkid>
83
+ <Startaddr>11105</Startaddr>
84
+ <Endaddr>11111</Endaddr>
85
+ <Startlatitude>33.581130</Startlatitude>
86
+ <Startlongitude>-112.298791</Startlongitude>
87
+ <Endlatitude>33.581111</Endlatitude>
88
+ <Endlongitude>-112.299074</Endlongitude>
89
+ </Location>
90
+ <Location>
91
+ <Name>W PENNSYLVANIA AVE</Name>
92
+ <Area>Youngtown</Area>
93
+ <Areacode>YG</Areacode>
94
+ <Region>1</Region>
95
+ <Zipname>85363 - Youngtown</Zipname>
96
+ <Latitude>33.581082</Latitude>
97
+ <Longitude>-112.2991235</Longitude>
98
+ <Landmarkid>0</Landmarkid>
99
+ <Startaddr>11109</Startaddr>
100
+ <Endaddr>11113</Endaddr>
101
+ <Startlatitude>33.581111</Startlatitude>
102
+ <Startlongitude>-112.299074</Startlongitude>
103
+ <Endlatitude>33.581053</Endlatitude>
104
+ <Endlongitude>-112.299173</Endlongitude>
105
+ </Location>
106
+ BODY
107
+
108
+ @locations = Ratis::Location.where :location => '1600 Pennsylvania Ave', :media => 'W', :max_answers => 1000
109
+ @first_location = @locations.first
110
+ end
111
+
112
+ describe '#where' do
113
+
114
+ it 'only makes one request' do
115
+ an_atis_request.should have_been_made.times 1
116
+ end
117
+
118
+ it 'requests the correct SOAP action' do
119
+ an_atis_request_for('Locate', 'Location' => '1600 Pennsylvania Ave', 'Media' => 'W', 'Maxanswers' => '1000').should have_been_made
120
+ end
121
+
122
+ it 'returns multiple locations' do
123
+ @locations.should have(2).items
124
+ end
125
+
126
+ it 'parses out fields correctly' do
127
+ @first_location.name.should eql 'W PENNSYLVANIA AVE'
128
+ @first_location.area.should eql 'Youngtown'
129
+ @first_location.response.should eql 'ambig'
130
+ @first_location.areacode.should eql 'YG'
131
+ @first_location.latitude.should eql '33.5811205'
132
+ @first_location.longitude.should eql '-112.2989325'
133
+ @first_location.landmark_id.should eql '0'
134
+ @first_location.address.should eql ''
135
+ @first_location.startaddr.should eql '11105'
136
+ @first_location.endaddr.should eql '11111'
137
+ @first_location.address_string.should eql '11105 - 11111 W PENNSYLVANIA AVE (in Youngtown)'
138
+ end
139
+
140
+ end
141
+
142
+ describe '#to_a' do
143
+ it 'returns lat, lon, name and landmark_id' do
144
+ @first_location.to_a.should eql ['33.5811205', '-112.2989325', 'W PENNSYLVANIA AVE', '0']
145
+ end
146
+ end
147
+
148
+ describe '#to_hash' do
149
+ it 'returns a subset of Location params' do
150
+ hash = {
151
+ :latitude => '33.5811205',
152
+ :longitude => '-112.2989325',
153
+ :name => 'W PENNSYLVANIA AVE',
154
+ :area => 'Youngtown',
155
+ :address => '',
156
+ :startaddr => '11105',
157
+ :endaddr => '11111',
158
+ :address_string => '11105 - 11111 W PENNSYLVANIA AVE (in Youngtown)',
159
+ :landmark_id => '0' }
160
+
161
+ HashDiff.diff(@first_location.to_hash, hash).should eql []
162
+ end
163
+
164
+ end
165
+
166
+ end
167
+
168
+ describe '#where' do
169
+
170
+ it 'defaults media to W' do
171
+ stub_atis_request.to_return( atis_response 'Locate', '1.12', 'ok', <<-BODY )
172
+ <Location>
173
+ <Name>Some place</Name>
174
+ </Location>
175
+ BODY
176
+
177
+ Ratis::Location.where :location => 'Some place', :max_answers => 1000
178
+ an_atis_request_for('Locate', 'Location' => 'Some place', 'Media' => 'W', 'Maxanswers' => '1000').should have_been_made
179
+ end
180
+
181
+ it 'requires a valid media' do
182
+ expect do
183
+ Ratis::Location.where :location => 'Some place', :media => 'XYZZY'
184
+ end.to raise_error ArgumentError, 'You must provide media of A|W|I'
185
+ end
186
+
187
+ it 'defaults max_answers to 20' do
188
+ stub_atis_request.to_return( atis_response 'Locate', '1.12', 'ok', <<-BODY )
189
+ <Location>
190
+ <Name>Some place</Name>
191
+ </Location>
192
+ BODY
193
+
194
+ Ratis::Location.where :location => 'Some place', :media => 'W'
195
+ an_atis_request_for('Locate', 'Location' => 'Some place', 'Media' => 'W', 'Maxanswers' => '20').should have_been_made
196
+ end
197
+
198
+ it 'requires a numeric max_answers' do
199
+ expect do
200
+ Ratis::Location.where :location => 'Some place', :max_answers => 'not a number'
201
+ end.to raise_error ArgumentError, 'You must provide a numeric max_answers'
202
+ end
203
+
204
+ end
205
+
206
+ end
207
+
@@ -0,0 +1,148 @@
1
+ require 'spec_helper'
2
+
3
+ # NOTE: this should be called NextBus2 or something as that's the API call it really makes.
4
+ # need to find all places where this is used and update them before being able to push a new
5
+ # gem version for this backwards breaking change
6
+ describe Ratis::NextBus2 do
7
+ before do
8
+ Ratis.reset
9
+ Ratis.configure do |config|
10
+ config.endpoint = 'http://soap.valleymetro.org/cgi-bin-soap-web-252/soap.cgi'
11
+ config.namespace = 'PX_WEB'
12
+ end
13
+ end
14
+
15
+ describe '#where' do
16
+ before do
17
+ # appid
18
+ # a short string that can be used to separate requests from different applications or different modules with
19
+ # Optional (highly recommended)
20
+ @today = Time.now.strftime("%m/%d/%Y")
21
+ @conditions = {:stop_id => 10050,
22
+ :app_id => 'ratis-specs'}
23
+ end
24
+
25
+ it 'stops' do
26
+ pending
27
+ # raises exception when no runs available:
28
+ # Ratis::Errors::SoapError:
29
+ # SOAP - no runs available
30
+ response = Ratis::NextBus2.where(@conditions.dup)
31
+ debugger
32
+ x = 1
33
+ end
34
+
35
+ it 'runs' do
36
+ pending
37
+ end
38
+ end
39
+
40
+ describe 'single next bus at 10496' do
41
+
42
+ let(:next_bus_time_scheduled) { 10.minutes.from_now.strftime '%H:%M %p' }
43
+ let(:next_bus_time_estimated) { 12.minutes.from_now.strftime '%H:%M %p' }
44
+
45
+ before do
46
+ stub_atis_request.to_return( atis_response 'Nextbus2', '1.3', '0', <<-BODY )
47
+ <Input>
48
+ <Stopid>10496</Stopid>
49
+ <Atisstopid>0</Atisstopid>
50
+ <Route></Route>
51
+ <Runs>999</Runs>
52
+ <Xmode></Xmode>
53
+ <Date>#{ Time.now.strftime '%m/%d/%y' }</Date>
54
+ <Time>#{ Time.now.strftime '%H:%M %p' }</Time>
55
+ </Input>
56
+ <Stops>
57
+ <Stop>
58
+ <Stopid>10496</Stopid>
59
+ <Atisstopid>366</Atisstopid>
60
+ <Stopstatustype>N</Stopstatustype>
61
+ <Description>FILLMORE ST & CENTRAL AVE</Description>
62
+ <Lat>33.454483</Lat>
63
+ <Long>-112.073307</Long>
64
+ <Stopposition>G</Stopposition>
65
+ <Heading>EB</Heading>
66
+ <Side>Far</Side>
67
+ </Stop>
68
+ </Stops>
69
+ <Runs>
70
+ <Run>
71
+ <Route>7</Route>
72
+ <Sign>7 7th Street to Union Hills Via Cent Station</Sign>
73
+ <Operator>AP</Operator>
74
+ <Direction>N</Direction>
75
+ <Status>N</Status>
76
+ <Servicetype>W</Servicetype>
77
+ <Routetype>B</Routetype>
78
+ <Triptime>#{ next_bus_time_scheduled }</Triptime>
79
+ <Tripid>85-20</Tripid>
80
+ <Adherence>0</Adherence>
81
+ <Estimatedtime>#{ next_bus_time_estimated }</Estimatedtime>
82
+ <Polltime></Polltime>
83
+ <Lat></Lat>
84
+ <Long></Long>
85
+ <Block>22</Block>
86
+ <Exception></Exception>
87
+ <Atisstopid>366</Atisstopid>
88
+ <Stopid>10496</Stopid>
89
+ </Run>
90
+ </Runs>
91
+ BODY
92
+
93
+ # @next_bus = Ratis::NextBus2.where :stop_id => 10496, :app_id => 'web'
94
+ end
95
+
96
+ describe '#where' do
97
+
98
+ it 'only makes one request' do
99
+ pending
100
+ an_atis_request.should have_been_made.times 1
101
+ end
102
+
103
+ it 'requests the correct SOAP action' do
104
+ pending
105
+ an_atis_request_for('Nextbus2', 'Stopid' => '10496', 'Appid' => 'web').should have_been_made
106
+ end
107
+
108
+ it 'returns a non nil NextBus' do
109
+ pending
110
+ @next_bus.should_not be_nil
111
+ end
112
+
113
+ end
114
+
115
+ describe '#to_hash' do
116
+
117
+ it 'returns a subset of NextBus params' do
118
+ pending
119
+ hash = {
120
+ :stopname => 'FILLMORE ST & CENTRAL AVE',
121
+ :signs => ['7 7th Street to Union Hills Via Cent Station'],
122
+ :runs => [
123
+ { :time => next_bus_time_estimated, :adherence => '0', :route => '7', :sign => '7 7th Street to Union Hills Via Cent Station' }
124
+ ]
125
+ }
126
+
127
+ HashDiff.diff(@next_bus.to_hash, hash).should eql []
128
+ end
129
+ end
130
+
131
+ describe '#to_hash_for_xml' do
132
+
133
+ it 'returns a subset of NextBus params' do
134
+ pending
135
+ hash = {
136
+ :stopname => 'FILLMORE ST & CENTRAL AVE',
137
+ :runs => [
138
+ { :time => next_bus_time_estimated, :adherence => '0', :route => '7', :sign => '7 7th Street to Union Hills Via Cent Station', :scheduled_time => next_bus_time_scheduled }
139
+ ]
140
+ }
141
+
142
+ HashDiff.diff(@next_bus.to_hash_for_xml, hash).should eql []
143
+ end
144
+ end
145
+ end
146
+
147
+ end
148
+