Skip to content

Commit

Permalink
Create standard deduction, update federal tax data migration. (#44)
Browse files Browse the repository at this point in the history
* Update federal tax bracket data migration.

* Add standard deduction to db.

* Monetize standard deduction.

* Add specs.

* Update specs.
  • Loading branch information
neb417 authored Jul 15, 2024
1 parent c4ee2dc commit 29c3325
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 10 deletions.
16 changes: 16 additions & 0 deletions app/models/standard_deduction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# == Schema Information
#
# Table name: standard_deductions
#
# id :bigint not null, primary key
# amount_cents :integer default(0), not null
# amount_currency :string default("USD"), not null
# created_at :datetime not null
# updated_at :datetime not null
#
class StandardDeduction < ApplicationRecord
monetize :amount_cents

validates :amount_cents, presence: true
validates :amount_currency, presence: true
end
2 changes: 1 addition & 1 deletion app/services/federal_tax_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ def calculate

def taxable_income
# 2024 standard deduction = 13,850
@taxable_income ||= income - Money.new(13_850_00)
@taxable_income ||= income - StandardDeduction.first.amount
end
end
15 changes: 8 additions & 7 deletions db/data/20240711124610_create_tax_tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

class CreateTaxTables < ActiveRecord::Migration[7.0]
def up
FederalTaxBracket.create(tier: "Tier 1", bottom_range: 0, top_range: 23_200, rate: 0.1, cumulative: 0)
FederalTaxBracket.create(tier: "Tier 2", bottom_range: 23_001, top_range: 94_300, rate: 0.12, cumulative: 2_320)
FederalTaxBracket.create(tier: "Tier 3", bottom_range: 94_301, top_range: 201_050, rate: 0.22, cumulative: 10_852)
FederalTaxBracket.create(tier: "Tier 4", bottom_range: 201_051, top_range: 383_900, rate: 0.24, cumulative: 34_337)
FederalTaxBracket.create(tier: "Tier 5", bottom_range: 383_901, top_range: 487_450, rate: 0.32, cumulative: 78_221)
FederalTaxBracket.create(tier: "Tier 6", bottom_range: 487_451, top_range: 731_200, rate: 0.35, cumulative: 111_357)
FederalTaxBracket.create(tier: "Tier 7", bottom_range: 731_201, top_range: 10_000_000, rate: 0.35, cumulative: 196_669)
# Federal tax brackets for single filers in 2024
FederalTaxBracket.create(tier: "Tier 1", bottom_range: 0, top_range: 11_600, rate: 0.1, cumulative: 0)
FederalTaxBracket.create(tier: "Tier 2", bottom_range: 11_601, top_range: 47_150, rate: 0.12, cumulative: 1_160)
FederalTaxBracket.create(tier: "Tier 3", bottom_range: 47_151, top_range: 100_525, rate: 0.22, cumulative: 5_426)
FederalTaxBracket.create(tier: "Tier 4", bottom_range: 100_526, top_range: 191_950, rate: 0.24, cumulative: 17_168.5)
FederalTaxBracket.create(tier: "Tier 5", bottom_range: 191_951, top_range: 243_725, rate: 0.32, cumulative: 39_110.5)
FederalTaxBracket.create(tier: "Tier 6", bottom_range: 243_726, top_range: 609_350, rate: 0.35, cumulative: 55_678.5)
FederalTaxBracket.create(tier: "Tier 7", bottom_range: 609_351, top_range: 10_000_000, rate: 0.35, cumulative: 183_647.25)
end

def down
Expand Down
12 changes: 12 additions & 0 deletions db/data/20240715131425_create_standard_deduction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class CreateStandardDeduction < ActiveRecord::Migration[7.0]
def up
# 2024 Standard Deduction is $13,850
StandardDeduction.create(amount: 13_850)
end

def down
raise ActiveRecord::IrreversibleMigration
end
end
2 changes: 1 addition & 1 deletion db/data_schema.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DataMigrate::Data.define(version: 20240711132613)
DataMigrate::Data.define(version: 20240715131425)
9 changes: 9 additions & 0 deletions db/migrate/20240715131211_create_standard_deductions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateStandardDeductions < ActiveRecord::Migration[7.0]
def change
create_table :standard_deductions do |t|
t.monetize :amount

t.timestamps
end
end
end
9 changes: 8 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions spec/factories/standard_deductions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# == Schema Information
#
# Table name: standard_deductions
#
# id :bigint not null, primary key
# amount_cents :integer default(0), not null
# amount_currency :string default("USD"), not null
# created_at :datetime not null
# updated_at :datetime not null
#
FactoryBot.define do
factory :standard_deduction do
# standard deduction amount is $13,850
amount_cents { 1_385_000 }
amount_currency { "USD" }
end
end
1 change: 1 addition & 0 deletions spec/features/dashboard/dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
let!(:fixed_expenses) { create_list(:fixed_expense, 2) }
let!(:saving_rate) { create(:savings_rate) }
let!(:investing_rate) { create(:savings_rate, name: "investing", rate: 0.02) }
let!(:standard_deduction) { create(:standard_deduction) }

describe "GET /index" do
it "routes to root path" do
Expand Down
16 changes: 16 additions & 0 deletions spec/models/standard_deduction_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# == Schema Information
#
# Table name: standard_deductions
#
# id :bigint not null, primary key
# amount_cents :integer default(0), not null
# amount_currency :string default("USD"), not null
# created_at :datetime not null
# updated_at :datetime not null
#
require "rails_helper"

RSpec.describe StandardDeduction, type: :model do
it { is_expected.to validate_presence_of(:amount_cents) }
it { is_expected.to validate_presence_of(:amount_currency) }
end
1 change: 1 addition & 0 deletions spec/services/federal_tax_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

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 }

Expand Down

0 comments on commit 29c3325

Please sign in to comment.