summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-21 15:08:26 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-21 15:08:26 +0000
commitc859c3bfd242288065fe5e2d887f7204f09e2335 (patch)
tree10febaf8774a3ea6ab3773c0dd97658d673fb280 /spec/models
parent28ce39a3e0e7b47e53939a15fb823af9c433327a (diff)
downloadgitlab-ce-c859c3bfd242288065fe5e2d887f7204f09e2335.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/concerns/milestoneish_spec.rb17
-rw-r--r--spec/models/merge_request_spec.rb63
2 files changed, 64 insertions, 16 deletions
diff --git a/spec/models/concerns/milestoneish_spec.rb b/spec/models/concerns/milestoneish_spec.rb
index d46c9747845..e39cbedde68 100644
--- a/spec/models/concerns/milestoneish_spec.rb
+++ b/spec/models/concerns/milestoneish_spec.rb
@@ -33,17 +33,32 @@ describe Milestone, 'Milestoneish' do
end
describe '#sorted_issues' do
- it 'sorts issues by label priority' do
+ before do
issue.labels << label_1
security_issue_1.labels << label_2
closed_issue_1.labels << label_3
+ end
+ it 'sorts issues by label priority' do
issues = milestone.sorted_issues(member)
expect(issues.first).to eq(issue)
expect(issues.second).to eq(security_issue_1)
expect(issues.third).not_to eq(closed_issue_1)
end
+
+ it 'limits issue count' do
+ stub_const('Milestoneish::DISPLAY_ISSUES_LIMIT', 4)
+
+ issues = milestone.sorted_issues(member)
+
+ # Cannot use issues.count here because it is sorting
+ # by a virtual column 'highest_priority' and it will break
+ # the query.
+ total_issues_count = issues.opened.unassigned.length + issues.opened.assigned.length + issues.closed.length
+ expect(issues.length).to eq(4)
+ expect(total_issues_count).to eq(4)
+ end
end
context 'attributes visibility' do
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index c6894c04385..9f256719248 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -277,6 +277,7 @@ describe MergeRequest do
describe 'respond to' do
it { is_expected.to respond_to(:unchecked?) }
+ it { is_expected.to respond_to(:checking?) }
it { is_expected.to respond_to(:can_be_merged?) }
it { is_expected.to respond_to(:cannot_be_merged?) }
it { is_expected.to respond_to(:merge_params) }
@@ -2084,43 +2085,75 @@ describe MergeRequest do
describe '#check_mergeability' do
let(:mergeability_service) { double }
+ subject { create(:merge_request, merge_status: 'unchecked') }
+
before do
allow(MergeRequests::MergeabilityCheckService).to receive(:new) do
mergeability_service
end
end
- context 'if the merge status is unchecked' do
- before do
- subject.mark_as_unchecked!
- end
-
+ shared_examples_for 'method that executes MergeabilityCheckService' do
it 'executes MergeabilityCheckService' do
expect(mergeability_service).to receive(:execute)
subject.check_mergeability
end
+
+ context 'when async is true' do
+ context 'and async_merge_request_check_mergeability feature flag is enabled' do
+ it 'executes MergeabilityCheckService asynchronously' do
+ expect(mergeability_service).to receive(:async_execute)
+
+ subject.check_mergeability(async: true)
+ end
+ end
+
+ context 'and async_merge_request_check_mergeability feature flag is disabled' do
+ before do
+ stub_feature_flags(async_merge_request_check_mergeability: false)
+ end
+
+ it 'executes MergeabilityCheckService' do
+ expect(mergeability_service).to receive(:execute)
+
+ subject.check_mergeability(async: true)
+ end
+ end
+ end
+ end
+
+ context 'if the merge status is unchecked' do
+ it_behaves_like 'method that executes MergeabilityCheckService'
+ end
+
+ context 'if the merge status is checking' do
+ before do
+ subject.mark_as_checking!
+ end
+
+ it_behaves_like 'method that executes MergeabilityCheckService'
end
context 'if the merge status is checked' do
- context 'and feature flag is enabled' do
- it 'executes MergeabilityCheckService' do
- expect(mergeability_service).not_to receive(:execute)
+ before do
+ subject.mark_as_mergeable!
+ end
+
+ context 'and merge_requests_conditional_mergeability_check feature flag is enabled' do
+ it 'does not call MergeabilityCheckService' do
+ expect(MergeRequests::MergeabilityCheckService).not_to receive(:new)
subject.check_mergeability
end
end
- context 'and feature flag is disabled' do
+ context 'and merge_requests_conditional_mergeability_check feature flag is disabled' do
before do
stub_feature_flags(merge_requests_conditional_mergeability_check: false)
end
- it 'does not execute MergeabilityCheckService' do
- expect(mergeability_service).to receive(:execute)
-
- subject.check_mergeability
- end
+ it_behaves_like 'method that executes MergeabilityCheckService'
end
end
end
@@ -3145,7 +3178,7 @@ describe MergeRequest do
describe 'check_state?' do
it 'indicates whether MR is still checking for mergeability' do
state_machine = described_class.state_machines[:merge_status]
- check_states = [:unchecked, :cannot_be_merged_recheck]
+ check_states = [:unchecked, :cannot_be_merged_recheck, :checking]
check_states.each do |merge_status|
expect(state_machine.check_state?(merge_status)).to be true