A platform for community discussion. Free, open, simple.
FIX: Don't update user_profile URLs unless upload is persisted.
Guo Xiang Tande85bb0a3951
diff --git a/lib/upload_recovery.rb b/lib/upload_recovery.rbindex 53762ee5fc2..fc64839a557 100644--- a/lib/upload_recovery.rb+++ b/lib/upload_recovery.rb@@ -64,7 +64,7 @@ class UploadRecoveryputs "#{background}"elserecover_user_profile_background(sha1, user_profile.user_id) do |upload|- user_profile.update!("#{column}" => upload.url)+ user_profile.update!("#{column}" => upload.url) if upload.persisted?endendenddiff --git a/spec/lib/upload_recovery_spec.rb b/spec/lib/upload_recovery_spec.rbindex f8e00ac4ecc..5e8e4500a92 100644--- a/spec/lib/upload_recovery_spec.rb+++ b/spec/lib/upload_recovery_spec.rb@@ -36,6 +36,7 @@ RSpec.describe UploadRecovery doafter do[upload, upload2].each do |u|+ next if upublic_path = "#{Discourse.store.public_dir}#{u.url}"[@@ -140,5 +141,31 @@ RSpec.describe UploadRecovery doexpect(user_profile.profile_background).to eq(upload.url)expect(user_profile.card_background).to eq(upload.url)end++ describe 'for a bad upload' do+ it 'should not update the urls' do+ user_profile = user.user_profile+ upload.destroy!++ profile_background = user_profile.profile_background.sub("default", "X")+ card_background = user_profile.card_background.sub("default", "X")++ user_profile.update_columns(+ profile_background: profile_background,+ card_background: card_background+ )++ SiteSetting.authorized_extensions = ''++ expect do+ upload_recovery.recover_user_profile_backgrounds+ end.to_not change { Upload.count }++ user_profile.reload++ expect(user_profile.profile_background).to eq(profile_background)+ expect(user_profile.card_background).to eq(card_background)+ end+ endendend