<commit_before>require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_stage_spec'

describe Gitlab::CycleAnalytics::TestStage do
  let(:stage_name) { :test }
  let(:project) { create(:project) }
  let(:stage) { described_class.new(project: project, options: { from: 2.days.ago, current_user: project.creator }) }

  it_behaves_like 'base stage'

  describe '#median' do
    let!(:issue_1) { create(:issue, project: project, created_at: 90.minutes.ago) }
    let!(:issue_2) { create(:issue, project: project, created_at: 60.minutes.ago) }
    let!(:issue_3) { create(:issue, project: project, created_at: 60.minutes.ago) }
    let!(:mr_1) { create(:merge_request, :closed, source_project: project, created_at: 60.minutes.ago) }
    let!(:mr_2) { create(:merge_request, :closed, source_project: project, created_at: 40.minutes.ago, source_branch: 'A') }
    let!(:mr_3) { create(:merge_request, source_project: project, created_at: 10.minutes.ago, source_branch: 'B') }
    let!(:mr_4) { create(:merge_request, source_project: project, created_at: 10.minutes.ago, source_branch: 'C') }
    let!(:mr_5) { create(:merge_request, source_project: project, created_at: 10.minutes.ago, source_branch: 'D') }

    before do
      mr_1.metrics.update!(latest_build_started_at: 32.minutes.ago, latest_build_finished_at: 2.minutes.ago)
      mr_2.metrics.update!(latest_build_started_at: 62.minutes.ago, latest_build_finished_at: 32.minutes.ago)
      mr_3.metrics.update!(latest_build_started_at: nil, latest_build_finished_at: nil)
      mr_4.metrics.update!(latest_build_started_at: nil, latest_build_finished_at: nil)
      mr_5.metrics.update!(latest_build_started_at: nil, latest_build_finished_at: nil)

      create(:merge_requests_closing_issues, merge_request: mr_1, issue: issue_1)
      create(:merge_requests_closing_issues, merge_request: mr_2, issue: issue_2)
      create(:merge_requests_closing_issues, merge_request: mr_3, issue: issue_3)
      create(:merge_requests_closing_issues, merge_request: mr_4, issue: issue_3)<commit_msg>Modify specs according to review<commit_after>require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_stage_spec'

describe Gitlab::CycleAnalytics::TestStage do
  let(:stage_name) { :test }
  let(:project) { create(:project) }
  let(:stage) { described_class.new(project: project, options: { from: 2.days.ago, current_user: project.creator }) }

  it_behaves_like 'base stage'

  describe '#median' do
    before do
      issue_1 = create(:issue, project: project, created_at: 90.minutes.ago)
      issue_2 = create(:issue, project: project, created_at: 60.minutes.ago)
      issue_3 = create(:issue, project: project, created_at: 60.minutes.ago)
      mr_1 = create(:merge_request, :closed, source_project: project, created_at: 60.minutes.ago)
      mr_2 = create(:merge_request, :closed, source_project: project, created_at: 40.minutes.ago, source_branch: 'A')
      mr_3 = create(:merge_request, source_project: project, created_at: 10.minutes.ago, source_branch: 'B')
      mr_4 = create(:merge_request, source_project: project, created_at: 10.minutes.ago, source_branch: 'C')
      mr_5 = create(:merge_request, source_project: project, created_at: 10.minutes.ago, source_branch: 'D')
      mr_1.metrics.update!(latest_build_started_at: 32.minutes.ago, latest_build_finished_at: 2.minutes.ago)
      mr_2.metrics.update!(latest_build_started_at: 62.minutes.ago, latest_build_finished_at: 32.minutes.ago)
      mr_3.metrics.update!(latest_build_started_at: nil, latest_build_finished_at: nil)
      mr_4.metrics.update!(latest_build_started_at: nil, latest_build_finished_at: nil)
      mr_5.metrics.update!(latest_build_started_at: nil, latest_build_finished_at: nil)

      create(:merge_requests_closing_issues, merge_request: mr_1, issue: issue_1)
      create(:merge_requests_closing_issues, merge_request: mr_2, issue: issue_2)
      create(:merge_requests_closing_issues, merge_request: mr_3, issue: issue_3)
      create(:merge_requests_closing_issues, merge_request: mr_4, issue: issue_3)
{'fraction_non_alphanumeric': 0.12222769837358305, 'fraction_numerical': 0.022178413011335635, 'mean_word_length': 5.765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6534859', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1348, 'n_words': 253}