summaryrefslogtreecommitdiff
path: root/spec/models/concerns/avatarable_spec.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-09-04 11:57:13 -0700
committerStan Hu <stanhu@gmail.com>2018-09-04 12:20:58 -0700
commitd4bdcfbf19b594646d597bae5eb6d0c0f7354362 (patch)
treef2e29f5c4b60128ffacd8103ef2867eeefc9b544 /spec/models/concerns/avatarable_spec.rb
parent8ff02cf7c43b7f7a2f5ca46aa678cfce67eab39b (diff)
downloadgitlab-ce-d4bdcfbf19b594646d597bae5eb6d0c0f7354362.tar.gz
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
Diffstat (limited to 'spec/models/concerns/avatarable_spec.rb')
-rw-r--r--spec/models/concerns/avatarable_spec.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/spec/models/concerns/avatarable_spec.rb b/spec/models/concerns/avatarable_spec.rb
index 76f734079b7..7d617cb7b19 100644
--- a/spec/models/concerns/avatarable_spec.rb
+++ b/spec/models/concerns/avatarable_spec.rb
@@ -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