Leverage fixtures for expense test

This commit is contained in:
Andrew Tomaka 2023-11-22 19:02:30 -05:00
parent 2fff930794
commit 05410a0b2e
Signed by: atomaka
GPG key ID: 61209BF70A5B18BE
2 changed files with 26 additions and 33 deletions

View file

@ -2,59 +2,38 @@ require "test_helper"
class ExpenseTest < ActiveSupport::TestCase
def test_monthly_converts_period_for_monthly
expense = Expense.new(period: :monthly, payment: 120.00)
expense = expenses(:monthly_expense)
assert_equal 120.00, expense.monthly
end
def test_monthly_converts_period_for_annually
expense = Expense.new(period: :annually, payment: 120.00)
expense = expenses(:annual_expense)
assert_equal 10.00, expense.monthly
end
def test_monthly_converts_period_for_weekly
expense = Expense.new(period: :weekly, payment: 120.00)
expense = expenses(:weekly_expense)
assert_equal 520.00, expense.monthly
end
def test_monthly_converts_period_for_quarterly
expense = Expense.new(period: :quarterly, payment: 120.00)
expense = expenses(:quarterly_expense)
assert_equal 40.00, expense.monthly
end
def test_total_calculates_total_of_expenses
Expense.destroy_all
Expense.create!(period: :monthly, payment: 120.00)
Expense.create!(period: :annually, payment: 120.00)
Expense.create!(period: :weekly, payment: 120.00)
Expense.create!(period: :quarterly, payment: 120.00)
assert_equal 480.00, Expense.total
end
def test_total_calculates_monthly_total
Expense.destroy_all
Expense.create!(period: :monthly, payment: 120.00)
Expense.create!(period: :annually, payment: 120.00)
Expense.create!(period: :weekly, payment: 120.00)
Expense.create!(period: :quarterly, payment: 120.00)
assert_equal 690.00, Expense.monthly_total
end
def test_total_calculates_credit_card_monthly_total
Expense.destroy_all
Expense.create!(period: :monthly, payment: 120.00, credit_card: true)
Expense.create!(period: :annually, payment: 120.00, credit_card: true)
Expense.create!(period: :weekly, payment: 120.00)
Expense.create!(period: :quarterly, payment: 120.00)
assert_equal 130.00, Expense.credit_card_monthly_total
end
end