From: Harry Wood Date: Wed, 4 May 2022 15:34:40 +0000 (+0100) Subject: Report verification render not redirect X-Git-Tag: live~1660^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/fcbccb6a441fb05ee92227dfa0cb90a2db60296c?ds=sidebyside Report verification render not redirect Fix an issue with the report verification, causing it to lose the text of a report if the user fails to fill in a category. By using a `render` instead of a `redirect_to`, the rails standard verification behaviour works better. It means we also get a nice red "can't be blank" message highlighting the specific missing field. --- diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index a04fab5b9..30cb9da7c 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -28,7 +28,8 @@ class ReportsController < ApplicationController redirect_to helpers.reportable_url(@report.issue.reportable), :notice => t(".successful_report") else - redirect_to new_report_path(:reportable_type => @report.issue.reportable_type, :reportable_id => @report.issue.reportable_id), :notice => t(".provide_details") + flash[:notice] = t(".provide_details") + render :action => "new" end end diff --git a/test/controllers/reports_controller_test.rb b/test/controllers/reports_controller_test.rb index e8f59ec5e..8374e76d9 100644 --- a/test/controllers/reports_controller_test.rb +++ b/test/controllers/reports_controller_test.rb @@ -63,10 +63,12 @@ class ReportsControllerTest < ActionDispatch::IntegrationTest category = "other" post reports_path(:report => { :category => category, - :issue => { :reportable_id => 1, :reportable_type => "User" } + :issue => { :reportable_id => target_user.id, :reportable_type => "User" } }) end - assert_response :redirect + assert_response :success + assert_template :new + assert_match(/Please provide the required details/, flash[:notice]) assert_equal 1, issue.reports.count end