The personal finance app for everyone
Isolate infinite loop bug, add timeout to actions (#583)
Zach Gollwitzerb1bfdef8ffa6
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 83ea0258..26daf58e 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -8,7 +8,7 @@ on:jobs:scan_ruby:runs-on: ubuntu-latest-+ timeout-minutes: 10steps:- name: Checkout codeuses: actions/checkout@v4@@ -24,7 +24,7 @@ jobs:scan_js:runs-on: ubuntu-latest-+ timeout-minutes: 10steps:- name: Checkout codeuses: actions/checkout@v4@@ -40,6 +40,7 @@ jobs:lint:runs-on: ubuntu-latest+ timeout-minutes: 10steps:- name: Checkout codeuses: actions/checkout@v4@@ -55,6 +56,7 @@ jobs:test:runs-on: ubuntu-latest+ timeout-minutes: 10services:postgres:diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rbindex dabcc32b..9a9b62c0 100644--- a/app/controllers/transactions_controller.rb+++ b/app/controllers/transactions_controller.rb@@ -63,6 +63,7 @@ class TransactionsController < ApplicationControllerrespond_to do |format|if @transaction.save+ @transaction.account.sync_laterformat.html { redirect_to transactions_url, notice: t(".success") }elseformat.html { render :new, status: :unprocessable_entity }@@ -73,6 +74,8 @@ class TransactionsController < ApplicationControllerdef updaterespond_to do |format|if @transaction.update(transaction_params)+ @transaction.account.sync_later+format.html { redirect_to transaction_url(@transaction), notice: t(".success") }format.turbo_stream dorender turbo_stream: [@@ -88,6 +91,7 @@ class TransactionsController < ApplicationControllerdef destroy@transaction.destroy!+ @transaction.account.sync_laterrespond_to do |format|format.html { redirect_to transactions_url, notice: t(".success") }diff --git a/app/controllers/valuations_controller.rb b/app/controllers/valuations_controller.rbindex e73c6287..bc1dd052 100644--- a/app/controllers/valuations_controller.rb+++ b/app/controllers/valuations_controller.rb@@ -7,6 +7,8 @@ class ValuationsController < ApplicationController# TODO: placeholder logic until we have a better abstraction for trends@valuation = @account.valuations.new(valuation_params.merge(currency: Current.family.currency))if @valuation.save+ @valuation.account.sync_later+respond_to do |format|format.html { redirect_to account_path(@account), notice: "Valuation created" }format.turbo_stream@@ -30,6 +32,8 @@ class ValuationsController < ApplicationControllerdef update@valuation = Valuation.find(params[:id])if @valuation.update(valuation_params)+ @valuation.account.sync_later+redirect_to account_path(@valuation.account), notice: "Valuation updated"elserender :edit, status: :unprocessable_entity@@ -42,7 +46,8 @@ class ValuationsController < ApplicationControllerdef destroy@valuation = Valuation.find(params[:id])@account = @valuation.account- @valuation.destroy+ @valuation.destroy!+ @account.sync_laterrespond_to do |format|format.html { redirect_to account_path(@account), notice: "Valuation deleted" }diff --git a/app/models/account.rb b/app/models/account.rbindex 14be3bcd..ec039faa 100644--- a/app/models/account.rb+++ b/app/models/account.rb@@ -6,9 +6,10 @@ class Account < ApplicationRecordbroadcasts_refreshesbelongs_to :family- has_many :balances- has_many :valuations- has_many :transactions++ has_many :balances, dependent: :destroy+ has_many :valuations, dependent: :destroy+ has_many :transactions, dependent: :destroymonetize :balancediff --git a/app/models/transaction.rb b/app/models/transaction.rbindex 2caecbe7..ecdda450 100644--- a/app/models/transaction.rb+++ b/app/models/transaction.rb@@ -6,8 +6,6 @@ class Transaction < ApplicationRecordvalidates :name, :date, :amount, :account, presence: true- after_commit :sync_account-monetize :amountscope :inflows, -> { where("amount > 0") }@@ -42,10 +40,4 @@ class Transaction < ApplicationRecordfiltersend-- private-- def sync_account- self.account.sync_later- endenddiff --git a/app/models/valuation.rb b/app/models/valuation.rbindex b19329ab..73a823e6 100644--- a/app/models/valuation.rb+++ b/app/models/valuation.rb@@ -3,7 +3,6 @@ class Valuation < ApplicationRecordbelongs_to :accountvalidates :account, :date, :value, presence: true- after_commit :sync_accountmonetize :valuescope :in_period, ->(period) { period.date_range.nil? ? all : where(date: period.date_range) }@@ -11,9 +10,4 @@ class Valuation < ApplicationRecorddef self.to_seriesTimeSeries.from_collection all, :value_moneyend-- private- def sync_account- self.account.sync_later- endenddiff --git a/test/models/account_test.rb b/test/models/account_test.rbindex 00d2b5b9..949335c6 100644--- a/test/models/account_test.rb+++ b/test/models/account_test.rb@@ -110,4 +110,22 @@ class AccountTest < ActiveSupport::TestCase# We know EUR -> NZD exchange rate is not available in fixturesassert_equal 0, account.series(currency: "NZD").values.countend++ test "should destroy dependent transactions" do+ assert_difference("Transaction.count", [email protected]) do+ @account.destroy+ end+ end++ test "should destroy dependent balances" do+ assert_difference("Account::Balance.count", [email protected]) do+ @account.destroy+ end+ end++ test "should destroy dependent valuations" do+ assert_difference("Valuation.count", [email protected]) do+ @account.destroy+ end+ endend