Sha256: 329b08dd515ee9926cbc8b03f53f525c2e087b6e5ff9a60c72df26ce3a1c44d7

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

# Encoding: UTF-8

require 'test_helper'
require 'traject/marc_reader'
require 'marc'

describe "Traject::MarcReader" do


  it "reads XML" do
    file = File.new(support_file_path "test_data.utf8.marc.xml")
    settings = Traject::Indexer::Settings.new("marc_source.type" => "xml")
    reader = Traject::MarcReader.new(file, settings)

    array = reader.to_a

    assert_equal 30, array.length
  end

  it "reads Marc binary" do
    file = File.new(support_file_path "test_data.utf8.mrc")
    settings = Traject::Indexer::Settings.new() # binary type is default
    reader = Traject::MarcReader.new(file, settings)

    array = reader.to_a

    assert_equal 30, array.length

    first = array.first

    assert_kind_of MARC::Record, first

    assert first['245']['a'].encoding.name, "UTF-8"
    assert_equal "Fikr-i Ayāz /", first['245']['a']
  end

  it "reads JSON" do
    file = File.new(support_file_path "test_data.utf8.json")
    settings = Traject::Indexer::Settings.new("marc_source.type" => "json")
    reader = Traject::MarcReader.new(file, settings)
    array = reader.to_a

    assert_equal 30, array.length

    first = array.first

    assert_kind_of MARC::Record, first

    assert first['245']['a'].encoding.name, "UTF-8"
    assert_equal "Fikr-i Ayāz /", first['245']['a']
  end    



end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
traject-0.16.0 test/marc_reader_test.rb
traject-0.15.0 test/marc_reader_test.rb