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
7624c680
Commit
7624c680
authored
Nov 03, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update EE-specific API helpers spec
parent
cfe1ff8b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
13 deletions
+21
-13
ee/lib/ee/api/helpers.rb
ee/lib/ee/api/helpers.rb
+2
-0
spec/ee/spec/lib/ee/api/helpers_spec.rb
spec/ee/spec/lib/ee/api/helpers_spec.rb
+19
-13
No files found.
ee/lib/ee/api/helpers.rb
View file @
7624c680
...
...
@@ -2,6 +2,8 @@ module EE
module
API
module
Helpers
def
current_user
return
@current_user
if
defined?
(
@current_user
)
user
=
super
::
Gitlab
::
Database
::
LoadBalancing
::
RackMiddleware
...
...
spec/ee/spec/lib/ee/api/helpers_spec.rb
View file @
7624c680
require
'spec_helper'
describe
EE
::
API
::
Helpers
do
let
(
:helper
)
{
Class
.
new
{
include
API
::
Helpers
}.
new
}
include
API
::
APIGuard
::
HelperMethods
include
API
::
Helpers
let
(
:options
)
{
{}
}
let
(
:params
)
{
{}
}
let
(
:env
)
do
{
'rack.input'
=>
''
,
'REQUEST_METHOD'
=>
'GET'
}
end
let
(
:header
)
{
}
before
do
allow
(
helper
).
to
receive
(
:env
).
and_return
({})
allow
(
Gitlab
::
Database
::
LoadBalancing
).
to
receive
(
:enable?
).
and_return
(
true
)
end
describe
'#current_user'
do
let
(
:user
)
{
build
(
:user
,
id:
42
)
}
before
do
allow
(
helper
).
to
receive
(
:sudo!
)
end
it
'handles sticking when a user could be found'
do
allow
(
helper
).
to
receive
(
:initial_current_user
).
and_return
(
user
)
allow
_any_instance_of
(
API
::
Helpers
).
to
receive
(
:initial_current_user
).
and_return
(
user
)
expect
(
Gitlab
::
Database
::
LoadBalancing
::
RackMiddleware
)
.
to
receive
(
:stick_or_unstick
).
with
(
{}
,
:user
,
42
)
.
to
receive
(
:stick_or_unstick
).
with
(
env
,
:user
,
42
)
helper
.
current_user
current_user
end
it
'does not handle sticking if no user could be found'
do
allow
(
helper
).
to
receive
(
:initial_current_user
).
and_return
(
nil
)
allow
_any_instance_of
(
API
::
Helpers
).
to
receive
(
:initial_current_user
).
and_return
(
nil
)
expect
(
Gitlab
::
Database
::
LoadBalancing
::
RackMiddleware
)
.
not_to
receive
(
:stick_or_unstick
)
helper
.
current_user
current_user
end
it
'returns the user if one could be found'
do
allow
(
helper
).
to
receive
(
:initial_current_user
).
and_return
(
user
)
allow
_any_instance_of
(
API
::
Helpers
).
to
receive
(
:initial_current_user
).
and_return
(
user
)
expect
(
helper
.
current_user
).
to
eq
(
user
)
expect
(
current_user
).
to
eq
(
user
)
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