From 2bfa9068f132db8472f25b8136364f283f18add9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 11 Aug 2021 05:09:45 +0200 Subject: [PATCH] Add and apply Rails/HttpStatus rubocop rule We were already using it in most places. Since rubocop-rails 2.11.0, this rule also detects offenses when using the `head` method, which we were using with a plain `404`. --- .rubocop.yml | 3 +++ app/controllers/direct_uploads_controller.rb | 2 +- app/controllers/pages_controller.rb | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 9f3e80d8f..c239baeb6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -245,6 +245,9 @@ Rails/HasManyOrHasOneDependent: Enabled: true Severity: refactor +Rails/HttpStatus: + Enabled: true + Rails/InverseOf: Enabled: true Exclude: diff --git a/app/controllers/direct_uploads_controller.rb b/app/controllers/direct_uploads_controller.rb index b46fdda29..8d820e47a 100644 --- a/app/controllers/direct_uploads_controller.rb +++ b/app/controllers/direct_uploads_controller.rb @@ -21,7 +21,7 @@ class DirectUploadsController < ApplicationController attachment_url: @direct_upload.relation.attachment.url } else render json: { errors: @direct_upload.errors[:attachment].join(", ") }, - status: 422 + status: :unprocessable_entity end end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 03bb40828..d33854784 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -14,6 +14,6 @@ class PagesController < ApplicationController render action: params[:id] end rescue ActionView::MissingTemplate - head 404, content_type: "text/html" + head :not_found, content_type: "text/html" end end