diff options
author | James Lopez <james@jameslopez.es> | 2016-10-20 16:20:04 +0200 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-11-17 08:22:55 +0100 |
commit | ebd5ced7eb296ce10160021d8999d21b36b24da9 (patch) | |
tree | 710dc319adbcfdabb8297333d77f0626b33bcedc /spec | |
parent | 52e2729bf44ff3376071c2462679b46e9f67a44e (diff) | |
download | gitlab-ce-ebd5ced7eb296ce10160021d8999d21b36b24da9.tar.gz |
Added test events specs and logic. Also fixed some SQL and refactored the pipeline worker spec.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/cycle_analytics/events_spec.rb | 24 | ||||
-rw-r--r-- | spec/workers/pipeline_metrics_worker_spec.rb | 18 |
2 files changed, 34 insertions, 8 deletions
diff --git a/spec/lib/gitlab/cycle_analytics/events_spec.rb b/spec/lib/gitlab/cycle_analytics/events_spec.rb index 4a329737c7e..404d9e6912c 100644 --- a/spec/lib/gitlab/cycle_analytics/events_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/events_spec.rb @@ -55,7 +55,7 @@ describe Gitlab::CycleAnalytics::Events do end it 'has the total time' do - expect(subject.code_events.first['total_time']).to eq('2 days') + expect(subject.code_events.first['total_time']).to eq('less than a minute') end it 'has a title' do @@ -75,6 +75,28 @@ describe Gitlab::CycleAnalytics::Events do end end + describe '#test_events' do + let!(:context) { create(:issue, project: project, created_at: 2.days.ago) } + let(:merge_request) { MergeRequest.first } + let!(:pipeline) { create(:ci_pipeline, + ref: merge_request.source_branch, + sha: merge_request.diff_head_sha, + project: context.project) } + + before do + pipeline.run! + pipeline.succeed! + end + + it 'has the build info as a pipeline' do + expect(subject.test_events.first['pipeline']).to eq(pipeline) + end + + it 'has the total time' do + expect(subject.test_events.first['total_time']).to eq('less than a minute') + end + end + def setup(context) milestone = create(:milestone, project: project) context.update(milestone: milestone) diff --git a/spec/workers/pipeline_metrics_worker_spec.rb b/spec/workers/pipeline_metrics_worker_spec.rb index 2c9e7c2cd02..2d47d93acec 100644 --- a/spec/workers/pipeline_metrics_worker_spec.rb +++ b/spec/workers/pipeline_metrics_worker_spec.rb @@ -15,32 +15,36 @@ describe PipelineMetricsWorker do end describe '#perform' do - subject { described_class.new.perform(pipeline.id) } + before do + described_class.new.perform(pipeline.id) + end context 'when pipeline is running' do let(:status) { 'running' } it 'records the build start time' do - subject - expect(merge_request.reload.metrics.latest_build_started_at).to be_like_time(pipeline.started_at) end it 'clears the build end time' do - subject - expect(merge_request.reload.metrics.latest_build_finished_at).to be_nil end + + it 'records the pipeline' do + expect(merge_request.reload.metrics.pipeline).to eq(pipeline) + end end context 'when pipeline succeeded' do let(:status) { 'success' } it 'records the build end time' do - subject - expect(merge_request.reload.metrics.latest_build_finished_at).to be_like_time(pipeline.finished_at) end + + it 'records the pipeline' do + expect(merge_request.reload.metrics.pipeline).to eq(pipeline) + end end end end |