Sha256: 90cfe85095ef3e4d289555d0d9ac8ee710638c8ed9e63846642681cd6a0e920a

Contents?: true

Size: 1.99 KB

Versions: 7

Compression:

Stored size: 1.99 KB

Contents

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 :each 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
  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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fossil-0.5.47 spec/models/flight_log_expense_spec.rb
fossil-0.5.46 spec/models/flight_log_expense_spec.rb
fossil-0.5.45 spec/models/flight_log_expense_spec.rb
fossil-0.5.44 spec/models/flight_log_expense_spec.rb
fossil-0.5.43 spec/models/flight_log_expense_spec.rb
fossil-0.5.42 spec/models/flight_log_expense_spec.rb
fossil-0.5.41 spec/models/flight_log_expense_spec.rb