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
53d801c4
Commit
53d801c4
authored
Jun 29, 2020
by
Dallas Reedy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for checking if gitlab.com or dev env
parent
ce4b36db
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
162 additions
and
138 deletions
+162
-138
ee/spec/controllers/trial_registrations_controller_spec.rb
ee/spec/controllers/trial_registrations_controller_spec.rb
+46
-48
ee/spec/controllers/trials_controller_spec.rb
ee/spec/controllers/trials_controller_spec.rb
+116
-90
No files found.
ee/spec/controllers/trial_registrations_controller_spec.rb
View file @
53d801c4
...
@@ -3,47 +3,57 @@
...
@@ -3,47 +3,57 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
TrialRegistrationsController
do
RSpec
.
describe
TrialRegistrationsController
do
let
(
:dev_env_or_com
)
{
true
}
before
do
allow
(
Gitlab
).
to
receive
(
:dev_env_or_com?
).
and_return
(
dev_env_or_com
)
end
shared_examples
'a dot-com only feature'
do
let
(
:success_status
)
{
:ok
}
context
'when not on gitlab.com and not in development environment'
do
let
(
:dev_env_or_com
)
{
false
}
it
{
is_expected
.
to
have_gitlab_http_status
(
:not_found
)
}
end
context
'when on gitlab.com or in dev environment'
do
it
{
is_expected
.
to
have_gitlab_http_status
(
success_status
)
}
end
end
describe
'#new'
do
describe
'#new'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:logged_in_user
)
{
nil
}
let
(
:get_params
)
{
{}
}
before
do
before
do
allow
(
Gitlab
).
to
receive
(
:com?
).
and_return
(
true
)
sign_in
(
logged_in_user
)
if
logged_in_user
.
present?
get
:new
,
params:
get_params
end
end
context
'when customer is authenticated'
do
subject
{
response
}
before
do
sign_in
(
user
)
end
it
'redirects to the new trial page'
do
it_behaves_like
'a dot-com only feature'
get
:new
expect
(
response
).
to
redirect_to
(
new_trial_url
)
context
'when customer is authenticated'
do
end
let_it_be
(
:logged_in_user
)
{
create
(
:user
)
}
it
'redirect keeps the query string parameters'
do
it
{
is_expected
.
to
redirect_to
(
new_trial_url
)
}
get_params
=
{
glm_source:
'some_source'
,
glm_content:
'some_content'
}
get
:new
,
params:
get_params
context
'when there are additional query params'
do
let
(
:get_params
)
{
{
glm_source:
'some_source'
,
glm_content:
'some_content'
}
}
expect
(
response
).
to
redirect_to
(
new_trial_url
(
get_params
))
it
{
is_expected
.
to
redirect_to
(
new_trial_url
(
get_params
))
}
end
end
end
end
context
'when customer is not authenticated'
do
context
'when customer is not authenticated'
do
it
'renders the regular template'
do
it
{
is_expected
.
to
render_template
(
:new
)
}
get
:new
expect
(
response
).
to
render_template
(
:new
)
end
end
end
end
end
describe
'#create'
do
describe
'#create'
do
before
do
stub_application_setting
(
send_user_confirmation_email:
true
)
end
let
(
:user_params
)
do
let
(
:user_params
)
do
{
{
first_name:
'John'
,
first_name:
'John'
,
...
@@ -54,35 +64,23 @@ RSpec.describe TrialRegistrationsController do
...
@@ -54,35 +64,23 @@ RSpec.describe TrialRegistrationsController do
}
}
end
end
context
'when invalid - instance is not GL.com'
do
before
do
before
do
stub_application_setting
(
send_user_confirmation_email:
true
)
allow
(
Gitlab
).
to
receive
(
:com?
).
and_return
(
false
)
post
:create
,
params:
{
user:
user_params
}
end
it
'returns 404 not found'
do
post
:create
,
params:
{
user:
user_params
}
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
end
context
'when valid'
do
it_behaves_like
'a dot-com only feature'
do
before
do
let
(
:success_status
)
{
:found
}
allow
(
Gitlab
).
to
receive
(
:com?
).
and_return
(
true
)
subject
{
response
}
end
end
it
'marks the account as unconfirmed'
do
post
:create
,
params:
{
user:
user_params
}
expect
(
User
.
last
).
not_to
be_confirmed
end
context
'derivation of name
'
do
it
'marks the account as unconfirmed
'
do
it
'sets name from first and last name'
do
expect
(
User
.
last
).
not_to
be_confirmed
post
:create
,
params:
{
user:
user_params
}
end
expect
(
User
.
last
.
name
).
to
eq
(
"
#{
user_params
[
:first_name
]
}
#{
user_params
[
:last_name
]
}
"
)
context
'derivation of name'
do
end
it
'sets name from first and last name'
do
expect
(
User
.
last
.
name
).
to
eq
(
"
#{
user_params
[
:first_name
]
}
#{
user_params
[
:last_name
]
}
"
)
end
end
end
end
end
end
...
...
ee/spec/controllers/trials_controller_spec.rb
View file @
53d801c4
...
@@ -3,133 +3,162 @@
...
@@ -3,133 +3,162 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
TrialsController
do
RSpec
.
describe
TrialsController
do
shared_examples
'an authenticated endpoint'
do
|
verb
,
action
|
let_it_be
(
:user
)
{
create
(
:user
,
email_opted_in:
true
)
}
it
'redirects to login page'
do
send
(
verb
,
action
)
expect
(
response
).
to
redirect_to
(
new_trial_registration_url
)
let
(
:dev_env_or_com
)
{
true
}
end
let
(
:logged_in
)
{
true
}
end
before
do
before
do
allow
(
::
Gitlab
).
to
receive
(
:com?
).
and_return
(
true
)
allow
(
::
Gitlab
).
to
receive
(
:dev_env_or_com?
).
and_return
(
dev_env_or_com
)
sign_in
(
user
)
if
logged_in
end
end
describe
'#new
'
do
shared_examples
'an authenticated endpoint
'
do
it_behaves_like
'an authenticated endpoint'
,
:get
,
:new
let
(
:success_status
)
{
:ok
}
context
'when invalid - instance is not GL.com'
do
context
'when not authenticated'
do
it
'returns 404 not found'
do
let
(
:logged_in
)
{
false
}
allow
(
::
Gitlab
).
to
receive
(
:com?
).
and_return
(
false
)
get
:new
it
{
is_expected
.
to
redirect_to
(
new_trial_registration_url
)
}
end
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
context
'when authenticated'
do
end
it
{
is_expected
.
to
have_gitlab_http_status
(
success_status
)
}
end
end
end
end
describe
'#create_lead'
do
shared_examples
'a dot-com only feature'
do
it_behaves_like
'an authenticated endpoint'
,
:post
,
:create_lead
let
(
:success_status
)
{
:ok
}
context
'when not on gitlab.com and not in development environment'
do
let
(
:dev_env_or_com
)
{
false
}
it
{
is_expected
.
to
have_gitlab_http_status
(
:not_found
)
}
end
context
'when on gitlab.com or in dev environment'
do
it
{
is_expected
.
to
have_gitlab_http_status
(
success_status
)
}
end
end
describe
'authenticated'
do
describe
'#new'
do
let
(
:user
)
{
create
(
:user
,
email_opted_in:
true
)
}
subject
do
let
(
:create_lead_result
)
{
nil
}
get
:new
response
end
it_behaves_like
'an authenticated endpoint'
it_behaves_like
'a dot-com only feature'
end
describe
'#create_lead'
do
let
(
:post_params
)
{
{}
}
let
(
:create_lead_result
)
{
nil
}
before
do
before
do
sign_in
(
user
)
allow_next_instance_of
(
GitlabSubscriptions
::
CreateLeadService
)
do
|
lead_service
|
expect
(
lead_service
).
to
receive
(
:execute
).
and_return
({
success:
create_lead_result
})
end
end
end
context
'response url'
do
subject
do
before
do
post
:create_lead
,
params:
post_params
allow_next_instance_of
(
GitlabSubscriptions
::
CreateLeadService
)
do
|
lead_service
|
response
expect
(
lead_service
).
to
receive
(
:execute
).
and_return
({
success:
create_lead_result
})
end
end
end
context
'on success'
do
it_behaves_like
'an authenticated endpoint'
let
(
:create_lead_result
)
{
true
}
it_behaves_like
'a dot-com only feature'
it
'redirects user to Step 3
'
do
context
'on success
'
do
post
:create_lead
let
(
:create_lead_result
)
{
true
}
expect
(
response
).
to
redirect_to
(
select_trials_url
)
it
{
is_expected
.
to
redirect_to
(
select_trials_url
)
}
end
end
end
context
'on failure'
do
let
(
:create_lead_result
)
{
false
}
context
'on failure'
do
it
{
is_expected
.
to
render_template
(
:new
)
}
let
(
:create_lead_result
)
{
false
}
end
it
'renders the :new template'
do
context
'request params to Lead Service'
do
post
:create_lead
let
(
:post_params
)
do
{
company_name:
'Gitlab'
,
company_size:
'1-99'
,
first_name:
user
.
first_name
,
last_name:
user
.
last_name
,
phone_number:
'1111111111'
,
number_of_users:
"20"
,
country:
'IN'
}
end
expect
(
response
).
to
render_template
(
:new
)
let
(
:extra_params
)
do
end
{
end
work_email:
user
.
email
,
uid:
user
.
id
,
skip_email_confirmation:
true
,
gitlab_com_trial:
true
,
provider:
'gitlab'
,
newsletter_segment:
user
.
email_opted_in
}
end
end
context
'request params to Lead Service'
do
let
(
:expected_params
)
do
it
'sends appropriate request params'
do
ActionController
::
Parameters
.
new
(
post_params
).
merge
(
extra_params
).
permit!
params
=
{
end
company_name:
'Gitlab'
,
company_size:
'1-99'
,
it
'sends appropriate request params'
do
first_name:
user
.
first_name
,
expect_next_instance_of
(
GitlabSubscriptions
::
CreateLeadService
)
do
|
lead_service
|
last_name:
user
.
last_name
,
expect
(
lead_service
).
to
receive
(
:execute
).
with
({
trial_user:
expected_params
}).
and_return
({
success:
true
})
phone_number:
'1111111111'
,
number_of_users:
"20"
,
country:
'IN'
}
extra_params
=
{
work_email:
user
.
email
,
uid:
user
.
id
,
skip_email_confirmation:
true
,
gitlab_com_trial:
true
,
provider:
'gitlab'
,
newsletter_segment:
user
.
email_opted_in
}
expected_params
=
ActionController
::
Parameters
.
new
(
params
).
merge
(
extra_params
).
permit!
expect_next_instance_of
(
GitlabSubscriptions
::
CreateLeadService
)
do
|
lead_service
|
expect
(
lead_service
).
to
receive
(
:execute
).
with
({
trial_user:
expected_params
}).
and_return
({
success:
true
})
end
post
:create_lead
,
params:
params
end
end
subject
end
end
end
end
end
end
describe
'#select'
do
describe
'#select'
do
it_behaves_like
'an authenticated endpoint'
,
:get
,
:select
subject
do
get
:select
response
end
it_behaves_like
'an authenticated endpoint'
it_behaves_like
'a dot-com only feature'
end
end
describe
'#apply'
do
describe
'#apply'
do
let
(
:user
)
{
create
(
:user
)
}
let
_it_be
(
:namespace
)
{
create
(
:namespace
,
owner_id:
user
.
id
,
path:
'namespace-test'
)
}
let
(
:namespace
)
{
create
(
:namespace
,
owner_id:
user
.
id
,
path:
'namespace-test'
)
}
let
(
:apply_trial_result
)
{
nil
}
let
(
:apply_trial_result
)
{
nil
}
let
(
:post_params
)
{
{
namespace_id:
namespace
.
id
}
}
before
do
before
do
sign_in
(
user
)
allow_any_instance_of
(
GitlabSubscriptions
::
ApplyTrialService
).
to
receive
(
:execute
)
do
allow_any_instance_of
(
GitlabSubscriptions
::
ApplyTrialService
).
to
receive
(
:execute
)
do
{
success:
apply_trial_result
}
{
success:
apply_trial_result
}
end
end
end
end
subject
do
post
:apply
,
params:
post_params
response
end
it_behaves_like
'an authenticated endpoint'
it_behaves_like
'a dot-com only feature'
context
'on success'
do
context
'on success'
do
let
(
:apply_trial_result
)
{
true
}
let
(
:apply_trial_result
)
{
true
}
it
"redirects to group's path with the parameter trial as true"
do
it
{
is_expected
.
to
redirect_to
(
"/
#{
namespace
.
path
}
?trial=true"
)
}
post
:apply
,
params:
{
namespace_id:
namespace
.
id
}
expect
(
response
).
to
redirect_to
(
"/
#{
namespace
.
path
}
?trial=true"
)
end
context
'with a new Group'
do
context
'with a new Group'
do
let
(
:post_params
)
{
{
new_group_name:
'GitLab'
}
}
it
'creates the Group'
do
it
'creates the Group'
do
expect
do
expect
{
subject
}.
to
change
{
Group
.
count
}.
to
(
1
)
post
:apply
,
params:
{
new_group_name:
'GitLab'
}
end
.
to
change
{
Group
.
count
}.
to
(
1
)
end
end
end
end
end
end
...
@@ -137,18 +166,15 @@ RSpec.describe TrialsController do
...
@@ -137,18 +166,15 @@ RSpec.describe TrialsController do
context
'on failure'
do
context
'on failure'
do
let
(
:apply_trial_result
)
{
false
}
let
(
:apply_trial_result
)
{
false
}
it
'renders the :select view'
do
it
{
is_expected
.
to
render_template
(
:select
)
}
post
:apply
,
params:
{
namespace_id:
namespace
.
id
}
expect
(
response
).
to
render_template
(
:select
)
end
context
'with a new Group'
do
context
'with a new Group'
do
it
'renders the :select view'
do
let
(
:post_params
)
{
{
new_group_name:
'admin'
}
}
post
:apply
,
params:
{
new_group_name:
'admin'
}
it
{
is_expected
.
to
render_template
(
:select
)
}
expect
(
response
).
to
render_template
(
:select
)
it
'does not create the Group'
do
expect
(
Group
.
count
).
to
eq
(
0
)
expect
{
subject
}.
not_to
change
{
Group
.
count
}.
from
(
0
)
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