2016-09-07 04:41:24 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-06-29 00:13:10 -04:00
|
|
|
describe 'CycleAnalytics#test' do
|
2016-09-20 15:17:37 -04:00
|
|
|
extend CycleAnalyticsHelpers::TestGeneration
|
|
|
|
|
2017-01-26 17:44:58 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-09-07 04:41:24 -04:00
|
|
|
let(:from_date) { 10.days.ago }
|
|
|
|
let(:user) { create(:user, :admin) }
|
2016-12-01 06:44:35 -05:00
|
|
|
subject { CycleAnalytics.new(project, from: from_date) }
|
2016-09-07 04:41:24 -04:00
|
|
|
|
2016-09-20 15:17:37 -04:00
|
|
|
generate_cycle_analytics_spec(
|
|
|
|
phase: :test,
|
|
|
|
data_fn: lambda do |context|
|
|
|
|
issue = context.create(:issue, project: context.project)
|
|
|
|
merge_request = context.create_merge_request_closing_issue(issue)
|
2017-05-19 16:51:07 -04:00
|
|
|
pipeline = context.create(:ci_pipeline, ref: merge_request.source_branch, sha: merge_request.diff_head_sha, project: context.project, head_pipeline_of: merge_request)
|
2016-09-20 15:17:37 -04:00
|
|
|
{ pipeline: pipeline, issue: issue }
|
|
|
|
end,
|
|
|
|
start_time_conditions: [["pipeline is started", -> (context, data) { data[:pipeline].run! }]],
|
|
|
|
end_time_conditions: [["pipeline is finished", -> (context, data) { data[:pipeline].succeed! }]],
|
|
|
|
post_fn: -> (context, data) do
|
|
|
|
context.merge_merge_requests_closing_issue(data[:issue])
|
|
|
|
end)
|
2016-09-07 04:41:24 -04:00
|
|
|
|
|
|
|
context "when the pipeline is for a regular merge request (that doesn't close an issue)" do
|
|
|
|
it "returns nil" do
|
2017-01-29 17:53:48 -05:00
|
|
|
issue = create(:issue, project: project)
|
|
|
|
merge_request = create_merge_request_closing_issue(issue)
|
|
|
|
pipeline = create(:ci_pipeline, ref: "refs/heads/#{merge_request.source_branch}", sha: merge_request.diff_head_sha)
|
2016-09-07 04:41:24 -04:00
|
|
|
|
2017-01-29 17:53:48 -05:00
|
|
|
pipeline.run!
|
|
|
|
pipeline.succeed!
|
2016-09-20 01:47:36 -04:00
|
|
|
|
2017-01-29 17:53:48 -05:00
|
|
|
merge_merge_requests_closing_issue(issue)
|
2016-09-07 04:41:24 -04:00
|
|
|
|
2016-12-01 06:44:35 -05:00
|
|
|
expect(subject[:test].median).to be_nil
|
2016-09-07 04:41:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the pipeline is not for a merge request" do
|
|
|
|
it "returns nil" do
|
2017-01-29 17:53:48 -05:00
|
|
|
pipeline = create(:ci_pipeline, ref: "refs/heads/master", sha: project.repository.commit('master').sha)
|
2016-09-07 04:41:24 -04:00
|
|
|
|
2017-01-29 17:53:48 -05:00
|
|
|
pipeline.run!
|
|
|
|
pipeline.succeed!
|
2016-09-07 04:41:24 -04:00
|
|
|
|
2016-12-01 06:44:35 -05:00
|
|
|
expect(subject[:test].median).to be_nil
|
2016-09-07 04:41:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the pipeline is dropped (failed)" do
|
|
|
|
it "returns nil" do
|
2017-01-29 17:53:48 -05:00
|
|
|
issue = create(:issue, project: project)
|
|
|
|
merge_request = create_merge_request_closing_issue(issue)
|
|
|
|
pipeline = create(:ci_pipeline, ref: "refs/heads/#{merge_request.source_branch}", sha: merge_request.diff_head_sha)
|
2016-09-07 04:41:24 -04:00
|
|
|
|
2017-01-29 17:53:48 -05:00
|
|
|
pipeline.run!
|
|
|
|
pipeline.drop!
|
2016-09-20 01:47:36 -04:00
|
|
|
|
2017-01-29 17:53:48 -05:00
|
|
|
merge_merge_requests_closing_issue(issue)
|
2016-09-07 04:41:24 -04:00
|
|
|
|
2016-12-01 06:44:35 -05:00
|
|
|
expect(subject[:test].median).to be_nil
|
2016-09-07 04:41:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the pipeline is cancelled" do
|
|
|
|
it "returns nil" do
|
2017-01-29 17:53:48 -05:00
|
|
|
issue = create(:issue, project: project)
|
|
|
|
merge_request = create_merge_request_closing_issue(issue)
|
|
|
|
pipeline = create(:ci_pipeline, ref: "refs/heads/#{merge_request.source_branch}", sha: merge_request.diff_head_sha)
|
2016-09-07 04:41:24 -04:00
|
|
|
|
2017-01-29 17:53:48 -05:00
|
|
|
pipeline.run!
|
|
|
|
pipeline.cancel!
|
2016-09-20 01:47:36 -04:00
|
|
|
|
2017-01-29 17:53:48 -05:00
|
|
|
merge_merge_requests_closing_issue(issue)
|
2016-09-07 04:41:24 -04:00
|
|
|
|
2016-12-01 06:44:35 -05:00
|
|
|
expect(subject[:test].median).to be_nil
|
2016-09-07 04:41:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|