Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Fix(lunchflow): Missing template on validation failure in create action (#2724)

sentry[bot]fb47e402473c
diff --git a/app/controllers/lunchflow_items_controller.rb b/app/controllers/lunchflow_items_controller.rb
index 0fe018a554..c52be446a9 100644
--- a/app/controllers/lunchflow_items_controller.rb
+++ b/app/controllers/lunchflow_items_controller.rb
@@ -441,7 +441,7 @@ class LunchflowItemsController < ApplicationController
locals: { error_message: @error_message }
), status: :unprocessable_entity
else
- render :new, status: :unprocessable_entity
+ redirect_back_or_to accounts_path, alert: @error_message
end
end
end
diff --git a/test/controllers/lunchflow_items_controller_test.rb b/test/controllers/lunchflow_items_controller_test.rb
new file mode 100644
index 0000000000..c8e03fb1ba
--- /dev/null
+++ b/test/controllers/lunchflow_items_controller_test.rb
@@ -0,0 +1,21 @@
+require "test_helper"
+
+class LunchflowItemsControllerTest < ActionDispatch::IntegrationTest
+ setup do
+ sign_in @user = users(:family_admin)
+ end
+
+ test "invalid non-Turbo create redirects instead of rendering a missing template" do
+ assert_no_difference "LunchflowItem.count" do
+ post lunchflow_items_url, params: {
+ lunchflow_item: {
+ name: "Invalid Lunchflow connection",
+ api_key: ""
+ }
+ }
+ end
+
+ assert_redirected_to accounts_path
+ assert_match "Api key can't be blank", flash[:alert]
+ end
+end