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
Léo-Paul Géneau
gitlab-ce
Commits
beedd40e
Commit
beedd40e
authored
Nov 28, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure user is authenticated to create a new snippet
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
333e83a2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
4 deletions
+47
-4
app/controllers/concerns/toggle_award_emoji.rb
app/controllers/concerns/toggle_award_emoji.rb
+1
-4
changelogs/unreleased/25026-authenticate-user-for-new-snippet.yml
...gs/unreleased/25026-authenticate-user-for-new-snippet.yml
+4
-0
spec/controllers/snippets_controller_spec.rb
spec/controllers/snippets_controller_spec.rb
+22
-0
spec/features/snippets/create_snippet_spec.rb
spec/features/snippets/create_snippet_spec.rb
+20
-0
No files found.
app/controllers/concerns/toggle_award_emoji.rb
View file @
beedd40e
module
ToggleAwardEmoji
extend
ActiveSupport
::
Concern
included
do
before_action
:authenticate_user!
,
only:
[
:toggle_award_emoji
]
end
def
toggle_award_emoji
authenticate_user!
name
=
params
.
require
(
:name
)
if
awardable
.
user_can_award?
(
current_user
,
name
)
...
...
changelogs/unreleased/25026-authenticate-user-for-new-snippet.yml
0 → 100644
View file @
beedd40e
---
title
:
Redirect to sign-in page when unauthenticated user tries to create a snippet
merge_request
:
7786
author
:
spec/controllers/snippets_controller_spec.rb
View file @
beedd40e
...
...
@@ -3,6 +3,28 @@ require 'spec_helper'
describe
SnippetsController
do
let
(
:user
)
{
create
(
:user
)
}
describe
'GET #new'
do
context
'when signed in'
do
before
do
sign_in
(
user
)
end
it
'responds with status 200'
do
get
:new
expect
(
response
).
to
have_http_status
(
200
)
end
end
context
'when not signed in'
do
it
'redirects to the sign in page'
do
get
:new
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
end
end
end
describe
'GET #show'
do
context
'when the personal snippet is private'
do
let
(
:personal_snippet
)
{
create
(
:personal_snippet
,
:private
,
author:
user
)
}
...
...
spec/features/snippets/create_snippet_spec.rb
0 → 100644
View file @
beedd40e
require
'rails_helper'
feature
'Create Snippet'
,
feature:
true
do
before
do
login_as
:user
visit
new_snippet_path
end
scenario
'Authenticated user creates a snippet'
do
fill_in
'personal_snippet_title'
,
with:
'My Snippet Title'
page
.
within
(
'.file-editor'
)
do
find
(
:xpath
,
"//input[@id='personal_snippet_content']"
).
set
'Hello World!'
end
click_button
'Create snippet'
expect
(
page
).
to
have_content
(
'My Snippet Title'
)
expect
(
page
).
to
have_content
(
'Hello World!'
)
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