The personal finance app for everyone (by everyone)
Ruby
chore(goals): drop copy-pasted duplicates and an unused lock-key helper (#3159)
buzzromainc26b16d36fc1
diff --git a/app/models/account.rb b/app/models/account.rbindex 3cbba8a715..57771ac2fe 100644--- a/app/models/account.rb+++ b/app/models/account.rb@@ -491,26 +491,6 @@ class Account < ApplicationRecordbalance.to_d - goal_earmarked_totalend- # Total fixed earmark this account currently has reserved across every- # non-archived goal (unallocated/whole-balance links reserve no fixed- # slice). Mirrors Budget#allocated_spending.- def goal_earmarked_total- GoalAccount.joins(:goal)- .where(account_id: id)- .where.not(allocated_amount: nil)- .where.not(goals: { state: "archived" })- .sum(:allocated_amount)- .to_d- end-- # Headroom left to earmark toward goals before fixed allocations exceed the- # balance. Negative means the account is over-earmarked. Intended to back a- # non-blocking over-allocation warning (UI is a follow-up). Mirrors- # Budget#available_to_allocate.- def free_to_earmark- balance.to_d - goal_earmarked_total- end-def logo_urlif institution_domain.present? && Setting.brand_fetch_client_id.present?logo_size = Setting.brand_fetch_logo_sizediff --git a/app/models/goal.rb b/app/models/goal.rbindex bc01420358..8d43946014 100644--- a/app/models/goal.rb+++ b/app/models/goal.rb@@ -45,10 +45,6 @@ class Goal < ApplicationRecordorder(Arel.sql("CASE state WHEN 'active' THEN 0 WHEN 'paused' THEN 1 WHEN 'completed' THEN 2 ELSE 3 END"))}- def self.advisory_lock_key_for(family_id)- Digest::SHA1.hexdigest("goals:family:#{family_id}").to_i(16) % (2**63)- end-# Family-wide map of non-archived goal earmarks, grouped by account_id:# { account_id => [{ goal_id:, allocated_amount: }, ...] }. The controller# assigns this to each goal on index (goal.pooled_allocations = ...) so thediff --git a/test/models/goal_test.rb b/test/models/goal_test.rbindex 3c9da94cf7..d4efc1aa82 100644--- a/test/models/goal_test.rb+++ b/test/models/goal_test.rb@@ -339,13 +339,6 @@ class GoalTest < ActiveSupport::TestCaseassert_equal :reached, @goal.display_statusend- test "advisory_lock_key_for is stable per family" do- k1 = Goal.advisory_lock_key_for(@family.id)- k2 = Goal.advisory_lock_key_for(@family.id)- assert_equal k1, k2- assert_kind_of Integer, k1- end-test "any_connected_account? reflects plaid_account presence" doassert @goal.any_connected_account?only_manual = goals(:emergency_fund)