Commit 6387ad2c authored by Eulyeon Ko's avatar Eulyeon Ko

Apply backend reviewer suggestions

- Annotate using :aggregate_failures over wrapping in blocks
- DRY creating objects and specs
parent 771d9576
......@@ -7,12 +7,12 @@ RSpec.describe MilestonesFinder do
let_it_be(:group) { create(:group) }
let_it_be(:project_1) { create(:project, namespace: group) }
let_it_be(:project_2) { create(:project, namespace: group) }
let_it_be(:milestone_2) { create(:milestone, group: group, start_date: now + 1.day, due_date: now + 2.days) }
let_it_be(:milestone_4) { create(:milestone, project: project_2, state: 'active', start_date: now + 4.days, due_date: now + 5.days) }
context 'without filters' do
let_it_be(:milestone_1) { create(:milestone, group: group, title: 'one test', start_date: now - 1.day, due_date: now) }
let_it_be(:milestone_2) { create(:milestone, group: group, start_date: now + 1.day, due_date: now + 2.days) }
let_it_be(:milestone_3) { create(:milestone, project: project_1, state: 'active', start_date: now + 2.days) }
let_it_be(:milestone_4) { create(:milestone, project: project_2, state: 'active', start_date: now + 4.days, due_date: now + 5.days) }
let_it_be(:milestone_5) { create(:milestone, group: group, due_date: now - 2.days) }
it 'returns milestones for projects' do
......@@ -37,12 +37,10 @@ RSpec.describe MilestonesFinder do
expect(result).to contain_exactly(milestone_5, milestone_1, milestone_2, milestone_3, milestone_4)
end
it 'orders milestones by due date' do
aggregate_failures do
expect(result.first).to eq(milestone_5)
expect(result.second).to eq(milestone_1)
expect(result.third).to eq(milestone_2)
end
it 'orders milestones by due date', :aggregate_failures do
expect(result.first).to eq(milestone_5)
expect(result.second).to eq(milestone_1)
expect(result.third).to eq(milestone_2)
end
context 'when expired_last param is used' do
......@@ -65,9 +63,7 @@ RSpec.describe MilestonesFinder do
context 'with filters' do
let_it_be(:milestone_1) { create(:milestone, group: group, state: 'closed', title: 'one test', start_date: now - 1.day, due_date: now) }
let_it_be(:milestone_2) { create(:milestone, group: group, start_date: now + 1.day, due_date: now + 2.days) }
let_it_be(:milestone_3) { create(:milestone, project: project_1, state: 'closed', start_date: now + 2.days, due_date: now + 3.days) }
let_it_be(:milestone_4) { create(:milestone, project: project_2, state: 'active', start_date: now + 4.days, due_date: now + 5.days) }
let(:params) do
{
......
......@@ -149,31 +149,21 @@ RSpec.describe Milestone do
end
describe '#expired? and #expired' do
let_it_be(:milestone) { build(:milestone, project: project) }
context "expired" do
before do
allow(milestone).to receive(:due_date).and_return(Date.today.prev_year)
end
let(:milestone) { build(:milestone, project: project, due_date: Date.today.prev_year) }
it 'returns true when due_date is in the past' do
aggregate_failures do
expect(milestone.expired?).to be_truthy
expect(milestone.expired).to eq true
end
it 'returns true when due_date is in the past', :aggregate_failures do
expect(milestone.expired?).to be_truthy
expect(milestone.expired).to eq true
end
end
context "not expired" do
before do
allow(milestone).to receive(:due_date).and_return(Date.today.next_year)
end
let(:milestone) { build(:milestone, project: project, due_date: Date.today.next_year) }
it 'returns false when due_date is in the future' do
aggregate_failures do
expect(milestone.expired?).to be_falsey
expect(milestone.expired).to eq false
end
it 'returns false when due_date is in the future', :aggregate_failures do
expect(milestone.expired?).to be_falsey
expect(milestone.expired).to eq false
end
end
end
......@@ -190,12 +180,6 @@ RSpec.describe Milestone do
end
end
describe '#can_be_closed?' do
let_it_be(:milestone) { build(:milestone, project: project) }
it { expect(milestone.can_be_closed?).to be_truthy }
end
describe '#can_be_closed?' do
let_it_be(:milestone) { build(:milestone, project: project) }
......@@ -475,12 +459,10 @@ RSpec.describe Milestone do
let_it_be(:milestone_6) { create(:milestone, title: 'Without due date2') }
context 'ordering by due_date ascending' do
it 'sorts by due date in ascending order (ties broken by id in desc order)' do
aggregate_failures do
expect(milestone_3.id).to be < (milestone_6.id)
expect(described_class.sort_with_expired_last('due_date_asc'))
.to eq([milestone_1, milestone_2, milestone_6, milestone_3, milestone_4, milestone_5])
end
it 'sorts by due date in ascending order (ties broken by id in desc order)', :aggregate_failures do
expect(milestone_3.id).to be < (milestone_6.id)
expect(described_class.sort_with_expired_last('due_date_asc'))
.to eq([milestone_1, milestone_2, milestone_6, milestone_3, milestone_4, milestone_5])
end
context 'unsupported sort_by param is presented' do
......@@ -492,12 +474,10 @@ RSpec.describe Milestone do
end
context 'ordering by due_date descending' do
it 'sorts by due date in descending order (ties broken by id in desc order)' do
aggregate_failures do
expect(milestone_3.id).to be < (milestone_6.id)
expect(described_class.sort_with_expired_last('due_date_desc'))
.to eq([milestone_2, milestone_1, milestone_6, milestone_3, milestone_5, milestone_4])
end
it 'sorts by due date in descending order (ties broken by id in desc order)', :aggregate_failures do
expect(milestone_3.id).to be < (milestone_6.id)
expect(described_class.sort_with_expired_last('due_date_desc'))
.to eq([milestone_2, milestone_1, milestone_6, milestone_3, milestone_5, milestone_4])
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