The personal finance app for everyone (by everyone)
Ruby
Let a balance value's note be cleared (#4806)
Yong Cong Sinc071e732658d
diff --git a/app/controllers/valuations_controller.rb b/app/controllers/valuations_controller.rbindex 605b6dfeaa..abc2bbdb9c 100644--- a/app/controllers/valuations_controller.rb+++ b/app/controllers/valuations_controller.rb@@ -69,8 +69,11 @@ class ValuationsController < ApplicationControllerdef updatereturn unless require_account_permission!(@entry.account)- # Notes updating is independent of reconciliation, just a simple CRUD operation- @entry.update!(notes: entry_params[:notes]) if entry_params[:notes].present?+ # Notes updating is independent of reconciliation, just a simple CRUD operation.+ # Saved whenever the form submits the field, so a cleared note stays cleared,+ # stored as nil like an entry that never had one; the balance confirmation+ # form does not send notes, so it leaves them alone.+ @entry.update!(notes: entry_params[:notes].presence) if entry_params.key?(:notes)if entry_params[:date].present? && entry_params[:amount].present?result = @entry.account.update_reconciliation(diff --git a/test/controllers/valuations_controller_test.rb b/test/controllers/valuations_controller_test.rbindex 54763fe88b..7fb5c4ad9e 100644--- a/test/controllers/valuations_controller_test.rb+++ b/test/controllers/valuations_controller_test.rb@@ -112,4 +112,24 @@ class ValuationsControllerTest < ActionDispatch::IntegrationTestassert_response :unprocessable_entityassert_match I18n.t("valuations.errors.amount_required"), response.bodyend++ test "clearing a note saves it cleared" do+ @entry.update!(notes: "Old note")++ patch valuation_url(@entry), params: { entry: { notes: "" } }++ assert_redirected_to account_url(@entry.account)+ assert_nil @entry.reload.notes+ end++ test "a balance update without the notes field keeps the note" do+ @entry.update!(notes: "Keep me")++ patch valuation_url(@entry), params: { entry: { amount: 22000, date: Date.current } }++ assert_redirected_to account_url(@entry.account)+ @entry.reload+ assert_equal 22000, @entry.amount+ assert_equal "Keep me", @entry.notes+ endend