<commit_before>require "spec_helper"
require 'section_reslugger'
require "gds_api/test_helpers/content_store"
require "gds_api/test_helpers/rummager"

describe SectionReslugger do
  include GdsApi::TestHelpers::ContentStore
  include GdsApi::TestHelpers::Organisations
  include GdsApi::TestHelpers::PublishingApiV2
  include GdsApi::TestHelpers::Rummager

  subject {
    described_class.new(
      'manual-slug',
      'old-section-slug',
      'new-section-slug'
    )
  }

  before {
    manual_record = ManualRecord.create!(
      manual_id: 'manual-id',
      slug: 'manual-slug',
      organisation_slug: 'organisation-slug'
    )
    SectionEdition.create!(
      section_uuid: 'section-id',
      slug: 'manual-slug/old-section-slug',
      title: 'section-edition-title',
      summary: 'section-edition-summary',
      body: 'section-edition-body'
    )
    manual_record.editions.create!(
      section_ids: [
        'section-id'
      ]
    )

    content_store_has_item('/manual-slug/old-section-slug')
    content_store_does_not_have_item('/manual-slug/new-section-slug')

    organisations_api_has_organisation('organisation-slug')

    stub_any_publishing_api_patch_links
    stub_any_publishing_api_put_content
    stub_any_publishing_api_publish

    stub_any_rummager_post
    stub_any_rummager_delete
  }

  it "doesn't raise any exceptions" do
    subject.call
  end
end
<commit_msg>Assert SectionReslugger removes old slug content from search index<commit_after>require "spec_helper"
require 'section_reslugger'
require "gds_api/test_helpers/content_store"
require "gds_api/test_helpers/rummager"

describe SectionReslugger do
  include GdsApi::TestHelpers::ContentStore
  include GdsApi::TestHelpers::Organisations
  include GdsApi::TestHelpers::PublishingApiV2
  include GdsApi::TestHelpers::Rummager

  subject {
    described_class.new(
      'manual-slug',
      'old-section-slug',
      'new-section-slug'
    )
  }

  before {
    manual_record = ManualRecord.create!(
      manual_id: 'manual-id',
      slug: 'manual-slug',
      organisation_slug: 'organisation-slug'
    )
    SectionEdition.create!(
      section_uuid: 'section-id',
      slug: 'manual-slug/old-section-slug',
      title: 'section-edition-title',
      summary: 'section-edition-summary',
      body: 'section-edition-body'
    )
    manual_record.editions.create!(
      section_ids: [
        'section-id'
      ]
    )

    content_store_has_item('/manual-slug/old-section-slug')
    content_store_does_not_have_item('/manual-slug/new-section-slug')

    organisations_api_has_organisation('organisation-slug')

    stub_any_publishing_api_patch_links
    stub_any_publishing_api_put_content
    stub_any_publishing_api_publish

    stub_any_rummager_post

    allow(Services.rummager).to receive(:delete_document)
  }

  it "doesn't raise any exceptions" do
    subject.call
  end

  it "removes content stored against the old section slug from the search index" do
    subject.call

    expect(Services.rummager).to have_received(:delete_document).with("manual_section", "/manual-slug/old-section-slug")
  end
end

{'fraction_non_alphanumeric': 0.10048, 'fraction_numerical': 0.00064, 'mean_word_length': 3.80184331797235, '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': '5812289', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1062, 'n_words': 156}