| ... | ... | @@ -117,6 +117,119 @@ describe Snippets::NotesController do |
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST create' do
|
|
|
|
context 'when a snippet is public' do
|
|
|
|
let(:request_params) do
|
|
|
|
{
|
|
|
|
note: attributes_for(:note_on_personal_snippet, noteable: public_snippet),
|
|
|
|
snippet_id: public_snippet.id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns status 302' do
|
|
|
|
post :create, params: request_params
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(302)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the note' do
|
|
|
|
expect { post :create, params: request_params }.to change { Note.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a snippet is internal' do
|
|
|
|
let(:request_params) do
|
|
|
|
{
|
|
|
|
note: attributes_for(:note_on_personal_snippet, noteable: internal_snippet),
|
|
|
|
snippet_id: internal_snippet.id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns status 302' do
|
|
|
|
post :create, params: request_params
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(302)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the note' do
|
|
|
|
expect { post :create, params: request_params }.to change { Note.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a snippet is private' do
|
|
|
|
let(:request_params) do
|
|
|
|
{
|
|
|
|
note: attributes_for(:note_on_personal_snippet, noteable: private_snippet),
|
|
|
|
snippet_id: private_snippet.id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not the author' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns status 404' do
|
|
|
|
post :create, params: request_params
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create the note' do
|
|
|
|
expect { post :create, params: request_params }.not_to change { Note.count }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user sends a snippet_id for a public snippet' do
|
|
|
|
let(:request_params) do
|
|
|
|
{
|
|
|
|
note: attributes_for(:note_on_personal_snippet, noteable: private_snippet),
|
|
|
|
snippet_id: public_snippet.id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns status 302' do
|
|
|
|
post :create, params: request_params
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(302)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the note on the public snippet' do
|
|
|
|
expect { post :create, params: request_params }.to change { Note.count }.by(1)
|
|
|
|
expect(Note.last.noteable).to eq public_snippet
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is the author' do
|
|
|
|
before do
|
|
|
|
sign_in(private_snippet.author)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns status 302' do
|
|
|
|
post :create, params: request_params
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(302)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the note' do
|
|
|
|
expect { post :create, params: request_params }.to change { Note.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE destroy' do
|
|
|
|
let(:request_params) do
|
|
|
|
{
|
| ... | ... | |
| ... | ... | |