<commit_before>require 'spec_helper'
require 'elasticsearch'

describe "search:rebuild_indices" do
  include_context "rake"

  before do
    TaskHelpers::ElasticsearchHelper.stub(:rebuild_indices)
  end

  its(:prerequisites) { should include("environment") }

  it "calls rebuild_indices with defaults" do
    TaskHelpers::ElasticsearchHelper.should_receive(:rebuild_indices).with(500, 5)

    subject.invoke
  end

  it "calls rebuild_indices with arguments" do
    # Rake calls receive arguments as strings.
    batch_size = '100'
    extra_catchup_minutes = '10'
    TaskHelpers::ElasticsearchHelper.should_receive(:rebuild_indices).with(
          batch_size.to_i, extra_catchup_minutes.to_i
    )

    subject.invoke(batch_size, extra_catchup_minutes)
  end
end

describe "search:catchup" do
  include_context "rake"

  before do
    TaskHelpers::ElasticsearchHelper.stub(:catchup_indices)
  end

  its(:prerequisites) { should include("environment") }

  it "calls catchup with defaults" do
    TaskHelpers::ElasticsearchHelper.should_receive(:catchup_indices).with(
        TaskHelpers::ElasticsearchHelper::INDEX_NAMES, anything, 500
    ) do |start_time_arg|
      start_time_arg.should be_within(1.second).of Time.now
    end

    subject.invoke
  end

  it "calls catchup with arguments" do
    # Rake calls receive arguments as strings.
    minutes = '2'
    batch_size = '100'
    TaskHelpers::ElasticsearchHelper.should_receive(:catchup_indices).with(
        TaskHelpers::ElasticsearchHelper::INDEX_NAMES, anything, batch_size.to_i
    ) do |start_time_arg|
      start_time_arg.should be_within((60 * minutes.to_i + 1).second).of Time.now
    end

    subject.invoke(minutes, batch_size)
  end
end<commit_msg>OEX-39: fixes tests of the rake command<commit_after>require 'spec_helper'
require 'elasticsearch'

describe "search:rebuild_indices" do
  include_context "rake"

  before do
    TaskHelpers::ElasticsearchHelper.stub(:rebuild_indices)
  end

  its(:prerequisites) { should include("environment") }

  it "calls rebuild_indices with defaults" do
    TaskHelpers::ElasticsearchHelper.should_receive(:rebuild_indices).with(500, 5)

    subject.invoke
  end

  it "calls rebuild_indices with arguments" do
    # Rake calls receive arguments as strings.
    batch_size = '100'
    extra_catchup_minutes = '10'
    TaskHelpers::ElasticsearchHelper.should_receive(:rebuild_indices).with(
          batch_size.to_i, extra_catchup_minutes.to_i
    )

    subject.invoke(batch_size, extra_catchup_minutes)
  end
end

describe "search:catchup" do
  include_context "rake"
  let(:indices) { TaskHelpers::ElasticsearchHelper::INDEX_NAMES }
  let(:comments_index_name) { Comment.index_name }
  let(:comment_threads_index_name) { CommentThread.index_name }

  before do
    TaskHelpers::ElasticsearchHelper.stub(:catchup_indices)
  end

  its(:prerequisites) { should include("environment") }

  it "calls catchup with defaults" do
    TaskHelpers::ElasticsearchHelper.should_receive(:catchup_indices).with(indices, anything, 500)

    subject.invoke(comments_index_name, comment_threads_index_name)
  end

  it "calls catchup with arguments" do
    # Rake calls receive arguments as strings.
    minutes = '2'
    batch_size = '100'
    TaskHelpers::ElasticsearchHelper.should_receive(:catchup_indices).with(indices, anything, batch_size.to_i)

    subject.invoke(comments_index_name, comment_threads_index_name, minutes, batch_size)
  end
end
{'fraction_non_alphanumeric': 0.0894356005788712, 'fraction_numerical': 0.010998552821997106, 'mean_word_length': 4.76, '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': '7301000', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1076, 'n_words': 220}