Skip to content

armgit / sure

Public Imported from GitHub
0

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.rb
index 8d9816b541..f66108f815 100644
--- a/test/controllers/bills_controller_test.rb
+++ b/test/controllers/bills_controller_test.rb
@@ -432,6 +432,10 @@ class BillsControllerTest < ActionDispatch::IntegrationTest
travel_to Date.current.end_of_month - 2.days
occurrence = snoozed_late_bill
travel_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 @user
pay(occurrence)
get bills_url
diff --git a/test/controllers/pages_controller_test.rb b/test/controllers/pages_controller_test.rb
index 2846a94efa..dd3b055295 100644
--- a/test/controllers/pages_controller_test.rb
+++ b/test/controllers/pages_controller_test.rb
@@ -903,7 +903,11 @@ class PagesControllerTest < ActionDispatch::IntegrationTest
end
test "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_month
diff --git a/test/controllers/reports_controller_test.rb b/test/controllers/reports_controller_test.rb
index 6be2d97e10..519f678f9d 100644
--- a/test/controllers/reports_controller_test.rb
+++ b/test/controllers/reports_controller_test.rb
@@ -116,6 +116,10 @@ class ReportsControllerTest < ActionDispatch::IntegrationTest
assert_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_path
assert_response :ok
assert_select "section[data-section-key='spending_vs_normal']" do
diff --git a/test/system/reports_test.rb b/test/system/reports_test.rb
index 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 do
sign_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