Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Keep the money field's currency handler next to the caller's action (#3916)

GFR25d9bf87a18d
diff --git a/app/views/shared/_money_field.html.erb b/app/views/shared/_money_field.html.erb
index 061991f0e4..27f2d19fb1 100644
--- a/app/views/shared/_money_field.html.erb
+++ b/app/views/shared/_money_field.html.erb
@@ -73,7 +73,12 @@
<% unless options[:hide_currency] %>
<div>
- <% currency_data = (options[:currency_data] || {}).merge({
+ <%# Callers pass symbol keys (e.g. `action:`), so stringify first:
+ otherwise delete("action") below misses the caller's action and
+ both an :action and an "action" key get rendered, and the
+ browser keeps only the first data-action attribute, dropping
+ money-field#handleCurrencyChange. %>
+ <% currency_data = (options[:currency_data] || {}).stringify_keys.merge({
"money-field-target": "currency",
"auto-submit-form-target": ("auto" if options[:auto_submit])
}.compact)
diff --git a/test/controllers/transactions_controller_test.rb b/test/controllers/transactions_controller_test.rb
index 6d84e7c2fe..8930aef5ef 100644
--- a/test/controllers/transactions_controller_test.rb
+++ b/test/controllers/transactions_controller_test.rb
@@ -87,6 +87,17 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
assert_equal parent_index + 1, child_index
end
+ # The form passes its own change action on the currency select; the money
+ # field must keep its handleCurrencyChange alongside it, or switching the
+ # currency never refreshes the amount's step and precision.
+ test "new form wires the currency select to both the money field and the transaction form" do
+ get new_transaction_path
+
+ assert_response :success
+ assert_select "select[data-money-field-target=currency][data-action=?]",
+ "change->money-field#handleCurrencyChange change->transaction-form#onCurrencyChange"
+ end
+
test "creates with transaction details" do
assert_difference [ "Entry.count", "Transaction.count" ], 1 do
post transactions_url, params: {