Add some model tests #9

Merged
atomaka merged 7 commits from model-tests into main 2023-11-22 21:41:07 -05:00
11 changed files with 113 additions and 37 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,13 +1,25 @@
# 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
amount: 10_000
member: one
another_included:
description: Salary
included: true
amount: 10_000.00
member: two

View file

@ -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

View file

@ -1,7 +1,39 @@
require "test_helper"
class ExpenseTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
def test_monthly_converts_period_for_monthly
expense = expenses(:monthly_expense)
assert_equal 120.00, expense.monthly
end
def test_monthly_converts_period_for_annually
expense = expenses(:annual_expense)
assert_equal 10.00, expense.monthly
end
def test_monthly_converts_period_for_weekly
expense = expenses(:weekly_expense)
assert_equal 520.00, expense.monthly
end
def test_monthly_converts_period_for_quarterly
expense = expenses(:quarterly_expense)
assert_equal 40.00, expense.monthly
end
def test_total_calculates_total_of_expenses
assert_equal 480.00, Expense.total
end
def test_total_calculates_monthly_total
assert_equal 690.00, Expense.monthly_total
end
def test_total_calculates_credit_card_monthly_total
assert_equal 130.00, Expense.credit_card_monthly_total
end
end

View file

@ -1,7 +1,7 @@
require "test_helper"
class IncomeTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
def test_total
assert_equal 110_000.00, Income.total
end
end

View file

@ -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

View file

@ -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

View file

@ -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