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
8662a798
Commit
8662a798
authored
Oct 01, 2020
by
Peter Leitzen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Speed up project helper specs
parent
2f9d7914
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
87 deletions
+18
-87
spec/helpers/projects_helper_spec.rb
spec/helpers/projects_helper_spec.rb
+18
-87
No files found.
spec/helpers/projects_helper_spec.rb
View file @
8662a798
...
...
@@ -5,16 +5,15 @@ require 'spec_helper'
RSpec
.
describe
ProjectsHelper
do
include
ProjectForksHelper
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be_with_reload
(
:project
)
{
create
(
:project
)
}
let_it_be_with_refind
(
:project_with_repo
)
{
create
(
:project
,
:repository
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
describe
'#project_incident_management_setting'
do
let
(
:project
)
{
create
(
:project
)
}
before
do
helper
.
instance_variable_set
(
:@project
,
project
)
end
describe
'#project_incident_management_setting'
do
context
'when incident_management_setting exists'
do
let
(
:project_incident_management_setting
)
do
create
(
:project_incident_management_setting
,
project:
project
)
...
...
@@ -40,20 +39,14 @@ RSpec.describe ProjectsHelper do
end
describe
'#error_tracking_setting_project_json'
do
let
(
:project
)
{
create
(
:project
)
}
context
'error tracking setting does not exist'
do
before
do
helper
.
instance_variable_set
(
:@project
,
project
)
end
it
'returns nil'
do
expect
(
helper
.
error_tracking_setting_project_json
).
to
be_nil
end
end
context
'error tracking setting exists'
do
let
!
(
:error_tracking_setting
)
{
create
(
:project_error_tracking_setting
,
project:
project
)
}
let
_it_be
(
:error_tracking_setting
)
{
create
(
:project_error_tracking_setting
,
project:
project
)
}
context
'api_url present'
do
let
(
:json
)
do
...
...
@@ -65,24 +58,16 @@ RSpec.describe ProjectsHelper do
}.
to_json
end
before
do
helper
.
instance_variable_set
(
:@project
,
project
)
end
it
'returns error tracking json'
do
expect
(
helper
.
error_tracking_setting_project_json
).
to
eq
(
json
)
end
end
context
'api_url not present'
do
before
do
it
'returns nil'
do
project
.
error_tracking_setting
.
api_url
=
nil
project
.
error_tracking_setting
.
enabled
=
false
helper
.
instance_variable_set
(
:@project
,
project
)
end
it
'returns nil'
do
expect
(
helper
.
error_tracking_setting_project_json
).
to
be_nil
end
end
...
...
@@ -98,8 +83,7 @@ RSpec.describe ProjectsHelper do
end
describe
"can_change_visibility_level?"
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:project_member
,
:reporter
,
user:
create
(
:user
),
project:
project
).
user
}
let_it_be
(
:user
)
{
create
(
:project_member
,
:reporter
,
user:
create
(
:user
),
project:
project
).
user
}
let
(
:forked_project
)
{
fork_project
(
project
,
user
)
}
it
"returns false if there are no appropriate permissions"
do
...
...
@@ -142,8 +126,7 @@ RSpec.describe ProjectsHelper do
end
describe
'#can_disable_emails?'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:project_member
,
:maintainer
,
user:
create
(
:user
),
project:
project
).
user
}
let_it_be
(
:user
)
{
create
(
:project_member
,
:maintainer
,
user:
create
(
:user
),
project:
project
).
user
}
it
'returns true for the project owner'
do
allow
(
helper
).
to
receive
(
:can?
).
with
(
project
.
owner
,
:set_emails_disabled
,
project
)
{
true
}
...
...
@@ -166,11 +149,7 @@ RSpec.describe ProjectsHelper do
end
describe
"readme_cache_key"
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
before
do
helper
.
instance_variable_set
(
:@project
,
project
)
end
let
(
:project
)
{
project_with_repo
}
it
"returns a valid cach key"
do
expect
(
helper
.
send
(
:readme_cache_key
)).
to
eq
(
"
#{
project
.
full_path
}
-
#{
project
.
commit
.
id
}
-readme"
)
...
...
@@ -184,8 +163,7 @@ RSpec.describe ProjectsHelper do
end
describe
"#project_list_cache_key"
,
:clean_gitlab_redis_shared_state
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
project_with_repo
}
before
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
...
...
@@ -249,8 +227,6 @@ RSpec.describe ProjectsHelper do
describe
'#load_pipeline_status'
do
it
'loads the pipeline status in batch'
do
project
=
build
(
:project
)
helper
.
load_pipeline_status
([
project
])
# Skip lazy loading of the `pipeline_status` attribute
pipeline_status
=
project
.
instance_variable_get
(
'@pipeline_status'
)
...
...
@@ -260,8 +236,6 @@ RSpec.describe ProjectsHelper do
end
describe
'#show_no_ssh_key_message?'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
end
...
...
@@ -282,8 +256,6 @@ RSpec.describe ProjectsHelper do
end
describe
'#show_no_password_message?'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
end
...
...
@@ -424,7 +396,6 @@ RSpec.describe ProjectsHelper do
before
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
helper
.
instance_variable_set
(
:@project
,
project
)
end
context
'when there is no current_user'
do
...
...
@@ -444,9 +415,6 @@ RSpec.describe ProjectsHelper do
end
describe
'#get_project_nav_tabs'
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
before
do
allow
(
helper
).
to
receive
(
:can?
)
{
true
}
end
...
...
@@ -543,7 +511,6 @@ RSpec.describe ProjectsHelper do
describe
'#show_projects'
do
let
(
:projects
)
do
create
(
:project
)
Project
.
all
end
...
...
@@ -568,8 +535,8 @@ RSpec.describe ProjectsHelper do
end
end
describe
(
'#push_to_create_project_command'
)
do
let
(
:user
)
{
create
(
:user
,
username:
'john'
)
}
describe
'#push_to_create_project_command'
do
let
(
:user
)
{
build_stubbed
(
:user
,
username:
'john'
)
}
it
'returns the command to push to create project over HTTP'
do
allow
(
Gitlab
::
CurrentSettings
.
current_application_settings
).
to
receive
(
:enabled_git_access_protocol
)
{
'http'
}
...
...
@@ -585,8 +552,6 @@ RSpec.describe ProjectsHelper do
end
describe
'#any_projects?'
do
let!
(
:project
)
{
create
(
:project
)
}
it
'returns true when projects will be returned'
do
expect
(
helper
.
any_projects?
(
Project
.
all
)).
to
eq
(
true
)
end
...
...
@@ -616,7 +581,7 @@ RSpec.describe ProjectsHelper do
end
describe
'#git_user_name'
do
let
(
:user
)
{
double
(
:user
,
name:
'John "A" Doe53'
)
}
let
(
:user
)
{
build_stubbed
(
:user
,
name:
'John "A" Doe53'
)
}
before
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
...
...
@@ -639,8 +604,6 @@ RSpec.describe ProjectsHelper do
end
context
'user logged in'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
end
...
...
@@ -665,7 +628,6 @@ RSpec.describe ProjectsHelper do
end
describe
'show_xcode_link'
do
let!
(
:project
)
{
create
(
:project
)
}
let
(
:mac_ua
)
{
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36'
}
let
(
:ios_ua
)
{
'Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3'
}
...
...
@@ -806,7 +768,7 @@ RSpec.describe ProjectsHelper do
describe
'#show_auto_devops_implicitly_enabled_banner?'
do
using
RSpec
::
Parameterized
::
TableSyntax
let
(
:user
)
{
create
(
:user
)
}
let
_it_be_with_reload
(
:project_with_auto_devops
)
{
create
(
:project
,
:repository
,
:auto_devops
)
}
let
(
:feature_visibilities
)
do
{
...
...
@@ -880,9 +842,9 @@ RSpec.describe ProjectsHelper do
with_them
do
let
(
:project
)
do
if
project_setting
.
nil?
create
(
:project
,
:repository
)
project_with_repo
else
create
(
:project
,
:repository
,
:auto_devops
)
project_with_auto_devops
end
end
...
...
@@ -903,14 +865,8 @@ RSpec.describe ProjectsHelper do
end
describe
'#can_import_members?'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:owner
)
{
project
.
owner
}
before
do
helper
.
instance_variable_set
(
:@project
,
project
)
end
it
'returns false if user cannot admin_project_member'
do
allow
(
helper
).
to
receive
(
:current_user
)
{
user
}
expect
(
helper
.
can_import_members?
).
to
eq
false
...
...
@@ -923,12 +879,6 @@ RSpec.describe ProjectsHelper do
end
describe
'#metrics_external_dashboard_url'
do
let
(
:project
)
{
create
(
:project
)
}
before
do
helper
.
instance_variable_set
(
:@project
,
project
)
end
context
'metrics_setting exists'
do
it
'returns external_dashboard_url'
do
metrics_setting
=
create
(
:project_metrics_setting
,
project:
project
)
...
...
@@ -945,12 +895,6 @@ RSpec.describe ProjectsHelper do
end
describe
'#grafana_integration_url'
do
let
(
:project
)
{
create
(
:project
)
}
before
do
helper
.
instance_variable_set
(
:@project
,
project
)
end
subject
{
helper
.
grafana_integration_url
}
it
{
is_expected
.
to
eq
(
nil
)
}
...
...
@@ -963,12 +907,6 @@ RSpec.describe ProjectsHelper do
end
describe
'#grafana_integration_token'
do
let
(
:project
)
{
create
(
:project
)
}
before
do
helper
.
instance_variable_set
(
:@project
,
project
)
end
subject
{
helper
.
grafana_integration_masked_token
}
it
{
is_expected
.
to
eq
(
nil
)
}
...
...
@@ -981,12 +919,6 @@ RSpec.describe ProjectsHelper do
end
describe
'#grafana_integration_enabled?'
do
let
(
:project
)
{
create
(
:project
)
}
before
do
helper
.
instance_variable_set
(
:@project
,
project
)
end
subject
{
helper
.
grafana_integration_enabled?
}
it
{
is_expected
.
to
eq
(
nil
)
}
...
...
@@ -999,7 +931,6 @@ RSpec.describe ProjectsHelper do
end
describe
'#project_license_name(project)'
,
:request_store
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:repository
)
{
project
.
repository
}
subject
{
project_license_name
(
project
)
}
...
...
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