require 'helper' # one.xml # LEADER 00000njm a2200000uu 4500 # 001 afc99990058366 # 003 DLC # 005 20071104155141.9 # 007 sd ummunniauub # 008 071103s1939 xxufmnne||||||||| u eng|| # 010 $a afc99990058366 # 040 $a DLC $c DLC # 245 04 $a The Texas ranger $h [sound recording] / $c Sung by Beale D. Taylor. # 260 $a Medina, Texas, $c 1939. # 300 $a 1 sound disc : $b analog, 33 1/3 rpm, mono. ; $c 12 in. # 651 0 $a Medina $z Texas $z United States of America. # 700 1 $a Lomax, John Avery, 1867-1948 $e Recording engineer. # 700 1 $a Lomax, Ruby T. (Ruby Terrill) $e Recording engineer. # 700 1 $a Taylor, Beale D. $e Singer. # 852 $a American Folklife Center, Library of Congress # 852 $a DLC class TestMarc4j4r < Test::Unit::TestCase def setup reader = MARC4J4R.reader(File.dirname(__FILE__) + '/one.xml', :marcxml) @r = reader.next end should "get the leader as a string" do assert_equal '00000njm a2200000uu 4500', @r.leader end should "get all fields with the given tag" do assert_equal 3, @r.find_by_tag('700').size end should "get all fields with any of the given tags" do assert_equal 6, @r.find_by_tag(['010','700', '852']).size end should "get an empty array trying to find a non-existent tag" do assert_equal [], @r.find_by_tag('002') end should "not return anything for a non-existent tag" do assert_equal 1, @r.find_by_tag(['010', '002']).size end should "get the value of a control tag" do assert_equal 'DLC', @r['003'].value end should "get a subfield value via field[]" do assert_equal 'Sung by Beale D. Taylor.', @r['245']['c'] end should "joing all values of a field with a space" do assert_equal "DLC DLC", @r['040'].value end should "Get the first field with a given tag via []" do assert_equal '700 1 $a Lomax, John Avery, 1867-1948 $e Recording engineer.', @r['700'].to_s end should "get the subfield values in order of the original record" do assert_equal ['Medina, Texas,', '1939.'], @r['260'].sub_values(['a', 'c']) assert_equal ['Medina, Texas,', '1939.'], @r['260'].sub_values(['c', 'a']) end should "get the subfield values in order of the codes I pass" do assert_equal [ '1939.', 'Medina, Texas,'], @r['260'].sub_values(['c', 'a'], true) end end