From a99ff288a5bf3a4cf81431cd1a4c43f1427026fc Mon Sep 17 00:00:00 2001
From: Benjamin Randolph <104036158+neb417@users.noreply.github.com>
Date: Sun, 14 Jan 2024 08:15:29 -0700
Subject: [PATCH] Refactor to update streams on multiple crud. (#37)
* Refactor to update streams on multiple crud.
* Capitalize new income on dashboard index
---
app/views/dashboard/index.html.erb | 20 ++----
app/views/fixed_expenses/_index.html.erb | 16 +++--
.../fixed_expenses/create.turbo_stream.erb | 51 +++++++--------
.../fixed_expenses/destroy.turbo_stream.erb | 47 +++++++-------
.../fixed_expenses/update.turbo_stream.erb | 47 +++++++-------
app/views/incomes/_index.html.erb | 18 +++---
app/views/incomes/update.turbo_stream.erb | 55 ++++++++--------
app/views/shared/_taxed_incomes.html.erb | 64 ++++++++++---------
app/views/shared/_total_costs.html.erb | 6 +-
spec/features/dashboard/dashboard_spec.rb | 3 -
10 files changed, 155 insertions(+), 172 deletions(-)
diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb
index 88086be..29aaf00 100644
--- a/app/views/dashboard/index.html.erb
+++ b/app/views/dashboard/index.html.erb
@@ -53,21 +53,17 @@
<%= turbo_frame_tag "income_header_frame" do %>
-
Income
+
Income
<%= link_to "New Income", new_income_path, data: { turbo_frame: :incomes }, class: "btn btn-primary" %>
<% end %>
- <%= turbo_frame_tag :incomes do %>
- <%= render "incomes/index" %>
- <% end %>
+ <%= render "incomes/index" %>
- <%= turbo_frame_tag "taxed_incomes" do %>
- <%= render partial: "shared/taxed_incomes",
- locals: { salary_taxed: @salary_taxed, hourly_taxed: @hourly_taxed } %>
- <% end %>
+ <%= render partial: "shared/taxed_incomes",
+ locals: { salary_taxed: @salary_taxed, hourly_taxed: @hourly_taxed } %>
@@ -79,13 +75,9 @@
<%= link_to "New Fixed Expense", new_fixed_expense_path, data: { turbo_frame: :fixed_expenses }, class: "btn btn-primary" %>
<% end %>
- <%= turbo_frame_tag :fixed_expenses do %>
- <%= render "fixed_expenses/index" %>
- <% end %>
+ <%= render "fixed_expenses/index" %>
- <%= turbo_frame_tag "total_costs" do %>
- <%= render partial: "shared/total_costs", locals: { total_cost: @total_cost } %>
- <% end %>
+ <%= render partial: "shared/total_costs", locals: { total_cost: @total_cost } %>
diff --git a/app/views/fixed_expenses/_index.html.erb b/app/views/fixed_expenses/_index.html.erb
index 964ec76..23f372b 100644
--- a/app/views/fixed_expenses/_index.html.erb
+++ b/app/views/fixed_expenses/_index.html.erb
@@ -1,8 +1,10 @@
-
- <% fixed_headings = %w[Expense Annual Monthly Bi-weekly] %>
- <% fixed_headings.each do |fixed_heading| %>
-
<%= fixed_heading %>
- <% end %>
-
+<%= turbo_frame_tag :fixed_expenses do %>
+
+ <% fixed_headings = %w[Expense Annual Monthly Bi-weekly] %>
+ <% fixed_headings.each do |fixed_heading| %>
+
<%= fixed_heading %>
+ <% end %>
+
-<%= render @fixed_expenses %>
+ <%= render @fixed_expenses %>
+<% end %>
diff --git a/app/views/fixed_expenses/create.turbo_stream.erb b/app/views/fixed_expenses/create.turbo_stream.erb
index eb1d77a..a0a203f 100644
--- a/app/views/fixed_expenses/create.turbo_stream.erb
+++ b/app/views/fixed_expenses/create.turbo_stream.erb
@@ -1,31 +1,28 @@
-<%= turbo_stream.replace "fixed_expenses" do %>
- <%= render @fixed_expenses %>
+<%= turbo_stream.replace :fixed_expenses do %>
+ <%= render "fixed_expenses/index" %>
<% end %>
-<%= turbo_stream.replace "total_costs" do %>
- <%= render partial: "shared/total_costs", locals: { total_cost: @total_cost } %>
-<% end %>
+<%= turbo_stream.update "total_costs",
+ partial: "shared/total_costs",
+ locals: { total_cost: @total_cost }
+%>
-<%= turbo_stream.replace "salary_budget" do %>
- <%= render partial: "budget/salary_budget",
- locals: {
- income: @salary_taxed,
- total_cost: @total_cost,
- investing_amount: @salary_invest,
- savings_amount: @salary_saving,
- guilt_free: @guilt_free_salary
- }
- %>
-<% end %>
+<%= turbo_stream.update "salary_budget",
+ partial: "budget/salary_budget",
+ locals: {
+ income: @salary_taxed,
+ total_cost: @total_cost,
+ investing_amount: @salary_invest,
+ savings_amount: @salary_saving,
+ guilt_free: @guilt_free_salary }
+%>
-<%= turbo_stream.replace "hourly_budget" do %>
- <%= render partial: "budget/hourly_budget",
- locals: {
- income: @hourly_taxed,
- total_cost: @total_cost,
- investing_amount: @hourly_invest,
- savings_amount: @hourly_saving,
- guilt_free: @guilt_free_hourly
- }
- %>
-<% end %>
+<%= turbo_stream.update "hourly_budget",
+ partial: "budget/hourly_budget",
+ locals: {
+ income: @hourly_taxed,
+ total_cost: @total_cost,
+ investing_amount: @hourly_invest,
+ savings_amount: @hourly_saving,
+ guilt_free: @guilt_free_hourly }
+%>
diff --git a/app/views/fixed_expenses/destroy.turbo_stream.erb b/app/views/fixed_expenses/destroy.turbo_stream.erb
index 083204b..e585d64 100644
--- a/app/views/fixed_expenses/destroy.turbo_stream.erb
+++ b/app/views/fixed_expenses/destroy.turbo_stream.erb
@@ -1,29 +1,26 @@
<%= turbo_stream.remove @fixed_expense %>
-<%= turbo_stream.replace "total_costs" do %>
- <%= render partial: "shared/total_costs", locals: { total_cost: @total_cost } %>
-<% end %>
+<%= turbo_stream.update "total_costs",
+ partial: "shared/total_costs",
+ locals: { total_cost: @total_cost }
+%>
-<%= turbo_stream.replace "salary_budget" do %>
- <%= render partial: "budget/salary_budget",
- locals: {
- income: @salary_taxed,
- total_cost: @total_cost,
- investing_amount: @salary_invest,
- savings_amount: @salary_saving,
- guilt_free: @guilt_free_salary
- }
- %>
-<% end %>
+<%= turbo_stream.update "salary_budget",
+ partial: "budget/salary_budget",
+ locals: {
+ income: @salary_taxed,
+ total_cost: @total_cost,
+ investing_amount: @salary_invest,
+ savings_amount: @salary_saving,
+ guilt_free: @guilt_free_salary }
+%>
-<%= turbo_stream.replace "hourly_budget" do %>
- <%= render partial: "budget/hourly_budget",
- locals: {
- income: @hourly_taxed,
- total_cost: @total_cost,
- investing_amount: @hourly_invest,
- savings_amount: @hourly_saving,
- guilt_free: @guilt_free_hourly
- }
- %>
-<% end %>
+<%= turbo_stream.update "hourly_budget",
+ partial: "budget/hourly_budget",
+ locals: {
+ income: @hourly_taxed,
+ total_cost: @total_cost,
+ investing_amount: @hourly_invest,
+ savings_amount: @hourly_saving,
+ guilt_free: @guilt_free_hourly }
+%>
diff --git a/app/views/fixed_expenses/update.turbo_stream.erb b/app/views/fixed_expenses/update.turbo_stream.erb
index 695ceee..8da550f 100644
--- a/app/views/fixed_expenses/update.turbo_stream.erb
+++ b/app/views/fixed_expenses/update.turbo_stream.erb
@@ -1,29 +1,26 @@
<%= turbo_stream.update @fixed_expense %>
-<%= turbo_stream.replace "total_costs" do %>
- <%= render partial: "shared/total_costs", locals: { total_cost: @total_cost } %>
-<% end %>
+<%= turbo_stream.update "total_costs",
+ partial: "shared/total_costs",
+ locals: { total_cost: @total_cost }
+%>
-<%= turbo_stream.replace "salary_budget" do %>
- <%= render partial: "budget/salary_budget",
- locals: {
- income: @salary_taxed,
- total_cost: @total_cost,
- investing_amount: @salary_invest,
- savings_amount: @salary_saving,
- guilt_free: @guilt_free_salary
- }
- %>
-<% end %>
+<%= turbo_stream.update "salary_budget",
+ partial: "budget/salary_budget",
+ locals: {
+ income: @salary_taxed,
+ total_cost: @total_cost,
+ investing_amount: @salary_invest,
+ savings_amount: @salary_saving,
+ guilt_free: @guilt_free_salary }
+%>
-<%= turbo_stream.replace "hourly_budget" do %>
- <%= render partial: "budget/hourly_budget",
- locals: {
- income: @hourly_taxed,
- total_cost: @total_cost,
- investing_amount: @hourly_invest,
- savings_amount: @hourly_saving,
- guilt_free: @guilt_free_hourly
- }
- %>
-<% end %>
+<%= turbo_stream.update "hourly_budget",
+ partial: "budget/hourly_budget",
+ locals: {
+ income: @hourly_taxed,
+ total_cost: @total_cost,
+ investing_amount: @hourly_invest,
+ savings_amount: @hourly_saving,
+ guilt_free: @guilt_free_hourly }
+%>
diff --git a/app/views/incomes/_index.html.erb b/app/views/incomes/_index.html.erb
index 43645c5..3353331 100644
--- a/app/views/incomes/_index.html.erb
+++ b/app/views/incomes/_index.html.erb
@@ -1,9 +1,11 @@
-Net Income
-
- <% income_headings = ["Income Type", "Rate", "Hours", "Weekly Gross"] %>
- <% income_headings.each do |income_heading| %>
-
<%= income_heading %>
- <% end %>
-
+<%= turbo_frame_tag :incomes do %>
+ Net Income
+
+ <% income_headings = ["Income Type", "Rate", "Hours", "Weekly Gross"] %>
+ <% income_headings.each do |income_heading| %>
+
<%= income_heading %>
+ <% end %>
+
-<%= render @incomes %>
+ <%= render @incomes %>
+<% end %>
diff --git a/app/views/incomes/update.turbo_stream.erb b/app/views/incomes/update.turbo_stream.erb
index e0124c8..7dac72e 100644
--- a/app/views/incomes/update.turbo_stream.erb
+++ b/app/views/incomes/update.turbo_stream.erb
@@ -1,34 +1,29 @@
<%= turbo_stream.update @income %>
-<%= turbo_stream.replace "taxed_incomes" do %>
- <%= render partial: "shared/taxed_incomes",
- locals: {
- salary_taxed: @salary_taxed,
- hourly_taxed: @hourly_taxed
- }
- %>
-<% end %>
+<%= turbo_stream.update "taxed_incomes",
+ partial: "shared/taxed_incomes",
+ locals: {
+ salary_taxed: @salary_taxed,
+ hourly_taxed: @hourly_taxed
+ }
+%>
-<%= turbo_stream.replace "salary_budget" do %>
- <%= render partial: "budget/salary_budget",
- locals: {
- income: @salary_taxed,
- total_cost: @total_cost,
- investing_amount: @salary_invest,
- savings_amount: @salary_saving,
- guilt_free: @guilt_free_salary
- }
- %>
-<% end %>
+<%= turbo_stream.update "salary_budget",
+ partial: "budget/salary_budget",
+ locals: {
+ income: @salary_taxed,
+ total_cost: @total_cost,
+ investing_amount: @salary_invest,
+ savings_amount: @salary_saving,
+ guilt_free: @guilt_free_salary }
+%>
-<%= turbo_stream.replace "hourly_budget" do %>
- <%= render partial: "budget/hourly_budget",
- locals: {
- income: @hourly_taxed,
- total_cost: @total_cost,
- investing_amount: @hourly_invest,
- savings_amount: @hourly_saving,
- guilt_free: @guilt_free_hourly
- }
- %>
-<% end %>
\ No newline at end of file
+<%= turbo_stream.update "hourly_budget",
+ partial: "budget/hourly_budget",
+ locals: {
+ income: @hourly_taxed,
+ total_cost: @total_cost,
+ investing_amount: @hourly_invest,
+ savings_amount: @hourly_saving,
+ guilt_free: @guilt_free_hourly }
+%>
\ No newline at end of file
diff --git a/app/views/shared/_taxed_incomes.html.erb b/app/views/shared/_taxed_incomes.html.erb
index 9625da5..d376c99 100644
--- a/app/views/shared/_taxed_incomes.html.erb
+++ b/app/views/shared/_taxed_incomes.html.erb
@@ -1,37 +1,39 @@
-Gross Income Annual
-
- <% fixed_headings = ["Income Type", "Federal Tax", "Fica Tax", "State Tax", "Annual"] %>
- <% fixed_headings.each do |fixed_heading| %>
-
<%= fixed_heading %>
- <% end %>
-
+<%= turbo_frame_tag "taxed_incomes" do %>
+ Gross Income Annual
+
+ <% fixed_headings = ["Income Type", "Federal Tax", "Fica Tax", "State Tax", "Annual"] %>
+ <% fixed_headings.each do |fixed_heading| %>
+
<%= fixed_heading %>
+ <% end %>
+
-
-
Salary
- <%= render partial: "shared/taxed_income", locals: { taxed_income: salary_taxed, annual: true } %>
-
+
+
Salary
+ <%= render partial: "shared/taxed_income", locals: { taxed_income: salary_taxed, annual: true } %>
+
-
-
Hourly
- <%= render partial: "shared/taxed_income", locals: { taxed_income: hourly_taxed, annual: true } %>
-
+
+
Hourly
+ <%= render partial: "shared/taxed_income", locals: { taxed_income: hourly_taxed, annual: true } %>
+
-
+
-Gross Income Bi-Weekly
-
- <% fixed_headings = ["Income Type", "Federal Tax", "Fica Tax", "State Tax", "Bi-weekly"] %>
- <% fixed_headings.each do |fixed_heading| %>
-
<%= fixed_heading %>
- <% end %>
-
+ Gross Income Bi-Weekly
+
+ <% fixed_headings = ["Income Type", "Federal Tax", "Fica Tax", "State Tax", "Bi-weekly"] %>
+ <% fixed_headings.each do |fixed_heading| %>
+
<%= fixed_heading %>
+ <% end %>
+
-
-
Salary
- <%= render partial: "shared/taxed_income", locals: { taxed_income: salary_taxed, annual: false } %>
-
+
+
Salary
+ <%= render partial: "shared/taxed_income", locals: { taxed_income: salary_taxed, annual: false } %>
+
-
-
Hourly
- <%= render partial: "shared/taxed_income", locals: { taxed_income: hourly_taxed, annual: false } %>
-
+
+
Hourly
+ <%= render partial: "shared/taxed_income", locals: { taxed_income: hourly_taxed, annual: false } %>
+
+<% end %>
diff --git a/app/views/shared/_total_costs.html.erb b/app/views/shared/_total_costs.html.erb
index a89dffe..cb33c5f 100644
--- a/app/views/shared/_total_costs.html.erb
+++ b/app/views/shared/_total_costs.html.erb
@@ -1,4 +1,5 @@
-
+<%= turbo_frame_tag "total_costs" do %>
+
Total
@@ -20,4 +21,5 @@
<%= render partial: "shared/total", locals: { total: total_cost.bi_weekly_cost } %>
-
+
+<% end %>
diff --git a/spec/features/dashboard/dashboard_spec.rb b/spec/features/dashboard/dashboard_spec.rb
index 7283ba2..c24ac68 100644
--- a/spec/features/dashboard/dashboard_spec.rb
+++ b/spec/features/dashboard/dashboard_spec.rb
@@ -25,9 +25,6 @@
end
it "has fixed expenses on the dashboard" do
- # create(:income, :with_all_types)
- # create(:federal_tax_bracket, :with_all_tiers)
- # fixed_expenses = create_list(:fixed_expense, 2)
fixed1 = fixed_expenses.first
fixed2 = fixed_expenses.last