From 31510d76e9850f5451d899dd9675590730e6551f Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Mon, 23 Jun 2025 15:21:38 +0300 Subject: [PATCH] Replace redirect with bad request error for new report with missing params --- app/controllers/reports_controller.rb | 2 +- config/locales/en.yml | 1 - test/controllers/reports_controller_test.rb | 7 +++++++ test/system/report_diary_entry_test.rb | 6 ------ 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index e4a0bf41b..3197d8553 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -14,7 +14,7 @@ class ReportsController < ApplicationController @report = Report.new @report.issue = Issue.find_or_initialize_by(create_new_report_params) else - redirect_to root_path, :notice => t(".missing_params") + head :bad_request end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 025740752..bd3fbefcf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1656,7 +1656,6 @@ en: reports: new: title_html: "Report %{link}" - missing_params: "Cannot create a new report" disclaimer: intro: "Before sending your report to the site moderators, please ensure that:" not_just_mistake: You are certain that the problem is not just a mistake diff --git a/test/controllers/reports_controller_test.rb b/test/controllers/reports_controller_test.rb index a7f65de62..61c7a80ca 100644 --- a/test/controllers/reports_controller_test.rb +++ b/test/controllers/reports_controller_test.rb @@ -1,6 +1,13 @@ require "test_helper" class ReportsControllerTest < ActionDispatch::IntegrationTest + def test_new_missing_parameters + session_for(create(:user)) + get new_report_path + + assert_response :bad_request + end + def test_new_report_without_login target_user = create(:user) get new_report_path(:reportable_id => target_user.id, :reportable_type => "User") diff --git a/test/system/report_diary_entry_test.rb b/test/system/report_diary_entry_test.rb index 52884c2c9..e8004ec1d 100644 --- a/test/system/report_diary_entry_test.rb +++ b/test/system/report_diary_entry_test.rb @@ -56,10 +56,4 @@ class ReportDiaryEntryTest < ApplicationSystemTestCase assert_not_predicate issue, :resolved? assert_predicate issue, :open? end - - def test_missing_report_params - sign_in_as(create(:user)) - visit new_report_path - assert_content I18n.t("reports.new.missing_params") - end end -- 2.39.5