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

Create filing status federal tax table types. #47

Merged
merged 4 commits into from
Nov 5, 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
33 changes: 22 additions & 11 deletions app/models/federal_tax_bracket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@
#
# Table name: federal_tax_brackets
#
# id :bigint not null, primary key
# bottom_range_cents :integer default(0), not null
# bottom_range_currency :string default("USD"), not null
# cumulative_cents :integer default(0), not null
# cumulative_currency :string default("USD"), not null
# rate :float
# tier :string
# top_range_cents :integer default(0), not null
# top_range_currency :string default("USD"), not null
# created_at :datetime not null
# updated_at :datetime not null
# id :bigint not null, primary key
# bottom_range_cents :integer default(0), not null
# bottom_range_currency :string default("USD"), not null
# cumulative_cents :integer default(0), not null
# cumulative_currency :string default("USD"), not null
# rate :float
# tier :string
# top_range_cents :integer default(0), not null
# top_range_currency :string default("USD"), not null
# created_at :datetime not null
# updated_at :datetime not null
# federal_tax_table_type_id :bigint
#
# Indexes
#
# index_federal_tax_brackets_on_federal_tax_table_type_id (federal_tax_table_type_id)
#
# Foreign Keys
#
# fk_rails_... (federal_tax_table_type_id => federal_tax_table_types.id)
#
class FederalTaxBracket < ApplicationRecord
belongs_to :federal_tax_table_type

monetize :bottom_range_cents
monetize :top_range_cents
monetize :cumulative_cents
Expand Down
15 changes: 15 additions & 0 deletions app/models/federal_tax_table_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# == Schema Information
#
# Table name: federal_tax_table_types
#
# id :bigint not null, primary key
# filing_status :string
# created_at :datetime not null
# updated_at :datetime not null
#
class FederalTaxTableType < ApplicationRecord
has_many :federal_tax_brackets

FILING_TYPES = %w[single married_filing_jointly married_filing_separately head_of_household]
validates :filing_status, presence: true, inclusion: FILING_TYPES
end
14 changes: 7 additions & 7 deletions db/data/20240711124610_create_tax_tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
class CreateTaxTables < ActiveRecord::Migration[7.0]
def up
# 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)
# 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
50 changes: 50 additions & 0 deletions db/data/20240910125100_create_tax_table_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

class CreateTaxTableTypes < ActiveRecord::Migration[7.0]
def up
FederalTaxTableType.create(filing_status: "single")
FederalTaxTableType.create(filing_status: "married_filing_jointly")
FederalTaxTableType.create(filing_status: "married_filing_separately")
FederalTaxTableType.create(filing_status: "head_of_household")

# 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, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "single").id)
FederalTaxBracket.create(tier: "Tier 2", bottom_range: 11_601, top_range: 47_150, rate: 0.12, cumulative: 1_160, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "single").id)
FederalTaxBracket.create(tier: "Tier 3", bottom_range: 47_151, top_range: 100_525, rate: 0.22, cumulative: 5_426, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "single").id)
FederalTaxBracket.create(tier: "Tier 4", bottom_range: 100_526, top_range: 191_950, rate: 0.24, cumulative: 17_168.5, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "single").id)
FederalTaxBracket.create(tier: "Tier 5", bottom_range: 191_951, top_range: 243_725, rate: 0.32, cumulative: 39_110.5, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "single").id)
FederalTaxBracket.create(tier: "Tier 6", bottom_range: 243_726, top_range: 609_350, rate: 0.35, cumulative: 55_678.5, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "single").id)
FederalTaxBracket.create(tier: "Tier 7", bottom_range: 609_351, top_range: 10_000_000, rate: 0.35, cumulative: 183_647.25, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "single").id)

