BigW Consortium Gitlab

code_spec.rb 2.75 KB
Newer Older
1 2 3
require 'spec_helper'

describe 'CycleAnalytics#code', feature: true do
4 5
  extend CycleAnalyticsHelpers::TestGeneration

6 7 8 9 10
  let(:project) { create(:project) }
  let(:from_date) { 10.days.ago }
  let(:user) { create(:user, :admin) }
  subject { CycleAnalytics.new(project, from: from_date) }

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
  context 'with deployment' do
    generate_cycle_analytics_spec(
      phase: :code,
      data_fn: -> (context) { { issue: context.create(:issue, project: context.project) } },
      start_time_conditions: [["issue mentioned in a commit",
                               -> (context, data) do
                                 context.create_commit_referencing_issue(data[:issue])
                               end]],
      end_time_conditions:   [["merge request that closes issue is created",
                               -> (context, data) do
                                 context.create_merge_request_closing_issue(data[:issue])
                               end]],
      post_fn: -> (context, data) do
        context.merge_merge_requests_closing_issue(data[:issue])
        context.deploy_master
      end)

    context "when a regular merge request (that doesn't close the issue) is created" do
      it "returns nil" do
        5.times do
          issue = create(:issue, project: project)

          create_commit_referencing_issue(issue)
          create_merge_request_closing_issue(issue, message: "Closes nothing")

          merge_merge_requests_closing_issue(issue)
          deploy_master
        end

        expect(subject.code).to be_nil
41
      end
42 43
    end
  end
44

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
  context 'without deployment' do
    generate_cycle_analytics_spec(
      phase: :code,
      data_fn: -> (context) { { issue: context.create(:issue, project: context.project) } },
      start_time_conditions: [["issue mentioned in a commit",
                               -> (context, data) do
                                 context.create_commit_referencing_issue(data[:issue])
                               end]],
      end_time_conditions:   [["merge request that closes issue is created",
                               -> (context, data) do
                                 context.create_merge_request_closing_issue(data[:issue])
                               end]],
      post_fn: -> (context, data) do
        context.merge_merge_requests_closing_issue(data[:issue])
      end)

    context "when a regular merge request (that doesn't close the issue) is created" do
      it "returns nil" do
        5.times do
          issue = create(:issue, project: project)

          create_commit_referencing_issue(issue)
          create_merge_request_closing_issue(issue, message: "Closes nothing")

          merge_merge_requests_closing_issue(issue)
        end

        expect(subject.code).to be_nil
      end
74 75 76
    end
  end
end