Commit ce527b68 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'improve/avatar_upload_only_images' of /home/git/repositories/gitlab/gitlabhq

parents ede3446c 62f1c977
......@@ -113,9 +113,8 @@ class User < ActiveRecord::Base
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
validates :notification_level, inclusion: { in: Notification.notification_levels }, presence: true
validate :namespace_uniq, if: ->(user) { user.username_changed? }
validate :avatar_type, if: ->(user) { user.avatar_changed? }
validates :avatar, file_size: { maximum: 100.kilobytes.to_i }
before_validation :generate_password, on: :create
......@@ -244,6 +243,12 @@ class User < ActiveRecord::Base
end
end
def avatar_type
unless self.avatar.image?
self.errors.add :avatar, "only images allowed"
end
end
# Groups user has access to
def authorized_groups
@authorized_groups ||= begin
......
......@@ -279,4 +279,18 @@ describe User do
User.by_username_or_id('bar').should be_nil
end
end
describe :avatar_type do
let(:user) { create(:user) }
it "should be true if avatar is image" do
user.update_attribute(:avatar, 'uploads/avatar.png')
user.avatar_type.should be_true
end
it "should be false if avatar is html page" do
user.update_attribute(:avatar, 'uploads/avatar.html')
user.avatar_type.should == ["only images allowed"]
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment