require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe TripLeg do 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(:arr_date_act_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 no pax/deadhead" do ## tl = TripLeg.new(:trip_number=>100,:leg_number=>1, :trip=>@t, :status=>1,:deadhead=>1) ## 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) # @trip_leg = TripLeg.first(:trip_number=>76478,:leg_number=>1) # @trip_leg = TripLeg.first(~:fueler_comment=>0,~:catering_comment=>0,~:limo_comment=>0) end it "comment field" do @trip_leg.comment_value.comment.should =="Contact: Chris Kelley 415-927-2123" 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 "catering comment value" do @trip_leg.catering_comment_value.comment.should == "Catering: Standard drinks and snacks for all live legs" end it "limo comment value" do @trip_leg.limo_comment_value.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 end