diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /spec/models/merge_request_spec.rb | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/models/merge_request_spec.rb')
-rw-r--r-- | spec/models/merge_request_spec.rb | 103 |
1 files changed, 67 insertions, 36 deletions
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index a77ca1e9a51..94b4c1901b8 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -99,16 +99,17 @@ RSpec.describe MergeRequest, factory_default: :keep do let_it_be(:merge_request1) { create(:merge_request, :unique_branches, reviewers: [user1])} let_it_be(:merge_request2) { create(:merge_request, :unique_branches, reviewers: [user2])} let_it_be(:merge_request3) { create(:merge_request, :unique_branches, reviewers: [])} + let_it_be(:merge_request4) { create(:merge_request, :draft_merge_request)} describe '.review_requested' do - it 'returns MRs that has any review requests' do + it 'returns MRs that have any review requests' do expect(described_class.review_requested).to eq([merge_request1, merge_request2]) end end describe '.no_review_requested' do - it 'returns MRs that has no review requests' do - expect(described_class.no_review_requested).to eq([merge_request3]) + it 'returns MRs that have no review requests' do + expect(described_class.no_review_requested).to eq([merge_request3, merge_request4]) end end @@ -119,8 +120,15 @@ RSpec.describe MergeRequest, factory_default: :keep do end describe '.no_review_requested_to' do - it 'returns MRs that the user has been requested to review' do - expect(described_class.no_review_requested_to(user1)).to eq([merge_request2, merge_request3]) + it 'returns MRs that the user has not been requested to review' do + expect(described_class.no_review_requested_to(user1)) + .to eq([merge_request2, merge_request3, merge_request4]) + end + end + + describe '.drafts' do + it 'returns MRs where draft == true' do + expect(described_class.drafts).to eq([merge_request4]) end end end @@ -296,7 +304,7 @@ RSpec.describe MergeRequest, factory_default: :keep do end it 'does not create duplicated metrics records when MR is concurrently updated' do - merge_request.metrics.destroy + merge_request.metrics.destroy! instance1 = MergeRequest.find(merge_request.id) instance2 = MergeRequest.find(merge_request.id) @@ -317,6 +325,38 @@ RSpec.describe MergeRequest, factory_default: :keep do expect(merge_request.target_project_id).to eq(merge_request.metrics.target_project_id) end end + + describe '#set_draft_status' do + let(:merge_request) { create(:merge_request) } + + context 'MR is a draft' do + before do + expect(merge_request.draft).to be_falsy + + merge_request.title = "Draft: #{merge_request.title}" + end + + it 'sets draft to true' do + merge_request.save! + + expect(merge_request.draft).to be_truthy + end + end + + context 'MR is not a draft' do + before do + expect(merge_request.draft).to be_falsey + + merge_request.title = "This is not a draft" + end + + it 'sets draft to true' do + merge_request.save! + + expect(merge_request.draft).to be_falsey + end + end + end end describe 'respond to' do @@ -347,7 +387,7 @@ RSpec.describe MergeRequest, factory_default: :keep do let(:sha) { 'b83d6e391c22777fca1ed3012fce84f633d7fed0' } it 'returns empty requests' do - latest_merge_request_diff = merge_request.merge_request_diffs.create + latest_merge_request_diff = merge_request.merge_request_diffs.create! MergeRequestDiffCommit.where( merge_request_diff_id: latest_merge_request_diff, @@ -459,7 +499,7 @@ RSpec.describe MergeRequest, factory_default: :keep do } create(:merge_request, params).tap do |mr| - diffs.times { mr.merge_request_diffs.create } + diffs.times { mr.merge_request_diffs.create! } mr.create_merge_head_diff end end @@ -891,7 +931,7 @@ RSpec.describe MergeRequest, factory_default: :keep do context 'when there are MR diffs' do it 'delegates to the MR diffs' do - merge_request.save + merge_request.save! expect(merge_request.merge_request_diff).to receive(:raw_diffs).with(hash_including(options)).and_call_original @@ -1036,20 +1076,20 @@ RSpec.describe MergeRequest, factory_default: :keep do context 'when there are MR diffs' do it 'returns the correct count' do - merge_request.save + merge_request.save! expect(merge_request.diff_size).to eq('105') end it 'returns the correct overflow count' do allow(Commit).to receive(:max_diff_options).and_return(max_files: 2) - merge_request.save + merge_request.save! expect(merge_request.diff_size).to eq('2+') end it 'does not perform highlighting' do - merge_request.save + merge_request.save! expect(Gitlab::Diff::Highlight).not_to receive(:new) @@ -1470,7 +1510,7 @@ RSpec.describe MergeRequest, factory_default: :keep do end it "can't remove a root ref" do - subject.update(source_branch: 'master', target_branch: 'feature') + subject.update!(source_branch: 'master', target_branch: 'feature') expect(subject.can_remove_source_branch?(user)).to be_falsey end @@ -2501,7 +2541,7 @@ RSpec.describe MergeRequest, factory_default: :keep do context 'with a completely different branch' do before do - subject.update(target_branch: 'csv') + subject.update!(target_branch: 'csv') end it_behaves_like 'returning all SHA' @@ -2509,7 +2549,7 @@ RSpec.describe MergeRequest, factory_default: :keep do context 'with a branch having no difference' do before do - subject.update(target_branch: 'branch-merged') + subject.update!(target_branch: 'branch-merged') subject.reload # make sure commits were not cached end @@ -3207,7 +3247,7 @@ RSpec.describe MergeRequest, factory_default: :keep do context 'and a failed pipeline is associated' do before do - pipeline.update(status: 'failed', sha: subject.diff_head_sha) + pipeline.update!(status: 'failed', sha: subject.diff_head_sha) allow(subject).to receive(:head_pipeline) { pipeline } end @@ -3216,7 +3256,7 @@ RSpec.describe MergeRequest, factory_default: :keep do context 'and a successful pipeline is associated' do before do - pipeline.update(status: 'success', sha: subject.diff_head_sha) + pipeline.update!(status: 'success', sha: subject.diff_head_sha) allow(subject).to receive(:head_pipeline) { pipeline } end @@ -3225,7 +3265,7 @@ RSpec.describe MergeRequest, factory_default: :keep do context 'and a skipped pipeline is associated' do before do - pipeline.update(status: 'skipped', sha: subject.diff_head_sha) + pipeline.update!(status: 'skipped', sha: subject.diff_head_sha) allow(subject).to receive(:head_pipeline).and_return(pipeline) end @@ -3530,7 +3570,7 @@ RSpec.describe MergeRequest, factory_default: :keep do before do # Update merge_request_diff so that #diff_refs will return commit.diff_refs allow(subject).to receive(:create_merge_request_diff) do - subject.merge_request_diffs.create( + subject.merge_request_diffs.create!( base_commit_sha: commit.parent_id, start_commit_sha: commit.parent_id, head_commit_sha: commit.sha @@ -3800,7 +3840,7 @@ RSpec.describe MergeRequest, factory_default: :keep do end it 'returns false if the merge request is merged' do - merge_request.update(state: 'merged') + merge_request.update!(state: 'merged') expect(merge_request.reload.reopenable?).to be_falsey end @@ -3880,14 +3920,6 @@ RSpec.describe MergeRequest, factory_default: :keep do let(:service_class) { 'Ci::CompareMetricsReportsService' } it { is_expected.to be_truthy } - - context 'with the metrics report flag disabled' do - before do - stub_feature_flags(merge_base_pipeline_for_metrics_comparison: false) - end - - it { is_expected.to be_falsey } - end end context 'when service class is Ci::CompareCodequalityReportsService' do @@ -4029,9 +4061,9 @@ RSpec.describe MergeRequest, factory_default: :keep do subject { create(:merge_request, importing: true, source_project: project) } - let!(:merge_request_diff1) { subject.merge_request_diffs.create(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') } - let!(:merge_request_diff2) { subject.merge_request_diffs.create(head_commit_sha: nil) } - let!(:merge_request_diff3) { subject.merge_request_diffs.create(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e') } + let!(:merge_request_diff1) { subject.merge_request_diffs.create!(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') } + let!(:merge_request_diff2) { subject.merge_request_diffs.create!(head_commit_sha: nil) } + let!(:merge_request_diff3) { subject.merge_request_diffs.create!(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e') } context 'with diff refs' do it 'returns the diffs' do @@ -4062,9 +4094,9 @@ RSpec.describe MergeRequest, factory_default: :keep do subject { create(:merge_request, importing: true, source_project: project) } - let!(:merge_request_diff1) { subject.merge_request_diffs.create(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') } - let!(:merge_request_diff2) { subject.merge_request_diffs.create(head_commit_sha: nil) } - let!(:merge_request_diff3) { subject.merge_request_diffs.create(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e') } + let!(:merge_request_diff1) { subject.merge_request_diffs.create!(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') } + let!(:merge_request_diff2) { subject.merge_request_diffs.create!(head_commit_sha: nil) } + let!(:merge_request_diff3) { subject.merge_request_diffs.create!(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e') } context 'when the diff refs are for an older merge request version' do let(:diff_refs) { merge_request_diff1.diff_refs } @@ -4108,7 +4140,7 @@ RSpec.describe MergeRequest, factory_default: :keep do it 'refreshes the number of open merge requests of the target project' do project = subject.target_project - expect { subject.destroy } + expect { subject.destroy! } .to change { project.open_merge_requests_count }.from(1).to(0) end end @@ -4874,7 +4906,6 @@ RSpec.describe MergeRequest, factory_default: :keep do subject { merge_request.enabled_reports[report_type] } before do - stub_feature_flags(drop_license_management_artifact: false) stub_licensed_features({ feature => true }) end |