2020-02-27 10:09:24 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe Gitlab::Checks::SnippetCheck do
|
2020-02-27 10:09:24 -05:00
|
|
|
include_context 'change access checks context'
|
|
|
|
|
|
|
|
let(:snippet) { create(:personal_snippet, :repository) }
|
|
|
|
let(:user_access) { Gitlab::UserAccessSnippet.new(user, snippet: snippet) }
|
|
|
|
|
|
|
|
subject { Gitlab::Checks::SnippetCheck.new(changes, logger: logger) }
|
|
|
|
|
2020-03-17 02:09:21 -04:00
|
|
|
describe '#validate!' do
|
2020-02-27 10:09:24 -05:00
|
|
|
it 'does not raise any error' do
|
2020-03-17 02:09:21 -04:00
|
|
|
expect { subject.validate! }.not_to raise_error
|
2020-02-27 10:09:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'trying to delete the branch' do
|
|
|
|
let(:newrev) { '0000000000000000000000000000000000000000' }
|
|
|
|
|
|
|
|
it 'raises an error' do
|
2020-03-17 02:09:21 -04:00
|
|
|
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.')
|
2020-02-27 10:09:24 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'trying to create the branch' do
|
|
|
|
let(:oldrev) { '0000000000000000000000000000000000000000' }
|
2020-03-03 10:08:08 -05:00
|
|
|
let(:ref) { 'refs/heads/feature' }
|
2020-02-27 10:09:24 -05:00
|
|
|
|
|
|
|
it 'raises an error' do
|
2020-03-17 02:09:21 -04:00
|
|
|
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.')
|
2020-02-27 10:09:24 -05:00
|
|
|
end
|
2020-03-03 10:08:08 -05:00
|
|
|
|
|
|
|
context "when branch is 'master'" do
|
|
|
|
let(:ref) { 'refs/heads/master' }
|
|
|
|
|
|
|
|
it "allows the operation" do
|
2020-03-17 02:09:21 -04:00
|
|
|
expect { subject.validate! }.not_to raise_error
|
2020-03-03 10:08:08 -05:00
|
|
|
end
|
|
|
|
end
|
2020-02-27 10:09:24 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|