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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
f9f3f399
Commit
f9f3f399
authored
Jun 05, 2020
by
Dallas Reedy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address reviewer feedback; simplify controller
parent
de49a547
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
48 deletions
+47
-48
app/controllers/registrations/experience_levels_controller.rb
...controllers/registrations/experience_levels_controller.rb
+2
-11
config/routes.rb
config/routes.rb
+1
-3
spec/controllers/registrations/experience_levels_controller_spec.rb
...ollers/registrations/experience_levels_controller_spec.rb
+44
-34
No files found.
app/controllers/registrations/experience_levels_controller.rb
View file @
f9f3f399
# frozen_string_literal: true
module
Registrations
class
ExperienceLevelsController
<
Devise
Controller
class
ExperienceLevelsController
<
Application
Controller
# This will need to be changed to simply 'devise' as part of
# https://gitlab.com/gitlab-org/growth/engineering/issues/64
layout
'devise_experimental_separate_sign_up_flow'
before_action
:authenticate_user!
before_action
:check_experiment_enabled
def
update
current_user
.
experience_level
=
params
[
:experience_level
]
if
current_user
.
save
set_flash_message!
:notice
,
:signed_up
flash
[
:message
]
=
I18n
.
t
(
'devise.registrations.signed_up'
)
redirect_to
group_path
(
params
[
:namespace_path
]
||
current_user
)
else
render
:show
...
...
@@ -25,13 +24,5 @@ module Registrations
def
check_experiment_enabled
access_denied!
unless
experiment_enabled?
(
:onboarding_issues
)
end
# Override the default translation scope of "devise.#{controller_name}" to
# reuse existing translations from the RegistrationsController. Also, this
# way we're much more likely to catch problems early if that controller is
# ever renamed.
def
translation_scope
"devise.
#{
RegistrationsController
.
controller_name
}
"
end
end
end
config/routes.rb
View file @
f9f3f399
...
...
@@ -48,9 +48,7 @@ Rails.application.routes.draw do
scope
path:
'/users/sign_up'
,
module: :registrations
,
as: :users_sign_up
do
get
:welcome
patch
:update_registration
devise_scope
:user
do
resource
:experience_level
,
only:
[
:show
,
:update
]
end
resource
:experience_level
,
only:
[
:show
,
:update
]
Gitlab
.
ee
do
resources
:groups
,
only:
[
:new
,
:create
]
...
...
spec/controllers/registrations/experience_levels_controller_spec.rb
View file @
f9f3f399
...
...
@@ -5,17 +5,10 @@ require 'spec_helper'
describe
Registrations
::
ExperienceLevelsController
do
let_it_be
(
:user
)
{
create
(
:user
)
}
before
do
@request
.
env
[
'devise.mapping'
]
=
Devise
.
mappings
[
:user
]
end
describe
'GET #show'
do
subject
{
get
:show
}
# I don't understand why these specs are failing. It's like we never
# actually hit the `authenticate_user!` hook, or that it doesn't really do
# what I expect it to do based on other tests.
xcontext
'with an unauthenticated user'
do
context
'with an unauthenticated user'
do
it
{
is_expected
.
to
have_gitlab_http_status
(
:redirect
)
}
it
{
is_expected
.
to
redirect_to
(
new_user_session_path
)
}
end
...
...
@@ -46,10 +39,7 @@ describe Registrations::ExperienceLevelsController do
let
(
:params
)
{
{}
}
# I don't understand why these specs are failing. It's like we never
# actually hit the `authenticate_user!` hook, or that it doesn't really do
# what I expect it to do based on other tests.
xcontext
'with an unauthenticated user'
do
context
'with an unauthenticated user'
do
it
{
is_expected
.
to
have_gitlab_http_status
(
:redirect
)
}
it
{
is_expected
.
to
redirect_to
(
new_user_session_path
)
}
end
...
...
@@ -60,42 +50,62 @@ describe Registrations::ExperienceLevelsController do
stub_experiment_for_user
(
onboarding_issues:
true
)
end
context
'when no
experience_level is s
ent'
do
context
'when no
t part of the onboarding issues experim
ent'
do
before
do
user
.
user_preference
.
update_attribute
(
:experience_level
,
:novic
e
)
stub_experiment_for_user
(
onboarding_issues:
fals
e
)
end
it
'will unset the user’s experience level'
do
expect
{
subject
}.
to
change
{
user
.
reload
.
experience_level
}.
to
(
nil
)
end
it
{
is_expected
.
to
have_gitlab_http_status
(
:not_found
)
}
end
context
'when an expected experience level is sent'
do
let
(
:params
)
{
{
experience_level: :novice
}
}
context
'when user is successfully updated'
do
it
{
is_expected
.
to
set_flash
[
:message
].
to
(
'Welcome! You have signed up successfully.'
)
}
context
'when no experience_level is sent'
do
before
do
user
.
user_preference
.
update_attribute
(
:experience_level
,
:novice
)
end
it
'sets the user’s experience level'
do
expect
{
subject
}.
to
change
{
user
.
reload
.
experience_level
}
it
'will unset the user’s experience level'
do
expect
{
subject
}.
to
change
{
user
.
reload
.
experience_level
}.
to
(
nil
)
end
end
end
context
'when an un
expected experience level is sent'
do
let
(
:params
)
{
{
experience_level: :nonexistent
}
}
context
'when an
expected experience level is sent'
do
let
(
:params
)
{
{
experience_level: :novice
}
}
it
'raises an exception'
do
expect
{
subject
}.
to
raise_error
(
ArgumentError
,
"'nonexistent' is not a valid experience_level"
)
it
'sets the user’s experience level'
do
expect
{
subject
}.
to
change
{
user
.
reload
.
experience_level
}.
to
(
'novice'
)
end
end
end
context
'when a namespace_path
is sent'
do
let
(
:params
)
{
{
namespace_path:
namespace
.
to_param
}
}
context
'when an unexpected experience level
is sent'
do
let
(
:params
)
{
{
experience_level: :nonexistent
}
}
it
{
is_expected
.
to
have_gitlab_http_status
(
:redirect
)
}
it
{
is_expected
.
to
redirect_to
(
group_path
(
namespace
))
}
it
'raises an exception'
do
expect
{
subject
}.
to
raise_error
(
ArgumentError
,
"'nonexistent' is not a valid experience_level"
)
end
end
context
'when a namespace_path is sent'
do
let
(
:params
)
{
{
namespace_path:
namespace
.
to_param
}
}
it
{
is_expected
.
to
have_gitlab_http_status
(
:redirect
)
}
it
{
is_expected
.
to
redirect_to
(
group_path
(
namespace
))
}
end
context
'when no namespace_path is sent'
do
it
{
is_expected
.
to
have_gitlab_http_status
(
:redirect
)
}
it
{
is_expected
.
to
redirect_to
(
user_path
(
user
))
}
end
end
context
'when no namespace_path is sent'
do
it
{
is_expected
.
to
have_gitlab_http_status
(
:redirect
)
}
it
{
is_expected
.
to
redirect_to
(
user_path
(
user
))
}
context
'when user update fails'
do
before
do
allow_any_instance_of
(
User
).
to
receive
(
:save
).
and_return
(
false
)
end
it
{
is_expected
.
to
render_template
(
:show
)
}
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