diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-05-05 16:23:51 -0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-05-24 16:49:15 -0400 |
commit | 3b2223f11676831f9e995095de13926e1a39b462 (patch) | |
tree | 0e486c2a30c717c3a978859dc1e3e7c52274ec52 /spec | |
parent | 673196e0a866683aecb9332f4554e72985e2ac87 (diff) | |
download | gitlab-ce-3b2223f11676831f9e995095de13926e1a39b462.tar.gz |
improve ordering sql for milestones
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/concerns/issuable_spec.rb | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index 2bb770df4fd..56a4313e8af 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -115,41 +115,30 @@ describe Issue, "Issuable" do end describe "#sort" do - #Correct order is: - #Issues/MRs with milestones ordered by date - #Issues/MRs with milestones without dates - #Issues/MRs without milestones + let(:project) { build_stubbed(:empty_project) } - let!(:issue) { create(:issue) } - let(:project) { issue.project } - let!(:early_milestone) { create(:milestone, project: project, due_date: 10.days.from_now) } - let!(:late_milestone) { create(:milestone, project: project, due_date: 30.days.from_now) } - let!(:issue1) { create(:issue, project: project, milestone: early_milestone) } - let!(:issue2) { create(:issue, project: project, milestone: late_milestone) } - let!(:issue3) { create(:issue, project: project) } - - - context "milestone due later" do - subject { Issue.where(project_id: project.id).order_milestone_due_desc } - before { @issues = subject } - - it "puts issues with nil values at the end of collection" do - expect(@issues.first).to eq(issue2) - expect(@issues.second).to eq(issue1) - expect(@issues.third).to eq(issue) - expect(@issues.fourth).to eq(issue3) - end - end + context "by milestone due date" do + #Correct order is: + #Issues/MRs with milestones ordered by date + #Issues/MRs with milestones without dates + #Issues/MRs without milestones - context "milestone due soon" do - subject { Issue.where(project_id: project.id).order_milestone_due_asc } - before { @issues = subject } + let!(:issue) { create(:issue, project: project) } + let!(:early_milestone) { create(:milestone, project: project, due_date: 10.days.from_now) } + let!(:late_milestone) { create(:milestone, project: project, due_date: 30.days.from_now) } + let!(:issue1) { create(:issue, project: project, milestone: early_milestone) } + let!(:issue2) { create(:issue, project: project, milestone: late_milestone) } + let!(:issue3) { create(:issue, project: project) } + + + it "sorts desc" do + issues = project.issues.sort('milestone_due_desc') + expect(issues).to match_array([issue2, issue1, issue, issue3]) + end - it "puts issues with nil values at the end of collection" do - expect(@issues.first).to eq(issue1) - expect(@issues.second).to eq(issue2) - expect(@issues.third).to eq(issue) - expect(@issues.fourth).to eq(issue3) + it "sorts asc" do + issues = project.issues.sort('milestone_due_asc') + expect(issues).to match_array([issue1, issue2, issue, issue3]) end end end |