Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
58a8d6e9
Commit
58a8d6e9
authored
Feb 29, 2016
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only validate avatar cropping values when avatar is present AND changed
Closes #13905
parent
128757a7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
app/models/user.rb
app/models/user.rb
+1
-1
spec/models/user_spec.rb
spec/models/user_spec.rb
+15
-1
No files found.
app/models/user.rb
View file @
58a8d6e9
...
...
@@ -169,7 +169,7 @@ class User < ActiveRecord::Base
validates
:avatar_crop_x
,
:avatar_crop_y
,
:avatar_crop_size
,
numericality:
{
only_integer:
true
},
presence:
true
,
if:
->
(
user
)
{
user
.
avatar?
}
if:
->
(
user
)
{
user
.
avatar?
&&
user
.
avatar_changed?
}
before_validation
:generate_password
,
on: :create
before_validation
:restricted_signup_domains
,
on: :create
...
...
spec/models/user_spec.rb
View file @
58a8d6e9
...
...
@@ -176,7 +176,7 @@ describe User, models: true do
end
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
.
avatar_crop_x
=
nil
...
...
@@ -184,6 +184,20 @@ describe User, models: true do
user
.
avatar_crop_size
=
nil
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment