Skip to content

Commit

Permalink
Lint Federal Tax Rates
Browse files Browse the repository at this point in the history
  • Loading branch information
neb417 committed Jun 12, 2023
1 parent c0f534b commit b6c8f55
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 35 deletions.
19 changes: 10 additions & 9 deletions app/controllers/federal_tax_brackets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class FederalTaxBracketsController < ApplicationController
before_action :set_federal_tax_bracket, only: %i[ show edit update destroy ]
before_action :set_federal_tax_bracket, only: %i[show edit update destroy]

# GET /federal_tax_brackets or /federal_tax_brackets.json
def index
Expand Down Expand Up @@ -61,13 +61,14 @@ def destroy
end

private
# Use callbacks to share common setup or constraints between actions.
def set_federal_tax_bracket
@federal_tax_bracket = FederalTaxBracket.find(params[:id])
end

# Only allow a list of trusted parameters through.
def federal_tax_bracket_params
params.require(:federal_tax_bracket).permit(:tier, :bottom_range, :top_range, :rate, :cumulative)
end
# Use callbacks to share common setup or constraints between actions.
def set_federal_tax_bracket
@federal_tax_bracket = FederalTaxBracket.find(params[:id])
end

# Only allow a list of trusted parameters through.
def federal_tax_bracket_params
params.require(:federal_tax_bracket).permit(:tier, :bottom_range, :top_range, :rate, :cumulative)
end
end
2 changes: 1 addition & 1 deletion app/models/federal_tax_bracket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FederalTaxBracket < ApplicationRecord
monetize :cumulative_cents

def self.order_by_range
all.order(:bottom_range_cents )
all.order(:bottom_range_cents)
end

def update_rate(rate:)
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/federal_tax_brackets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
tier { Faker::Name.name }
bottom_range_cents { Faker::Number.within(range: 1..10) }
top_range_cents { Faker::Number.within(range: 11..20) }
rate { Faker::Number.within(range: 0.01..0.5)}
rate { Faker::Number.within(range: 0.01..0.5) }
cumulative_cents { Faker::Number.within(range: 1..20) }
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"

RSpec.describe "federal_tax_brackets/edit", type: :view do
let(:federal_tax_bracket) {
Expand All @@ -19,7 +19,6 @@
render

assert_select "form[action=?][method=?]", federal_tax_bracket_path(federal_tax_bracket), "post" do

assert_select "input[name=?]", "federal_tax_bracket[tier]"

assert_select "input[name=?]", "federal_tax_bracket[bottom_range]"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"

RSpec.describe "federal_tax_brackets/index", type: :feature do
# before(:each) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"

RSpec.describe "federal_tax_brackets/new", type: :view do
before(:each) do
Expand All @@ -15,7 +15,6 @@
render

assert_select "form[action=?][method=?]", federal_tax_brackets_path, "post" do

assert_select "input[name=?]", "federal_tax_bracket[tier]"

assert_select "input[name=?]", "federal_tax_bracket[bottom_range]"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"

RSpec.describe "federal_tax_brackets/show", type: :feature do
# before(:each) do
Expand All @@ -10,8 +10,8 @@
# cumulative: 5
# ))
# end
let!(:fed1) { create(:federal_tax_bracket) }
let!(:fed2) { create(:federal_tax_bracket) }
let!(:fed1) { create(:federal_tax_bracket) }
let!(:fed2) { create(:federal_tax_bracket) }

it "renders attributes in <p>" do
visit federal_tax_bracket_path(fed2)
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/federal_tax_brackets_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"

# Specs in this file have access to a helper object that includes
# the FederalTaxBracketsHelper. For example:
Expand Down
2 changes: 1 addition & 1 deletion spec/models/federal_tax_bracket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# created_at :datetime not null
# updated_at :datetime not null
#
require 'rails_helper'
require "rails_helper"

RSpec.describe FederalTaxBracket, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
Expand Down
21 changes: 8 additions & 13 deletions spec/requests/federal_tax_brackets_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"

# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to test the controller code that
Expand All @@ -13,7 +13,6 @@
# sticking to rails and rspec-rails APIs to keep things simple and stable.

RSpec.describe "/federal_tax_brackets", type: :request do

# This should return the minimal set of attributes required to create a valid
# FederalTaxBracket. As you add validations to FederalTaxBracket, be sure to
# adjust the attributes here as well.
Expand Down Expand Up @@ -60,29 +59,27 @@
context "with valid parameters" do
it "creates a new FederalTaxBracket" do
expect {
post federal_tax_brackets_url, params: { federal_tax_bracket: valid_attributes }
post federal_tax_brackets_url, params: {federal_tax_bracket: valid_attributes}
}.to change(FederalTaxBracket, :count).by(1)
end

it "redirects to the created federal_tax_bracket" do
post federal_tax_brackets_url, params: { federal_tax_bracket: valid_attributes }
post federal_tax_brackets_url, params: {federal_tax_bracket: valid_attributes}
expect(response).to redirect_to(federal_tax_bracket_url(FederalTaxBracket.last))
end
end

context "with invalid parameters" do
it "does not create a new FederalTaxBracket" do
expect {
post federal_tax_brackets_url, params: { federal_tax_bracket: invalid_attributes }
post federal_tax_brackets_url, params: {federal_tax_bracket: invalid_attributes}
}.to change(FederalTaxBracket, :count).by(0)
end


it "renders a response with 422 status (i.e. to display the 'new' template)" do
post federal_tax_brackets_url, params: { federal_tax_bracket: invalid_attributes }
post federal_tax_brackets_url, params: {federal_tax_bracket: invalid_attributes}
expect(response).to have_http_status(:unprocessable_entity)
end

end
end

Expand All @@ -94,27 +91,25 @@

it "updates the requested federal_tax_bracket" do
federal_tax_bracket = FederalTaxBracket.create! valid_attributes
patch federal_tax_bracket_url(federal_tax_bracket), params: { federal_tax_bracket: new_attributes }
patch federal_tax_bracket_url(federal_tax_bracket), params: {federal_tax_bracket: new_attributes}
federal_tax_bracket.reload
skip("Add assertions for updated state")
end

it "redirects to the federal_tax_bracket" do
federal_tax_bracket = FederalTaxBracket.create! valid_attributes
patch federal_tax_bracket_url(federal_tax_bracket), params: { federal_tax_bracket: new_attributes }
patch federal_tax_bracket_url(federal_tax_bracket), params: {federal_tax_bracket: new_attributes}
federal_tax_bracket.reload
expect(response).to redirect_to(federal_tax_bracket_url(federal_tax_bracket))
end
end

context "with invalid parameters" do

it "renders a response with 422 status (i.e. to display the 'edit' template)" do
federal_tax_bracket = FederalTaxBracket.create! valid_attributes
patch federal_tax_bracket_url(federal_tax_bracket), params: { federal_tax_bracket: invalid_attributes }
patch federal_tax_bracket_url(federal_tax_bracket), params: {federal_tax_bracket: invalid_attributes}
expect(response).to have_http_status(:unprocessable_entity)
end

end
end

Expand Down
1 change: 0 additions & 1 deletion spec/routing/federal_tax_brackets_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
expect(get: "/federal_tax_brackets/1/edit").to route_to("federal_tax_brackets#edit", id: "1")
end


it "routes to #create" do
expect(post: "/federal_tax_brackets").to route_to("federal_tax_brackets#create")
end
Expand Down

0 comments on commit b6c8f55

Please sign in to comment.