LoginSignup
2
1

More than 1 year has passed since last update.

Rails 7.0で"DEPRECATION WARNING: image/jpg is not a valid content type"のようなエラーが出た場合

Posted at

発生した問題

Rails 7.0にバージョンアップしてテストを実行したら以下のようなエラーメッセージが出ました。

DEPRECATION WARNING: image/jpg is not a valid content type, it should not be used when creating a blob, and support for it will be removed in Rails 7.1. If you want to keep supporting this content type past Rails 7.1, add it to `config.active_storage.variable_content_types`. Dismiss this warning by setting `config.active_storage.silence_invalid_content_types_warning = true`. (called from public_send at /Users/jnito/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/factory_bot-6.2.0/lib/factory_bot/attribute_assigner.rb:16)

原因

FactoryBotのコードで書いたContent typeが不正でした('image/jpg')。

FactoryBot.define do
  factory :note do
    message { "My important note." }
    association :project
    user { project.owner }

    trait :with_attachment do
      attachment { Rack::Test::UploadedFile.new("#{Rails.root}/spec/files/attachment.jpg", 'image/jpg') }
    end
  end
end

修正方法

Content typeを修正したら直りました('image/jpeg')。

 FactoryBot.define do
   factory :note do
     message { "My important note." }
     association :project
     user { project.owner }

     trait :with_attachment do
-      attachment { Rack::Test::UploadedFile.new("#{Rails.root}/spec/files/attachment.jpg", 'image/jpg') }
+      attachment { Rack::Test::UploadedFile.new("#{Rails.root}/spec/files/attachment.jpg", 'image/jpeg') }
     end
   end
 end

NOTE: English version is also available:

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1