<commit_before>require 'rails_helper'

RSpec.describe I18nContent, type: :model do
  let(:i18n_content) { build(:i18n_content) }

  it 'is valid' do
    expect(i18n_content).to be_valid
  end

  it 'is not valid if key is not unique' do
    new_content = create(:i18n_content)

    expect(i18n_content).not_to be_valid
    expect(i18n_content.errors.size).to eq(1)
  end

  context 'Scopes' do
    it 'return one record when #by_key is used' do
      content      = create(:i18n_content)
      key          = 'debates.form.debate_title'
      debate_title = create(:i18n_content, key: key)

      expect(I18nContent.all.size).to eq(2)

      query = I18nContent.by_key(key)

      expect(query.size).to eq(1)
      expect(query).to eq([debate_title])
    end

    it 'return all matching records when #begins_with_key is used' do
      debate_translation = create(:i18n_content)
      debate_title       = create(:i18n_content, key: 'debates.form.debate_title')
      proposal_title     = create(:i18n_content, key: 'proposals.form.proposal_title')

      expect(I18nContent.all.size).to eq(3)

      query = I18nContent.begins_with_key('debates')

      expect(query.size).to eq(2)
      expect(query).to eq([debate_translation, debate_title])
      expect(query).not_to include(proposal_title)
    end
  end
<commit_msg>Improve readability for I18nContent#begins_with_key spec<commit_after>require 'rails_helper'

RSpec.describe I18nContent, type: :model do
  let(:i18n_content) { build(:i18n_content) }

  it 'is valid' do
    expect(i18n_content).to be_valid
  end

  it 'is not valid if key is not unique' do
    new_content = create(:i18n_content)

    expect(i18n_content).not_to be_valid
    expect(i18n_content.errors.size).to eq(1)
  end

  context 'Scopes' do
    it 'return one record when #by_key is used' do
      content      = create(:i18n_content)
      key          = 'debates.form.debate_title'
      debate_title = create(:i18n_content, key: key)

      expect(I18nContent.all.size).to eq(2)

      query = I18nContent.by_key(key)

      expect(query.size).to eq(1)
      expect(query).to eq([debate_title])
    end

    it 'return all matching records when #begins_with_key is used' do
      debate_text    = create(:i18n_content, key: 'debates.form.debate_text')
      debate_title   = create(:i18n_content, key: 'debates.form.debate_title')
      proposal_title = create(:i18n_content, key: 'proposals.form.proposal_title')

      expect(I18nContent.all.size).to eq(3)

      query = I18nContent.begins_with_key('debates')

      expect(query.size).to eq(2)
      expect(query).to eq([debate_text, debate_title])
      expect(query).not_to include(proposal_title)
    end
  end

{'fraction_non_alphanumeric': 0.10699740836727138, 'fraction_numerical': 0.028137726767863754, 'mean_word_length': 3.400651465798046, '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': '3808873', 'n_tokens_mistral': 1025, 'n_tokens_neox': 951, 'n_words': 196}