fossil 0.5.31 → 0.5.32
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/fossil.gemspec +1 -1
- data/lib/models/trip_leg.rb +12 -0
- data/spec/models/trip_leg_spec.rb +126 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.32
|
data/fossil.gemspec
CHANGED
data/lib/models/trip_leg.rb
CHANGED
@@ -925,4 +925,16 @@ class TripLeg < Sequel::Model(:'trip legs')
|
|
925
925
|
def total_fuel_cost
|
926
926
|
arrival_fuel_cost + departure_fuel_cost
|
927
927
|
end
|
928
|
+
|
929
|
+
def departure_fuel_purchased_quantity
|
930
|
+
departure_fuel_expenses.inject(0) { |sum, e| sum + e.quantity.to_i }
|
931
|
+
end
|
932
|
+
|
933
|
+
def arrival_fuel_purchased_quantity
|
934
|
+
arrival_fuel_expenses.inject(0) { |sum, e| sum + e.quantity.to_i }
|
935
|
+
end
|
936
|
+
|
937
|
+
def total_fuel_purchased_quantity
|
938
|
+
departure_fuel_purchased_quantity + arrival_fuel_purchased_quantity
|
939
|
+
end
|
928
940
|
end
|
@@ -359,5 +359,131 @@ describe TripLeg do
|
|
359
359
|
@tl.total_fuel_cost.should == 200.0
|
360
360
|
end
|
361
361
|
end
|
362
|
+
|
363
|
+
describe 'arrival fuel quantity' do
|
364
|
+
|
365
|
+
it 'should not have a quantity if there are no fuel flight log expenses' do
|
366
|
+
@tl.arrival_fuel_purchased_quantity.should == 0.0
|
367
|
+
end
|
368
|
+
|
369
|
+
it 'should have a quantity if there is an arrival fuel flight log expense' do
|
370
|
+
fe = FlightLogExpense.new(:type => 1, :arrival_airport => 1)
|
371
|
+
fe.quantity = 300
|
372
|
+
stub(@tl).fuel_expenses { [fe] }
|
373
|
+
|
374
|
+
@tl.arrival_fuel_purchased_quantity.should == 300
|
375
|
+
end
|
376
|
+
|
377
|
+
it 'should not have a quantity if the fuel flight log expense is not arrival' do
|
378
|
+
fe = FlightLogExpense.new(:type => 1, :arrival_airport => 0)
|
379
|
+
fe.quantity = 300
|
380
|
+
stub(@tl).fuel_expenses { [fe] }
|
381
|
+
|
382
|
+
@tl.arrival_fuel_purchased_quantity.should == 0
|
383
|
+
end
|
384
|
+
|
385
|
+
it 'should total the quantities if there are more than one fuel flight log expenses' do
|
386
|
+
fles = []
|
387
|
+
(1..4).each do |n|
|
388
|
+
fe = FlightLogExpense.new(:type => 1, :arrival_airport => 1)
|
389
|
+
fe.quantity = n * 100
|
390
|
+
fles << fe
|
391
|
+
end
|
392
|
+
stub(@tl).fuel_expenses { fles }
|
393
|
+
|
394
|
+
@tl.arrival_fuel_purchased_quantity.should == 1000.0
|
395
|
+
end
|
396
|
+
|
397
|
+
it 'should total the quantities but only for fuel expenses that are arrival, ignoring departures' do
|
398
|
+
fles = []
|
399
|
+
(1..4).each do |n|
|
400
|
+
arrival = ( n > 2 ? 1 : 0 )
|
401
|
+
fe = FlightLogExpense.new(:type => 1, :arrival_airport => arrival)
|
402
|
+
fe.quantity = n * 100
|
403
|
+
fles << fe
|
404
|
+
end
|
405
|
+
stub(@tl).fuel_expenses { fles }
|
406
|
+
|
407
|
+
@tl.arrival_fuel_purchased_quantity.should == 700.0
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
describe 'departure fuel quantity' do
|
412
|
+
|
413
|
+
it 'should not have a quantity if there are no fuel flight log expenses' do
|
414
|
+
@tl.departure_fuel_purchased_quantity.should == 0.0
|
415
|
+
end
|
416
|
+
|
417
|
+
it 'should have a quantity if there is an departure fuel flight log expense' do
|
418
|
+
fe = FlightLogExpense.new(:type => 1, :arrival_airport => 0)
|
419
|
+
fe.quantity = 300
|
420
|
+
stub(@tl).fuel_expenses { [fe] }
|
421
|
+
|
422
|
+
@tl.departure_fuel_purchased_quantity.should == 300
|
423
|
+
end
|
424
|
+
|
425
|
+
it 'should not have a quantity if the fuel flight log expense is not departure' do
|
426
|
+
fe = FlightLogExpense.new(:type => 1, :arrival_airport => 1)
|
427
|
+
fe.quantity = 300
|
428
|
+
stub(@tl).fuel_expenses { [fe] }
|
429
|
+
|
430
|
+
@tl.departure_fuel_purchased_quantity.should == 0
|
431
|
+
end
|
432
|
+
|
433
|
+
it 'should total the quantities if there are more than one fuel flight log expenses' do
|
434
|
+
fles = []
|
435
|
+
(1..4).each do |n|
|
436
|
+
fe = FlightLogExpense.new(:type => 1, :arrival_airport => 0)
|
437
|
+
fe.quantity = n * 100
|
438
|
+
fles << fe
|
439
|
+
end
|
440
|
+
stub(@tl).fuel_expenses { fles }
|
441
|
+
|
442
|
+
@tl.departure_fuel_purchased_quantity.should == 1000.0
|
443
|
+
end
|
444
|
+
|
445
|
+
it 'should total the quantities but only for fuel expenses that are departure, ignoring arrivals' do
|
446
|
+
fles = []
|
447
|
+
(1..4).each do |n|
|
448
|
+
arrival = ( n <= 2 ? 1 : 0 )
|
449
|
+
fe = FlightLogExpense.new(:type => 1, :arrival_airport => arrival)
|
450
|
+
fe.quantity = n * 100
|
451
|
+
fles << fe
|
452
|
+
end
|
453
|
+
stub(@tl).fuel_expenses { fles }
|
454
|
+
|
455
|
+
@tl.departure_fuel_purchased_quantity.should == 700.0
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
describe 'total fuel quantities' do
|
460
|
+
it 'should not have a total quantity if there are no fuel flight log expenses' do
|
461
|
+
stub(@tl).departure_fuel_purchased_quantity { 0 }
|
462
|
+
stub(@tl).arrival_fuel_purchased_quantity { 0 }
|
463
|
+
|
464
|
+
@tl.total_fuel_purchased_quantity.should == 0.0
|
465
|
+
end
|
466
|
+
|
467
|
+
it 'should have a total quantity if there are departure fuel expense quantities' do
|
468
|
+
stub(@tl).departure_fuel_purchased_quantity { 100.0 }
|
469
|
+
stub(@tl).arrival_fuel_purchased_quantity { 0.0 }
|
470
|
+
|
471
|
+
@tl.total_fuel_purchased_quantity.should == 100.0
|
472
|
+
end
|
473
|
+
|
474
|
+
it 'should have a total quantity if there are arrival fuel expense quantities' do
|
475
|
+
stub(@tl).departure_fuel_purchased_quantity { 0.0 }
|
476
|
+
stub(@tl).arrival_fuel_purchased_quantity { 100.0 }
|
477
|
+
|
478
|
+
@tl.total_fuel_purchased_quantity.should == 100.0
|
479
|
+
end
|
480
|
+
|
481
|
+
it 'should have a total quantity if there are both arrival and departure fuel expense quantities' do
|
482
|
+
stub(@tl).departure_fuel_purchased_quantity { 100.0 }
|
483
|
+
stub(@tl).arrival_fuel_purchased_quantity { 100.0 }
|
484
|
+
|
485
|
+
@tl.total_fuel_purchased_quantity.should == 200.0
|
486
|
+
end
|
487
|
+
end
|
362
488
|
end
|
363
489
|
end
|