FIX: Properly associate user_profiles background urls via upload id.

`Upload#url` is more likely and can change from time to time. When it
does changes, we don't want to have to look through multiple tables to
ensure that the URLs are all up to date. Instead, we simply associate
uploads properly to `UserProfile` so that it does not have to replicate
the URLs in the table.
This commit is contained in:
Guo Xiang Tan
2019-04-29 11:58:52 +08:00
committed by Guo Xiang Tan
parent c9f6beba05
commit 24347ace10
39 changed files with 360 additions and 384 deletions

View File

@ -197,58 +197,4 @@ RSpec.describe UploadRecovery do
end
end
end
describe "#recover_user_profile_backgrounds" do
before do
user.user_profile.update!(
profile_background: upload.url,
card_background: upload.url
)
end
it "should recover the background uploads" do
user_profile = user.user_profile
upload.destroy!
user_profile.update_columns(
profile_background: user_profile.profile_background.sub("default", "X"),
card_background: user_profile.card_background.sub("default", "X")
)
expect do
upload_recovery.recover_user_profile_backgrounds
end.to change { Upload.count }.by(1)
user_profile.reload
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