From b460ae31cf0bbbf9cefd49c06f222207fab455f0 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Wed, 22 Nov 2023 18:51:53 -0500 Subject: [PATCH 1/7] Add model tests for Expense --- test/models/expense_test.rb | 59 +++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/test/models/expense_test.rb b/test/models/expense_test.rb index 67ac22a..1b3389a 100644 --- a/test/models/expense_test.rb +++ b/test/models/expense_test.rb @@ -1,7 +1,60 @@ require "test_helper" class ExpenseTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def test_monthly_converts_period_for_monthly + expense = Expense.new(period: :monthly, payment: 120.00) + + assert_equal 120.00, expense.monthly + end + + def test_monthly_converts_period_for_annually + expense = Expense.new(period: :annually, payment: 120.00) + + assert_equal 10.00, expense.monthly + end + + def test_monthly_converts_period_for_weekly + expense = Expense.new(period: :weekly, payment: 120.00) + + assert_equal 520.00, expense.monthly + end + + def test_monthly_converts_period_for_quarterly + expense = Expense.new(period: :quarterly, payment: 120.00) + + 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 -- 2.45.2 From 2fff930794d5a9d9d02fc4f1e7ddcc02e54277eb Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Wed, 22 Nov 2023 18:58:53 -0500 Subject: [PATCH 2/7] Add income tests --- test/fixtures/incomes.yml | 22 ++++++++++++++-------- test/models/income_test.rb | 6 +++--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/test/fixtures/incomes.yml b/test/fixtures/incomes.yml index 7bf8b25..16c5156 100644 --- a/test/fixtures/incomes.yml +++ b/test/fixtures/incomes.yml @@ -1,13 +1,19 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - description: MyString - included: false - amount: 9.99 +included_1: + description: Salary + included: true + amount: 85_000.00 member: one -two: - description: MyString +included_2: + description: Salary + included: true + amount: 15_000.00 + member: one + +excluded: + description: Bonus included: false - amount: 9.99 - member: two + amount: 10_000 + member: one diff --git a/test/models/income_test.rb b/test/models/income_test.rb index 0b7dc86..a582f18 100644 --- a/test/models/income_test.rb +++ b/test/models/income_test.rb @@ -1,7 +1,7 @@ require "test_helper" class IncomeTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def test_total + assert_equal 100_000.00, Income.total + end end -- 2.45.2 From 05410a0b2e8338c2d74cc45ad1c066b3a914c4b7 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Wed, 22 Nov 2023 19:02:30 -0500 Subject: [PATCH 3/7] 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 -- 2.45.2 From c0e0c4ef8f6ea039e6b98b948baa89fc440dccaa Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Wed, 22 Nov 2023 19:04:00 -0500 Subject: [PATCH 4/7] Use new fixtures for controller tests --- test/controllers/expenses_controller_test.rb | 2 +- test/controllers/incomes_controller_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/controllers/expenses_controller_test.rb b/test/controllers/expenses_controller_test.rb index 4f218a6..4a69bbb 100644 --- a/test/controllers/expenses_controller_test.rb +++ b/test/controllers/expenses_controller_test.rb @@ -2,7 +2,7 @@ require "test_helper" class ExpensesControllerTest < ActionDispatch::IntegrationTest setup do - @expense = expenses(:one) + @expense = expenses(:monthly_expense) end test "should get index" do diff --git a/test/controllers/incomes_controller_test.rb b/test/controllers/incomes_controller_test.rb index 361a2f4..ced234a 100644 --- a/test/controllers/incomes_controller_test.rb +++ b/test/controllers/incomes_controller_test.rb @@ -2,7 +2,7 @@ require "test_helper" class IncomesControllerTest < ActionDispatch::IntegrationTest setup do - @income = incomes(:one) + @income = incomes(:included_1) end test "should get index" do -- 2.45.2 From 2c785a8ee1fa5ed79238913124aae25d9fc515ca Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Wed, 22 Nov 2023 19:04:54 -0500 Subject: [PATCH 5/7] Use fixtures in system tests --- test/system/expenses_test.rb | 2 +- test/system/incomes_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/system/expenses_test.rb b/test/system/expenses_test.rb index abb3fe9..9d162d8 100644 --- a/test/system/expenses_test.rb +++ b/test/system/expenses_test.rb @@ -2,7 +2,7 @@ require "application_system_test_case" class ExpensesTest < ApplicationSystemTestCase setup do - @expense = expenses(:one) + @expense = expenses(:monthly_expense) end test "visiting the index" do diff --git a/test/system/incomes_test.rb b/test/system/incomes_test.rb index ab77bf0..7a6863c 100644 --- a/test/system/incomes_test.rb +++ b/test/system/incomes_test.rb @@ -2,7 +2,7 @@ require "application_system_test_case" class IncomesTest < ApplicationSystemTestCase setup do - @income = incomes(:one) + @income = incomes(:included_1) end test "visiting the index" do -- 2.45.2 From 7bcb669773a31070519106fe0a5f63cac30ca8e3 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Wed, 22 Nov 2023 19:17:45 -0500 Subject: [PATCH 6/7] More fixture / model test --- test/fixtures/incomes.yml | 6 ++++++ test/models/income_test.rb | 2 +- test/models/member_test.rb | 26 +++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/test/fixtures/incomes.yml b/test/fixtures/incomes.yml index 16c5156..f6d8fb0 100644 --- a/test/fixtures/incomes.yml +++ b/test/fixtures/incomes.yml @@ -17,3 +17,9 @@ excluded: included: false amount: 10_000 member: one + +another_included: + description: Salary + included: true + amount: 10_000.00 + member: two diff --git a/test/models/income_test.rb b/test/models/income_test.rb index a582f18..2b682fe 100644 --- a/test/models/income_test.rb +++ b/test/models/income_test.rb @@ -2,6 +2,6 @@ require "test_helper" class IncomeTest < ActiveSupport::TestCase def test_total - assert_equal 100_000.00, Income.total + assert_equal 110_000.00, Income.total end end diff --git a/test/models/member_test.rb b/test/models/member_test.rb index 4fec230..d98f1f5 100644 --- a/test/models/member_test.rb +++ b/test/models/member_test.rb @@ -1,7 +1,27 @@ require "test_helper" class MemberTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def member + members(:one) + end + + def test_income + assert_equal 110_000.00, member.income + end + + def test_included_income + assert_equal 100_000.00, member.included_income + end + + def test_others_included_income + assert_equal 10_000.00, member.others_included_income + end + + def test_burden_percent + assert_equal 0.91, member.burden_percent + end + + def test_burden_amount + assert_equal 627.90, member.burden_amount + end end -- 2.45.2 From 6272fd7cf903989a5560d455daaca1f861fac08a Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Wed, 22 Nov 2023 20:06:38 -0500 Subject: [PATCH 7/7] Test credit card bill --- test/fixtures/credit_card_bills.yml | 8 ++------ test/models/credit_card_bill_test.rb | 8 +++++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/test/fixtures/credit_card_bills.yml b/test/fixtures/credit_card_bills.yml index ca0607b..4aa6d0c 100644 --- a/test/fixtures/credit_card_bills.yml +++ b/test/fixtures/credit_card_bills.yml @@ -1,9 +1,5 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: - description: MyString - amount: 9.99 - -two: - description: MyString - amount: 9.99 + description: Credit Card Bill One + amount: 1_000.00 diff --git a/test/models/credit_card_bill_test.rb b/test/models/credit_card_bill_test.rb index f0558a5..d40a388 100644 --- a/test/models/credit_card_bill_test.rb +++ b/test/models/credit_card_bill_test.rb @@ -1,7 +1,9 @@ require "test_helper" class CreditCardBillTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def test_unpaid + credit_card_bill = credit_card_bills(:one) + + assert_equal 870.00, credit_card_bill.unpaid + end end -- 2.45.2