Commit 58a8d6e9 authored by Robert Speicher's avatar Robert Speicher

Only validate avatar cropping values when avatar is present AND changed

Closes #13905
parent 128757a7
...@@ -169,7 +169,7 @@ class User < ActiveRecord::Base ...@@ -169,7 +169,7 @@ class User < ActiveRecord::Base
validates :avatar_crop_x, :avatar_crop_y, :avatar_crop_size, validates :avatar_crop_x, :avatar_crop_y, :avatar_crop_size,
numericality: { only_integer: true }, numericality: { only_integer: true },
presence: true, presence: true,
if: ->(user) { user.avatar? } if: ->(user) { user.avatar? && user.avatar_changed? }
before_validation :generate_password, on: :create before_validation :generate_password, on: :create
before_validation :restricted_signup_domains, on: :create before_validation :restricted_signup_domains, on: :create
......
...@@ -176,7 +176,7 @@ describe User, models: true do ...@@ -176,7 +176,7 @@ describe User, models: true do
end end
describe 'avatar' do describe 'avatar' do
it 'only validates when avatar is present' do it 'only validates when avatar is present and changed' do
user = build(:user, :with_avatar) user = build(:user, :with_avatar)
user.avatar_crop_x = nil user.avatar_crop_x = nil
...@@ -184,6 +184,20 @@ describe User, models: true do ...@@ -184,6 +184,20 @@ describe User, models: true do
user.avatar_crop_size = nil user.avatar_crop_size = nil
expect(user).not_to be_valid expect(user).not_to be_valid
expect(user.errors.keys).
to match_array %i(avatar_crop_x avatar_crop_y avatar_crop_size)
end
it 'does not validate when avatar has not changed' do
user = create(:user, :with_avatar)
expect { user.avatar_crop_x = nil }.not_to change(user, :valid?)
end
it 'does not validate when avatar is not present' do
user = create(:user)
expect { user.avatar_crop_y = nil }.not_to change(user, :valid?)
end end
end 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