diff options
Diffstat (limited to 'spec/lib/gitlab/checks/force_push_spec.rb')
-rw-r--r-- | spec/lib/gitlab/checks/force_push_spec.rb | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/spec/lib/gitlab/checks/force_push_spec.rb b/spec/lib/gitlab/checks/force_push_spec.rb index 49e02fe5cec..8cdee727d3d 100644 --- a/spec/lib/gitlab/checks/force_push_spec.rb +++ b/spec/lib/gitlab/checks/force_push_spec.rb @@ -6,14 +6,34 @@ RSpec.describe Gitlab::Checks::ForcePush do let_it_be(:project) { create(:project, :repository) } describe '.force_push?' do - it 'returns false if the repo is empty' do - allow(project).to receive(:empty_repo?).and_return(true) + let(:old_rev) { 'HEAD~' } + let(:new_rev) { 'HEAD' } - expect(described_class.force_push?(project, 'HEAD', 'HEAD~')).to be(false) + subject(:force_push) { described_class.force_push?(project, old_rev, new_rev) } + + context 'when the repo is empty' do + before do + allow(project).to receive(:empty_repo?).and_return(true) + end + + it 'returns false' do + expect(force_push).to be(false) + end end - it 'checks if old rev is an anchestor' do - expect(described_class.force_push?(project, 'HEAD', 'HEAD~')).to be(true) + context 'when new rev is a descendant of old rev' do + it 'returns false' do + expect(force_push).to be(false) + end + end + + context 'when new rev is not a descendant of old rev' do + let(:old_rev) { 'HEAD' } + let(:new_rev) { 'HEAD~' } + + it 'returns true' do + expect(force_push).to be(true) + end end end end |