require 'spec_helper' describe Ratis::Itinerary do describe 'single itinerary, single service' do before do stub_atis_request.to_return( atis_response 'Plantrip', '1.27', '0', <<-BODY ) 33.452082 -112.074374 0 Origin 33.446347 -112.068689 0 Destination 07/26/2012 T N D 2.00 0.4 0.4 0.4 N 0 0.21 W Y VAN BUREN/1ST AVE LIGHT RAIL STATION 1859 VAN BUREN/1ST AVE LIGHT RAIL STATION PH 33.452252 -112.075081 07/26/12 10880 10012 N 11 O NB Far N LTRL Metro light rail To Sycamore/Main E METRO W 46880 17074 14 N L N 0 0.000000 0.000000 N 0 0 0 1.75 0.00 0.85 0.00 3RD STREET/JEFFERSON LIGHT RAIL STATION 1903 3RD STREET/JEFFERSON LIGHT RAIL STATION PH 33.446270 -112.069777 07/26/12 10892 10014 N 13 O NB Far N 0.07 E Y 4 1.75 0.85 1|0|1.75|0.85~W|06:59 PM|07:03 PM|LTRL| |W|E|L|12|0|1956|14|46880|METRO|10880|11|10892|13|BUSFARE|0|0|0|R~ 1|46880|11|13 N 0.63 0.92 0.260 0.881 BODY @itineraries = Ratis::Itinerary.where( :date => '07/26/2012', :time => '1843', :minimize => 'T', :origin_lat => '33.452082', :origin_long => '-112.074374', :destination_lat => '33.446347', :destination_long => '-112.068689' ) end describe '#where' do 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('Plantrip', 'Date' => '07/26/2012', 'Time' => '1843', 'Minimize' => 'T', 'Originlat' => '33.452082', 'Originlong' => '-112.074374', 'Destinationlat' => '33.446347', 'Destinationlong' => '-112.068689' ).should have_been_made end it 'returns one itinerary' do @itineraries.should have(1).item @itineraries.first.should be_a_kind_of Ratis::Itinerary end end describe '#legs' do it 'returns one leg' do @itineraries.first.legs.should have(1).item @itineraries.first.legs.first.should_not be_nil end end it 'marshalls the members to their correct type' do itinerary = @itineraries.first itinerary.co2_auto = 0.881 itinerary.co2_transit = 0.260 itinerary.final_walk_dir = 'E' itinerary.reduced_fare = 0.85 itinerary.regular_fare = 1.75 itinerary.transit_time = 4 end end describe 'three itineraries, each with multiple service' do before do stub_atis_request.to_return( atis_response 'Plantrip', '1.27', '0', <<-BODY ) 33.452082 -112.074374 7234 CENTRAL STATION 33.432254 -111.904625 7542 TEMPE MARKETPLACE 07/31/2012 T N D 2.00 0.50 0.50 0.50 N 0 0.21 W Y VAN BUREN/1ST AVE LIGHT RAIL STATION 0931 VAN BUREN/1ST AVE LIGHT RAIL STATION PH 33.452252 -112.075081 07/31/12 10880 10012 N 11 O NB Far N LTRL Metro light rail To Sycamore/Main E METRO W 46860 17027 3 N L N 0 0.000000 0.000000 N 0 0 0 1.75 0.00 0.85 0.00 MCCLINTOCK DR/APACHE LIGHT RAIL STATION 1007 MCCLINTOCK DR/APACHE LIGHT RAIL STATION TE 33.414688 -111.908882 07/31/12 10887 10025 N 26 O NB Far N 0 N MCCLINTOCK DR & APACHE BLVD 1013 MCCLINTOCK DR & APACHE BLVD TE 33.414938 -111.909100 07/31/12 3431 15090 N 32 O NB Far N 81 81 Haydn/Mclintk To Raintree/Nrthsight N VEOLIA-TEM W 38240 4082 4 N B N 0 0.000000 0.000000 N 0 0 0 1.75 0.00 0.85 0.00 TEMPE MARKETPLACE 1020 TEMPE MARKETPLACE TE 33.432256 -111.904661 07/31/12 10453 14167 N 36 unknown N 0 N 49 3.50 1.70 2|0|3.50|1.70~W|09:31 AM|10:07 AM|LTRL| |W|E|L|10|0|1944|3|46860|METRO|10880|11|10887|26|BUSFARE|0|0|0|R~T|10:13 AM|10:20 AM|81| |W|N|B|2|0|1609|4|38240|VEOLIA-TEM|3431|32|10453|36|BUSFARE|0|0|0|B~ 2|46860|11|26|38240|32|36 N 12.39 12.63 5.437 12.125 0.21 W Y VAN BUREN/1ST AVE LIGHT RAIL STATION 0931 VAN BUREN/1ST AVE LIGHT RAIL STATION PH 33.452252 -112.075081 07/31/12 10880 10012 N 11 O NB Far N LTRL Metro light rail To Sycamore/Main E METRO W 46860 17027 3 N L N 0 0.000000 0.000000 N 0 0 0 1.75 0.00 0.85 0.00 VETERANS WAY/COLLEGE LIGHT RAIL STATION 0959 VETERANS WAY/COLLEGE LIGHT RAIL STATION TE 33.426222 -111.936477 07/31/12 10895 10022 N 22 O NB Far N 0 N TEMPE TRANSIT CENTER NORTH SIDE 1031 TEMPE TRANSIT CENTER NORTH SIDE TE 33.425740 -111.935929 07/31/12 11042 14163 N 42 unknown N 62 62 Hardy/Guadalupe To Tempe Marketplace N VEOLIA-TEM W 37140 4049 5 N B N 0 0.000000 0.000000 N 0 0 0 1.75 0.00 0.85 0.00 TEMPE MARKETPLACE 1044 TEMPE MARKETPLACE TE 33.432256 -111.904661 07/31/12 10453 14167 N 51 unknown N 0 N 73 3.50 1.70 2|0|3.50|1.70~W|09:31 AM|09:59 AM|LTRL| |W|E|L|10|0|1944|3|46860|METRO|10880|11|10895|22|BUSFARE|0|0|0|R~T|10:31 AM|10:44 AM|62| |W|N|B|1|0|1279|5|37140|VEOLIA-TEM|11042|42|10453|51|BUSFARE|0|0|0|B~ 2|46860|11|22|37140|42|51 N 11.82 12.08 5.520 11.597 0.21 W Y VAN BUREN/1ST AVE LIGHT RAIL STATION 0931 VAN BUREN/1ST AVE LIGHT RAIL STATION PH 33.452252 -112.075081 07/31/12 10880 10012 N 11 O NB Far N LTRL Metro light rail To Sycamore/Main E METRO W 46860 17027 3 N L N 0 0.000000 0.000000 N 0 0 0 1.75 0.00 0.85 0.00 MCCLINTOCK DR/APACHE LIGHT RAIL STATION 1007 MCCLINTOCK DR/APACHE LIGHT RAIL STATION TE 33.414688 -111.908882 07/31/12 10887 10025 N 26 O NB Far N 0 N MCCLINTOCK DR & APACHE BLVD 1043 MCCLINTOCK DR & APACHE BLVD TE 33.414938 -111.909100 07/31/12 3431 15090 N 32 O NB Far N 81 81 Haydn/Mclintk To Raintree/Nrthsight N VEOLIA-TEM W 38241 4085 4 N B N 0 0.000000 0.000000 N 0 0 0 1.75 0.00 0.85 0.00 TEMPE MARKETPLACE 1050 TEMPE MARKETPLACE TE 33.432256 -111.904661 07/31/12 10453 14167 N 36 unknown N 0 N 79 3.50 1.70 2|0|3.50|1.70~W|09:31 AM|10:07 AM|LTRL| |W|E|L|10|0|1944|3|46860|METRO|10880|11|10887|26|BUSFARE|0|0|0|R~T|10:43 AM|10:50 AM|81| |W|N|B|2|0|1610|4|38241|VEOLIA-TEM|3431|32|10453|36|BUSFARE|0|0|0|B~ 2|46860|11|26|38241|32|36 N 12.39 12.63 5.437 12.125 BODY @itineraries = Ratis::Itinerary.where( :date => '07/31/2012', :time => '0914', :minimize => 'T', :origin_lat => '33.452082', :origin_long => '-112.074374', :destination_lat => '33.432254', :destination_long => '-111.904625' ) end describe '#where' do 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('Plantrip', 'Date' => '07/31/2012', 'Time' => '0914', 'Minimize' => 'T', 'Originlat' => '33.452082', 'Originlong' => '-112.074374', 'Destinationlat' => '33.432254', 'Destinationlong' => '-111.904625' ).should have_been_made end it 'returns three itineraries' do @itineraries.should have(3).item @itineraries.each { |itin| itin.should be_a_kind_of Ratis::Itinerary } end end end end