Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/snippets_controller_spec.rb')
-rw-r--r--spec/controllers/snippets_controller_spec.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/controllers/snippets_controller_spec.rb b/spec/controllers/snippets_controller_spec.rb
index 510db4374c0..c8f9e4256c9 100644
--- a/spec/controllers/snippets_controller_spec.rb
+++ b/spec/controllers/snippets_controller_spec.rb
@@ -664,4 +664,56 @@ describe SnippetsController do
expect(json_response.keys).to match_array(%w(body references))
end
end
+
+ describe 'DELETE #destroy' do
+ let!(:snippet) { create :personal_snippet, author: user }
+
+ context 'when current user has ability to destroy the snippet' do
+ before do
+ sign_in(user)
+ end
+
+ it 'removes the snippet' do
+ delete :destroy, params: { id: snippet.to_param }
+
+ expect { snippet.reload }.to raise_error(ActiveRecord::RecordNotFound)
+ end
+
+ context 'when snippet is succesfuly destroyed' do
+ it 'redirects to the project snippets page' do
+ delete :destroy, params: { id: snippet.to_param }
+
+ expect(response).to redirect_to(dashboard_snippets_path)
+ end
+ end
+
+ context 'when snippet is not destroyed' do
+ before do
+ allow(snippet).to receive(:destroy).and_return(false)
+ controller.instance_variable_set(:@snippet, snippet)
+ end
+
+ it 'renders the snippet page with errors' do
+ delete :destroy, params: { id: snippet.to_param }
+
+ expect(flash[:alert]).to eq('Failed to remove snippet.')
+ expect(response).to redirect_to(snippet_path(snippet))
+ end
+ end
+ end
+
+ context 'when current_user does not have ability to destroy the snippet' do
+ let(:another_user) { create(:user) }
+
+ before do
+ sign_in(another_user)
+ end
+
+ it 'responds with status 404' do
+ delete :destroy, params: { id: snippet.to_param }
+
+ expect(response).to have_gitlab_http_status(404)
+ end
+ end
+ end
end