mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
committed by
Guo Xiang Tan
parent
c9f6beba05
commit
24347ace10
@@ -668,11 +668,11 @@ describe DiscourseSingleSignOn do
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
user.user_profile.reload
|
||||
profile_background = user.user_profile.profile_background
|
||||
profile_background_url = user.profile_background_upload.url
|
||||
|
||||
# initial creation ...
|
||||
expect(profile_background).to_not eq(nil)
|
||||
expect(profile_background).to_not eq('')
|
||||
expect(profile_background_url).to_not eq(nil)
|
||||
expect(profile_background_url).to_not eq('')
|
||||
|
||||
FileHelper.stubs(:download) { raise "should not be called" }
|
||||
sso.profile_background_url = "https://some.new/avatar.png"
|
||||
@@ -681,7 +681,7 @@ describe DiscourseSingleSignOn do
|
||||
user.user_profile.reload
|
||||
|
||||
# profile_background updated but no override specified ...
|
||||
expect(user.user_profile.profile_background).to eq(profile_background)
|
||||
expect(user.profile_background_upload.url).to eq(profile_background_url)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -704,33 +704,24 @@ describe DiscourseSingleSignOn do
|
||||
end
|
||||
|
||||
it "deal with no profile_background_url passed for an existing user with a profile_background" do
|
||||
Sidekiq::Testing.inline! do
|
||||
# Deliberately not setting profile_background_url so it should not update
|
||||
sso_record.user.user_profile.update_columns(profile_background: '')
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
user.user_profile.reload
|
||||
# Deliberately not setting profile_background_url so it should not update
|
||||
sso_record.user.user_profile.clear_profile_background
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
|
||||
expect(user).to_not be_nil
|
||||
expect(user.user_profile.profile_background).to eq('')
|
||||
end
|
||||
expect(user.profile_background_upload).to eq(nil)
|
||||
end
|
||||
|
||||
it "deal with a profile_background_url passed for an existing user with a profile_background" do
|
||||
Sidekiq::Testing.inline! do
|
||||
FileHelper.stubs(:download).returns(logo)
|
||||
url = "http://example.com/a_different_image.png"
|
||||
stub_request(:get, url).to_return(body: logo)
|
||||
|
||||
sso_record.user.user_profile.update_columns(profile_background: '')
|
||||
sso_record.user.user_profile.clear_profile_background
|
||||
sso.profile_background_url = "http://example.com/a_different_image.png"
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
|
||||
sso.profile_background_url = "http://example.com/a_different_image.png"
|
||||
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
user.user_profile.reload
|
||||
|
||||
expect(user).to_not be_nil
|
||||
expect(user.user_profile.profile_background).to_not eq('')
|
||||
end
|
||||
expect(user.profile_background_upload).to_not eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -744,16 +735,14 @@ describe DiscourseSingleSignOn do
|
||||
sso.username = "sam"
|
||||
sso.card_background_url = "http://awesome.com/image.png"
|
||||
sso.suppress_welcome_message = true
|
||||
|
||||
FileHelper.stubs(:download).returns(file_from_fixtures("logo.png"))
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
user.user_profile.reload
|
||||
card_background = user.user_profile.card_background
|
||||
card_background_url = user.user_profile.card_background_upload.url
|
||||
|
||||
# initial creation ...
|
||||
expect(card_background).to_not eq(nil)
|
||||
expect(card_background).to_not eq('')
|
||||
expect(card_background_url).to be_present
|
||||
|
||||
FileHelper.stubs(:download) { raise "should not be called" }
|
||||
sso.card_background_url = "https://some.new/avatar.png"
|
||||
@@ -762,7 +751,9 @@ describe DiscourseSingleSignOn do
|
||||
user.user_profile.reload
|
||||
|
||||
# card_background updated but no override specified ...
|
||||
expect(user.user_profile.card_background).to eq(card_background)
|
||||
expect(user.user_profile.card_background_upload.url).to eq(
|
||||
card_background_url
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -785,33 +776,25 @@ describe DiscourseSingleSignOn do
|
||||
end
|
||||
|
||||
it "deal with no card_background_url passed for an existing user with a card_background" do
|
||||
Sidekiq::Testing.inline! do
|
||||
# Deliberately not setting card_background_url so it should not update
|
||||
sso_record.user.user_profile.update_columns(card_background: '')
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
user.user_profile.reload
|
||||
# Deliberately not setting card_background_url so it should not update
|
||||
sso_record.user.user_profile.clear_card_background
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
|
||||
expect(user).to_not be_nil
|
||||
expect(user.user_profile.card_background).to eq('')
|
||||
end
|
||||
expect(user.user_profile.card_background_upload).to eq(nil)
|
||||
end
|
||||
|
||||
it "deal with a card_background_url passed for an existing user with a card_background_url" do
|
||||
Sidekiq::Testing.inline! do
|
||||
FileHelper.stubs(:download).returns(logo)
|
||||
url = "http://example.com/a_different_image.png"
|
||||
stub_request(:get, url).to_return(body: logo)
|
||||
|
||||
sso_record.user.user_profile.update_columns(card_background: '')
|
||||
sso_record.user.user_profile.clear_card_background
|
||||
sso.card_background_url = url
|
||||
|
||||
sso.card_background_url = "http://example.com/a_different_image.png"
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
user.user_profile.reload
|
||||
|
||||
expect(user).to_not be_nil
|
||||
expect(user.user_profile.card_background).to_not eq('')
|
||||
end
|
||||
expect(user.user_profile.card_background_upload.url).to_not eq('')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user