The personal finance app for everyone (by everyone)
Ruby
Fix three buttons that sent the wrong HTTP method (#4258)
alexcastgonz85fd5253ad7b
diff --git a/app/views/imports/_ready.html.erb b/app/views/imports/_ready.html.erbindex 85b8e93ad9..0d92d8084b 100644--- a/app/views/imports/_ready.html.erb+++ b/app/views/imports/_ready.html.erb@@ -100,7 +100,7 @@</div><% if import_summary_empty %>- <%= render DS::Button.new(text: t(".back_to_imports"), href: imports_path, variant: :secondary, full_width: true) %>+ <%= render DS::Link.new(text: t(".back_to_imports"), href: imports_path, variant: :secondary, full_width: true) %><% else %><%= render DS::Button.new(text: t(".publish_import"), href: publish_import_path(import), method: :post, full_width: true) %><% end %>diff --git a/app/views/imports/_revert_failure.html.erb b/app/views/imports/_revert_failure.html.erbindex 6c4872d069..67468c4dc4 100644--- a/app/views/imports/_revert_failure.html.erb+++ b/app/views/imports/_revert_failure.html.erb@@ -14,7 +14,8 @@<%= render DS::Button.new(text: t(".try_again"),full_width: true,- href: revert_import_path(import)+ href: revert_import_path(import),+ method: :put) %></div></div>diff --git a/app/views/reports/google_sheets_instructions.html.erb b/app/views/reports/google_sheets_instructions.html.erbindex 3eb8f4bb24..0df96ecb4e 100644--- a/app/views/reports/google_sheets_instructions.html.erb+++ b/app/views/reports/google_sheets_instructions.html.erb@@ -47,7 +47,7 @@data: { action: "click->DS--dialog#close" }) %><% else %>- <%= render DS::Button.new(+ <%= render DS::Link.new(text: t("reports.google_sheets_instructions.go_to_api_keys"),variant: "primary",full_width: true,diff --git a/test/controllers/imports_controller_test.rb b/test/controllers/imports_controller_test.rbindex 05b3d4046f..3b7f11661e 100644--- a/test/controllers/imports_controller_test.rb+++ b/test/controllers/imports_controller_test.rb@@ -31,6 +31,33 @@ class ImportsControllerTest < ActionDispatch::IntegrationTestassert_select "form[data-turbo-frame=_top] input[type=file][onchange='this.form.requestSubmit()']", count: 2end+ # DS::Button with an href renders button_to, which POSTs unless given a+ # method. revert only routes PUT, so Try again hit a routing error.+ test "try again on a failed revert PUTs to revert" do+ import = imports(:transaction)+ import.update_columns(status: "revert_failed")+ TransactionImport.any_instance.stubs(uploaded?: true, publishable?: true)++ get import_url(import)++ assert_response :success+ assert_select "form[action=?]", revert_import_path(import) do+ assert_select "input[name=_method][value=put]"+ end+ end++ # POSTing to imports_path is create, which needs import params.+ test "back to imports on an empty import is a link to the imports page" do+ import = imports(:transaction)+ TransactionImport.any_instance.stubs(uploaded?: true, publishable?: true)++ get import_url(import)++ assert_response :success+ assert_select "a[href=?]", imports_path, text: I18n.t("imports.ready.back_to_imports")+ assert_select "form[action=?]", imports_path, count: 0+ end+test "cancel marks a lost import as failed" doimport = imports(:transaction)import.update_columns(status: "importing", updated_at: 2.hours.ago)diff --git a/test/controllers/reports_controller_test.rb b/test/controllers/reports_controller_test.rbindex 1329d2aeff..e36d3ab42b 100644--- a/test/controllers/reports_controller_test.rb+++ b/test/controllers/reports_controller_test.rb@@ -761,6 +761,15 @@ class ReportsControllerTest < ActionDispatch::IntegrationTestassert_no_match(/#{Regexp.escape(I18n.t("reports.investment_performance.sells_count", count: 2))}/, response.body)end+ # POSTing to settings_api_keys_path is create, which needs api_key params.+ test "google sheets instructions link to the API keys page" do+ get google_sheets_instructions_reports_url++ assert_response :success+ assert_select "a[href=?][data-turbo-frame=_top]", settings_api_keys_path, text: I18n.t("reports.google_sheets_instructions.go_to_api_keys")+ assert_select "form[action=?]", settings_api_keys_path, count: 0+ end+private# n EUR-priced disposals in a USD account, each on its own date with its# own rate row, so every one needs a distinct lookup.