FIX: Don't update user_profile URLs unless upload is persisted.

This commit is contained in:
Guo Xiang Tan 2018-10-01 14:20:50 +08:00
parent 4b517d460d
commit de85bb0a39
2 changed files with 28 additions and 1 deletions

View File

@ -64,7 +64,7 @@ class UploadRecovery
puts "#{background}"
else
recover_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?
end
end
end

View File

@ -36,6 +36,7 @@ RSpec.describe UploadRecovery do
after do
[upload, upload2].each do |u|
next if u
public_path = "#{Discourse.store.public_dir}#{u.url}"
[
@ -140,5 +141,31 @@ RSpec.describe UploadRecovery do
expect(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
end
end
end