summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/shared_examples/controllers/binary_blob_shared_examples.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/support/shared_examples/controllers/binary_blob_shared_examples.rb b/spec/support/shared_examples/controllers/binary_blob_shared_examples.rb
new file mode 100644
index 00000000000..c1ec515f1fe
--- /dev/null
+++ b/spec/support/shared_examples/controllers/binary_blob_shared_examples.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+RSpec.shared_examples 'editing snippet checks blob is binary' do
+ before do
+ sign_in(user)
+
+ allow_next_instance_of(Blob) do |blob|
+ allow(blob).to receive(:binary?).and_return(binary)
+ end
+
+ subject
+ end
+
+ context 'when blob is text' do
+ let(:binary) { false }
+
+ it 'responds with status 200' do
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to render_template(:edit)
+ end
+ end
+
+ context 'when blob is binary' do
+ let(:binary) { true }
+
+ it 'redirects away' do
+ expect(response).to redirect_to(gitlab_snippet_path(snippet))
+ end
+ end
+end
+
+RSpec.shared_examples 'updating snippet checks blob is binary' do
+ before do
+ sign_in(user)
+
+ allow_next_instance_of(Blob) do |blob|
+ allow(blob).to receive(:binary?).and_return(binary)
+ end
+
+ subject
+ end
+
+ context 'when blob is text' do
+ let(:binary) { false }
+
+ it 'updates successfully' do
+ expect(snippet.reload.title).to eq title
+ expect(response).to redirect_to(gitlab_snippet_path(snippet))
+ end
+ end
+
+ context 'when blob is binary' do
+ let(:binary) { true }
+
+ it 'redirects away without updating' do
+ expect(response).to redirect_to(gitlab_snippet_path(snippet))
+ expect(snippet.reload.title).not_to eq title
+ end
+ end
+end