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 ...@@ -9,7 +9,7 @@ module Avatarable
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
validate :avatar_type, if: ->(user) { user.avatar.present? && user.avatar_changed? } 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 mount_uploader :avatar, AvatarUploader
title: Disable project avatar validation if avatar has not changed
type: performance
...@@ -12,6 +12,26 @@ describe Avatarable do ...@@ -12,6 +12,26 @@ describe Avatarable do
stub_config_setting(relative_url_root: relative_url_root) stub_config_setting(relative_url_root: relative_url_root)
end 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')
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 describe '#avatar_path' do
using RSpec::Parameterized::TableSyntax 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