Skip to content

Commit

Permalink
Update test suit
Browse files Browse the repository at this point in the history
  • Loading branch information
neb417 committed Nov 7, 2023
1 parent e306208 commit 1bafd95
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 17 deletions.
38 changes: 33 additions & 5 deletions spec/factories/federal_tax_brackets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,38 @@
#
FactoryBot.define do
factory :federal_tax_bracket do
tier { Faker::Name.name }
bottom_range_cents { Faker::Number.within(range: 1..10) }
top_range_cents { Faker::Number.within(range: 11..20) }
rate { Faker::Number.within(range: 0.01..0.5) }
cumulative_cents { Faker::Number.within(range: 1..20) }
tier { 'Tier 1' }
bottom_range_cents { 0 }
top_range_cents { 100000 }
rate { 0.1 }
cumulative_cents { 0 }

trait :tier_2 do
tier { 'Tier 2' }
bottom_range_cents { 1000100 }
top_range_cents { 10000000 }
rate { 0.15 }
cumulative_cents { 200000 }
end

trait :tier_3 do
tier { 'Tier 2' }
bottom_range_cents { 10000100 }
top_range_cents { 50000000 }
rate { 0.25 }
cumulative_cents { 500000 }
end

# trait :with_all_tiers do
# after :create do |_record|
# create(:federal_tax_bracket, :tier_2)
# create(:federal_tax_bracket, :tier_3)
# end
# end
#
# to_create do |instance|
# instance.id = FederalTaxBracket.find_or_create_by(tier: instance.tier).id
# instance.reload
# end
end
end
26 changes: 22 additions & 4 deletions spec/factories/incomes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,27 @@
#
FactoryBot.define do
factory :income do
income_type { "MyString" }
rate { 1 }
hours { 1 }
weekly_income { 1 }
income_type { "Salary" }
rate_cents { 5_000_000 }
hours { 40 }
weekly_income_cents { 5_000_000 / 52 }

trait :hourly do
income_type { "Hourly" }
rate_cents { 300_000 }
hours { 40 }
weekly_income_cents { 300_000 * 40 }
end

# trait :with_all_types do
# after :create do |_record|
# create(:income, :hourly)
# end
# end

# to_create do |instance|
# instance.id = Income.find_or_create_by(income_type: instance.income_type).id
# instance.reload
# end
end
end
17 changes: 10 additions & 7 deletions spec/features/dashboard/dashboard_spec.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
require "rails_helper"

RSpec.describe "Dashboard", type: :feature do
let!(:income1) { create(:income)}
let!(:income2) { create(:income, :hourly)}
let!(:fed1) { create(:federal_tax_bracket)}
let!(:fed2) { create(:federal_tax_bracket, :tier_2)}
let!(:fed3) { create(:federal_tax_bracket, :tier_3)}
let!(:fixed_expenses) { create_list(:fixed_expense, 2)}

describe "GET /index" do
it "routes to root path" do
visit root_path
expect(page).to have_content "Dashboard"
end

it "has incomes on dashboard" do
incomes = create_list(:income, 3)
income1 = incomes.first
income2 = incomes.second
income3 = incomes.third

visit root_path

expect(page).to have_content income1.income_type
expect(page).to have_content income2.income_type
expect(page).to have_content income3.income_type
expect(page).to have_link "New Income"
end

it "has fixed expenses on the dashboard" do
fixed_expenses = create_list(:fixed_expense, 2)
# create(:income, :with_all_types)
# create(:federal_tax_bracket, :with_all_tiers)
# fixed_expenses = create_list(:fixed_expense, 2)
fixed1 = fixed_expenses.first
fixed2 = fixed_expenses.last

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ))
# end
let!(:fed1) { create(:federal_tax_bracket) }
let!(:fed2) { create(:federal_tax_bracket) }
let!(:fed2) { create(:federal_tax_bracket, :tier_2) }

it "renders attributes in <p>" do
visit federal_tax_bracket_path(fed2)
Expand Down

0 comments on commit 1bafd95

Please sign in to comment.