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
5f2d45c9
Commit
5f2d45c9
authored
Nov 15, 2016
by
Cagdas Gerede
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add authentication for for create action. Add more tests for for new and create actions
parent
37cad729
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
8 deletions
+56
-8
app/controllers/projects/forks_controller.rb
app/controllers/projects/forks_controller.rb
+1
-2
spec/controllers/projects/forks_controller_spec.rb
spec/controllers/projects/forks_controller_spec.rb
+55
-6
No files found.
app/controllers/projects/forks_controller.rb
View file @
5f2d45c9
...
@@ -4,6 +4,7 @@ class Projects::ForksController < Projects::ApplicationController
...
@@ -4,6 +4,7 @@ class Projects::ForksController < Projects::ApplicationController
# Authorize
# Authorize
before_action
:require_non_empty_project
before_action
:require_non_empty_project
before_action
:authorize_download_code!
before_action
:authorize_download_code!
before_action
:authenticate_user!
,
only:
[
:new
,
:create
]
def
index
def
index
base_query
=
project
.
forks
.
includes
(
:creator
)
base_query
=
project
.
forks
.
includes
(
:creator
)
...
@@ -29,8 +30,6 @@ class Projects::ForksController < Projects::ApplicationController
...
@@ -29,8 +30,6 @@ class Projects::ForksController < Projects::ApplicationController
end
end
def
new
def
new
return
authenticate_user!
unless
current_user
@namespaces
=
current_user
.
manageable_namespaces
@namespaces
=
current_user
.
manageable_namespaces
@namespaces
.
delete
(
@project
.
namespace
)
@namespaces
.
delete
(
@project
.
namespace
)
end
end
...
...
spec/controllers/projects/forks_controller_spec.rb
View file @
5f2d45c9
...
@@ -69,15 +69,64 @@ describe Projects::ForksController do
...
@@ -69,15 +69,64 @@ describe Projects::ForksController do
end
end
describe
'GET new'
do
describe
'GET new'
do
context
'when user is not logged in'
do
def
get_new
before
{
sign_out
(
user
)
}
it
'redirects to the sign-in page'
do
get
:new
,
get
:new
,
namespace_id:
project
.
namespace
.
to_param
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
project_id:
project
.
to_param
end
context
'when user is signed in'
do
it
'responds with status 200'
do
sign_in
(
user
)
get_new
expect
(
response
).
to
have_http_status
(
200
)
end
end
context
'when user is not signed in'
do
it
'redirects to the sign-in page'
do
sign_out
(
user
)
get_new
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
end
end
end
describe
'POST create'
do
def
post_create
post
:create
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
namespace_key:
user
.
namespace
.
id
end
context
'when user is signed in'
do
it
'responds with status 302'
do
sign_in
(
user
)
post_create
expect
(
response
).
to
have_http_status
(
302
)
expected_import_url
=
namespace_project_import_url
(
user
.
namespace
,
project
)
expect
(
response
.
headers
[
'Location'
]).
to
eq
(
expected_import_url
)
end
end
context
'when user is not signed in'
do
it
'redirects to the sign-in page'
do
sign_out
(
user
)
post_create
expect
(
response
).
to
redirect_to
(
root_path
+
'users/sign_in'
)
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
end
end
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