blacklight-marc 5.4.0 → 5.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f0fb70263ceb51ccdd8cd3d861101dbc74bf1df
4
- data.tar.gz: 7ef0b31a16dbcaafa8a4afa3c09c523f766e00aa
3
+ metadata.gz: 75e8d8a88f4be661346d59f902344e109f02e672
4
+ data.tar.gz: 024738cc6d5c0e46cee5c91f2881afc7d3569f61
5
5
  SHA512:
6
- metadata.gz: 77bdd9fd66ca82d8f11fcde0c392105327772ba0eb44bc665aa9c868ad3df7d8e96f0a836139519055e74dfdcc42349ed573b061c3a91b357e944eb4af605389
7
- data.tar.gz: 23bdcd829106648025d26239dd506ccbde04901707cf46ee354d3ea8bff32f25cee9bc3bbdb43e383fea4ad1dc4bd8779d97a12d1d5bc6f44203b9d833598ba8
6
+ metadata.gz: a1ce25d123310609c7fd38aa374bc9128a5c439974f5944285120b14501f69826cd559d2537e6b6c5cd1533cdc494ee0dfdbe05a7a9a142785f1595f6233b9ce
7
+ data.tar.gz: ddb00a986af2a989198c6def0b246858e0b501f57416805f056315f476bbede3622a52cde86420d9466ae7619b70a3e029bd119d5a09325c2aecfe7cbac94aab
data/.travis.yml CHANGED
@@ -1,15 +1,30 @@
1
1
  notifications:
2
2
  email: false
3
3
 
4
+
4
5
  rvm:
5
- - 2.1.1
6
- - 2.0.0
7
- - 1.9.3
8
- - jruby-19mode
6
+ - 2.1.4
7
+
8
+ matrix:
9
+ include:
10
+ - rvm: 2.1.4
11
+ env: "RAILS_VERSION=4.0.12"
12
+ - rvm: 2.0.0
13
+ env: "RAILS_VERSION=4.1.8"
14
+ - rvm: 1.9.3
15
+ env: "RAILS_VERSION=4.1.8"
16
+ - rvm: jruby
17
+ env: "RAILS_VERSION=4.1.8 JRUBY_OPTS=\"-J-Xms512m -J-Xmx1024m\""
18
+ - rvm: 2.1.4
19
+ env: "RAILS_VERSION=4.2.0.rc3"
9
20
 
10
21
  before_install:
11
22
  - gem install bundler
12
23
 
24
+ env:
25
+ - "RAILS_VERSION=3.2.21"
26
+ - "RAILS_VERSION=4.1.8"
27
+
13
28
  notifications:
14
29
  irc: "irc.freenode.org#blacklight"
15
30
  email:
data/Gemfile CHANGED
@@ -9,19 +9,20 @@ gemspec path: File.expand_path('..', __FILE__)
9
9
  gem 'simplecov', '~> 0.7.1', require: false
10
10
  gem 'coveralls', require: false
11
11
 
12
- gem 'engine_cart', '~> 0.3.0'
13
-
14
- # pin to known-working versions of rails and dependencies
15
- gem 'rails', '4.0.4'
16
- gem 'sass', '~> 3.2.15'
17
- gem 'sprockets', '~> 2.11.0'
18
-
19
- group :test do
20
- gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
21
- end
22
-
23
12
  file = File.expand_path("Gemfile", ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path("../spec/internal", __FILE__))
24
13
  if File.exists?(file)
25
14
  puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
26
15
  instance_eval File.read(file)
16
+ else
17
+ gem 'rails', ENV['RAILS_VERSION']
18
+
19
+ # explicitly include sass-rails to get compatible sprocket dependencies
20
+ if ENV['RAILS_VERSION'] and ENV['RAILS_VERSION'] =~ /^4.2/
21
+ gem 'sass-rails', ">= 5.0.0.beta1"
22
+ gem 'responders', "~> 2.0"
23
+ else
24
+ gem 'sass-rails', "< 5.0"
25
+ gem 'coffee-rails', "~> 4.0.0"
26
+ end
27
27
  end
28
+ gem 'transpec'
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
- ZIP_URL = "https://github.com/projectblacklight/blacklight-jetty/archive/v4.0.0.zip"
2
+ ZIP_URL = "https://github.com/projectblacklight/blacklight-jetty/archive/v4.10.2.zip"
3
3
 
4
4
  require 'jettywrapper'
5
5
  require 'rspec/core/rake_task'
@@ -17,14 +17,16 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "blacklight", ">= 5.4.0.rc1", "< 6.0"
20
+ spec.add_dependency "blacklight", "~> 5.8"
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 1.3"
23
23
  spec.add_development_dependency "rake"