# Federal tax brackets for married joint filers in 2024
FederalTaxBracket.create(tier: "Tier 1", bottom_range: 0, top_range: 23_200, rate: 0.1, cumulative: 0, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_jointly").id)
FederalTaxBracket.create(tier: "Tier 2", bottom_range: 23_201, top_range: 94_300, rate: 0.12, cumulative: 2_320, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_jointly").id)
FederalTaxBracket.create(tier: "Tier 3", bottom_range: 94_301, top_range: 201_050, rate: 0.22, cumulative: 10_852, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_jointly").id)
FederalTaxBracket.create(tier: "Tier 4", bottom_range: 201_051, top_range: 383_900, rate: 0.24, cumulative: 34_337, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_jointly").id)
FederalTaxBracket.create(tier: "Tier 5", bottom_range: 383_901, top_range: 487_450, rate: 0.32, cumulative: 78_221, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_jointly").id)
FederalTaxBracket.create(tier: "Tier 6", bottom_range: 487_451, top_range: 731_200, rate: 0.35, cumulative: 111_357, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_jointly").id)
FederalTaxBracket.create(tier: "Tier 7", bottom_range: 731_201, top_range: 10_000_000, rate: 0.35, cumulative: 196_669.50, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_jointly").id)

# Federal tax brackets for married separate filers in 2024
FederalTaxBracket.create(tier: "Tier 1", bottom_range: 0, top_range: 11_600, rate: 0.1, cumulative: 0, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_separately").id)
FederalTaxBracket.create(tier: "Tier 2", bottom_range: 11_601, top_range: 47_150, rate: 0.12, cumulative: 1_160, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_separately").id)
FederalTaxBracket.create(tier: "Tier 3", bottom_range: 47_151, top_range: 100_525, rate: 0.22, cumulative: 5_426, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_separately").id)
FederalTaxBracket.create(tier: "Tier 4", bottom_range: 100_526, top_range: 191_950, rate: 0.24, cumulative: 17_168.5, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_separately").id)
FederalTaxBracket.create(tier: "Tier 5", bottom_range: 191_951, top_range: 243_725, rate: 0.32, cumulative: 39_110.5, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_separately").id)
FederalTaxBracket.create(tier: "Tier 6", bottom_range: 243_726, top_range: 365_600, rate: 0.35, cumulative: 55_678.5, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_separately").id)
FederalTaxBracket.create(tier: "Tier 7", bottom_range: 365_601, top_range: 10_000_000, rate: 0.35, cumulative: 98_334.75, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "married_filing_separately").id)

# Federal tax brackets for head of household filers in 2024
FederalTaxBracket.create(tier: "Tier 1", bottom_range: 0, top_range: 16_550, rate: 0.1, cumulative: 0, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "head_of_household").id)
FederalTaxBracket.create(tier: "Tier 2", bottom_range: 16_551, top_range: 63_100, rate: 0.12, cumulative: 1_655, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "head_of_household").id)
FederalTaxBracket.create(tier: "Tier 3", bottom_range: 63_101, top_range: 100_500, rate: 0.22, cumulative: 7_241, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "head_of_household").id)
FederalTaxBracket.create(tier: "Tier 4", bottom_range: 100_501, top_range: 191_950, rate: 0.24, cumulative: 15_469, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "head_of_household").id)
FederalTaxBracket.create(tier: "Tier 5", bottom_range: 191_951, top_range: 243_700, rate: 0.32, cumulative: 37_417, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "head_of_household").id)
FederalTaxBracket.create(tier: "Tier 6", bottom_range: 243_701, top_range: 609_350, rate: 0.35, cumulative: 53_977, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "head_of_household").id)
FederalTaxBracket.create(tier: "Tier 7", bottom_range: 609_351, top_range: 10_000_000, rate: 0.35, cumulative: 181_954.5, federal_tax_table_type_id: FederalTaxTableType.find_by(filing_status: "head_of_household").id)
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: 20240715131425)
DataMigrate::Data.define(version: 20240910125100)
11 changes: 11 additions & 0 deletions db/migrate/20240911123818_create_federal_tax_table_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateFederalTaxTableTypes < ActiveRecord::Migration[7.0]
def change
create_table :federal_tax_table_types do |t|
t.string :filing_status

t.timestamps
end

add_reference :federal_tax_brackets, :federal_tax_table_type, foreign_key: true
end
end
11 changes: 10 additions & 1 deletion db/schema.rb

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

33 changes: 22 additions & 11 deletions spec/factories/federal_tax_brackets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,33 @@
#
# Table name: federal_tax_brackets
#
# id :bigint not null, primary key
# bottom_range_cents :integer default(0), not null
# bottom_range_currency :string default("USD"), not null
# cumulative_cents :integer default(0), not null
# cumulative_currency :string default("USD"), not null
# rate :float
# tier :string
# top_range_cents :integer default(0), not null
# top_range_currency :string default("USD"), not null
# created_at :datetime not null
# updated_at :datetime not null
# id :bigint not null, primary key
# bottom_range_cents :integer default(0), not null
# bottom_range_currency :string default("USD"), not null
# cumulative_cents :integer default(0), not null
# cumulative_currency :string default("USD"), not null
# rate :float
# tier :string
# top_range_cents :integer default(0), not null
# top_range_currency :string default("USD"), not null
# created_at :datetime not null
# updated_at :datetime not null
# federal_tax_table_type_id :bigint
#
# Indexes
#
# index_federal_tax_brackets_on_federal_tax_table_type_id (federal_tax_table_type_id)
#
# Foreign Keys
#
# fk_rails_... (federal_tax_table_type_id => federal_tax_table_types.id)
#
FactoryBot.define do
# tax_brackets = 10% on first $1,000, 15% from $1,001 to $100,000, 25% from $100,001 to $500,000

factory :federal_tax_bracket do
federal_tax_table_type

tier { "Tier 1" }
bottom_range_cents { 0 }
top_range_cents { 100_000 } # $1,000.00
Expand Down
34 changes: 34 additions & 0 deletions spec/factories/federal_tax_table_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# == Schema Information
#
# Table name: federal_tax_table_types
#
# id :bigint not null, primary key
# filing_status :string
# created_at :datetime not null
# updated_at :datetime not null
#
FactoryBot.define do
factory :federal_tax_table_type do
filing_status { "single" }

trait :married_filing_jointly do
filing_status { "married_filing_jointly" }
end

trait :married_filing_separately do
filing_status { "married_filing_separately" }
end

trait :head_of_household do
filing_status { "head_of_household" }
end

trait :with_all_statuses do
after :create do |_record|
create(:federal_tax_table_type, :married_filing_jointly)
create(:federal_tax_table_type, :married_filing_separately)
create(:federal_tax_table_type, :head_of_household)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
bottom_range: 1,
top_range: 1,
rate: 1.5,
cumulative: 1
cumulative: 1,
federal_tax_table_type: create(:federal_tax_table_type)
)
}

Expand Down
31 changes: 20 additions & 11 deletions spec/models/federal_tax_bracket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@
#
# Table name: federal_tax_brackets
#
# id :bigint not null, primary key
# bottom_range_cents :integer default(0), not null
# bottom_range_currency :string default("USD"), not null
# cumulative_cents :integer default(0), not null
# cumulative_currency :string default("USD"), not null
# rate :float
# tier :string
# top_range_cents :integer default(0), not null
# top_range_currency :string default("USD"), not null
# created_at :datetime not null
# updated_at :datetime not null
# id :bigint not null, primary key
# bottom_range_cents :integer default(0), not null
# bottom_range_currency :string default("USD"), not null
# cumulative_cents :integer default(0), not null
# cumulative_currency :string default("USD"), not null
# rate :float
# tier :string
# top_range_cents :integer default(0), not null
# top_range_currency :string default("USD"), not null
# created_at :datetime not null
# updated_at :datetime not null
# federal_tax_table_type_id :bigint
#
# Indexes
#
# index_federal_tax_brackets_on_federal_tax_table_type_id (federal_tax_table_type_id)
#
# Foreign Keys
#
# fk_rails_... (federal_tax_table_type_id => federal_tax_table_types.id)
#
require "rails_helper"

Expand Down
14 changes: 14 additions & 0 deletions spec/models/federal_tax_table_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# == Schema Information
#
# Table name: federal_tax_table_types
#
# id :bigint not null, primary key
# filing_status :string
# created_at :datetime not null
# updated_at :datetime not null
#
require "rails_helper"

RSpec.describe FederalTaxTableType, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading