2018-12-04 06:55:49 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe Gitlab::Checks::DiffCheck do
|
2018-12-04 06:55:49 -05:00
|
|
|
include_context 'change access checks context'
|
|
|
|
|
|
|
|
describe '#validate!' do
|
2021-01-05 10:10:02 -05:00
|
|
|
context 'when commits is empty' do
|
|
|
|
it 'does not call find_changed_paths' do
|
|
|
|
expect(project.repository).not_to receive(:find_changed_paths)
|
2018-12-04 06:55:49 -05:00
|
|
|
|
|
|
|
subject.validate!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-05 10:10:02 -05:00
|
|
|
context 'when commits is not empty' do
|
2018-12-04 06:55:49 -05:00
|
|
|
before do
|
2021-01-05 10:10:02 -05:00
|
|
|
allow(project.repository).to receive(:new_commits).and_return(
|
|
|
|
project.repository.commits_between('be93687618e4b132087f430a4d8fc3a609c9b77c', '54fcc214b94e78d7a41a9a8fe6d87a5e59500e51')
|
|
|
|
)
|
2018-12-04 06:55:49 -05:00
|
|
|
end
|
|
|
|
|
2021-01-05 10:10:02 -05:00
|
|
|
context 'when deletion is true' do
|
|
|
|
let(:newrev) { Gitlab::Git::BLANK_SHA }
|
2020-12-04 01:09:34 -05:00
|
|
|
|
2021-01-05 10:10:02 -05:00
|
|
|
it 'does not call find_changed_paths' do
|
|
|
|
expect(project.repository).not_to receive(:find_changed_paths)
|
2020-12-04 01:09:34 -05:00
|
|
|
|
2021-01-05 10:10:02 -05:00
|
|
|
subject.validate!
|
2018-12-04 06:55:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-05 10:10:02 -05:00
|
|
|
context 'with LFS not enabled' do
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:lfs_enabled?).and_return(false)
|
2018-12-04 06:55:49 -05:00
|
|
|
end
|
2018-12-28 05:44:25 -05:00
|
|
|
|
2021-01-05 10:10:02 -05:00
|
|
|
it 'does not invoke :lfs_file_locks_validation' do
|
|
|
|
expect(subject).not_to receive(:lfs_file_locks_validation)
|
2018-12-28 05:44:25 -05:00
|
|
|
|
|
|
|
subject.validate!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-05 10:10:02 -05:00
|
|
|
context 'with LFS enabled' do
|
|
|
|
let(:owner) { create(:user) }
|
|
|
|
let!(:lock) { create(:lfs_file_lock, user: owner, project: project, path: 'README') }
|
2018-12-28 05:44:25 -05:00
|
|
|
|
2021-01-05 10:10:02 -05:00
|
|
|
before do
|
|
|
|
allow(project).to receive(:lfs_enabled?).and_return(true)
|
2018-12-28 05:44:25 -05:00
|
|
|
end
|
|
|
|
|
2021-01-05 10:10:02 -05:00
|
|
|
context 'when change is sent by a different user' do
|
|
|
|
it 'raises an error if the user is not allowed to update the file' do
|
|
|
|
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, "The path 'README' is locked in Git LFS by #{lock.user.name}")
|
|
|
|
end
|
|
|
|
end
|
2018-12-28 05:44:25 -05:00
|
|
|
|
2021-01-05 10:10:02 -05:00
|
|
|
context 'when change is sent by the author of the lock' do
|
|
|
|
let(:user) { owner }
|
2018-12-28 05:44:25 -05:00
|
|
|
|
2021-01-05 10:10:02 -05:00
|
|
|
it "doesn't raise any error" do
|
|
|
|
expect { subject.validate! }.not_to raise_error
|
|
|
|
end
|
2018-12-28 05:44:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-12-04 06:55:49 -05:00
|
|
|
end
|
|
|
|
end
|