2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-26 03:19:32 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe 'CycleAnalytics#issue' 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-08-26 06:48:52 -04:00
|
|
|
let(:from_date) { 10.days.ago }
|
2016-09-20 01:47:36 -04:00
|
|
|
let(:user) { create(:user, :admin) }
|
2019-07-10 07:42:54 -04:00
|
|
|
|
2019-07-08 07:11:10 -04:00
|
|
|
subject { CycleAnalytics::ProjectLevel.new(project, options: { from: from_date }) }
|
2016-08-26 03:19:32 -04:00
|
|
|
|
2016-09-20 15:17:37 -04:00
|
|
|
generate_cycle_analytics_spec(
|
|
|
|
phase: :issue,
|
|
|
|
data_fn: -> (context) { { issue: context.build(:issue, project: context.project) } },
|
|
|
|
start_time_conditions: [["issue created", -> (context, data) { data[:issue].save }]],
|
|
|
|
end_time_conditions: [["issue associated with a milestone",
|
|
|
|
-> (context, data) do
|
|
|
|
if data[:issue].persisted?
|
|
|
|
data[:issue].update(milestone: context.create(:milestone, project: context.project))
|
|
|
|
end
|
|
|
|
end],
|
|
|
|
["list label added to issue",
|
|
|
|
-> (context, data) do
|
|
|
|
if data[:issue].persisted?
|
|
|
|
data[:issue].update(label_ids: [context.create(:label, lists: [context.create(:list)]).id])
|
|
|
|
end
|
|
|
|
end]],
|
|
|
|
post_fn: -> (context, data) do
|
|
|
|
if data[:issue].persisted?
|
2018-02-21 07:13:56 -05:00
|
|
|
context.create_merge_request_closing_issue(context.user, context.project, data[:issue].reload)
|
|
|
|
context.merge_merge_requests_closing_issue(context.user, context.project, data[:issue])
|
2016-09-20 15:17:37 -04:00
|
|
|
end
|
|
|
|
end)
|
2016-09-02 08:03:32 -04:00
|
|
|
|
|
|
|
context "when a regular label (instead of a list label) is added to the issue" do
|
|
|
|
it "returns nil" do
|
2017-01-29 17:53:48 -05:00
|
|
|
regular_label = create(:label)
|
|
|
|
issue = create(:issue, project: project)
|
|
|
|
issue.update(label_ids: [regular_label.id])
|
2016-09-20 01:47:36 -04:00
|
|
|
|
2018-02-21 07:13:56 -05:00
|
|
|
create_merge_request_closing_issue(user, project, issue)
|
|
|
|
merge_merge_requests_closing_issue(user, project, issue)
|
2016-09-02 02:49:40 -04:00
|
|
|
|
2016-12-01 06:44:35 -05:00
|
|
|
expect(subject[:issue].median).to be_nil
|
2016-08-26 03:19:32 -04:00
|
|
|
end
|
2016-09-02 02:49:40 -04:00
|
|
|
end
|
2016-08-26 03:19:32 -04:00
|
|
|
end
|