The personal finance app for everyone (by everyone)
Ruby
Fix four tests that fail in the first days of a month (#4637)
Yong Cong Sin6372ce92f186
diff --git a/test/controllers/bills_controller_test.rb b/test/controllers/bills_controller_test.rbindex 8d9816b541..f66108f815 100644--- a/test/controllers/bills_controller_test.rb+++ b/test/controllers/bills_controller_test.rb@@ -432,6 +432,10 @@ class BillsControllerTest < ActionDispatch::IntegrationTesttravel_to Date.current.end_of_month - 2.daysoccurrence = snoozed_late_billtravel_to occurrence.reload.effective_due_on - 2.days+ # Run in the first days of a month, this lands more than+ # Session::INACTIVITY_TIMEOUT after setup signed in, with no request in+ # between to keep the session alive; the user would sign in again.+ sign_in @userpay(occurrence)get bills_urldiff --git a/test/controllers/pages_controller_test.rb b/test/controllers/pages_controller_test.rbindex 2846a94efa..dd3b055295 100644--- a/test/controllers/pages_controller_test.rb+++ b/test/controllers/pages_controller_test.rb@@ -903,7 +903,11 @@ class PagesControllerTest < ActionDispatch::IntegrationTestendtest "dashboard spending trend header treats current month final day as in progress" do- selected_month = (0..24).map { |i| i.months.ago.beginning_of_month.to_date }+ # A fully past month. In the first days of a month that follows a longer+ # one the search would otherwise pick the current month, and the fixture+ # transactions dated a few days ago would land in the previous month's+ # total.+ selected_month = (1..24).map { |i| i.months.ago.beginning_of_month.to_date }.find { |m| (m - 1.month).end_of_month.day > m.end_of_month.day }previous_month = (selected_month - 1.month).beginning_of_monthdiff --git a/test/controllers/reports_controller_test.rb b/test/controllers/reports_controller_test.rbindex 6be2d97e10..519f678f9d 100644--- a/test/controllers/reports_controller_test.rb+++ b/test/controllers/reports_controller_test.rb@@ -116,6 +116,10 @@ class ReportsControllerTest < ActionDispatch::IntegrationTestassert_select "section[data-section-key='spending_vs_normal']", count: 0@user.update!(preferences: @user.preferences.merge("preview_features_enabled" => true))+ # The treemap only draws spending inside the period, which for the current+ # month runs up to today; fixture transactions are dated a few days ago, so+ # on the 1st there would be nothing to draw.+ create_transaction(date: Date.current, amount: 50, category: categories(:food_and_drink))get reports_pathassert_response :okassert_select "section[data-section-key='spending_vs_normal']" dodiff --git a/test/system/reports_test.rb b/test/system/reports_test.rbindex 4499bef26e..7fed3edbdb 100644--- a/test/system/reports_test.rb+++ b/test/system/reports_test.rb@@ -1,8 +1,14 @@require "application_system_test_case"class ReportsTest < ApplicationSystemTestCase+ include EntriesTestHelper+setup dosign_in users(:family_admin)+ # The breakdown table, whose Amount link one test follows, only renders+ # when the month has transactions; fixtures are dated a few days ago, which+ # on the 1st is last month.+ create_transaction(date: Date.current, amount: 50, category: categories(:food_and_drink))visit reports_path(period_type: :monthly)# The tooltip only shows once the page's controllers are connected, so