Commit 3ca064ee authored by Semyon Pupkov's avatar Semyon Pupkov

Add missing tests for download snippet

ref: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6720
parent 21e3712a
...@@ -116,9 +116,8 @@ describe SnippetsController do ...@@ -116,9 +116,8 @@ describe SnippetsController do
end end
end end
describe 'GET #raw' do %w(raw download).each do |action|
let(:user) { create(:user) } describe "GET #{action}" 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) }
...@@ -132,25 +131,35 @@ describe SnippetsController do ...@@ -132,25 +131,35 @@ describe SnippetsController do
let(:other_personal_snippet) { create(:personal_snippet, :private, author: other_author) } let(:other_personal_snippet) { create(:personal_snippet, :private, author: other_author) }
it 'responds with status 404' do it 'responds with status 404' do
get :raw, id: other_personal_snippet.to_param get action, id: other_personal_snippet.to_param
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
context 'when signed in user is the author' do context 'when signed in user is the author' do
it 'renders the raw snippet' do before { get action, id: personal_snippet.to_param }
get :raw, id: personal_snippet.to_param
it 'responds with status 200' do
expect(assigns(:snippet)).to eq(personal_snippet) expect(assigns(:snippet)).to eq(personal_snippet)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it 'has expected headers' do
expect(response.header['Content-Type']).to eq('text/plain; charset=utf-8')
if action == :download
expect(response.header['Content-Disposition']).to match(/attachment/)
elsif action == :raw
expect(response.header['Content-Disposition']).to match(/inline/)
end
end
end end
end end
context 'when not signed in' do context 'when not signed in' do
it 'redirects to the sign in page' do it 'redirects to the sign in page' do
get :raw, id: personal_snippet.to_param get action, id: personal_snippet.to_param
expect(response).to redirect_to(new_user_session_path) expect(response).to redirect_to(new_user_session_path)
end end
...@@ -165,8 +174,8 @@ describe SnippetsController do ...@@ -165,8 +174,8 @@ describe SnippetsController do
sign_in(user) sign_in(user)
end end
it 'renders the raw snippet' do it 'responds with status 200' do
get :raw, id: personal_snippet.to_param get action, id: personal_snippet.to_param
expect(assigns(:snippet)).to eq(personal_snippet) expect(assigns(:snippet)).to eq(personal_snippet)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -175,7 +184,7 @@ describe SnippetsController do ...@@ -175,7 +184,7 @@ describe SnippetsController do
context 'when not signed in' do context 'when not signed in' do
it 'redirects to the sign in page' do it 'redirects to the sign in page' do
get :raw, id: personal_snippet.to_param get action, id: personal_snippet.to_param
expect(response).to redirect_to(new_user_session_path) expect(response).to redirect_to(new_user_session_path)
end end
...@@ -190,8 +199,8 @@ describe SnippetsController do ...@@ -190,8 +199,8 @@ describe SnippetsController do
sign_in(user) sign_in(user)
end end
it 'renders the raw snippet' do it 'responds with status 200' do
get :raw, id: personal_snippet.to_param get action, id: personal_snippet.to_param
expect(assigns(:snippet)).to eq(personal_snippet) expect(assigns(:snippet)).to eq(personal_snippet)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -199,8 +208,8 @@ describe SnippetsController do ...@@ -199,8 +208,8 @@ describe SnippetsController do
end end
context 'when not signed in' do context 'when not signed in' do
it 'renders the raw snippet' do it 'responds with status 200' do
get :raw, id: personal_snippet.to_param get action, id: personal_snippet.to_param
expect(assigns(:snippet)).to eq(personal_snippet) expect(assigns(:snippet)).to eq(personal_snippet)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -215,7 +224,7 @@ describe SnippetsController do ...@@ -215,7 +224,7 @@ describe SnippetsController do
end end
it 'responds with status 404' do it 'responds with status 404' do
get :raw, id: 'doesntexist' get action, id: 'doesntexist'
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
...@@ -223,13 +232,14 @@ describe SnippetsController do ...@@ -223,13 +232,14 @@ describe SnippetsController do
context 'when not signed in' do context 'when not signed in' do
it 'responds with status 404' do it 'responds with status 404' do
get :raw, id: 'doesntexist' get action, id: 'doesntexist'
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
end end
end end
end
context 'award emoji on snippets' do context 'award emoji on snippets' do
let(:personal_snippet) { create(:personal_snippet, :public, author: user) } let(:personal_snippet) { create(:personal_snippet, :public, author: user) }
......
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