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
Boxiang Sun
gitlab-ce
Commits
82bafd00
Commit
82bafd00
authored
Aug 17, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make username update fail if namespace part fails
parent
f0ac0daf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
1 deletion
+57
-1
app/models/user.rb
app/models/user.rb
+1
-1
spec/models/user_spec.rb
spec/models/user_spec.rb
+56
-0
No files found.
app/models/user.rb
View file @
82bafd00
...
...
@@ -837,7 +837,7 @@ class User < ActiveRecord::Base
create_namespace!
(
path:
username
,
name:
username
)
unless
namespace
if
username_changed?
namespace
.
update_attributes
(
path:
username
,
name:
username
)
namespace
.
update_attributes
!
(
path:
username
,
name:
username
)
end
end
...
...
spec/models/user_spec.rb
View file @
82bafd00
...
...
@@ -2024,4 +2024,60 @@ describe User do
expect
(
user
.
projects_limit_left
).
to
eq
(
5
)
end
end
describe
'#ensure_namespace_correct'
do
context
'for a new user'
do
let
(
:user
)
{
build
(
:user
)
}
it
'creates the namespace'
do
expect
(
user
.
namespace
).
to
be_nil
user
.
save!
expect
(
user
.
namespace
).
not_to
be_nil
end
end
context
'for an existing user'
do
let
(
:username
)
{
'foo'
}
let
(
:user
)
{
create
(
:user
,
username:
username
)
}
context
'when the user is updated'
do
context
'when the username is changed'
do
let
(
:new_username
)
{
'bar'
}
it
'changes the namespace (just to compare to when username is not changed)'
do
expect
do
user
.
update_attributes!
(
username:
new_username
)
end
.
to
change
{
user
.
namespace
.
updated_at
}
end
it
'updates the namespace name'
do
user
.
update_attributes!
(
username:
new_username
)
expect
(
user
.
namespace
.
name
).
to
eq
(
new_username
)
end
it
'updates the namespace path'
do
user
.
update_attributes!
(
username:
new_username
)
expect
(
user
.
namespace
.
path
).
to
eq
(
new_username
)
end
context
'when there is a validation error (namespace name taken) while updating namespace'
do
let!
(
:conflicting_namespace
)
{
create
(
:group
,
name:
new_username
,
path:
'quz'
)
}
it
"causes the user save to fail"
do
expect
(
user
.
update_attributes
(
username:
new_username
)).
to
be_falsey
expect
(
user
.
namespace
.
errors
.
messages
[
:name
].
first
).
to
eq
(
'has already been taken'
)
end
end
end
context
'when the username is not changed'
do
it
'does not change the namespace'
do
expect
do
user
.
update_attributes!
(
email:
'asdf@asdf.com'
)
end
.
not_to
change
{
user
.
namespace
.
updated_at
}
end
end
end
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