Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Fix export polling missing template error (#796) (#721)

Dream91b79053fd33
diff --git a/app/controllers/family_exports_controller.rb b/app/controllers/family_exports_controller.rb
index d3a9163f52..cc9226a54d 100644
--- a/app/controllers/family_exports_controller.rb
+++ b/app/controllers/family_exports_controller.rb
@@ -26,7 +26,11 @@ class FamilyExportsController < ApplicationController
[ t("breadcrumbs.home"), root_path ],
[ t("breadcrumbs.exports"), family_exports_path ]
]
- render layout: "settings"
+
+ respond_to do |format|
+ format.html { render layout: "settings" }
+ format.turbo_stream { redirect_to family_exports_path }
+ end
end
def download
diff --git a/app/javascript/controllers/polling_controller.js b/app/javascript/controllers/polling_controller.js
index 97cc252c1e..0e9e743f8a 100644
--- a/app/javascript/controllers/polling_controller.js
+++ b/app/javascript/controllers/polling_controller.js
@@ -35,7 +35,7 @@ export default class extends Controller {
try {
const response = await fetch(this.urlValue, {
headers: {
- Accept: "text/vnd.turbo-stream.html",
+ Accept: "text/html",
"Turbo-Frame": this.element.id,
},
});
diff --git a/test/controllers/family_exports_controller_test.rb b/test/controllers/family_exports_controller_test.rb
index a7a820ae3a..217a6c170f 100644
--- a/test/controllers/family_exports_controller_test.rb
+++ b/test/controllers/family_exports_controller_test.rb
@@ -140,6 +140,17 @@ class FamilyExportsControllerTest < ActionDispatch::IntegrationTest
assert_not ActiveStorage::Attachment.exists?(file_id)
end
+ test "index responds to html with settings layout" do
+ get family_exports_path
+ assert_response :success
+ assert_select "title" # rendered with layout
+ end
+
+ test "index responds to turbo_stream without raising MissingTemplate" do
+ get family_exports_path, headers: { "Accept" => "text/vnd.turbo-stream.html" }
+ assert_redirected_to family_exports_path
+ end
+
test "non-admin cannot delete export" do
export = @family.family_exports.create!(status: "completed")
sign_in @non_admin