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

@ -41,13 +41,11 @@ describe UserSerializer do
end
context "with a user" do
let(:user) { Fabricate.build(:user, user_profile: Fabricate.build(:user_profile)) }
let(:user) { Fabricate(:user) }
let(:serializer) { UserSerializer.new(user, scope: Guardian.new, root: false) }
let(:json) { serializer.as_json }
it "produces json" do
expect(json).to be_present
end
let(:upload) { Fabricate(:upload) }
let(:upload2) { Fabricate(:upload) }
context "with `enable_names` true" do
before do
@ -69,23 +67,15 @@ describe UserSerializer do
end
end
context "with filled out card background" do
context "with filled out backgrounds" do
before do
user.user_profile.card_background = 'http://card.com'
user.user_profile.upload_card_background(upload)
user.user_profile.upload_profile_background(upload2)
end
it "has a profile background" do
expect(json[:card_background]).to eq 'http://card.com'
end
end
context "with filled out profile background" do
before do
user.user_profile.profile_background = 'http://background.com'
end
it "has a profile background" do
expect(json[:profile_background]).to eq 'http://background.com'
expect(json[:card_background_upload_url]).to eq(upload.url)
expect(json[:profile_background_upload_url]).to eq(upload2.url)
end
end