24
- spec.add_development_dependency "rspec"
25
- spec.add_development_dependency "rspec-rails"
24
+ spec.add_development_dependency "rspec-rails", '~> 3.0'
25
+ spec.add_development_dependency "rspec-activemodel-mocks"
26
26
  spec.add_development_dependency "jettywrapper"
27
27
  spec.add_development_dependency "capybara"
28
+ spec.add_development_dependency "engine_cart", "~> 0.4"
29
+
28
30
  spec.add_dependency "rails"
29
31
  # Let's allow future versions of marc, count on
30
32
  # them to be backwards compat until 1.1
@@ -1,7 +1,7 @@
1
1
  module Blacklight::Marc
2
2
  module Catalog
3
3
  def librarian_view
4
- @response, @document = get_solr_response_for_doc_id
4
+ @response, @document = get_solr_response_for_doc_id params[:id]
5
5
 
6
6
  respond_to do |format|
7
7
  format.html
@@ -11,7 +11,7 @@ module Blacklight::Marc
11
11
 
12
12
  # grabs a bunch of documents to export to endnote
13
13
  def endnote
14
- @response, @documents = get_solr_response_for_field_values(SolrDocument.unique_key,params[:id])
14
+ @response, @documents = get_solr_response_for_document_ids(params[:id])
15
15
  respond_to do |format|
16
16
  format.endnote { render :layout => false }
17
17
  end
@@ -1,5 +1,5 @@
1
1
  module Blacklight
2
2
  module Marc
3
- VERSION = "5.4.0"
3
+ VERSION = "5.5.0"
4
4
  end
5
5
  end
@@ -43,17 +43,23 @@ module Blacklight::Solr::Document::Marc
43
43
  def load_marc
44
44
  case _marc_format_type.to_s
45
45
  when 'marcxml'
46
- records = MARC::XMLReader.new(StringIO.new( fetch(_marc_source_field) )).to_a
47
- return records[0]
46
+ marc_record_from_marcxml
48
47
  when 'marc21'
49
- return MARC::Record.new_from_marc( fetch(_marc_source_field) )
48
+ return MARC::Record.new_from_marc( fetch(_marc_source_field) )
49
+ when 'json'
50
+ return MARC::Record.new_from_hash( JSON.parse( fetch(_marc_source_field) ) )
50
51
  else
51
-
52
- raise UnsupportedMarcFormatType.new("Only marcxml and marc21 are supported, this documents format is #{_marc_format_type} and the current extension parameters are #{self.class.extension_parameters.inspect}")
52
+ raise UnsupportedMarcFormatType.new("Only marcxml, marc21, and json are supported, this documents format is #{_marc_format_type} and the current extension parameters are #{self.class.extension_parameters.inspect}")
53
53
  end
54
+ rescue Exception => e
55
+ raise e if e.is_a? UnsupportedMarcFormatType
56
+
57
+ Rails.logger.error("Blacklight failed to parse MARC record. Exception was: #{e}")
54
58
  end
55
59
 
56
-
60
+ def marc_record_from_marcxml
61
+ MARC::XMLReader.new(StringIO.new( fetch(_marc_source_field) )).to_a.first
62
+ end
57
63
 
58
64
  def _marc_helper
59
65
  @_marc_helper ||= (
@@ -5,8 +5,8 @@ describe BlacklightMarcHelper do
5
5
  let(:two) { SolrDocument.new }
6
6
  describe "render_refworks_texts" do
7
7
  before do
8
- one.stub(:export_as_refworks_marc_txt => 'one')
9
- two.stub(:export_as_refworks_marc_txt => 'two')
8
+ allow(one).to receive_messages(export_as_refworks_marc_txt: 'one')
9
+ allow(two).to receive_messages(export_as_refworks_marc_txt: 'two')
10
10
  end
11
11
  it "should render_refworks_texts" do
12
12
  expect(helper.render_refworks_texts([one, two])).to eq "one\ntwo\n"
@@ -16,8 +16,8 @@ describe BlacklightMarcHelper do
16
16
 
17
17
  describe "render_endnote_texts" do
18
18
  before do
19
- one.stub(:export_as_endnote => 'one')
20
- two.stub(:export_as_endnote => 'two')
19
+ allow(one).to receive_messages(export_as_endnote: 'one')
20
+ allow(two).to receive_messages(export_as_endnote: 'two')
21
21
  end
22
22
  it "should render_endnote_texts" do
23
23
  expect(helper.render_endnote_texts([one, two])).to eq "one\ntwo\n"
@@ -19,6 +19,10 @@ def get_hash_without_marcxml
19
19
  {'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ī']}]}}
20
20
  end
21
21
 
