Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

feat: pre-fill new rules with the merchant name (#5336)

matted0ea6acbe0a
diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb
index 6c904a3589..502ec04c81 100644
--- a/app/controllers/transactions_controller.rb
+++ b/app/controllers/transactions_controller.rb
@@ -181,7 +181,8 @@ class TransactionsController < ApplicationController
flash[:cta] = {
type: "category_rule",
category_id: transaction.category_id,
- category_name: transaction.category.name
+ category_name: transaction.category.name,
+ merchant_name: @entry.name
}
end
diff --git a/test/controllers/transaction_categories_controller_test.rb b/test/controllers/transaction_categories_controller_test.rb
index 2e60292262..cdbbdb2db8 100644
--- a/test/controllers/transaction_categories_controller_test.rb
+++ b/test/controllers/transaction_categories_controller_test.rb
@@ -46,6 +46,7 @@ class TransactionCategoriesControllerTest < ActionDispatch::IntegrationTest
assert_response :success
# The prompt is rendered into the turbo-stream response (flash is cleared once rendered).
assert_match %r{/rules/new\?[^"]*action_value=#{category.id}}, response.body
+ assert_match %r{/rules/new\?[^"]*name=AMZN\+Mktp\+UK}, response.body
end
test "does not offer a rule prompt when an existing rule already covers this transaction" do
diff --git a/test/controllers/transactions_controller_test.rb b/test/controllers/transactions_controller_test.rb
index c9ef120189..3435717f3e 100644
--- a/test/controllers/transactions_controller_test.rb
+++ b/test/controllers/transactions_controller_test.rb
@@ -597,7 +597,7 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
entryable_attributes: {
id: @entry.entryable_id,
tag_ids: [ tags(:one).id, tags(:two).id ],
- category_id: Category.first.id,
+ category_id: categories(:income).id,
merchant_id: Merchant.first.id
}
}
@@ -611,12 +611,13 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
assert_equal "USD", @entry.currency
assert_equal -100, @entry.amount
assert_equal [ tags(:one).id, tags(:two).id ].sort, @entry.entryable.tag_ids.sort
- assert_equal Category.first.id, @entry.entryable.category_id
+ assert_equal categories(:income).id, @entry.entryable.category_id
assert_equal Merchant.first.id, @entry.entryable.merchant_id
assert_equal "test notes", @entry.notes
assert_equal false, @entry.excluded
assert_equal "Transaction updated", flash[:notice]
+ assert_equal "Updated name", flash[:cta][:merchant_name]
assert_redirected_to account_url(@entry.account)
assert_enqueued_with(job: SyncJob)
end