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 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, :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, :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, :trip=>@t) tl.passenger_list.should == "" end end end