Commit ce4d1a57 authored by David Kim's avatar David Kim

Merge branch 'kerrizor/add_drafts_scope_to_merge_requests' into 'master'

Add .drafts scope to MergeRequests

See merge request gitlab-org/gitlab!62718
parents 931015ab 93c77e14
...@@ -269,6 +269,7 @@ class MergeRequest < ApplicationRecord ...@@ -269,6 +269,7 @@ class MergeRequest < ApplicationRecord
scope :merged, -> { with_state(:merged) } scope :merged, -> { with_state(:merged) }
scope :closed_and_merged, -> { with_states(:closed, :merged) } scope :closed_and_merged, -> { with_states(:closed, :merged) }
scope :open_and_closed, -> { with_states(:opened, :closed) } scope :open_and_closed, -> { with_states(:opened, :closed) }
scope :drafts, -> { where(draft: true) }
scope :from_source_branches, ->(branches) { where(source_branch: branches) } scope :from_source_branches, ->(branches) { where(source_branch: branches) }
scope :by_commit_sha, ->(sha) do scope :by_commit_sha, ->(sha) do
where('EXISTS (?)', MergeRequestDiff.select(1).where('merge_requests.latest_merge_request_diff_id = merge_request_diffs.id').by_commit_sha(sha)).reorder(nil) where('EXISTS (?)', MergeRequestDiff.select(1).where('merge_requests.latest_merge_request_diff_id = merge_request_diffs.id').by_commit_sha(sha)).reorder(nil)
......
...@@ -99,6 +99,7 @@ RSpec.describe MergeRequest, factory_default: :keep do ...@@ -99,6 +99,7 @@ RSpec.describe MergeRequest, factory_default: :keep do
let_it_be(:merge_request1) { create(:merge_request, :unique_branches, reviewers: [user1])} 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_request2) { create(:merge_request, :unique_branches, reviewers: [user2])}
let_it_be(:merge_request3) { create(:merge_request, :unique_branches, reviewers: [])} 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 describe '.review_requested' do
it 'returns MRs that have any review requests' do it 'returns MRs that have any review requests' do
...@@ -108,7 +109,7 @@ RSpec.describe MergeRequest, factory_default: :keep do ...@@ -108,7 +109,7 @@ RSpec.describe MergeRequest, factory_default: :keep do
describe '.no_review_requested' do describe '.no_review_requested' do
it 'returns MRs that have no review requests' do it 'returns MRs that have no review requests' do
expect(described_class.no_review_requested).to eq([merge_request3]) expect(described_class.no_review_requested).to eq([merge_request3, merge_request4])
end end
end end
...@@ -120,7 +121,14 @@ RSpec.describe MergeRequest, factory_default: :keep do ...@@ -120,7 +121,14 @@ RSpec.describe MergeRequest, factory_default: :keep do
describe '.no_review_requested_to' do describe '.no_review_requested_to' do
it 'returns MRs that the user has not been requested to review' do 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]) 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 end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment