From 05410a0b2e8338c2d74cc45ad1c066b3a914c4b7 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Wed, 22 Nov 2023 19:02:30 -0500 Subject: [PATCH] Leverage fixtures for expense test --- test/fixtures/expenses.yml | 30 ++++++++++++++++++++++-------- test/models/expense_test.rb | 29 ++++------------------------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/test/fixtures/expenses.yml b/test/fixtures/expenses.yml index 3c0ef47..5e267f5 100644 --- a/test/fixtures/expenses.yml +++ b/test/fixtures/expenses.yml @@ -1,15 +1,29 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - description: MyString - payment: 9.99 - period: 1 +monthly_expense: + description: Monthly Expense + payment: 120.00 + period: monthly + credit_card: true + estimated: false + +annual_expense: + description: Annual Expense + payment: 120.00 + period: annually + credit_card: true + estimated: false + +weekly_expense: + description: Weekly Expense + payment: 120.00 + period: weekly credit_card: false estimated: false -two: - description: MyString - payment: 9.99 - period: 1 +quarterly_expense: + description: Quarterly Expense + payment: 120.00 + period: quarterly credit_card: false estimated: false diff --git a/test/models/expense_test.rb b/test/models/expense_test.rb index 1b3389a..97e0831 100644 --- a/test/models/expense_test.rb +++ b/test/models/expense_test.rb @@ -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