require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe FlightLogExpense do describe 'fuel expense' do before :each do @fe = FlightLogExpense.new(:type => 1) end describe '#fuel_cost' do it 'should not have a cost if it doesnt have a quantity' do @fe.quantity = 0 @fe.fuel_cost.should == 0.0 end it 'should calculate cost based on quantity and rate' do @fe.quantity = 100 stub(@fe).fuel_rate { 4.0 } @fe.fuel_cost.should == 400.0 end end describe '#fuel_rate' do it 'should not have a rate if the airport fuel pricing cannnot be determined' do @fe.quantity = 100 stub(@fe).airport_fuel_lookup { {} } @fe.fuel_rate.should == 0.0 end describe 'different fuel tiers' do before do 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 } stub(@fe).airport_fuel_lookup { airport_fuel } end it 'find rate for quantity at lowest tier' do @fe.quantity = 100 @fe.fuel_rate.should == 3.93 end it 'find rate for quantity at middle tier' do @fe.quantity = 1001 @fe.fuel_rate.should == 3.73 end it 'find rate for quantity at highest tier' do @fe.quantity = 2002 @fe.fuel_rate.should == 3.62 end end end describe '#fuel_passdown_hash' do before :each do atlantic_fbo = AirportFbo.new( :name => "ATLANTIC AVIATION SERVIC" ) signature_fbo = AirportFbo.new( :name => "SIGNATURE FLIGHT SUPPORT" ) @trip_leg = TripLeg.new( :trip_number => 12345, :leg_number => 1, :aircraft_id => "C750", :departure_icao => "KSFO", :arrival_icao => "KTEB", :departure_fbo => signature_fbo, :arrival_fbo => atlantic_fbo, :dept_date_act_local => 40123, :depart_date_local => 40124 ) @vendor = Vendor.new( :company_2 => "Landmark Aviation", :company_1 => "Landmark", :vendor_id => "LMAR" ) stub(@fe).trip_leg { @trip_leg } stub(@fe).vendor { @vendor } stub(@fe).fuel_rate { 4.12 } @fe.quantity = 1234 @fe.arrival_airport = 0 @expected = { :leg_date => 40123, :trip_number => 12345, :leg_number => 1, :ac => "C750", :airport => "KTEB", :fbo => "ATLANTIC AVIATION SERVIC", :vendor => "Landmark Aviation", :fuel_rate => 4.12, :fuel_quantity => 1234, :fuel_cost => 5084.08 } end it 'should use arrival attributes if the expense is arrival' do @fe.arrival_airport = 1 @fe.fuel_passdown_hash.should == @expected end it 'should use departure attributes if the expense is departure' do @expected[:fbo] = "SIGNATURE FLIGHT SUPPORT" @expected[:airport] = "KSFO" @fe.fuel_passdown_hash.should == @expected end it 'should use vendor company_1 if company_2 is blank or nil' do @vendor.company_2 = "" @fe.fuel_passdown_hash[:vendor].should == "Landmark" end it 'should use vendor vendor_id if company_2 and company_1 are blank or nil' do @vendor.company_2 = "" @vendor.company_1 = "" @fe.fuel_passdown_hash[:vendor].should == "LMAR" end end end it 'should give the type as a string' do FlightLogExpense.new(:arrival_airport => 0).type_string.should == "departure" FlightLogExpense.new(:arrival_airport => 1).type_string.should == "arrival" end end