22
+ def get_hash_with_bad_marcxml
23
+ {'responseHeader'=>{'status'=>0,'QTime'=>0,'params'=>{'q'=>'id:00282214','wt'=>'ruby'}},'response'=>{'numFound'=>1,'start'=>0,'docs'=>[{'id'=>'00282214', "marc_display" =>'<record xmlns=\'http://www.loc.gov/MARC21/slim\'><leader>00799cam a2200241 a 4500</leader><blarg tag=\'001\'> 00282214 </controlfield><controlfield tag=\'003\'>DLC</controlfield><controlfield tag=\'005\'>20090120022042.0</controlfield><controlfield tag=\'008\'>000417s1998 pk 000 0 urdo </controlfield><datafield tag=\'010\' ind1=\' \' ind2=\' \'><subfield code=\'a\'> 00282214 </subfield></datafield><datafield tag=\'025\' ind1=\' \' ind2=\' \'><subfield code=\'a\'>P-U-00282214; 05; 06</subfield></datafield><datafield tag=\'040\' ind1=\' \' ind2=\' \'><subfield code=\'a\'>DLC</subfield><subfield code=\'c\'>DLC</subfield><subfield code=\'d\'>DLC</subfield></datafield><datafield tag=\'041\' ind1=\'1\' ind2=\' \'><subfield code=\'a\'>urd</subfield><subfield code=\'h\'>snd</subfield></datafield><datafield tag=\'042\' ind1=\' \' ind2=\' \'><subfield code=\'a\'>lcode</subfield></datafield><datafield tag=\'050\' ind1=\'0\' ind2=\'0\'><subfield code=\'a\'>PK2788.9.A9</subfield><subfield code=\'b\'>F55 1998</subfield></datafield><datafield tag=\'100\' ind1=\'1\' ind2=\' \'><subfield code=\'a\'>Ayaz, Shaikh,</subfield><subfield code=\'d\'>1923-1997.</subfield></datafield><datafield tag=\'245\' ind1=\'1\' ind2=\'0\'><subfield code=\'a\'>Fikr-i Ayāz /</subfield><subfield code=\'c\'>murattibīn, Āṣif Farruk̲h̲ī, Shāh Muḥammad Pīrzādah.</subfield></datafield><datafield tag=\'260\' ind1=\' \' ind2=\' \'><subfield code=\'a\'>Karācī :</subfield><subfield code=\'b\'>Dāniyāl,</subfield><subfield code=\'c\'>[1998]</subfield></datafield><datafield tag=\'300\' ind1=\' \' ind2=\' \'><subfield code=\'a\'>375 p. ;</subfield><subfield code=\'c\'>23 cm.</subfield></datafield><datafield tag=\'546\' ind1=\' \' ind2=\' \'><subfield code=\'a\'>In Urdu.</subfield></datafield><datafield tag=\'520\' ind1=\' \' ind2=\' \'><subfield code=\'a\'>Selected poems and articles from the works of renowned Sindhi poet; chiefly translated from Sindhi.</subfield></datafield><datafield tag=\'700\' ind1=\'1\' ind2=\' \'><subfield code=\'a\'>Farruk̲h̲ī, Āṣif,</subfield><subfield code=\'d\'>1959-</subfield></datafield><datafield tag=\'700\' ind1=\'1\' ind2=\' \'><subfield code=\'a\'>Pīrzādah, Shāh Muḥammad.</subfield></datafield></record>','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ī']}]}}
24
+ end
25
+
22
26
  describe SolrDocument do
23
27
 
24
28
  before(:each) do
@@ -41,19 +45,24 @@ end
41
45
  it "should have a valid to_marc" do
42
46
  @solrdoc = SolrDocument.new(@hash_with_marcxml)
43
47
 
44
- @solrdoc.should respond_to(:to_marc)
45
- @solrdoc.to_marc.should be_kind_of(MARC::Record)
48
+ expect(@solrdoc).to respond_to(:to_marc)
49
+ expect(@solrdoc.to_marc).to be_kind_of(MARC::Record)
46
50
  end
47
51
 
48
52
  it "should not try to create marc for objects w/out stored marc (marcxml test only at this time)" do
49
- # TODO: Create another double object that does not have marc-xml in it and make
50
- # sure everything fails gracefully
51
53
  @hash_without_marcxml = get_hash_without_marcxml['response']['docs'][0]
52
54
  @solrdoc_without_marc = SolrDocument.new(@hash_without_marcxml)
53
- @solrdoc_without_marc.should_not respond_to(:to_marc)
54
- # legacy check
55
- # @solrdoc_without_marc.should respond_to(:marc)
56
- # @solrdoc_without_marc.marc.should == nil
55
+
56
+ expect(@solrdoc_without_marc).not_to respond_to(:to_marc)
57
57
  end
58
+
59
+ it "should fail gracefully when given bad marc xml" do
60
+ hash_with_bad_marcxml = get_hash_with_bad_marcxml['response']['docs'][0]
61
+ @solrdoc = SolrDocument.new(hash_with_bad_marcxml)
62
+ expect(Rails.logger).to receive(:error).with(/Blacklight failed to parse MARC record. Exception was: Missing end tag for 'blarg'/)
63
+ expect(@solrdoc).to respond_to(:to_marc)
64
+ expect(@solrdoc.to_marc).to be_nil
65
+ end
66
+
58
67
  end
