improved specs for avatar

This commit is contained in:
Régis Hanol
2013-08-24 22:37:31 +02:00
parent 2ce59d2585
commit 3b9e62e6b9
3 changed files with 95 additions and 6 deletions

View File

@ -7,7 +7,7 @@ class UsersController < ApplicationController
skip_before_filter :authorize_mini_profiler, only: [:avatar]
skip_before_filter :check_xhr, only: [:show, :password_reset, :update, :activate_account, :authorize_email, :user_preferences_redirect, :avatar]
before_filter :ensure_logged_in, only: [:username, :update, :change_email, :user_preferences_redirect]
before_filter :ensure_logged_in, only: [:username, :update, :change_email, :user_preferences_redirect, :upload_avatar, :toggle_avatar]
# we need to allow account creation with bad CSRF tokens, if people are caching, the CSRF token on the
# page is going to be empty, this means that server will see an invalid CSRF and blow the session
@ -346,13 +346,18 @@ class UsersController < ApplicationController
upload = Upload.create_for(user.id, file, filesize)
user.uploaded_avatar_template = nil
user.uploaded_avatar = upload
user.use_uploaded_avatar = true
user.save!
Jobs.enqueue(:generate_avatars, upload_id: upload.id)
render json: { url: upload.url }
render json: {
url: upload.url,
width: upload.width,
height: upload.height,
}
rescue FastImage::ImageFetchFailure
render status: 422, text: I18n.t("upload.images.fetch_failure")