# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'rubygems' require 'marc' # WARNING!!! # If you set any values in Blacklight here, you must reset them to the original # values in an after() block so other tests get expected results. # Blacklight is a Singleton for application configuration. ## TODO: ALL these specs probably really ought to be on the modules # being tested, not on the bare SolrDocument class that has no logic # of it's own, it just includes modules. No? jrochkind 29 Mar 2010 def get_hash_with_marcxml {'responseHeader'=>{'status'=>0,'QTime'=>0,'params'=>{'q'=>'id:00282214','wt'=>'ruby'}},'response'=>{'numFound'=>1,'start'=>0,'docs'=>[{'id'=>'00282214', "marc_display" =>'00799cam a2200241 a 4500 00282214 DLC20090120022042.0000417s1998 pk 000 0 urdo 00282214 P-U-00282214; 05; 06DLCDLCDLCurdsndlcodePK2788.9.A9F55 1998Ayaz, Shaikh,1923-1997.Fikr-i Ayāz /murattibīn, Āṣif Farruk̲h̲ī, Shāh Muḥammad Pīrzādah.Karācī :Dāniyāl,[1998]375 p. ;23 cm.In Urdu.Selected poems and articles from the works of renowned Sindhi poet; chiefly translated from Sindhi.Farruk̲h̲ī, Āṣif,1959-Pīrzādah, Shāh Muḥammad.','timestamp'=>'2009-03-26T18:15:31.074Z','material_type_display'=>['375 p'],'title_display'=>['Fikr-i Ayāz'],'author_display'=>['Farruk̲h̲ī, Āṣif','Pīrzādah, Shāh Muḥammad'],'language_facet'=>['Urdu'],'format'=>['Book'],'published_display'=>['Karācī']}]}} end def get_hash_without_marcxml {'responseHeader'=>{'status'=>0,'QTime'=>0,'params'=>{'q'=>'id:00282214','wt'=>'ruby'}},'response'=>{'numFound'=>1,'start'=>0,'docs'=>[{'id'=>'00282214','timestamp'=>'2009-03-26T18:15:31.074Z','material_type_display'=>['375 p'],'title_display'=>['Fikr-i Ayāz'],'author_display'=>['Farruk̲h̲ī, Āṣif','Pīrzādah, Shāh Muḥammad'],'language_facet'=>['Urdu'],'format'=>['Book'],'published_display'=>['Karācī']}]}} end def get_hash_with_marc21 reader = MARC::Reader.new(File.dirname(__FILE__) + '/../data/test_data.utf8.mrc') # doing weird i= stuff to get only first record. reader.first, or i = 0, i+1 didn't work and this was the only way I could get it working. Needs refactoring. i = "1st" for record in reader if i == "1st" first_rec = record.to_marc end i = "not1st" end return {'responseHeader'=>{'status'=>0,'QTime'=>0,'params'=>{'q'=>'id:00282214','wt'=>'ruby'}},'response'=>{'numFound'=>1,'start'=>0,'docs'=>[{'id'=>'00282214', "marc_display" => first_rec, 'timestamp'=>'2009-03-26T18:15:31.074Z','material_type_display'=>['375 p'],'title_display'=>['Fikr-i Ayāz'],'author_display'=>['Farruk̲h̲ī, Āṣif','Pīrzādah, Shāh Muḥammad'],'language_facet'=>['Urdu'],'format'=>['Book'],'published_display'=>['Karācī']}]}} end describe SolrDocument do before(:each) do @hash_with_marcxml = get_hash_with_marcxml['response']['docs'][0] SolrDocument.extension_parameters[:marc_source_field] = :marc_display SolrDocument.extension_parameters[:marc_format_type] = :marcxml # rsolr seems to reload SolrDocument from time to time, so we can't # count on the initializer to register the extension, need to re-register # it. SolrDocument.registered_extensions = nil SolrDocument.use_extension( Blacklight::Solr::Document::Marc ) { |document| document.has_key?(:marc_display)} @solrdoc = SolrDocument.new(@hash_with_marcxml) end describe "new" do it "should take a Hash as the argument" do expect { SolrDocument.new(@hash_with_marcxml) }.not_to raise_error end end describe "access methods" do it "should have the right value for title_display" do expect(@solrdoc[:title_display]).not_to be_nil end it "should have the right value for format" do expect(@solrdoc[:format][0]).to eq('Book') end it "should provide the item's solr id" do expect(@solrdoc.id).to eq('00282214') end end describe "ruby marc creation" do it "should have a valid to_marc" do @solrdoc = SolrDocument.new(@hash_with_marcxml) expect(@solrdoc).to respond_to(:to_marc) expect(@solrdoc.to_marc).to be_kind_of(MARC::Record) end it "should not try to create marc for objects w/out stored marc (marcxml test only at this time)" do # TODO: Create another double object that does not have marc-xml in it and make # sure everything fails gracefully @hash_without_marcxml = get_hash_without_marcxml['response']['docs'][0] @solrdoc_without_marc = SolrDocument.new(@hash_without_marcxml) expect(@solrdoc_without_marc).not_to respond_to(:to_marc) # legacy check # @solrdoc_without_marc.should respond_to(:marc) # @solrdoc_without_marc.marc.should == nil end end end