<commit_before>require 'rails_helper'
require 'repositories/feature_review_repository'

RSpec.describe Repositories::FeatureReviewRepository do
  subject(:repository) { Repositories::FeatureReviewRepository.new }

  describe '#table_name' do
    let(:active_record_class) { class_double(Snapshots::FeatureReview, table_name: 'the_table_name') }

    subject(:repository) { Repositories::FeatureReviewRepository.new(active_record_class) }

    it 'delegates to the active record class backing the repository' do
      expect(repository.table_name).to eq('the_table_name')
    end
  end

  describe '#feature_reviews_for' do
    it 'returns matching URLs' do
      [
        build(:jira_event, comment_body: "Review: #{feature_review_url(frontend: 'abc', backend: 'NON1')}"),
        build(:jira_event, comment_body: "Review: #{feature_review_url(frontend: 'NON2', backend: 'def')}"),
        build(:jira_event, comment_body: "Review: #{feature_review_url(frontend: 'NON2', backend: 'NON3')}"),
        build(:jira_event, comment_body: "Review: #{feature_review_url(frontend: 'ghi',  backend: 'NON3')} "\
                                         "and: #{feature_review_url(frontend: 'NON4', backend: 'NON5')}"),
      ].each do |event|
        repository.apply(event)
      end

      expect(repository.feature_reviews_for(%w(abc def ghi))).to match_array([
        feature_review_url(frontend: 'abc', backend: 'NON1'),
        feature_review_url(frontend: 'NON2', backend: 'def'),
        feature_review_url(frontend: 'ghi', backend: 'NON3'),
      ])
    end
  end
end<commit_msg>Made tests for FeatureReviewRepository more explicit<commit_after>require 'rails_helper'
require 'repositories/feature_review_repository'

RSpec.describe Repositories::FeatureReviewRepository do
  subject(:repository) { Repositories::FeatureReviewRepository.new }

  describe '#table_name' do
    let(:active_record_class) { class_double(Snapshots::FeatureReview, table_name: 'the_table_name') }

    subject(:repository) { Repositories::FeatureReviewRepository.new(active_record_class) }

    it 'delegates to the active record class backing the repository' do
      expect(repository.table_name).to eq('the_table_name')
    end
  end

  describe '#apply' do
    let(:active_record_class) { class_double(Snapshots::FeatureReview) }

    subject(:repository) { Repositories::FeatureReviewRepository.new(active_record_class) }

    it 'creates a snapshot for each feature review url in the event comment' do
      expect(active_record_class).to receive(:create!).with(url: feature_review_url(frontend: 'abc', backend: 'NON1'), versions: ['NON1', 'abc'])
      expect(active_record_class).to receive(:create!).with(url: feature_review_url(frontend: 'NON2', backend: 'def'), versions: ['def', 'NON2'])
      expect(active_record_class).to receive(:create!).with(url: feature_review_url(frontend: 'NON2', backend: 'NON3'), versions: ['NON3', 'NON2'])
      expect(active_record_class).to receive(:create!).with(url: feature_review_url(frontend: 'ghi',  backend: 'NON3'), versions: ['NON3', 'ghi'])
      expect(active_record_class).to receive(:create!).with(url: feature_review_url(frontend: 'NON4', backend: 'NON5'), versions: ['NON5', 'NON4'])

      [
        build(:jira_event, comment_body: "Review: #{feature_review_url(frontend: 'abc', backend: 'NON1')}"),
        build(:jira_event, comment_body: "Review: #{feature_review_url(frontend: 'NON2', backend: 'def')}"),
        build(:jira_event, comment_body: "Review: #{feature_review_url(frontend: 'NON2', backend: 'NON3')}"),
        build(:jira_event, comment_body: "Review: #{feature_review_url(frontend: 'ghi',  backend: 'NON3')} "\
                                         "and: #{feature_review_url(frontend: 'NON4', backend: 'NON5')}"),
      ].each do |event|
        repository.apply(event)
      end
    end
  end

  describe '#feature_reviews_for' do
    it 'returns the latest snapshots for the versions specified' do
      Snapshots::FeatureReview.create!(url: feature_review_url(frontend: 'abc', backend: 'NON1'), versions: ['NON1', 'abc'])
      Snapshots::FeatureReview.create!(url: feature_review_url(frontend: 'NON2', backend: 'def'), versions: ['def', 'NON2'])
      Snapshots::FeatureReview.create!(url: feature_review_url(frontend: 'NON2', backend: 'NON3'), versions: ['NON3', 'NON2'])
      Snapshots::FeatureReview.create!(url: feature_review_url(frontend: 'ghi',  backend: 'NON3'), versions: ['NON3', 'ghi'])
      Snapshots::FeatureReview.create!(url: feature_review_url(frontend: 'NON4', backend: 'NON5'), versions: ['NON5', 'NON4'])

      expect(repository.feature_reviews_for(%w(abc def ghi))).to match_array([
        feature_review_url(frontend: 'abc', backend: 'NON1'),
        feature_review_url(frontend: 'NON2', backend: 'def'),
        feature_review_url(frontend: 'ghi', backend: 'NON3'),
      ])
    end
  end
end
{'fraction_non_alphanumeric': 0.1466011466011466, 'fraction_numerical': 0.009828009828009828, 'mean_word_length': 4.935601458080194, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5214799', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1502, 'n_words': 313}