The personal finance app for everyone (by everyone)
Ruby
Treat a blank Reports period as this month (#5722)
jezmorc4a24827df73
diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rbindex 81a1c3421a..32921319d3 100644--- a/app/controllers/reports_controller.rb+++ b/app/controllers/reports_controller.rb@@ -98,7 +98,7 @@ class ReportsController < ApplicationControllerenddef export_transactions- @period_type = params[:period_type]&.to_sym || :monthly+ @period_type = requested_period_type@start_date = parse_date_param(:start_date) || default_start_date@end_date = parse_date_param(:end_date) || default_end_date@@ -157,7 +157,7 @@ class ReportsController < ApplicationControllerenddef picker- @period_type = params[:period_type]&.to_sym || :monthly+ @period_type = requested_period_type@start_date = parse_date_param(:start_date) || Date.current.beginning_of_month@category_selection = category_selection@trend_granularity = trend_granularity@@ -168,8 +168,13 @@ class ReportsController < ApplicationControllerendprivate+ # A blank period_type (`?period_type=`) means the default, as report_query keys it.+ def requested_period_type+ params[:period_type].presence&.to_sym || :monthly+ end+def setup_report_period(show_flash: false)- @period_type = params[:period_type]&.to_sym || :monthly+ @period_type = requested_period_type@start_date = parse_date_param(:start_date) || default_start_date@end_date = parse_date_param(:end_date) || default_end_datediff --git a/test/controllers/reports_controller_test.rb b/test/controllers/reports_controller_test.rbindex ba45ab47f0..3074bbf2d5 100644--- a/test/controllers/reports_controller_test.rb+++ b/test/controllers/reports_controller_test.rb@@ -600,6 +600,21 @@ class ReportsControllerTest < ActionDispatch::IntegrationTestendend+ test "a blank period is this month's report, so the plain page can be served from it" do+ budget = Budget.find_or_bootstrap(@family, start_date: Date.current.beginning_of_month)+ budget.budget_categories.find_or_initialize_by(category: @family.categories.expenses.first)+ .update!(budgeted_spending: Money.new(50000, @family.currency))++ with_memory_cache do+ get reports_path(period_type: "")+ assert_select "p", text: I18n.t("reports.summary.of_budget_used")++ ReportsController.any_instance.expects(:render_report_body).never+ get reports_path+ assert_select "p", text: I18n.t("reports.summary.of_budget_used")+ end+ end+test "changing whether investment contributions count as spending builds the report again" dowith_memory_cache doget reports_path(period_type: :ytd)