Skip to content

Instantly share code, notes, and snippets.

@kibaekr
Created January 24, 2013 21:23
Show Gist options
  • Save kibaekr/4627888 to your computer and use it in GitHub Desktop.
Save kibaekr/4627888 to your computer and use it in GitHub Desktop.
module Ratis
class RoutePattern
attr_accessor :description, :area, :lat, :long, :point, :atisstopid, :stopid
def self.where(conditions)
#just trying to find by date for now. once this works, will add servicetype condition
date = conditions.delete(:date).to_s.upcase
raise ArgumentError.new('You must provide a date') if date.blank?
#not sure what below code does
Ratis.all_conditions_used? conditions
response = Request.get 'Routepattern', {'Date' => date}
return [] unless response.success?
response.to_array(:routepattern_response, :stops, :stop).map do |stop|
atis_stop = RoutePattern.new
atis_stop.description = stop[:description]
atis_stop.area = stop[:area]
atis_stop.lat = stop[:lat]
atis_stop.long = stop[:long]
atis_stop.point = stop[:point]
atis_stop.atisstopid = stop[:atisstopid]
atis_stop.stopid = stop[:stopid]
atis_stop
end
end
end
end
require 'spec_helper'
describe Ratis::RoutePattern do
before do
stub_atis_request.to_return( atis_response 'Routepattern', '1.5', '0', <<-BODY )
<Stops>
<Stop>
<Description>text description of the stop</Description>
<Area> area description </Area>
<Lat> 32 </Lat>
<Long> 60 </Long>
<Point> ±dd.nnnnnn, ±ddd.nnnnnn </Point>
<Atisstopid> NNNNN </Atisstopid>
<Stopid> string </Stopid>
</Stop>
<Stop>
<Description>text description of the stop 2</Description>
<Area> area description 2 </Area>
<Lat> 322 </Lat>
<Long> 602 </Long>
<Point> ±dd.nnnnnn, ±ddd.nnnnnn </Point>
<Atisstopid> SSSSS </Atisstopid>
<Stopid> string 2 </Stopid>
</Stop>
</Stops>
BODY
#### what do i substitute for :date => :all?
@stops = Ratis::RoutePattern.where :date => 11/11/11
end
it 'only makes one request' do
an_atis_request.should have_been_made.times 1
end
it 'requests the correct SOAP action' do
an_atis_request_for('Routepattern', 'Date' => 'ALL').should have_been_made
end
it 'should return all stops' do
@stops.should have(2).items
@stops[0].description.should eql 'text description of the stop'
@stops[0].area.should eql 'area description'
@stops[0].lat.should eql '32'
@stops[0].long.should eql '60'
@stops[0].point.should eql '±dd.nnnnnn, ±ddd.nnnnnn'
@stops[0].atisstopid.should eql 'NNNNN'
@stops[0].stopid.should eql 'string'
@stops[1].description.should eql 'text description of the stop 2'
@stops[1].area.should eql 'area description 2'
@stops[1].lat.should eql '322'
@stops[1].long.should eql '602'
@stops[1].point.should eql '±dd.nnnnnn, ±ddd.nnnnnn'
@stops[1].atisstopid.should eql 'SSSSS'
@stops[1].stopid.should eql 'string 2'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment