From c6c78d2865791667aaed976f8f385d385c8cde0f Mon Sep 17 00:00:00 2001 From: Benjamin Randolph <104036158+neb417@users.noreply.github.com> Date: Tue, 10 Sep 2024 06:45:38 -0600 Subject: [PATCH] Update specs. (#45) --- app/services/federal_tax_calculator.rb | 9 ++------- spec/services/federal_tax_calculator_spec.rb | 6 ++---- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/app/services/federal_tax_calculator.rb b/app/services/federal_tax_calculator.rb index 37577ac..4fc3eca 100644 --- a/app/services/federal_tax_calculator.rb +++ b/app/services/federal_tax_calculator.rb @@ -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 diff --git a/spec/services/federal_tax_calculator_spec.rb b/spec/services/federal_tax_calculator_spec.rb index d9a2dea..0ab8377 100644 --- a/spec/services/federal_tax_calculator_spec.rb +++ b/spec/services/federal_tax_calculator_spec.rb @@ -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