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
a13b872b
Commit
a13b872b
authored
Sep 18, 2020
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Speed up ee/spec/requests/api/search_spec.rb
parent
fb0b4a31
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
33 deletions
+30
-33
ee/spec/requests/api/search_spec.rb
ee/spec/requests/api/search_spec.rb
+30
-33
No files found.
ee/spec/requests/api/search_spec.rb
View file @
a13b872b
...
...
@@ -2,36 +2,35 @@
require
'spec_helper'
RSpec
.
describe
API
::
Search
do
RSpec
.
describe
API
::
Search
,
factory_default: :keep
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:namespace
)
{
create_default
(
:namespace
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
,
:wiki_repo
,
name:
'awesome project'
,
group:
group
)
}
shared_examples
'response is correct'
do
|
schema
:,
size:
1
|
it
{
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
}
it
{
expect
(
response
).
to
match_response_schema
(
schema
)
}
it
{
expect
(
response
).
to
include_limited_pagination_headers
}
it
{
expect
(
json_response
.
size
).
to
eq
(
size
)
}
it
'responds correctly'
do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
match_response_schema
(
schema
)
expect
(
response
).
to
include_limited_pagination_headers
expect
(
json_response
.
size
).
to
eq
(
size
)
end
end
shared_examples
'pagination'
do
|
scope
:,
search:
'*'
|
it
'returns a different result for each page'
do
get
api
(
endpoint
,
user
),
params:
{
scope:
scope
,
search:
search
,
page:
1
,
per_page:
1
}
expect
(
json_response
.
count
).
to
eq
(
1
)
first
=
json_response
.
first
get
api
(
endpoint
,
user
),
params:
{
scope:
scope
,
search:
search
,
page:
2
,
per_page:
1
}
second
=
Gitlab
::
Json
.
parse
(
response
.
body
).
first
expect
(
first
).
not_to
eq
(
second
)
end
it
'returns 1 result when per_page is 1'
do
get
api
(
endpoint
,
user
),
params:
{
scope:
scope
,
search:
search
,
per_page:
1
}
expect
(
json_response
.
count
).
to
eq
(
1
)
end
it
'returns 2 results when per_page is 2'
do
get
api
(
endpoint
,
user
),
params:
{
scope:
scope
,
search:
search
,
per_page:
2
}
expect
(
Gitlab
::
Json
.
parse
(
response
.
body
).
count
).
to
eq
(
2
)
...
...
@@ -39,19 +38,15 @@ RSpec.describe API::Search do
end
shared_examples
'elasticsearch disabled'
do
it
'returns 400 error for wiki_blobs scope'
do
it
'returns 400 error for wiki_blobs
, blobs and commits
scope'
do
get
api
(
endpoint
,
user
),
params:
{
scope:
'wiki_blobs'
,
search:
'awesome'
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
it
'returns 400 error for blobs scope'
do
get
api
(
endpoint
,
user
),
params:
{
scope:
'blobs'
,
search:
'monitors'
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
it
'returns 400 error for commits scope'
do
get
api
(
endpoint
,
user
),
params:
{
scope:
'commits'
,
search:
'folder'
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
...
...
@@ -84,11 +79,13 @@ RSpec.describe API::Search do
project
.
wiki
.
index_wiki_blobs
ensure_elasticsearch_index!
end
it_behaves_like
'response is correct'
,
schema:
'public_api/v4/blobs'
do
before
do
get
api
(
endpoint
,
user
),
params:
{
scope:
'wiki_blobs'
,
search:
'awesome'
}
end
it_behaves_like
'response is correct'
,
schema:
'public_api/v4/blobs'
end
it_behaves_like
'pagination'
,
scope:
'wiki_blobs'
end
...
...
@@ -100,11 +97,11 @@ RSpec.describe API::Search do
end
context
'for commits scope'
do
it_behaves_like
'response is correct'
,
schema:
'public_api/v4/commits_details'
,
size:
2
do
before
do
get
api
(
endpoint
,
user
),
params:
{
scope:
'commits'
,
search:
'folder'
}
end
it_behaves_like
'response is correct'
,
schema:
'public_api/v4/commits_details'
,
size:
2
end
it_behaves_like
'pagination'
,
scope:
'commits'
...
...
@@ -124,11 +121,11 @@ RSpec.describe API::Search do
end
context
'for blobs scope'
do
it_behaves_like
'response is correct'
,
schema:
'public_api/v4/blobs'
do
before
do
get
api
(
endpoint
,
user
),
params:
{
scope:
'blobs'
,
search:
'monitors'
}
end
it_behaves_like
'response is correct'
,
schema:
'public_api/v4/blobs'
end
it_behaves_like
'pagination'
,
scope:
'blobs'
...
...
@@ -404,11 +401,11 @@ RSpec.describe API::Search do
end
context
'for blobs scope'
do
it_behaves_like
'response is correct'
,
schema:
'public_api/v4/blobs'
,
size:
2
do
before
do
get
api
(
endpoint
,
user
),
params:
{
scope:
'blobs'
,
search:
'monitors'
}
end
it_behaves_like
'response is correct'
,
schema:
'public_api/v4/blobs'
,
size:
2
end
context
'filters'
do
it
'by filename'
do
...
...
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