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
0f6500d5
Commit
0f6500d5
authored
May 10, 2019
by
James Edwards-Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added RoutableActions tests
parent
b575b303
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
0 deletions
+119
-0
spec/controllers/concerns/routable_actions_spec.rb
spec/controllers/concerns/routable_actions_spec.rb
+119
-0
No files found.
spec/controllers/concerns/routable_actions_spec.rb
0 → 100644
View file @
0f6500d5
# frozen_string_literal: true
require
'spec_helper'
describe
RoutableActions
do
controller
(
::
ApplicationController
)
do
include
RoutableActions
# rubocop:disable RSpec/DescribedClass
before_action
:routable
def
routable
@klass
=
params
[
:type
].
constantize
@routable
=
find_routable!
(
params
[
:type
].
constantize
,
params
[
:id
])
end
def
show
head
:ok
end
end
def
get_routable
(
routable
)
get
:show
,
params:
{
id:
routable
.
full_path
,
type:
routable
.
class
}
end
describe
'#find_routable!'
do
context
'when signed in'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
sign_in
(
user
)
end
context
'with a project'
do
let
(
:routable
)
{
create
(
:project
)
}
context
'when authorized'
do
before
do
routable
.
add_guest
(
user
)
end
it
'returns the project'
do
get_routable
(
routable
)
expect
(
assigns
[
:routable
]).
to
be_a
(
Project
)
end
it
'allows access'
do
get_routable
(
routable
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
it
'prevents access when not authorized'
do
get_routable
(
routable
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
context
'with a group'
do
let
(
:routable
)
{
create
(
:group
,
:private
)
}
context
'when authorized'
do
before
do
routable
.
add_guest
(
user
)
end
it
'returns the group'
do
get_routable
(
routable
)
expect
(
assigns
[
:routable
]).
to
be_a
(
Group
)
end
it
'allows access'
do
get_routable
(
routable
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
it
'prevents access when not authorized'
do
get_routable
(
routable
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
context
'with a user'
do
let
(
:routable
)
{
user
}
it
'allows access when authorized'
do
get_routable
(
routable
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
it
'prevents access when unauthorized'
do
allow
(
subject
).
to
receive
(
:can?
).
and_return
(
false
)
get_routable
(
user
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
end
context
'when not signed in'
do
it
'redirects to sign in for private resouces'
do
routable
=
create
(
:project
,
:private
)
get_routable
(
routable
)
expect
(
response
).
to
have_gitlab_http_status
(
302
)
expect
(
response
.
location
).
to
end_with
(
'/users/sign_in'
)
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