gitlab-org--gitlab-foss/spec/lib/gitlab/cycle_analytics/events_spec.rb

84 lines
2.2 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Gitlab::CycleAnalytics::Events do
let(:project) { create(:project) }
let(:from_date) { 10.days.ago }
let(:user) { create(:user, :admin) }
subject { described_class.new(project: project, from: from_date) }
before do
setup(context)
end
2016-10-19 10:47:09 +00:00
describe '#issue_events' do
2016-10-17 16:03:17 +00:00
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
2016-10-19 10:47:09 +00:00
it 'has the total time' do
expect(subject.issue_events.first['total_time']).to eq('2 days')
2016-10-17 12:57:23 +00:00
end
it 'has a title' do
2016-10-18 08:06:42 +00:00
expect(subject.issue_events.first['title']).to eq(context.title)
2016-10-17 12:57:23 +00:00
end
it 'has an iid' do
2016-10-18 08:06:42 +00:00
expect(subject.issue_events.first['iid']).to eq(context.iid.to_s)
2016-10-17 12:57:23 +00:00
end
it 'has a created_at timestamp' do
2016-10-18 08:06:42 +00:00
expect(subject.issue_events.first['created_at']).to end_with('ago')
2016-10-17 12:57:23 +00:00
end
it "has the author's name" do
2016-10-18 08:06:42 +00:00
expect(subject.issue_events.first['name']).to eq(context.author.name)
end
end
2016-10-19 10:47:09 +00:00
describe '#plan_events' do
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
it 'has the first referenced commit' do
expect(subject.plan_events.first['commit'].message).to eq('commit message')
2016-10-19 10:47:09 +00:00
end
it 'has the total time' do
expect(subject.plan_events.first['total_time']).to eq('less than a minute')
end
end
describe '#code_events' do
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
before do
create_commit_referencing_issue(context)
end
it 'has the total time' do
expect(subject.code_events.first['total_time']).to eq('2 days')
end
it 'has a title' do
expect(subject.code_events.first['title']).to eq('Awesome merge_request')
end
it 'has an iid' do
expect(subject.code_events.first['iid']).to eq(context.iid.to_s)
end
it 'has a created_at timestamp' do
expect(subject.code_events.first['created_at']).to end_with('ago')
end
it "has the author's name" do
expect(subject.code_events.first['name']).to eq(context.author.name)
2016-10-19 10:47:09 +00:00
end
end
def setup(context)
2016-10-14 15:33:21 +00:00
milestone = create(:milestone, project: project)
context.update(milestone: milestone)
create_merge_request_closing_issue(context)
end
end