Commit 91003c6e authored by Robert Speicher's avatar Robert Speicher

Merge branch 'sh-disable-unnecessary-avatar-revalidation' into 'master'

Disable project avatar validation if avatar has not changed

Closes #51053

See merge request gitlab-org/gitlab-ce!21506
parents 265b4913 d4bdcfbf
......@@ -9,7 +9,7 @@ module Avatarable
include Gitlab::Utils::StrongMemoize
validate :avatar_type, if: ->(user) { user.avatar.present? && user.avatar_changed? }
validates :avatar, file_size: { maximum: 200.kilobytes.to_i }
validates :avatar, file_size: { maximum: 200.kilobytes.to_i }, if: :avatar_changed?
mount_uploader :avatar, AvatarUploader
......
---
title: Disable project avatar validation if avatar has not changed
merge_request:
author:
type: performance
......@@ -12,6 +12,26 @@ describe Avatarable do
stub_config_setting(relative_url_root: relative_url_root)
end
describe '#update' do
let(:validator) { project._validators[:avatar].detect { |v| v.is_a?(FileSizeValidator) } }
context 'when avatar changed' do
it 'validates the file size' do
expect(validator).to receive(:validate_each).and_call_original
project.update(avatar: 'uploads/avatar.png')
end
end
context 'when avatar was not changed' do
it 'skips validation of file size' do
expect(validator).not_to receive(:validate_each)
project.update(name: 'Hello world')
end
end
end
describe '#avatar_path' do
using RSpec::Parameterized::TableSyntax
......
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