# -*- encoding : utf-8 -*- require 'spec_helper' # 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_bad_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 describe SolrDocument do # SolrDocument leaks to other classes, so subclass here to test extension behavior let(:test_rig) { Class.new(SolrDocument) } before do test_rig.extension_parameters[:marc_source_field] = :marc_display test_rig.extension_parameters[:marc_format_type] = :marcxml test_rig.registered_extensions = nil test_rig.use_extension( Blacklight::Solr::Document::Marc ) { |document| document.has_key?(:marc_display)} end before(:each) do @hash_with_marcxml = get_hash_with_marcxml['response']['docs'][0] @solrdoc = test_rig.new(@hash_with_marcxml) end describe "ruby marc creation" do it "should have a valid to_marc" do @solrdoc = test_rig.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 @hash_without_marcxml = get_hash_without_marcxml['response']['docs'][0] @solrdoc_without_marc = test_rig.new(@hash_without_marcxml) expect(@solrdoc_without_marc).not_to respond_to(:to_marc) end it "should fail gracefully when given bad marc xml" do hash_with_bad_marcxml = get_hash_with_bad_marcxml['response']['docs'][0] @solrdoc = test_rig.new(hash_with_bad_marcxml) expect(Rails.logger).to receive(:error).with(/Blacklight failed to parse MARC record. Exception was: Missing end tag for 'blarg'/) expect(@solrdoc).to respond_to(:to_marc) expect(@solrdoc.to_marc).to be_nil end end end