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
48582035
Commit
48582035
authored
Apr 06, 2022
by
minahilnichols
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing specs
parent
521b072b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
19 deletions
+107
-19
ee/app/controllers/registrations/company_controller.rb
ee/app/controllers/registrations/company_controller.rb
+8
-2
ee/spec/controllers/registrations/company_controller_spec.rb
ee/spec/controllers/registrations/company_controller_spec.rb
+99
-17
No files found.
ee/app/controllers/registrations/company_controller.rb
View file @
48582035
...
...
@@ -25,9 +25,15 @@ module Registrations
private
def
authenticate_user!
return
if
current_user
redirect_to
new_trial_registration_path
,
alert:
I18n
.
t
(
'devise.failure.unauthenticated'
)
end
def
company_params
params
.
permit
(
:first_name
,
:last_name
,
:company_name
,
:company_size
,
:phone_number
,
:country
,
:
state
,
:website_url
,
:namespace_id
,
:glm_content
,
:glm_source
)
params
.
permit
(
:first_name
,
:last_name
,
:company_name
,
:company_size
,
:phone_number
,
:
country
,
:state
,
:website_url
,
:glm_content
,
:glm_source
)
.
merge
(
extra_params
)
end
...
...
ee/spec/controllers/registrations/company_controller_spec.rb
View file @
48582035
...
...
@@ -3,34 +3,116 @@
require
'spec_helper'
RSpec
.
describe
Registrations
::
CompanyController
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:user
)
{
create
(
:user
,
email_opted_in:
true
,
last_name:
'Doe'
)
}
describe
'GET #new'
do
subject
{
get
:new
}
let
(
:logged_in
)
{
true
}
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
)
}
before
do
sign_in
(
user
)
if
logged_in
allow
(
::
Gitlab
).
to
receive
(
:com?
).
and_return
(
true
)
end
context
'with an authenticated user'
do
let
(
:com
)
{
true
}
shared_examples
'an authenticated endpoint'
do
context
'when not authenticated'
do
let
(
:logged_in
)
{
false
}
it
{
is_expected
.
to
redirect_to
(
new_trial_registration_url
)
}
end
context
'when authenticated'
do
it
{
is_expected
.
to
have_gitlab_http_status
(
:ok
)
}
end
end
shared_examples
'a dot-com only feature'
do
context
'when not on gitlab.com'
do
before
do
sign_in
(
user
)
allow
(
::
Gitlab
).
to
receive
(
:com?
).
and_return
(
com
)
allow
(
::
Gitlab
).
to
receive
(
:com?
).
and_return
(
false
)
end
it
{
is_expected
.
to
have_gitlab_http_status
(
:not_found
)
}
end
context
'when on
.com'
do
context
'when on gitlab
.com'
do
it
{
is_expected
.
to
have_gitlab_http_status
(
:ok
)
}
end
end
describe
'#new'
do
subject
{
get
:new
}
it_behaves_like
'an authenticated endpoint'
it_behaves_like
'a dot-com only feature'
context
'on render'
do
it
{
is_expected
.
to
render_template
'layouts/minimal'
}
it
{
is_expected
.
to
render_template
(
:new
)
}
end
end
context
'when not on .com'
do
let
(
:com
)
{
false
}
describe
'#create'
do
using
RSpec
::
Parameterized
::
TableSyntax
context
'on success'
do
let
(
:params
)
do
{
company_name:
'GitLab'
,
company_size:
'1-99'
,
phone_number:
'+1 23 456-78-90'
,
country:
'US'
,
state:
'CA'
,
website_url:
'gitlab.com'
,
work_email:
user
.
email
,
uid:
user
.
id
,
provider:
'gitlab'
,
setup_for_company:
user
.
setup_for_company
,
skip_email_confirmation:
true
,
gitlab_com_trial:
true
,
newsletter_segment:
user
.
email_opted_in
}
end
it
{
is_expected
.
to
have_gitlab_http_status
(
:not_found
)
}
let
(
:hand_raise_params
)
{
ActionController
::
Parameters
.
new
(
params
).
permit!
}
let
(
:lead_params
)
{
{
trial_user:
hand_raise_params
}
}
let
(
:trial_onboarding_flow
)
{
new_users_sign_up_groups_project_path
(
trial_onboarding_flow:
true
)
}
let
(
:skip_trial
)
{
new_users_sign_up_groups_project_path
(
skip_trial:
true
)
}
where
(
:trial
,
:expected_params
,
:post_service
,
:redirect_query
)
do
true
|
ref
(
:lead_params
)
|
GitlabSubscriptions
::
CreateLeadService
|
ref
(
:trial_onboarding_flow
)
false
|
ref
(
:hand_raise_params
)
|
GitlabSubscriptions
::
CreateHandRaiseLeadService
|
ref
(
:skip_trial
)
end
with_them
do
it
'calls the correct service'
do
expect_next_instance_of
(
post_service
)
do
|
service
|
expect
(
service
).
to
receive
(
:execute
).
with
(
expected_params
).
and_return
({
success:
true
})
end
post_params
=
params
.
merge
(
trial:
trial
)
post
:create
,
params:
post_params
expect
(
response
).
to
have_gitlab_http_status
(
:redirect
)
expect
(
response
).
to
redirect_to
(
redirect_query
)
end
end
end
context
'on failure'
do
where
(
:trial
,
:post_service
)
do
true
|
GitlabSubscriptions
::
CreateLeadService
false
|
GitlabSubscriptions
::
CreateHandRaiseLeadService
end
with_them
do
it
'calls the correct service'
do
expect_next_instance_of
(
post_service
)
do
|
service
|
expect
(
service
).
to
receive
(
:execute
).
and_return
(
ServiceResponse
.
error
(
message:
'failed'
))
end
post
:create
,
params:
{
trial:
trial
}
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
render_template
(
:new
)
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