Sha256: a3fb18e87f946247c478b6073c89f6e5dc62ae7d511b235b9d1d8a6e175e36a3

Contents?: true

Size: 1.78 KB

Versions: 10

Compression:

Stored size: 1.78 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
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
fossil-0.5.40 spec/models/flight_log_expense_spec.rb
fossil-0.5.39 spec/models/flight_log_expense_spec.rb
fossil-0.5.38 spec/models/flight_log_expense_spec.rb
fossil-0.5.37 spec/models/flight_log_expense_spec.rb
fossil-0.5.36 spec/models/flight_log_expense_spec.rb
fossil-0.5.35 spec/models/flight_log_expense_spec.rb
fossil-0.5.34 spec/models/flight_log_expense_spec.rb
fossil-0.5.33 spec/models/flight_log_expense_spec.rb
fossil-0.5.32 spec/models/flight_log_expense_spec.rb
fossil-0.5.31 spec/models/flight_log_expense_spec.rb