2016-07-25 17:23:27 -04:00
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe MilestonesHelper do
|
2016-11-15 12:48:30 -05:00
|
|
|
|
describe "#milestone_date_range" do
|
|
|
|
|
def result_for(*args)
|
|
|
|
|
milestone_date_range(build(:milestone, *args))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
let(:yesterday) { Date.yesterday }
|
|
|
|
|
let(:tomorrow) { yesterday + 2 }
|
|
|
|
|
let(:format) { '%b %-d, %Y' }
|
|
|
|
|
let(:yesterday_formatted) { yesterday.strftime(format) }
|
|
|
|
|
let(:tomorrow_formatted) { tomorrow.strftime(format) }
|
|
|
|
|
|
|
|
|
|
it { expect(result_for(due_date: nil, start_date: nil)).to be_nil }
|
|
|
|
|
it { expect(result_for(due_date: tomorrow)).to eq("expires on #{tomorrow_formatted}") }
|
|
|
|
|
it { expect(result_for(due_date: yesterday)).to eq("expired on #{yesterday_formatted}") }
|
|
|
|
|
it { expect(result_for(start_date: tomorrow)).to eq("starts on #{tomorrow_formatted}") }
|
|
|
|
|
it { expect(result_for(start_date: yesterday)).to eq("started on #{yesterday_formatted}") }
|
2017-02-24 12:07:29 -05:00
|
|
|
|
it { expect(result_for(start_date: yesterday, due_date: tomorrow)).to eq("#{yesterday_formatted}–#{tomorrow_formatted}") }
|
2016-11-15 12:48:30 -05:00
|
|
|
|
end
|
|
|
|
|
|
2016-07-25 17:23:27 -04:00
|
|
|
|
describe '#milestone_counts' do
|
2017-01-25 17:10:32 -05:00
|
|
|
|
let(:project) { create(:empty_project) }
|
2016-07-25 17:23:27 -04:00
|
|
|
|
let(:counts) { helper.milestone_counts(project.milestones) }
|
|
|
|
|
|
2016-08-24 13:29:27 -04:00
|
|
|
|
context 'when there are milestones' do
|
|
|
|
|
it 'returns the correct counts' do
|
2017-01-25 17:10:32 -05:00
|
|
|
|
create_list(:active_milestone, 2, project: project)
|
|
|
|
|
create(:closed_milestone, project: project)
|
|
|
|
|
|
2016-08-24 13:29:27 -04:00
|
|
|
|
expect(counts).to eq(opened: 2, closed: 1, all: 3)
|
|
|
|
|
end
|
2016-07-25 17:23:27 -04:00
|
|
|
|
end
|
2016-08-22 18:58:28 -04:00
|
|
|
|
|
2016-08-24 13:29:27 -04:00
|
|
|
|
context 'when there are only milestones of one type' do
|
|
|
|
|
it 'returns the correct counts' do
|
2017-01-25 17:10:32 -05:00
|
|
|
|
create_list(:active_milestone, 2, project: project)
|
|
|
|
|
|
2016-08-24 13:29:27 -04:00
|
|
|
|
expect(counts).to eq(opened: 2, closed: 0, all: 2)
|
|
|
|
|
end
|
2016-07-25 17:23:27 -04:00
|
|
|
|
end
|
|
|
|
|
|
2016-08-24 13:29:27 -04:00
|
|
|
|
context 'when there are no milestones' do
|
|
|
|
|
it 'returns the correct counts' do
|
|
|
|
|
expect(counts).to eq(opened: 0, closed: 0, all: 0)
|
|
|
|
|
end
|
2016-08-22 18:58:28 -04:00
|
|
|
|
end
|
2016-07-25 17:23:27 -04:00
|
|
|
|
end
|
|
|
|
|
end
|