Skip to content

Commit

Permalink
Update specs. (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
neb417 authored Sep 10, 2024
1 parent 29c3325 commit c6c78d2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
9 changes: 2 additions & 7 deletions app/services/federal_tax_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@ def call
attr_accessor :income

def calculate
bracket = FederalTaxBracket.where("bottom_range_cents <= ?", taxable_income.fractional).order(:bottom_range_cents).last
taxable_at_bracket_rate = Money.new(taxable_income - bracket.bottom_range)
bracket = FederalTaxBracket.where("bottom_range_cents <= ?", income.fractional).order(:bottom_range_cents).last
taxable_at_bracket_rate = Money.new(income - bracket.bottom_range)
rated = bracket.rate * taxable_at_bracket_rate
rated + bracket.cumulative
end

def taxable_income
# 2024 standard deduction = 13,850
@taxable_income ||= income - StandardDeduction.first.amount
end
end
6 changes: 2 additions & 4 deletions spec/services/federal_tax_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@

let!(:salary_income) { create(:income) }
let!(:tax_brackets) { create(:federal_tax_bracket, :with_all_tiers) }
let!(:standard_deduction) { create(:standard_deduction) }

it { expect(service).to be_a Money }

it "calculates federal tax" do
# salary_income = $50,000
# standard_deduction = $13,850
# tax_brackets = 10% on first $1,000, 15% from $1,001 to $100,000, 25% from $100,001 to $500,000

expect(service.format).to eq("$5,372.35")
expect((salary_income.rate - service).format).to eq("$44,627.65")
expect(service.format).to eq("$7,449.85")
expect((salary_income.rate - service).format).to eq("$42,550.15")
end
end

0 comments on commit c6c78d2

Please sign in to comment.