RSpec実行した時に下記のメッセージが大量に出たので対応しました。
アプリケーションログにも出ていると思います。

DEPRECATION WARNIN:廃止の警告
いずれ廃止するので対応しておいてね。という案内ですね。
Gem以外にもRubyのバージョンアップでも出る事があるので、
こまめに対応しておくとバージョンアップが楽になります。

現象

1行目が大量に出て、対応すると2行目が大量に出ます。
似てるので対応できていないんじゃないかと誤解しました。

DEPRECATION WARNING: #extension_whitelist is deprecated,
 use #extension_allowlist instead. (called from block (2 levels) in <main>
 at /Users/xxxx/workspace/rails-app-origin/spec/support/user_contexts.rb:30)

DEPRECATION WARNING: #content_type_whitelist is deprecated,
 use #content_type_allowlist instead. (called from block (2 levels) in <main>
 at /Users/xxxx/workspace/rails-app-origin/spec/support/user_contexts.rb:30)

spec/support/user_contexts.rb:30

	user.image = fixture_file_upload(TEST_IMAGE_FILE, TEST_IMAGE_TYPE)

対応

下記を変更すればOKですが、

app/uploaders/image_uploader.rb

-  def extension_whitelist
+  def extension_allowlist

-  def content_type_whitelist	
+  def content_type_allowlist

言語ファイルの名前も変わってます。
こちらは無くても警告でないので、気付き難いです。

config/locales/ja.yml

       carrierwave_processing_error: '処理に失敗しました。' # failed to be processed
       carrierwave_integrity_error: '許可されたファイルタイプではありません。別のファイルを使用してください。' # is not of an allowed file type
       carrierwave_download_error: 'ダウンロードできません。' # could not be downloaded
-      extension_whitelist_error: '%{allowed_types}のいずれかのファイルを使用してください。'
+      extension_allowlist_error: '%{extension}はアップロードできません。使用できるタイプ: %{allowed_types}' # "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
+      extension_denylist_error: "%{extension}はアップロードできません。使用できないタイプ: %{prohibited_types}" # "You are not allowed to upload %{extension} files, prohibited types: %{prohibited_types}"
-      content_type_whitelist_error: '%{allowed_types}のいずれかのファイルを使用してください。'
+      content_type_allowlist_error: "%{content_type}はアップロードできません。使用できるタイプ: %{allowed_types}" # "You are not allowed to upload %{content_type} files, allowed types: %{allowed_types}"
+      content_type_denylist_error: '%{content_type}はアップロードできません。' # "You are not allowed to upload %{content_type} files"
       rmagick_processing_error: '画像変換に失敗しました。別のファイルを使用してください。' # "Failed to manipulate with rmagick, maybe it is not an image?"
       mini_magick_processing_error: '画像変換に失敗しました。別のファイルを使用してください。' # "Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: %{e}"
+      vips_processing_error: "画像変換に失敗しました。別のファイルを使用してください。" # "Failed to manipulate with vips, maybe it is not an image? Original Error: %{e}"
       min_size_error: '%{min_size}以上のファイルを使用してください。' # "File size should be greater than %{min_size}"
       max_size_error: '%{max_size}以下のファイルを使用してください。' # "File size should be less than %{max_size}"

何故変えたのか?

対応前に、RuboCopの新しいルールを適用した所、下記のエラーが出ました。
これに対応し始めたんでしょうね。
ちゃんと、DEPRECATION WARNINGで対応開始しているのは流石です。

app/uploaders/image_uploader.rb:54:11: C: Naming/InclusiveLanguage:
 Consider replacing problematic term 'white list' with 'allowlist' or 'permit'.
  # Add a white list of extensions which are allowed to be uploaded.
          ^^^^^^^^^^
app/uploaders/image_uploader.rb:56:17: C: Naming/InclusiveLanguage:
 Consider replacing problematic term 'whitelist' with 'allowlist' or 'permit'.
  def extension_whitelist
                ^^^^^^^^^
app/uploaders/image_uploader.rb:60:20: C: Naming/InclusiveLanguage:
 Consider replacing problematic term 'whitelist' with 'allowlist' or 'permit'.
  def content_type_whitelist
                   ^^^^^^^^^

1件目のコメントは修正せずに、.rubocop_todo.ymlで例外に入れる事にしました。


参考までに、今回のコミット内容です。
https://dev.azure.com/nightonly/rails-app-origin/_git/rails-app-origin/commit/dc4279e4a87c3d874c596f1bda8ca1fe885ded6b

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です