@@ -453,4 +453,55 @@ class BudgetTest < ActiveSupport::TestCase
453453 # Other Investments synthetic categories previously caused this to return 0
454454 assert spending >= 75 , "Uncategorized actual spending should include the $75 transaction, got #{ spending } "
455455 end
456+
457+ test "actual_spending and actual_income exclude one-time transactions" do
458+ family = families ( :empty )
459+ account = family . accounts . create! (
460+ name : "Checking" ,
461+ currency : family . currency ,
462+ balance : 5000 ,
463+ accountable : Depository . new
464+ )
465+ income_category = family . categories . create! ( name : "Income" )
466+ expense_category = family . categories . create! ( name : "Groceries" )
467+
468+ Entry . create! (
469+ account : account ,
470+ entryable : Transaction . create! ( category : expense_category , kind : "standard" ) ,
471+ date : Date . current ,
472+ name : "Groceries" ,
473+ amount : 100 ,
474+ currency : family . currency
475+ )
476+ Entry . create! (
477+ account : account ,
478+ entryable : Transaction . create! ( category : expense_category , kind : "one_time" ) ,
479+ date : Date . current ,
480+ name : "One-time expense" ,
481+ amount : 250 ,
482+ currency : family . currency
483+ )
484+ Entry . create! (
485+ account : account ,
486+ entryable : Transaction . create! ( category : income_category , kind : "standard" ) ,
487+ date : Date . current ,
488+ name : "Paycheck" ,
489+ amount : -500 ,
490+ currency : family . currency
491+ )
492+ Entry . create! (
493+ account : account ,
494+ entryable : Transaction . create! ( category : income_category , kind : "one_time" ) ,
495+ date : Date . current ,
496+ name : "One-time bonus" ,
497+ amount : -300 ,
498+ currency : family . currency
499+ )
500+
501+ budget = Budget . find_or_bootstrap ( family , start_date : Date . current . beginning_of_month )
502+ budget = Budget . find ( budget . id )
503+
504+ assert_equal 100 , budget . actual_spending
505+ assert_equal 500 , budget . actual_income
506+ end
456507end
0 commit comments