diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-06-01 08:32:40 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-06-01 08:32:40 +0300 |
commit | 272b8dca80eddfcf40933ad5295e9d11f8b1fa93 (patch) | |
tree | 9cafcf1ce1643fbfa1d3237e1af3a569f48d8459 /spec/models/merge_request_spec.rb | |
parent | 0e22b50df8b269ccae32ab68b9ba26e7eea861b0 (diff) | |
parent | 50fda506e3bc93af47c8ebcbfc7d38c7ae55467d (diff) |
Merge branch 'master' into per-project-pipeline-iid
Diffstat (limited to 'spec/models/merge_request_spec.rb')
-rw-r--r-- | spec/models/merge_request_spec.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index aa968dda41f..65cc9372cbe 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -14,6 +14,65 @@ describe MergeRequest do it { is_expected.to have_many(:merge_request_diffs) } end + describe '#squash_in_progress?' do + shared_examples 'checking whether a squash is in progress' do + let(:repo_path) { subject.source_project.repository.path } + let(:squash_path) { File.join(repo_path, "gitlab-worktree", "squash-#{subject.id}") } + + before do + system(*%W(#{Gitlab.config.git.bin_path} -C #{repo_path} worktree add --detach #{squash_path} master)) + end + + it 'returns true when there is a current squash directory' do + expect(subject.squash_in_progress?).to be_truthy + end + + it 'returns false when there is no squash directory' do + FileUtils.rm_rf(squash_path) + + expect(subject.squash_in_progress?).to be_falsey + end + + it 'returns false when the squash directory has expired' do + time = 20.minutes.ago.to_time + File.utime(time, time, squash_path) + + expect(subject.squash_in_progress?).to be_falsey + end + + it 'returns false when the source project has been removed' do + allow(subject).to receive(:source_project).and_return(nil) + + expect(subject.squash_in_progress?).to be_falsey + end + end + + context 'when Gitaly squash_in_progress is enabled' do + it_behaves_like 'checking whether a squash is in progress' + end + + context 'when Gitaly squash_in_progress is disabled', :disable_gitaly do + it_behaves_like 'checking whether a squash is in progress' + end + end + + describe '#squash?' do + let(:merge_request) { build(:merge_request, squash: squash) } + subject { merge_request.squash? } + + context 'disabled in database' do + let(:squash) { false } + + it { is_expected.to be_falsy } + end + + context 'enabled in database' do + let(:squash) { true } + + it { is_expected.to be_truthy } + end + end + describe 'modules' do subject { described_class } |