Commit 58f70f91 authored by Stan Hu's avatar Stan Hu
Browse files

Disable project avatar validation if avatar has not changed

Every time a column in the projects table is changed, the Avatarable concern
would validate that the avatar file size was under 200K.  This not only delays
the database changes, but it also can lead to unrelated failures if the HTTP
request fails for some reason.

Closes #51053
parent 2e7b51fe2115
......@@ -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
type: performance
......@@ -12,6 +12,26 @@
stub_config_setting(relative_url_root: relative_url_root)
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')
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')
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