Change avatar error message to include allowed file formats

This commit is contained in:
Fabian Schneider 2018-03-11 20:56:07 +01:00
parent afd2d38111
commit 839589fde3
6 changed files with 9 additions and 10 deletions

View File

@ -21,7 +21,7 @@ module Avatarable
def avatar_type def avatar_type
unless self.avatar.image? unless self.avatar.image?
self.errors.add :avatar, "only images allowed" errors.add :avatar, "file format is not supported. Please try one of the following supported formats: #{AvatarUploader::IMAGE_EXT.join(', ')}"
end end
end end

View File

@ -189,12 +189,6 @@ class Group < Namespace
owners.include?(user) && owners.size == 1 owners.include?(user) && owners.size == 1
end end
def avatar_type
unless self.avatar.image?
self.errors.add :avatar, "only images allowed"
end
end
def post_create_hook def post_create_hook
Gitlab::AppLogger.info("Group \"#{name}\" was created") Gitlab::AppLogger.info("Group \"#{name}\" was created")

View File

@ -0,0 +1,5 @@
---
title: Change avatar error message to include allowed file formats
merge_request: 17747
author: Fabian Schneider
type: changed

View File

@ -240,7 +240,7 @@ describe Group do
it "is false if avatar is html page" do it "is false if avatar is html page" do
group.update_attribute(:avatar, 'uploads/avatar.html') group.update_attribute(:avatar, 'uploads/avatar.html')
expect(group.avatar_type).to eq(["only images allowed"]) expect(group.avatar_type).to eq(["file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff"])
end end
end end

View File

@ -922,7 +922,7 @@ describe Project do
it 'is false if avatar is html page' do it 'is false if avatar is html page' do
project.update_attribute(:avatar, 'uploads/avatar.html') project.update_attribute(:avatar, 'uploads/avatar.html')
expect(project.avatar_type).to eq(['only images allowed']) expect(project.avatar_type).to eq(['file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff'])
end end
end end

View File

@ -1222,7 +1222,7 @@ describe User do
it 'is false if avatar is html page' do it 'is false if avatar is html page' do
user.update_attribute(:avatar, 'uploads/avatar.html') user.update_attribute(:avatar, 'uploads/avatar.html')
expect(user.avatar_type).to eq(['only images allowed']) expect(user.avatar_type).to eq(['file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff'])
end end
end end