Commit beedd40e authored by Rémy Coutable's avatar Rémy Coutable

Ensure user is authenticated to create a new snippet

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 333e83a2
module ToggleAwardEmoji module ToggleAwardEmoji
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do
before_action :authenticate_user!, only: [:toggle_award_emoji]
end
def toggle_award_emoji def toggle_award_emoji
authenticate_user!
name = params.require(:name) name = params.require(:name)
if awardable.user_can_award?(current_user, name) if awardable.user_can_award?(current_user, name)
......
---
title: Redirect to sign-in page when unauthenticated user tries to create a snippet
merge_request: 7786
author:
...@@ -3,6 +3,28 @@ require 'spec_helper' ...@@ -3,6 +3,28 @@ require 'spec_helper'
describe SnippetsController do describe SnippetsController do
let(:user) { create(:user) } 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 describe 'GET #show' do
context 'when the personal snippet is private' do context 'when the personal snippet is private' do
let(:personal_snippet) { create(:personal_snippet, :private, author: user) } let(:personal_snippet) { create(:personal_snippet, :private, author: user) }
......
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment