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
bd578d96
Commit
bd578d96
authored
Aug 18, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add namespace errors from User#after_update
parent
cb1e2375
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
3 deletions
+26
-3
app/models/user.rb
app/models/user.rb
+6
-1
spec/models/user_spec.rb
spec/models/user_spec.rb
+6
-1
spec/services/users/update_service_spec.rb
spec/services/users/update_service_spec.rb
+14
-1
No files found.
app/models/user.rb
View file @
bd578d96
...
@@ -837,7 +837,12 @@ class User < ActiveRecord::Base
...
@@ -837,7 +837,12 @@ class User < ActiveRecord::Base
create_namespace!
(
path:
username
,
name:
username
)
unless
namespace
create_namespace!
(
path:
username
,
name:
username
)
unless
namespace
if
username_changed?
if
username_changed?
namespace
.
update_attributes!
(
path:
username
,
name:
username
)
unless
namespace
.
update_attributes
(
path:
username
,
name:
username
)
namespace
.
errors
.
each
do
|
attribute
,
message
|
self
.
errors
.
add
(
:"namespace_
#{
attribute
}
"
,
message
)
end
raise
ActiveRecord
::
RecordInvalid
.
new
(
namespace
)
end
end
end
end
end
...
...
spec/models/user_spec.rb
View file @
bd578d96
...
@@ -2063,10 +2063,15 @@ describe User do
...
@@ -2063,10 +2063,15 @@ describe User do
context
'when there is a validation error (namespace name taken) while updating namespace'
do
context
'when there is a validation error (namespace name taken) while updating namespace'
do
let!
(
:conflicting_namespace
)
{
create
(
:group
,
name:
new_username
,
path:
'quz'
)
}
let!
(
:conflicting_namespace
)
{
create
(
:group
,
name:
new_username
,
path:
'quz'
)
}
it
"causes the user save to fail"
do
it
'causes the user save to fail'
do
expect
(
user
.
update_attributes
(
username:
new_username
)).
to
be_falsey
expect
(
user
.
update_attributes
(
username:
new_username
)).
to
be_falsey
expect
(
user
.
namespace
.
errors
.
messages
[
:name
].
first
).
to
eq
(
'has already been taken'
)
expect
(
user
.
namespace
.
errors
.
messages
[
:name
].
first
).
to
eq
(
'has already been taken'
)
end
end
it
'adds the namespace errors to the user'
do
user
.
update_attributes
(
username:
new_username
)
expect
(
user
.
errors
.
full_messages
.
first
).
to
eq
(
'Namespace name has already been taken'
)
end
end
end
end
end
...
...
spec/services/users/update_service_spec.rb
View file @
bd578d96
...
@@ -12,9 +12,22 @@ describe Users::UpdateService do
...
@@ -12,9 +12,22 @@ describe Users::UpdateService do
end
end
it
'returns an error result when record cannot be updated'
do
it
'returns an error result when record cannot be updated'
do
result
=
{}
expect
do
expect
do
update_user
(
user
,
{
email:
'invalid'
})
result
=
update_user
(
user
,
{
email:
'invalid'
})
end
.
not_to
change
{
user
.
reload
.
email
}
end
.
not_to
change
{
user
.
reload
.
email
}
expect
(
result
[
:status
]).
to
eq
(
:error
)
expect
(
result
[
:message
]).
to
eq
(
'Email is invalid'
)
end
it
'includes namespace error messages'
do
create
(
:group
,
name:
'taken'
,
path:
'something_else'
)
result
=
{}
expect
do
result
=
update_user
(
user
,
{
username:
'taken'
})
end
.
not_to
change
{
user
.
reload
.
username
}
expect
(
result
[
:status
]).
to
eq
(
:error
)
expect
(
result
[
:message
]).
to
eq
(
'Namespace name has already been taken'
)
end
end
def
update_user
(
user
,
opts
)
def
update_user
(
user
,
opts
)
...
...
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