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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
a9212e0f
Commit
a9212e0f
authored
Nov 27, 2017
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some unit tests for lib/api/helpers.rb
parent
97f966c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
109 additions
and
0 deletions
+109
-0
spec/lib/api/helpers_spec.rb
spec/lib/api/helpers_spec.rb
+109
-0
No files found.
spec/lib/api/helpers_spec.rb
0 → 100644
View file @
a9212e0f
require
'spec_helper'
describe
API
::
Helpers
do
subject
{
Class
.
new
.
include
(
described_class
).
new
}
describe
'#find_namespace'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
shared_examples
'namespace finder'
do
context
'when namespace exists'
do
it
'returns requested namespace'
do
expect
(
subject
.
find_namespace
(
existing_id
)).
to
eq
(
namespace
)
end
end
context
"when namespace doesn't exists"
do
it
'returns nil'
do
expect
(
subject
.
find_namespace
(
non_existing_id
)).
to
be_nil
end
end
end
context
'when ID is used as an argument'
do
let
(
:existing_id
)
{
namespace
.
id
}
let
(
:non_existing_id
)
{
9999
}
it_behaves_like
'namespace finder'
end
context
'when PATH is used as an argument'
do
let
(
:existing_id
)
{
namespace
.
path
}
let
(
:non_existing_id
)
{
'non-existing-path'
}
it_behaves_like
'namespace finder'
end
end
shared_examples
'user namespace finder'
do
let
(
:user1
)
{
create
(
:user
)
}
before
do
allow
(
subject
).
to
receive
(
:current_user
).
and_return
(
user1
)
allow
(
subject
).
to
receive
(
:header
).
and_return
(
nil
)
allow
(
subject
).
to
receive
(
:not_found!
).
and_raise
(
'404 Namespace not found'
)
end
context
'when namespace is group'
do
let
(
:namespace
)
{
create
(
:group
)
}
context
'when user has access to group'
do
before
do
namespace
.
add_guest
(
user1
)
namespace
.
save!
end
it
'returns requested namespace'
do
expect
(
namespace_finder
).
to
eq
(
namespace
)
end
end
context
"when user doesn't have access to group"
do
it
'raises not found error'
do
expect
{
namespace_finder
}.
to
raise_error
(
RuntimeError
,
'404 Namespace not found'
)
end
end
end
context
"when namespace is user's personal namespace"
do
let
(
:namespace
)
{
create
(
:namespace
)
}
context
'when user owns the namespace'
do
before
do
namespace
.
owner
=
user1
namespace
.
save!
end
it
'returns requested namespace'
do
expect
(
namespace_finder
).
to
eq
(
namespace
)
end
end
context
"when user doesn't own the namespace"
do
it
'raises not found error'
do
expect
{
namespace_finder
}.
to
raise_error
(
RuntimeError
,
'404 Namespace not found'
)
end
end
end
end
describe
'#find_namespace!'
do
let
(
:namespace_finder
)
do
subject
.
find_namespace!
(
namespace
.
id
)
end
it_behaves_like
'user namespace finder'
end
describe
'#user_namespace'
do
let
(
:namespace_finder
)
do
subject
.
user_namespace
end
before
do
allow
(
subject
).
to
receive
(
:params
).
and_return
({
id:
namespace
.
id
})
end
it_behaves_like
'user namespace finder'
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