Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Migrate the test suite to Minitest 6.1

Juan José Mata2ae6c237980e
diff --git a/Gemfile b/Gemfile
index 9927a63d39..9be49ea42b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -145,10 +145,10 @@ group :development, :test do
end
group :test do
- # Minitest 6 removes minitest/mock and requires a separate test-suite migration.
- gem "minitest", "~> 5.27"
gem "capybara"
gem "selenium-webdriver"
+ gem "minitest", "~> 6.1"
+ gem "minitest-mock"
gem "mocha"
gem "vcr"
gem "webmock"
diff --git a/Gemfile.lock b/Gemfile.lock
index 24ad073add..93a188765a 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -436,7 +436,10 @@ GEM
benchmark
logger
mini_mime (1.1.5)
- minitest (5.27.0)
+ minitest (6.1.0)
+ drb (~> 2.0)
+ prism (>= 1.5, < 3)
+ minitest-mock (5.27.0)
mocha (2.7.1)
ruby2_keywords (>= 0.0.5)
msgpack (1.8.2)
@@ -579,7 +582,7 @@ GEM
pp (0.6.3)
prettyprint
prettyprint (0.2.0)
- prism (1.4.0)
+ prism (1.9.0)
propshaft (1.1.0)
actionpack (>= 7.0.0)
activesupport (>= 7.0.0)
@@ -959,7 +962,8 @@ DEPENDENCIES
logtail-rails
lookbook (= 2.3.11)
lucide-rails
- minitest (~> 5.27)
+ minitest (~> 6.1)
+ minitest-mock
mocha
octokit
omniauth (~> 2.2)
diff --git a/test/controllers/api/v1/transactions_controller_test.rb b/test/controllers/api/v1/transactions_controller_test.rb
index dee8ac5687..338ea7c1de 100644
--- a/test/controllers/api/v1/transactions_controller_test.rb
+++ b/test/controllers/api/v1/transactions_controller_test.rb
@@ -1008,14 +1008,13 @@ class Api::V1::TransactionsControllerTest < ActionDispatch::IntegrationTest
%w[category_id merchant_id].each do |attribute|
test "update with a #{attribute} that does not exist is refused" do
- before = @transaction.reload.public_send(attribute)
-
- put api_v1_transaction_url(@transaction),
- params: { transaction: { attribute => SecureRandom.uuid } },
- headers: api_headers(@api_key)
+ assert_no_changes -> { @transaction.reload.public_send(attribute) } do
+ put api_v1_transaction_url(@transaction),
+ params: { transaction: { attribute => SecureRandom.uuid } },
+ headers: api_headers(@api_key)
+ end
assert_response :unprocessable_entity
- assert_equal before, @transaction.reload.public_send(attribute)
end
test "create with a #{attribute} that does not exist is refused and creates nothing" do
diff --git a/test/controllers/pages_controller_test.rb b/test/controllers/pages_controller_test.rb
index dd3b055295..e2d214dee0 100644
--- a/test/controllers/pages_controller_test.rb
+++ b/test/controllers/pages_controller_test.rb
@@ -268,14 +268,13 @@ class PagesControllerTest < ActionDispatch::IntegrationTest
end
test "update_preferences ignores malformed dashboard_section_layout without erroring" do
- previous_height = @user.reload.dashboard_section_height("net_worth_chart")
-
- patch "/dashboard/preferences", params: {
- preferences: { dashboard_section_layout: "not-a-hash" }
- }, as: :json
+ assert_no_changes -> { @user.reload.dashboard_section_height("net_worth_chart") } do
+ patch "/dashboard/preferences", params: {
+ preferences: { dashboard_section_layout: "not-a-hash" }
+ }, as: :json
+ end
assert_response :ok
- assert_equal previous_height, @user.reload.dashboard_section_height("net_worth_chart")
end
test "dashboard memoizes income statement period totals while rendering" do
diff --git a/test/controllers/recurring_transactions_controller_test.rb b/test/controllers/recurring_transactions_controller_test.rb
index 2a95555557..f61c573598 100644
--- a/test/controllers/recurring_transactions_controller_test.rb
+++ b/test/controllers/recurring_transactions_controller_test.rb
@@ -1439,10 +1439,10 @@ class RecurringTransactionsControllerTest < ActionDispatch::IntegrationTest
end
assert_redirected_to root_path
- original_name = @recurring_transaction.name
- patch recurring_transaction_url(@recurring_transaction), params: { recurring_transaction: { name: "Renamed" } }
+ assert_no_changes -> { @recurring_transaction.reload.name } do
+ patch recurring_transaction_url(@recurring_transaction), params: { recurring_transaction: { name: "Renamed" } }
+ end
assert_redirected_to root_path
- assert_equal original_name, @recurring_transaction.reload.name
suggestion = create_series(name: "Maybe A Bill", status: "suggested")
post confirm_recurring_transaction_url(suggestion)
diff --git a/test/controllers/transactions/bulk_updates_controller_test.rb b/test/controllers/transactions/bulk_updates_controller_test.rb
index 8e2b975a0f..6e19d079e0 100644
--- a/test/controllers/transactions/bulk_updates_controller_test.rb
+++ b/test/controllers/transactions/bulk_updates_controller_test.rb
@@ -204,21 +204,21 @@ class Transactions::BulkUpdatesControllerTest < ActionDispatch::IntegrationTest
test "bulk update skips entries from accounts the user can only read" do
read_only_account = accounts(:credit_card) # shared read_only with family_member
entry = create_transaction(account: read_only_account, name: "Starbucks")
- original_category = entry.transaction.category
sign_in users(:family_member)
- post transactions_bulk_update_url, params: {
- bulk_update: {
- entry_ids: [ entry.id ],
- category_id: categories(:food_and_drink).id,
- notes: "Changed by a read-only member"
+ assert_no_changes -> { entry.reload.transaction.category } do
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: [ entry.id ],
+ category_id: categories(:food_and_drink).id,
+ notes: "Changed by a read-only member"
+ }
}
- }
+ end
assert_redirected_to transactions_url
assert_equal "0 transactions updated", flash[:notice]
- assert_equal original_category, entry.reload.transaction.category
assert_nil entry.notes
end
diff --git a/test/controllers/transfers_controller_test.rb b/test/controllers/transfers_controller_test.rb
index c9524795f8..ba88330c96 100644
--- a/test/controllers/transfers_controller_test.rb
+++ b/test/controllers/transfers_controller_test.rb
@@ -669,13 +669,13 @@ class TransfersControllerTest < ActionDispatch::IntegrationTest
# family_member: full_control on depository (outflow), read_only on credit_card (inflow)
sign_in users(:family_member)
transfer = transfers(:one)
- original_inflow_kind = transfer.inflow_transaction.kind
- patch transfer_url(transfer), params: { transfer: { status: "confirmed" } }
+ assert_no_changes -> { transfer.inflow_transaction.reload.kind } do
+ patch transfer_url(transfer), params: { transfer: { status: "confirmed" } }
+ end
assert_redirected_to transactions_url
assert transfer.reload.pending?
- assert_equal original_inflow_kind, transfer.inflow_transaction.reload.kind
end
test "can add notes to transfer" do
diff --git a/test/models/plaid_account/liabilities/student_loan_processor_test.rb b/test/models/plaid_account/liabilities/student_loan_processor_test.rb
index b1287e79a0..ca82cb8a62 100644
--- a/test/models/plaid_account/liabilities/student_loan_processor_test.rb
+++ b/test/models/plaid_account/liabilities/student_loan_processor_test.rb
@@ -123,7 +123,11 @@ class PlaidAccount::Liabilities::StudentLoanProcessorTest < ActiveSupport::TestC
PlaidAccount::Liabilities::StudentLoanProcessor.new(@plaid_account).process
- assert_equal expected, @plaid_account.current_account.loan.reload.term_months, "payoff on #{payoff}"
+ if expected.nil?
+ assert_nil @plaid_account.current_account.loan.reload.term_months, "payoff on #{payoff}"
+ else
+ assert_equal expected, @plaid_account.current_account.loan.reload.term_months, "payoff on #{payoff}"
+ end
end
end
diff --git a/test/models/portfolio/flow_classifier_test.rb b/test/models/portfolio/flow_classifier_test.rb
index 879d483cee..de04785aa8 100644
--- a/test/models/portfolio/flow_classifier_test.rb
+++ b/test/models/portfolio/flow_classifier_test.rb
@@ -252,8 +252,13 @@ class Portfolio::FlowClassifierTest < ActiveSupport::TestCase
shapes.each do |flag, expected|
entry = create_labelled_transaction(account: @brokerage, label: "Dividend", amount: -10, extra: { "plaid" => { "pending" => flag } })
- assert_equal expected, @family_scope.classify(entry.reload), "Ruby, pending=#{flag.inspect}"
- assert_equal expected, @family_scope.classify_ids([ entry.id ])[entry.id], "SQL, pending=#{flag.inspect}"
+ if expected.nil?
+ assert_nil @family_scope.classify(entry.reload), "Ruby, pending=#{flag.inspect}"
+ assert_nil @family_scope.classify_ids([ entry.id ])[entry.id], "SQL, pending=#{flag.inspect}"
+ else
+ assert_equal expected, @family_scope.classify(entry.reload), "Ruby, pending=#{flag.inspect}"
+ assert_equal expected, @family_scope.classify_ids([ entry.id ])[entry.id], "SQL, pending=#{flag.inspect}"
+ end
end
end
@@ -300,8 +305,6 @@ class Portfolio::FlowClassifierTest < ActiveSupport::TestCase
assert_equal corpus.size, sql.size
ruby.each do |id, ruby_class|
entry = corpus.find { |e| e.id == id }
- # assert_nil / assert_equal split so a nil expectation does not trip
- # Minitest's deprecation of assert_equal nil.
message =
"scope #{classifier.scope_account_ids.size} accounts: #{entry.name} (#{entry.entryable_type}, #{entry.entryable.try(:investment_activity_label).inspect}, kind #{entry.entryable.try(:kind).inspect})"
if ruby_class.nil?