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
53ef1de4
Commit
53ef1de4
authored
Mar 30, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix production admin fixture to use the new `Users::CreateService`
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
68aa43fd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
4 deletions
+23
-4
app/services/users/create_service.rb
app/services/users/create_service.rb
+1
-1
db/fixtures/production/001_admin.rb
db/fixtures/production/001_admin.rb
+5
-3
spec/services/users/create_service_spec.rb
spec/services/users/create_service_spec.rb
+17
-0
No files found.
app/services/users/create_service.rb
View file @
53ef1de4
...
...
@@ -94,7 +94,7 @@ module Users
def
build_user_params
if
current_user
&
.
is_admin?
user_params
=
params
.
slice
(
*
admin_create_params
)
user_params
[
:created_by_id
]
=
current_user
.
id
user_params
[
:created_by_id
]
=
current_user
&
.
id
if
params
[
:reset_password
]
user_params
.
merge!
(
force_random_password:
true
,
password_expires_at:
nil
)
...
...
db/fixtures/production/001_admin.rb
View file @
53ef1de4
...
...
@@ -12,10 +12,12 @@ else
user_args
[
:password
]
=
ENV
[
'GITLAB_ROOT_PASSWORD'
]
end
user
=
User
.
new
(
user_args
)
user
.
skip_confirmation!
# Only admins can create other admin users in Users::CreateService so to solve
# the chicken-and-egg problem, we pass a non-persisted admin user to the service.
transient_admin
=
User
.
new
(
admin:
true
)
user
=
Users
::
CreateService
.
new
(
transient_admin
,
user_args
.
merge!
(
skip_confirmation:
true
)).
execute
if
user
.
save
if
user
.
persisted?
puts
"Administrator account created:"
.
color
(
:green
)
puts
puts
"login: root"
.
color
(
:green
)
...
...
spec/services/users/create_service_spec.rb
View file @
53ef1de4
...
...
@@ -61,6 +61,23 @@ describe Users::CreateService, services: true do
)
end
context
'when the current_user is not persisted'
do
let
(
:admin_user
)
{
build
(
:admin
)
}
it
'persists the given attributes and sets created_by_id to nil'
do
user
=
service
.
execute
user
.
reload
expect
(
user
).
to
have_attributes
(
name:
params
[
:name
],
username:
params
[
:username
],
email:
params
[
:email
],
password:
params
[
:password
],
created_by_id:
nil
)
end
end
it
'user is not confirmed if skip_confirmation param is not present'
do
expect
(
service
.
execute
).
not_to
be_confirmed
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