Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Include the family currency in the Reports cache key (#5885)

Erywim7b0356eee719
diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb
index 97e63efd2c..03114aa48a 100644
--- a/app/controllers/reports_controller.rb
+++ b/app/controllers/reports_controller.rb
@@ -313,13 +313,13 @@ class ReportsController < ApplicationController
].join("|"))
end
- # The family's settings that change a report's figures or how it reads
- # (currency is already in family.build_cache_key). Part of the key, not the
- # version: a build made under other settings is never served.
+ # The family's settings that change a report's figures or how it reads.
+ # Part of the key, not the version: a build made under other settings is
+ # never served, even while its replacement is still being built.
def report_family_settings_version
family = Current.family
Digest::SHA256.hexdigest([
- family.investment_contributions_as_spending, family.month_start_day, family.date_format,
+ family.currency, family.investment_contributions_as_spending, family.month_start_day, family.date_format,
family.household_budget_enabled, family.personal_budgets, family.moniker
].join("|"))
end
diff --git a/test/controllers/reports_controller_test.rb b/test/controllers/reports_controller_test.rb
index 1d0d6f2e8d..d1da2ad3c3 100644
--- a/test/controllers/reports_controller_test.rb
+++ b/test/controllers/reports_controller_test.rb
@@ -625,6 +625,21 @@ class ReportsControllerTest < ActionDispatch::IntegrationTest
end
end
+ test "changing the family currency builds the report again" do
+ with_memory_cache do
+ get reports_path(period_type: :ytd)
+ assert_response :ok
+
+ @family.update!(currency: "EUR")
+
+ ReportsController.any_instance.expects(:render_report_body).once
+ .returns({ notes: "", has_transactions: true, summary: "<p id=rebuilt></p>", sections: [] })
+ get reports_path(period_type: :ytd)
+
+ assert_select "#rebuilt"
+ end
+ end
+
test "assigning a tag marks the cached report stale" do
with_memory_cache do
get reports_path(period_type: :ytd)