From: Tom Hughes Date: Mon, 15 Jul 2019 20:18:13 +0000 (+0100) Subject: Fix rubocop warning X-Git-Tag: live~2474 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/d2d3f2c9fdb76eb8193eaa079868504b8b9906c5 Fix rubocop warning --- diff --git a/lib/tasks/upgrade_avatars.rake b/lib/tasks/upgrade_avatars.rake index 3316f7e56..0466609ff 100644 --- a/lib/tasks/upgrade_avatars.rake +++ b/lib/tasks/upgrade_avatars.rake @@ -1,17 +1,17 @@ namespace "storage" do task :upgrade_avatars => :environment do User.active.where.not(:image_file_name => nil).in_batches.each_record do |user| - unless user.avatar.attached? - io = File.open(user.image.path) - filename = user.image.original_filename - content_type = if user.image.content_type.nil? - MimeMagic.by_magic(io)&.type - else - user.image.content_type - end + next if user.avatar.attached? - user.avatar.attach(:io => io, :filename => filename, :content_type => content_type) - end + io = File.open(user.image.path) + filename = user.image.original_filename + content_type = if user.image.content_type.nil? + MimeMagic.by_magic(io)&.type + else + user.image.content_type + end + + user.avatar.attach(:io => io, :filename => filename, :content_type => content_type) end end end