Skip to content

Commit

Permalink
Refactor turbo stream fixed (#8)
Browse files Browse the repository at this point in the history
* Remove unused concern

* Remove unused code and return index to update for tests that put/patch

* Remove unused code
  • Loading branch information
neb417 authored Oct 9, 2023
1 parent ee18ddb commit 7e03276
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 45 deletions.
1 change: 0 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
class ApplicationController < ActionController::Base
include SetDashboardInstanceVariables
end
12 changes: 0 additions & 12 deletions app/controllers/concerns/set_dashboard_instance_variables.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class DashboardController < ApplicationController
include SetDashboardInstanceVariables
def index
@incomes = Income.all
@fixed_expenses = FixedExpense.get_ordered
Expand Down
1 change: 0 additions & 1 deletion app/controllers/fixed_expenses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def destroy
@fixed_expenses = FixedExpense.get_ordered
respond_to do |format|
format.html { redirect_to fixed_expenses_path, notice: "Fixed expense was successfully destroyed." }
# format.turbo_stream { render turbo_stream: turbo_stream.remove(@fixed_expense) }
format.turbo_stream
end
end
Expand Down
26 changes: 1 addition & 25 deletions app/javascript/controllers/fixed_expense_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,5 @@ import { Controller } from "@hotwired/stimulus"
// import { get } from "@rails/request.js"

export default class extends Controller {
static targets = [ "fixedTotals" ]

updateTotals(event) {
const data = Object.fromEntries(new FormData(event.target).entries())
console.log(data)
console.log(data["fixed_expense[amount]"])
console.log(data["fixed_expense[frequency]"])
console.log(this.fixedTotalsTarget)
let amount = data["fixed_expense[amount]"]
let frequency = data["fixed_expense[frequency]"]
// get(`/fixed_expenses/total_expenses?`)
}
}


// export default class extends Controller {
// static targets = ["monthlyPaymentDisplay"]
//
// homeDataUpdate(event){
// let homeId = event.target.selectedOptions[0].value
// let target = this.monthlyPaymentDisplayTarget.id
// get(`/recurring_payments/monthly_payment?home=${homeId}&target=${target}`,{
// responseKind: "turbo-stream"
// })
// }
// }
}
2 changes: 1 addition & 1 deletion spec/requests/fixed_expenses_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
end
end

describe "PATCH /index" do
describe "PATCH /update" do
context "with valid parameters" do
let(:new_attributes) {
skip("Add a hash of attributes valid for your model")
Expand Down
4 changes: 2 additions & 2 deletions spec/routing/fixed_expenses_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
expect(post: "/fixed_expenses").to route_to("fixed_expenses#create")
end

it "routes to #index via PUT" do
it "routes to #update via PUT" do
expect(put: "/fixed_expenses/1").to route_to("fixed_expenses#update", id: "1")
end

it "routes to #index via PATCH" do
it "routes to #update via PATCH" do
expect(patch: "/fixed_expenses/1").to route_to("fixed_expenses#update", id: "1")
end

Expand Down
4 changes: 2 additions & 2 deletions spec/routing/incomes_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
expect(post: "/incomes").to route_to("incomes#create")
end

it "routes to #index via PUT" do
it "routes to #update via PUT" do
expect(put: "/incomes/1").to route_to("incomes#update", id: "1")
end

it "routes to #index via PATCH" do
it "routes to #update via PATCH" do
expect(patch: "/incomes/1").to route_to("incomes#update", id: "1")
end

Expand Down

0 comments on commit 7e03276

Please sign in to comment.