require 'spec_helper' # LEADER 00734njm a2200217uu 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 describe "MARC4J4R_basic_retrieval_stuff" do before do @one = MARC4J4R::Reader.new("#{DIR}/one.dat").first @batch = MARC4J4R::Reader.new("#{DIR}/batch.dat").collect end it "can get the leader" do @one.leader.should.equal "00734njm a2200217uu 4500" end it "can read a control field correctly" do @one['001'].value.should.equal "afc99990058366" end it "can find all the fields" do fields = @one.collect fields.size.should.equal 16 end it "should get the first 245 for this record" do @one['245'].to_s.should.equal "245 04 $a The Texas ranger $h [sound recording] / $c Sung by Beale D. Taylor." end end describe "MARC4J4R::Record #find_by_tag" do before do @one = MARC4J4R::Reader.new("#{DIR}/one.dat").first @df = MARC4J4R::DataField.new('260') @df << MARC4J4R::SubField.new('a', 'Medina, Texas,') @df << MARC4J4R::SubField.new('c', '1939.') @cf = MARC4J4R::ControlField.new('005', '20071104155141.9') end it "gets an empty array for non-existant tag(s)" do @one.find_by_tag('999').should.equal [] end it "gets an empty arry for set of non-existant tags" do @one.find_by_tag(['998', '999']).should.equal [] end it "gets a single field for the 260 as string" do onetag = @one.find_by_tag('260') onetag.should.equal [@df] end it "gets a single field for the 260 as an array" do onetag = @one.find_by_tag('260') @one.find_by_tag(['260']).should.equal [@df] end it "gets both the 260 and 005" do @one.find_by_tag(['005', '260']).should.equal [@cf, @df] end it "returns fields in the order their tags were requested" do @one.find_by_tag(['260', '005']).should.equal [@df, @cf] end it "allows caller to force return of tags in original order" do @one.find_by_tag(['260', '005'], true).should.equal [@cf, @df] end it "finds all instances of requested tags" do @one.find_by_tag('700').size.should.equal 3 @one.find_by_tag('852').size.should.equal 2 @one.find_by_tag(['852', '700']).size.should.equal 5 end it "returns duplicate-tag fields in the order from the record" do first = @one['700'] @one.find_by_tag('700')[0].should.equal first end end