Let the third-currency reports test run on a month's first two days

Merged
GA
2mo ago
+3-1

Problem

ci / test_unit fails on main and on every PR on the 1st and 2nd of each month, in ReportsControllerTest#test_a_disposal_carried_in_a_third_currency_is_converted,_not_passed_through_at_parity:

ActiveRecord::RecordInvalid: Validation failed: Date has already been taken
    test/controllers/reports_controller_test.rb:57

The test (from #3616) creates an EUR→GBP rate dated Date.current.beginning_of_month. test/fixtures/exchange_rates.yml already holds EUR→GBP rows dated Date.current and 1.day.ago, so on the 1st and 2nd the new row duplicates one of them and trips validates :date, uniqueness: { scope: %i[from_currency to_currency] }. Main's scheduled run on 2026-10-01 at 01:53 UTC failed this way before anything merged that day.

Moving the date doesn't work: on the 1st, the first of the month is the only day in the report's default period.

Fix

The test now updates the fixture's row when one exists for that date and creates it otherwise, so the rate is 0.8 either way:

ExchangeRate.find_or_initialize_by(from_currency: "EUR", to_currency: "GBP", date: date).update!(rate: 0.8)

Test-only change; no app code is touched.

Validation

Run on 2026-10-01, one of the failing days:

  • Without the change, the test fails as above. With it, test/controllers/reports_controller_test.rb passes (40 runs, 0 failures).
  • bin/rails test: 10429 runs, 0 failures, 0 errors.
  • RuboCop is clean on the changed file.

Summary by CodeRabbit

  • Tests
    • Updated a report test to avoid exchange-rate conflicts when a rate already exists for the test date.