Commit 0f7a098b authored by Etienne Baqué's avatar Etienne Baqué

Added tests for issuable concern file

Added tests with scenario including milestones, releases and issues.
Fixed some scopes in issuable concern file.
parent 57e6c04b
......@@ -580,9 +580,9 @@ class IssuableFinder
def by_release(items)
if releases?
items = if filter_by_no_release?
items.left_joins_milestones_joins_no_release
items.without_release
elsif filter_by_any_release?
items.left_joins_milestones_joins_releases
items.any_release
else
items.with_release(params[:release_tag])
end
......
......@@ -123,19 +123,18 @@ module Issuable
scope :order_milestone_due_desc, -> { left_joins_milestones.reorder(Arel.sql('milestones.due_date IS NULL, milestones.id IS NULL, milestones.due_date DESC')) }
scope :order_milestone_due_asc, -> { left_joins_milestones.reorder(Arel.sql('milestones.due_date IS NULL, milestones.id IS NULL, milestones.due_date ASC')) }
scope :left_joins_milestones_joins_no_release, -> do
joins("LEFT OUTER JOIN milestones
LEFT OUTER JOIN milestone_releases ON milestones.id = milestone_releases.milestone_id
ON #{table_name}.milestone_id = milestones.id"
).where('milestone_releases.release_id IS NULL')
scope :without_release, -> do
joins("LEFT OUTER JOIN milestones AS ms ON #{table_name}.milestone_id = ms.id
LEFT OUTER JOIN milestone_releases AS ms_rl ON ms.id = ms_rl.milestone_id"
).where('ms_rl.release_id IS NULL')
end
scope :left_joins_milestones_joins_releases, -> do
joins("LEFT OUTER JOIN milestones
joins("LEFT OUTER JOIN milestones AS ms
JOIN milestone_releases
JOIN releases ON milestone_releases.release_id = releases.id
ON milestones.id = milestone_releases.milestone_id
ON #{table_name}.milestone_id = milestones.id"
ON ms.id = milestone_releases.milestone_id
ON #{table_name}.milestone_id = ms.id"
).where('milestone_releases.release_id IS NOT NULL').distinct
end
......
......@@ -852,4 +852,125 @@ describe Issuable do
it_behaves_like 'matches_cross_reference_regex? fails fast'
end
end
# Testing the release related scopes with the following setup:
# - release_1
# - milestone_1
# - issue_1
# - issue_2
# - milestone_2
# - issue_3
#
# - release_2
# - milestone_2
# - issue_3
# - milestone_3
# - (no issue)
#
# - release_3
# - milestone_4
# - issue_4
# - milestone_5
# - issue_4
#
# - release_4
# - milestone_3
# - (no issue)
#
# - milestone_6 (no release)
# - issue_5
#
# - issue_6 (no milestone, no release)
describe 'release scopes' do
let_it_be(:project) { create(:project) }
let_it_be(:release_1) { create(:release, tag: 'v1.0', project: project) }
let_it_be(:release_2) { create(:release, tag: 'v2.0', project: project) }
let_it_be(:release_3) { create(:release, tag: 'v3.0', project: project) }
let_it_be(:release_4) { create(:release, tag: 'v4.0', project: project) }
let_it_be(:milestone_1) { create(:milestone, title: 'm1', project: project) }
let_it_be(:milestone_2) { create(:milestone, title: 'm2', project: project) }
let_it_be(:milestone_3) { create(:milestone, title: 'm3', project: project) }
let_it_be(:milestone_4) { create(:milestone, title: 'm4', project: project) }
let_it_be(:milestone_5) { create(:milestone, title: 'm5', project: project) }
let_it_be(:milestone_6) { create(:milestone, title: 'm6', project: project) }
let_it_be(:issue_1) { create(:issue, project: project) }
let_it_be(:issue_2) { create(:issue, project: project) }
let_it_be(:issue_3) { create(:issue, project: project) }
let_it_be(:issue_4) { create(:issue, project: project) }
let_it_be(:issue_5) { create(:issue, project: project) }
let_it_be(:issue_6) { create(:issue, project: project) }
let_it_be(:items) { Issue.all }
before(:all) do
milestone_1.issues = [issue_1, issue_2]
milestone_2.issues = [issue_3]
milestone_4.issues = [issue_4]
milestone_5.issues = [issue_4]
milestone_6.issues = [issue_5]
release_1.milestones = [milestone_1, milestone_2]
release_2.milestones = [milestone_2, milestone_3]
release_3.milestones = [milestone_4, milestone_5]
release_4.milestones = [milestone_3]
end
describe '#without_release' do
it 'returns the issues not tied to any milestone and the ones tied to milestone with no release' do
expect(items.without_release).to contain_exactly(issue_5, issue_6)
end
end
describe '#any_release' do
it 'returns all issues tied to a release' do
expect(items.any_release).to contain_exactly(issue_1, issue_2, issue_3, issue_4)
end
end
describe '#with_release' do
it 'returns the issues tied a specfic release' do
expect(items.with_release('v1.0')).to contain_exactly(issue_1, issue_2, issue_3)
end
context 'when a release has a milestone with one issue and another one with no issue' do
it 'returns that one issue' do
expect(items.with_release('v2.0')).to contain_exactly(issue_3)
end
context 'when the milestone with no issue is added as a filter' do
it 'returns an empty list' do
expect(items.with_release('v2.0').with_milestone('m3')).to be_empty
end
end
context 'when the milestone with the issue is added as a filter' do
it 'returns this issue' do
expect(items.with_release('v2.0').with_milestone('m2')).to contain_exactly(issue_3)
end
end
end
context 'when an issue is tied to multiple milestones under the same release' do
it 'returns this issue only once' do
expect(items.with_release('v3.0')).to contain_exactly(issue_4)
end
end
context 'when there is no issue under a specific release' do
it 'returns no issue' do
expect(items.with_release('v4.0')).to be_empty
end
end
context 'when a non-existant release tag is passed in' do
it 'returns no issue' do
expect(items.with_release('v999.0')).to be_empty
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