Sha256: a53e5f89ae71b94d2a76890039d19c58171c87ab1c3ca340a6e4020cb83b70b2

Contents?: true

Size: 1.43 KB

Versions: 14

Compression:

Stored size: 1.43 KB

Contents

require 'test_helper'

describe "Traject::Indexer#process_record" do
  before do
    @writer = Traject::ArrayWriter.new
    @indexer = Traject::Indexer.new(writer: @writer) do
      to_field "record", lambda { |rec, acc| acc << rec }
    end
    @record = {key: "value"}
  end

  it "sends to writer" do
    @indexer.process_record(@record)
    assert_equal [{"record" => [@record] }], @writer.values
  end

  it "returns context" do
    context = @indexer.process_record(@record)
    assert context.is_a?(Traject::Indexer::Context)
    assert_equal @record, context.source_record
  end

  it "skips if skipped" do
    @indexer = Traject::Indexer.new(writer: @writer) do
      to_field "record", lambda { |rec, acc, context| acc << rec; context.skip! }
    end
    context = @indexer.process_record(@record)

    assert context.skip?
    assert_equal [], @writer.values
  end

  it "raises exceptions out" do
    @indexer = Traject::Indexer.new(writer: @writer) do
      to_field "record", lambda { |rec, acc, context| acc << rec; raise ArgumentError, "intentional" }
    end
    assert_raises(ArgumentError) do
      @indexer.process_record(@record)
    end
  end

  it "aliases <<" do
    assert_equal @indexer.method(:process_record), @indexer.method(:<<)

    @indexer << @record
  end

  it "raises on completed indexer" do
    @indexer.complete
    assert_raises Traject::Indexer::CompletedStateError do
      @indexer.process_record(@record)
    end
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
traject-3.8.2 test/indexer/process_record_test.rb
traject-3.8.1 test/indexer/process_record_test.rb
traject-3.8.0 test/indexer/process_record_test.rb
traject-3.7.0 test/indexer/process_record_test.rb
traject-3.6.0 test/indexer/process_record_test.rb
traject-3.5.0 test/indexer/process_record_test.rb
traject-3.4.0 test/indexer/process_record_test.rb
traject-3.3.0 test/indexer/process_record_test.rb
traject-3.2.0 test/indexer/process_record_test.rb
traject-3.1.0 test/indexer/process_record_test.rb
traject-3.1.0.rc1 test/indexer/process_record_test.rb
traject-3.0.0 test/indexer/process_record_test.rb
traject-3.0.0.alpha.2 test/indexer/process_record_test.rb
traject-3.0.0.alpha.1 test/indexer/process_record_test.rb