Sha256: 9ab0fc4de0007db8d18ec2359d90318c96f76554bac4795de88532d549d09c0f

Contents?: true

Size: 881 Bytes

Versions: 15

Compression:

Stored size: 881 Bytes

Contents

require 'test_helper'

describe "Indexer Macros#to_field" do
  before do
    @indexer = Traject::Indexer.new
    @record = MARC::Reader.new(support_file_path  "manufacturing_consent.marc").to_a.first
  end

  it "works with simple literal" do
    @indexer.configure do
      extend Traject::Macros::Basic

      to_field "source", literal("MY LIBRARY")
    end

    output = @indexer.map_record(@record)

    assert_equal ["MY LIBRARY"], output["source"]
  end

  it "works with macro AND block" do
    called = false

    @indexer.configure do
      extend Traject::Macros::Basic
      to_field "source", literal("MY LIBRARY") do |record, accumulator, context|
        called = true
        accumulator << "SECOND VALUE"
      end
    end

    output = @indexer.map_record(@record)

    assert called
    assert_equal ["MY LIBRARY", "SECOND VALUE"], output["source"]
  end



end

Version data entries

15 entries across 15 versions & 1 rubygems

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