require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe TripLeg do describe "leg_status" do it "shows scheduled maint status" do t = TripLeg.filter(:trip_number=>68070,:leg_number=> 5).first t.leg_status.should == "MAINT" end end describe "arrival_airport assoc works" do before :all do set_fos_db([Airport]) end it "when there is an arrival_icao" do trip_leg = TripLeg.new(:arrival_icao=>'KSFO') trip_leg.arrival_airport.should_not == nil end it "when there is no arrival_icao but there is arrival_ap_prefix and arrival_airport_id" do trip_leg = TripLeg.new(:arrival_icao=>'', :arrival_ap_prefix=>'K', :arrival_airport_id=>'SFO') trip_leg.arrival_airport.should_not == nil end it "when there is no arrival_ap_prefix or arrival_airport_id" do trip_leg = TripLeg.new(:arrival_icao=>'', :arrival_ap_prefix=>'', :arrival_airport_id=>'') trip_leg.arrival_airport.should == nil end end describe "departure_airport assoc works" do before :all do set_fos_db([Airport]) end it "when there is an departure_icao" do trip_leg = TripLeg.new(:departure_icao=>'KSFO') trip_leg.departure_airport.should_not == nil end it "when there is no departure_icao but there is depart_ap_prefix and depart_airport_id" do trip_leg = TripLeg.new(:departure_icao=>'', :depart_ap_prefix=>'K', :depart_airport_id=>'SFO') trip_leg.departure_airport.should_not == nil end it "when there is no departure_icao or arrival_ap_prefix or arrival_airport_id" do trip_leg = TripLeg.new(:departure_icao=>'', :depart_ap_prefix=>'', :depart_airport_id=>'') trip_leg.departure_airport.should == nil end end it "ebt_time method produces correct Time with minutes" do dept_date_act_gmt = Date.new(2000, 1, 1) tl = TripLeg.new(:arrival_date_gmt=>dept_date_act_gmt.to_fos_days, :eta_gmt=>40, :dept_date_gmt=>dept_date_act_gmt.to_fos_days, :etd_gmt=>20) tl.ebt_time.should == Time.from_minutes(20) end it "ebt_time method produces correct Time with minutes" do dept_date_act_gmt = Date.new(2000, 1, 1) tl = TripLeg.new(:arrival_date_gmt=>dept_date_act_gmt.to_fos_days, :eta_gmt=>40, :dept_date_gmt=>dept_date_act_gmt.to_fos_days, :etd_gmt=>20) tl.ebt_time.should == Time.from_minutes(20) end it "actual take off date_time dates are after dept_date_act_gmt if take off time is less than depart time" do dept_date_act_gmt = Date.new(1900, 1, 1) tl = TripLeg.new(:dept_date_act_gmt=>dept_date_act_gmt.to_fos_days, :t_o_time_act_gmt=>20, :dept_time_act_gmt=>1420) tl.actual_takeoff_date_time_gmt.should == DateTime.new(1900, 1, 2, 0, 20, 0) end it "actual take off date_time dates are the same as dept_date_act_gmt if take off time is not less than depart time" do dept_date_act_gmt = Date.new(1900, 1, 1) tl = TripLeg.new(:dept_date_act_gmt=>dept_date_act_gmt.to_fos_days, :t_o_time_act_gmt=>40, :dept_time_act_gmt=>20) tl.actual_takeoff_date_time_gmt.should == DateTime.new(1900, 1, 1, 0, 40, 0) end it "actual landing date_time dates are before arr_date_act_gmt if on time time is greater than landing time" do arr_date_act_gmt = Date.new(1900, 1, 2) tl = TripLeg.new(:arrival_date_gmt=>arr_date_act_gmt.to_fos_days, :land_time_act_gmt=>1420, :arriv_time_act_gmt=>20) tl.actual_land_date_time_gmt.should == DateTime.new(1900, 1, 1, 23, 40, 0) end it "actual landing date_time dates are the same as arr_date_act_gmt if on time time is not greater than landing time" do arr_date_act_gmt = Date.new(1900, 1, 2) tl = TripLeg.new(:arrival_date_gmt=>arr_date_act_gmt.to_fos_days, :land_time_act_gmt=>20, :arriv_time_act_gmt=>40) tl.actual_land_date_time_gmt.should == DateTime.new(1900, 1, 2, 0, 20, 0) end it "actual arrival date_time base are correctly calculating the tz offset" do arr_date_act_gmt = Date.new(1900, 1, 2) arriv_time_act_gmt = 1420 home_tz_gmt_offset = -70 tl = TripLeg.new(:arrival_date_gmt => arr_date_act_gmt.to_fos_days, :arriv_time_act_gmt => arriv_time_act_gmt, :home_tz_gmt_offset => home_tz_gmt_offset) tl.actual_arrival_date_time_base.should == DateTime.new(1900, 1, 2, 16, 40, 0) end it "actual departure date_time base are correctly calculating the tz offset" do dept_date_act_gmt = Date.new(1900, 1, 2) dept_time_act_gmt = 1420 home_tz_gmt_offset = -70 tl = TripLeg.new(:dept_date_act_gmt => dept_date_act_gmt.to_fos_days, :dept_time_act_gmt => dept_time_act_gmt, :home_tz_gmt_offset=>home_tz_gmt_offset) tl.actual_departure_date_time_base.should == DateTime.new(1900, 1, 2, 16, 40, 0) end it "should properly convert nautical miles to statute miles with 1 significant digit" do tl = TripLeg.new(:nautical_miles => 285) tl.custom_statute_miles.should == 327.9 end it "should properly handle nautical miles to statute miles when nautical_miles is nil" do tl = TripLeg.new(:nautical_miles => nil) tl.custom_statute_miles.should == 0 end describe "should find correct passenger list" do before :each do @p1 = TripPassenger.new(:name=>"dan", :departure_leg_number=>0, :arrival_leg_number=>0, :lead_pax=>0) @p2 = TripPassenger.new(:name=>"rob", :departure_leg_number=>1, :arrival_leg_number=>1, :lead_pax=>0) @p3 = TripPassenger.new(:name=>"eric", :departure_leg_number=>1, :arrival_leg_number=>2, :lead_pax=>1) @t = Trip.new(:trip_number=>100) end it "when leg has no passengers" do mock(@t).passengers { [] } tl = TripLeg.new(:trip_number=>100, :leg_number=>1, :trip=>@t) tl.passenger_list.should == '' end it "when leg has some in range ( and put lead pax name first )" do stub(@t).passengers { [@p1, @p2, @p3] } tl = TripLeg.new(:trip_number=>100, :leg_number=>1, :verify_date=>0, :trip=>@t) tl.passenger_list.should == "eric (lead pax) : rob" end it "when leg has 1 in range" do stub(@t).passengers { [@p1, @p2, @p3] } tl = TripLeg.new(:trip_number=>100, :leg_number=>2, :verify_date=>0, :trip=>@t) tl.passenger_list.should == "eric (lead pax)" end it "when leg has none in range" do stub(@t).passengers { [@p1, @p2, @p3] } tl = TripLeg.new(:trip_number=>100, :leg_number=>3, :verify_date=>0, :trip=>@t) tl.passenger_list.should == "" end end it "method total_trip_statute_miles returns a value" do @t = Trip.new(:total_statute_miles=>100) tl = TripLeg.new(:trip_number=>100, :leg_number=>3, :trip=>@t) tl.total_trip_statute_miles.should == 10.0 end describe 'crew brief fields' do before :all do set_fos_db([TripLeg, Comment]) @trip_leg = TripLeg.first(:trip_number=>50885, :leg_number=>1) end it "catering departure value" do @trip_leg.catering_departure.should == 1 end it "departure fbo comment value" do @trip_leg.departure_fbo_comment_value.comment.should == "3028 Peacekeeper Way\r\nSacramento, CA 95652" end it "arrival fbo comment value" do @trip_leg.arrival_fbo_comment_value.comment.should == "Auto-selected FBO not preferred" end it "catering comment value" do @trip_leg.departure_catering_comment__comment.should == "Catering: Standard drinks and snacks for all live legs" end it "limo comment value" do @trip_leg.arrival_transport_comment__comment.should == "Transportation: Passenger arranged for all live legs" end it "crew fbo comment value" do @trip_leg.crew_fbo_comment_value.should == nil end end ## NEED TO REMOVE, TESTS SHOULD BE IN FlightLogExpense spec # describe "fuel passdown data columns" do # # it "query fuel info from real trip leg actually works" do # set_fos_db([TripLeg,AirportFuel,AirportFbo,FlightLogExpense]) ## trip_leg = TripLeg.first(:trip_number=>67579,:leg_number=>3) # trip_leg = TripLeg.first(:trip_number=>79203,:leg_number=>1) ## trip_leg = TripLeg.select(:'trip legs__trip_number'). ## filter(:trip_number=>67579,:leg_number=>3). ## inner_join(:flight_log_expense,) ## first ## p trip_leg.trip_number # trip_leg.dept_fuel_quantity.should == 433 # trip_leg.dept_fuel_cost.should == 1437.56 # trip_leg.dept_fuel_rate.should == 3.32 # trip_leg.arr_fuel_quantity.should == 0 # trip_leg.arr_fuel_cost.should == 0 # trip_leg.arr_fuel_rate.should == 0 # end # # describe "with airport fuel data" do # before :each do # #expect the method airport_fuel_lookup to be called and return a prepopulated hash # hash_with_airport_fuel = {:"qty 1"=>1, :"cost 1"=>393, # :"qty 2"=>1000, :"cost 2"=>373, # :"qty 3"=>2000, :"cost 3"=>362, # :"qty 4"=>0, :"cost 4"=>0, # :"qty 5"=>0, :"cost 5"=>0, # :"qty 6"=>0, :"cost 6"=>0, # :"qty 7"=>0, :"cost 7"=>0, # :"qty 8"=>0, :"cost 8"=>0, # :"qty 9"=>0, :"cost 9"=>0, # :"qty 10"=>0, :"cost 10"=>0, # :quantity=>970} # fe = FlightLogExpense.new(:type => 1,:arrival_airport => 0, :quantity => 970) # @tl = TripLeg.new # mock(@tl).airport_fuel_lookup(is_a(String)) {hash_with_airport_fuel} # stub(@tl).fuel_expense {fe} # end # # it "fuel quantity for leg with airport fuel" do # @tl.dept_fuel_quantity.should == 970 # @tl.arr_fuel_quantity.should == 0 # end # # it "fuel rate for leg with airport fuel" do # @tl.dept_fuel_rate.should == 3.93 # @tl.arr_fuel_rate.should == 0 # end # # it "fuel cost for leg with airport fuel" do # @tl.dept_fuel_cost.to_s.should == "3812.1" # @tl.arr_fuel_cost.to_s.should == "0" # end # end # # describe "without airport fuel data" do # before :each do # #expect the method airport_fuel_lookup to be called and return a prepopulated hash # hash_without_airport_fuel = {:quantity=>970} # @tl = TripLeg.new # fe = FlightLogExpense.new(:type => 1,:arrival_airport => 0, :quantity => 970) # mock(@tl).airport_fuel_lookup(is_a(String)) {hash_without_airport_fuel} # stub(@tl).fuel_expense {fe} # end # # it "fuel quantity for leg without airport fuel" do # @tl.dept_fuel_quantity.should == 970 # @tl.arr_fuel_quantity.should == 0 # end # # it "fuel rate for leg without airport fuel" do # @tl.dept_fuel_rate.should == 0 # @tl.arr_fuel_rate.should == 0 # end # # it "fuel cost for leg without airport fuel" do # @tl.dept_fuel_cost.should == 0 # @tl.arr_fuel_cost.should == 0 # end # end # end # # describe "without any data at all" do # before :each do ## hash_without_any_data = nil # @tl = TripLeg.new # fe = nil ## mock(@tl).airport_fuel_lookup(is_a(String)) {hash_without_any_data} # stub(@tl).fuel_expense {fe} # end # # it "fuel quantity for leg without any data" do # @tl.dept_fuel_quantity.should == 0 # @tl.arr_fuel_quantity.should == 0 # end # # it "fuel rate for leg without any data" do # @tl.dept_fuel_rate.should == 0 # @tl.arr_fuel_rate.should == 0 # end # # it "fuel cost for leg without any data" do # @tl.dept_fuel_cost.should == 0 # @tl.arr_fuel_cost.should == 0 # end # end # # # FUEL PASSDOWN SPECS # describe "different tier pricing selection" do # it "has fuel qty <= second lowest tier" do # fuel_data_hash = { :"qty 1"=>1, :"cost 1"=>393, # :"qty 2"=>1000, :"cost 2"=>373, # :"qty 3"=>2000, :"cost 3"=>362, # :"qty 4"=>0, :"cost 4"=>0, # :"qty 5"=>0, :"cost 5"=>0, # :"qty 6"=>0, :"cost 6"=>0, # :"qty 7"=>0, :"cost 7"=>0, # :"qty 8"=>0, :"cost 8"=>0, # :"qty 9"=>0, :"cost 9"=>0, # :"qty 10"=>0, :"cost 10"=>0, # :quantity=>970} # tl = TripLeg.new # fe = FlightLogExpense.new(:type => 1,:arrival_airport => 0, :quantity => 970) # mock(tl).airport_fuel_lookup(is_a(String)).times(2) {fuel_data_hash} # stub(tl).fuel_expense {fe} # tl.dept_fuel_cost.to_s.should == "3812.1" # # fe.arrival_airport = 1 # stub(tl).fuel_expense {fe} # tl.arr_fuel_cost.to_s.should == "3812.1" # end # # it "has fuel qty >= highest tier" do # fuel_data_hash = { :"qty 1"=>1, :"cost 1"=>393, # :"qty 2"=>1000, :"cost 2"=>373, # :"qty 3"=>2000, :"cost 3"=>362, # :"qty 4"=>3000, :"cost 4"=>352, # :"qty 5"=>4000, :"cost 5"=>342, # :"qty 6"=>5000, :"cost 6"=>332, # :"qty 7"=>6000, :"cost 7"=>322, # :"qty 8"=>7000, :"cost 8"=>312, # :"qty 9"=>8000, :"cost 9"=>302, # :"qty 10"=>9000, :"cost 10"=>292, # :quantity=>10000} # tl = TripLeg.new # fe = FlightLogExpense.new(:type => 1,:arrival_airport => 0, :quantity=>10000) # mock(tl).airport_fuel_lookup(is_a(String)).times(2) {fuel_data_hash} # stub(tl).fuel_expense {fe} # # tl.dept_fuel_cost.should == 29200 # # fe.arrival_airport = 1 # stub(tl).fuel_expense {fe} # tl.arr_fuel_cost.should == 29200 # end # # it "has fuel qty in the middle of fuel tiers" do # fuel_data_hash = { :"qty 1"=>1, :"cost 1"=>393, # :"qty 2"=>1000, :"cost 2"=>373, # :"qty 3"=>2000, :"cost 3"=>362, # :"qty 4"=>0, :"cost 4"=>0, # :"qty 5"=>0, :"cost 5"=>0, # :"qty 6"=>0, :"cost 6"=>0, # :"qty 7"=>0, :"cost 7"=>0, # :"qty 8"=>0, :"cost 8"=>0, # :"qty 9"=>0, :"cost 9"=>0, # :"qty 10"=>0, :"cost 10"=>0, # :quantity=>1100} # tl = TripLeg.new # fe = FlightLogExpense.new(:type => 1,:arrival_airport => 0, :quantity=>1100) # mock(tl).airport_fuel_lookup(is_a(String)).times(2) {fuel_data_hash} # stub(tl).fuel_expense {fe} # # tl.dept_fuel_cost.should == 4103 # # fe.arrival_airport = 1 # stub(tl).fuel_expense {fe} # tl.arr_fuel_cost.should == 4103 # end # end # END FUEL PASSDOWN RELATED TESTS #### end