Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove standard deduction from fed tax calculation #45

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading