From b6c8f55db501ee23b3359cf882524382a08bdb4e Mon Sep 17 00:00:00 2001 From: "Benjamin Randolphgit config --global user.email neb417@gmail.comgit config --global init.defaultBranch maingit config --global core.editor atom" Date: Mon, 12 Jun 2023 08:22:05 -0600 Subject: [PATCH] Lint Federal Tax Rates --- .../federal_tax_brackets_controller.rb | 19 +++++++++-------- app/models/federal_tax_bracket.rb | 2 +- spec/factories/federal_tax_brackets.rb | 2 +- .../edit.html.tailwindcss_spec.rb | 3 +-- .../index.html.tailwindcss_spec.rb | 2 +- .../new.html.tailwindcss_spec.rb | 3 +-- .../show.html.tailwindcss_spec.rb | 6 +++--- .../federal_tax_brackets_helper_spec.rb | 2 +- spec/models/federal_tax_bracket_spec.rb | 2 +- spec/requests/federal_tax_brackets_spec.rb | 21 +++++++------------ .../federal_tax_brackets_routing_spec.rb | 1 - 11 files changed, 28 insertions(+), 35 deletions(-) diff --git a/app/controllers/federal_tax_brackets_controller.rb b/app/controllers/federal_tax_brackets_controller.rb index 77a5d9b..fd6f2e4 100644 --- a/app/controllers/federal_tax_brackets_controller.rb +++ b/app/controllers/federal_tax_brackets_controller.rb @@ -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 @@ -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 diff --git a/app/models/federal_tax_bracket.rb b/app/models/federal_tax_bracket.rb index f8426ea..4459a84 100644 --- a/app/models/federal_tax_bracket.rb +++ b/app/models/federal_tax_bracket.rb @@ -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:) diff --git a/spec/factories/federal_tax_brackets.rb b/spec/factories/federal_tax_brackets.rb index 20520c2..befc1d7 100644 --- a/spec/factories/federal_tax_brackets.rb +++ b/spec/factories/federal_tax_brackets.rb @@ -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 diff --git a/spec/features/federal_tax_brackets/edit.html.tailwindcss_spec.rb b/spec/features/federal_tax_brackets/edit.html.tailwindcss_spec.rb index 393411d..a1fc918 100644 --- a/spec/features/federal_tax_brackets/edit.html.tailwindcss_spec.rb +++ b/spec/features/federal_tax_brackets/edit.html.tailwindcss_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe "federal_tax_brackets/edit", type: :view do let(:federal_tax_bracket) { @@ -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]" diff --git a/spec/features/federal_tax_brackets/index.html.tailwindcss_spec.rb b/spec/features/federal_tax_brackets/index.html.tailwindcss_spec.rb index 24da7cf..4506181 100644 --- a/spec/features/federal_tax_brackets/index.html.tailwindcss_spec.rb +++ b/spec/features/federal_tax_brackets/index.html.tailwindcss_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe "federal_tax_brackets/index", type: :feature do # before(:each) do diff --git a/spec/features/federal_tax_brackets/new.html.tailwindcss_spec.rb b/spec/features/federal_tax_brackets/new.html.tailwindcss_spec.rb index e8a94f7..707ab10 100644 --- a/spec/features/federal_tax_brackets/new.html.tailwindcss_spec.rb +++ b/spec/features/federal_tax_brackets/new.html.tailwindcss_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe "federal_tax_brackets/new", type: :view do before(:each) do @@ -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]" diff --git a/spec/features/federal_tax_brackets/show.html.tailwindcss_spec.rb b/spec/features/federal_tax_brackets/show.html.tailwindcss_spec.rb index 5d9c7a6..3706e38 100644 --- a/spec/features/federal_tax_brackets/show.html.tailwindcss_spec.rb +++ b/spec/features/federal_tax_brackets/show.html.tailwindcss_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe "federal_tax_brackets/show", type: :feature do # before(:each) do @@ -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

" do visit federal_tax_bracket_path(fed2) diff --git a/spec/helpers/federal_tax_brackets_helper_spec.rb b/spec/helpers/federal_tax_brackets_helper_spec.rb index 7cb8193..4e92c9b 100644 --- a/spec/helpers/federal_tax_brackets_helper_spec.rb +++ b/spec/helpers/federal_tax_brackets_helper_spec.rb @@ -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: diff --git a/spec/models/federal_tax_bracket_spec.rb b/spec/models/federal_tax_bracket_spec.rb index 1a7faea..65d8c2e 100644 --- a/spec/models/federal_tax_bracket_spec.rb +++ b/spec/models/federal_tax_bracket_spec.rb @@ -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__}" diff --git a/spec/requests/federal_tax_brackets_spec.rb b/spec/requests/federal_tax_brackets_spec.rb index 30a9876..cc7a98b 100644 --- a/spec/requests/federal_tax_brackets_spec.rb +++ b/spec/requests/federal_tax_brackets_spec.rb @@ -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 @@ -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. @@ -60,12 +59,12 @@ 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 @@ -73,16 +72,14 @@ 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 @@ -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 diff --git a/spec/routing/federal_tax_brackets_routing_spec.rb b/spec/routing/federal_tax_brackets_routing_spec.rb index 7225590..352823e 100644 --- a/spec/routing/federal_tax_brackets_routing_spec.rb +++ b/spec/routing/federal_tax_brackets_routing_spec.rb @@ -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