59
- end
68
+ end
@@ -17,7 +17,7 @@ describe "Blacklight::Solr::Document::Marc" do
17
17
  end
18
18
  it "should read and parse a marc binary file" do
19
19
  document = @mock_class.new(:marc => sample_marc_binary )
20
- document.to_marc.should == marc_from_string(:binary => sample_marc_binary )
20
+ expect(document.to_marc).to eq(marc_from_string(:binary => sample_marc_binary ))
21
21
  end
22
22
  end
23
23
 
@@ -27,13 +27,23 @@ describe "Blacklight::Solr::Document::Marc" do
27
27
  end
28
28
  it "should read and parse a marc xml file" do
29
29
  document = @mock_class.new(:marc => sample_marc_xml)
30
- document.to_marc.should == marc_from_string(:xml => sample_marc_xml)
30
+ expect(document.to_marc).to eq(marc_from_string(:xml => sample_marc_xml))
31
+ end
32
+ end
33
+
34
+ describe "marc json mode" do
35
+ before(:each) do
36
+ @mock_class.extension_parameters[:marc_format_type] = :json
37
+ end
38
+ it "should read and parse a marc json file" do
39
+ document = @mock_class.new(:marc => sample_marc_json)
40
+ expect(document.to_marc).to eq(marc_from_string(:json => sample_marc_json))
31
41
  end
32
42
  end
33
43
 
34
44
  it "should register all its export formats" do
35
45
  document = @mock_class.new
36
- Set.new(document.export_formats.keys).should be_superset(Set.new([:marc, :marcxml, :openurl_ctx_kev, :refworks_marc_txt, :endnote, :xml]))
46
+ expect(Set.new(document.export_formats.keys)).to be_superset(Set.new([:marc, :marcxml, :openurl_ctx_kev, :refworks_marc_txt, :endnote, :xml]))
37
47
  end
38
48
 
39
49
 
@@ -75,6 +85,11 @@ describe "Blacklight::Solr::Document::Marc" do
75
85
  def sample_marc_binary
76
86
  "00386pam a22001094a 4500001000900000003000600009008004100015245008900056260005400145700004500199700003200244\036a4802615\036SIRSI\036020828s2003 enkaf b 001 0 eng \03600\037aApples :\037bbotany, production, and uses /\037cedited by D.C. Ferree and I.J. Warrington.\036 \037aOxon, U.K. ;\037aCambridge, MA :\037bCABI Pub.,\037cc2003.\0361 \037aFerree, David C.\037q(David Curtis),\037d1943-\0361 \037aWarrington, I. J.\037q(Ian J.)\036\035"
77
87
  end
88
+
89
+ def sample_marc_json
90
+ "{\"leader\":\"00386pam a22001094a 4500\",\"fields\":[{\"001\":\"a4802615\"},{\"003\":\"SIRSI\"},{\"008\":\"020828s2003 enkaf b 001 0 eng \"},{\"245\":{\"ind1\":\"0\",\"ind2\":\"0\",\"subfields\":[{\"a\":\"Apples :\"},{\"b\":\"botany, production, and uses /\"},{\"c\":\"edited by D.C. Ferree and I.J. Warrington.\"}]}},{\"260\":{\"ind1\":\" \",\"ind2\":\" \",\"subfields\":[{\"a\":\"Oxon, U.K. ;\"},{\"a\":\"Cambridge, MA :\"},{\"b\":\"CABI Pub.,\"},{\"c\":\"c2003.\"}]}},{\"700\":{\"ind1\":\"1\",\"ind2\":\" \",\"subfields\":[{\"a\":\"Ferree, David C.\"},{\"q\":\"(David Curtis),\"},{\"d\":\"1943-\"}]}},{\"700\":{\"ind1\":\"1\",\"ind2\":\" \",\"subfields\":[{\"a\":\"Warrington, I. J.\"},{\"q\":\"(Ian J.)\"}]}}]}"
91
+ end
92
+
78
93
  def marc_from_string(args = {})
79
94
  if args[:binary]
80
95
  reader = MARC::Reader.new(StringIO.new(args[:binary]))
@@ -82,6 +97,9 @@ describe "Blacklight::Solr::Document::Marc" do
82
97
  elsif args[:xml]
83
98
  reader = MARC::XMLReader.new(StringIO.new(args[:xml]))
84
99
  reader.each {|rec| return rec }
100
+ elsif args[:json]
101
+ rec = MARC::Record.new_from_hash(JSON.parse(args[:json]))
102
+ return rec
85
103
  end
86
104
  return nil
87
105
  end