Sha256: bf60cefceabdff42fbc22d698739ecfa82b10a9ee30ac659f9c436d60056ad2d

Contents?: true

Size: 880 Bytes

Versions: 12

Compression:

Stored size: 880 Bytes

Contents

require 'test_helper'

describe "Indexer Macros:" 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.instance_eval 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.instance_eval 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

12 entries across 12 versions & 1 rubygems

Version Path
traject-0.16.0 test/indexer/macros_test.rb
traject-0.15.0 test/indexer/macros_test.rb
traject-0.14.1 test/indexer/macros_test.rb
traject-0.13.2 test/indexer/macros_test.rb
traject-0.13.1 test/indexer/macros_test.rb
traject-0.13.0 test/indexer/macros_test.rb
traject-0.12.0 test/indexer/macros_test.rb
traject-0.11.0 test/indexer/macros_test.rb
traject-0.10.0 test/indexer/macros_test.rb
traject-0.9.1 test/indexer/macros_test.rb
traject-0.0.2 test/indexer/macros_test.rb
traject-0.0.1 test/indexer/macros_test.rb