FIX: make sure we also save the user_avatar.custom_upload_id

This commit is contained in:
Régis Hanol 2015-05-29 10:21:41 +02:00
parent 95fb32f3e5
commit cb025a65e0
2 changed files with 6 additions and 1 deletions
app/controllers
spec/controllers

View file

@ -503,15 +503,18 @@ class UsersController < ApplicationController
def pick_avatar def pick_avatar
user = fetch_user_from_params user = fetch_user_from_params
guardian.ensure_can_edit!(user) guardian.ensure_can_edit!(user)
upload_id = params[:upload_id] upload_id = params[:upload_id]
user.uploaded_avatar_id = upload_id user.uploaded_avatar_id = upload_id
# ensure we associate the custom avatar properly # ensure we associate the custom avatar properly
if upload_id && !user.user_avatar.contains_upload?(upload_id) if upload_id && user.user_avatar.custom_upload_id != upload_id
user.user_avatar.custom_upload_id = upload_id user.user_avatar.custom_upload_id = upload_id
end end
user.save! user.save!
user.user_avatar.save!
render json: success_json render json: success_json
end end

View file

@ -1323,10 +1323,12 @@ describe UsersController do
it 'it successful' do it 'it successful' do
xhr :put, :pick_avatar, username: user.username, upload_id: 111 xhr :put, :pick_avatar, username: user.username, upload_id: 111
expect(user.reload.uploaded_avatar_id).to eq(111) expect(user.reload.uploaded_avatar_id).to eq(111)
expect(user.user_avatar.reload.custom_upload_id).to eq(111)
expect(response).to be_success expect(response).to be_success
xhr :put, :pick_avatar, username: user.username xhr :put, :pick_avatar, username: user.username
expect(user.reload.uploaded_avatar_id).to eq(nil) expect(user.reload.uploaded_avatar_id).to eq(nil)
expect(user.user_avatar.reload.custom_upload_id).to eq(111)
expect(response).to be_success expect(response).to be_success
end end