Skip to content

Commit

Permalink
Test against a released version of blacklight (#100)
Browse files Browse the repository at this point in the history
* Test against a released version of blacklight

* Update CI test matrix

* Get atom spec running again, closes #97

* Remove some unneeded 'require' statements

* Appease zeitwerk by moving the document mixins within the blacklight-marc namespace

* Remove extensions from view specs

Co-authored-by: Jane Sandberg <js7389@princeton.edu>
  • Loading branch information
cbeer and sandbergja authored Mar 16, 2022
1 parent 0652934 commit be6d8b5
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 45 deletions.
27 changes: 7 additions & 20 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rails_version: [6.1.1]
ruby: [2.7, 3.0]
env:
RAILS_VERSION: ${{ matrix.rails_version }}
steps:
- uses: actions/checkout@v2
- name: Set up Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Install dependencies with Rails ${{ matrix.rails_version }}
run: bundle install
- name: Run tests
run: bundle exec rake
test_rails52:
runs-on: ubuntu-latest
strategy:
matrix:
rails_version: [5.2.4.4, 6.0.3.4]
ruby: [2.7]
rails_version: [6.1.4.7, 7.0.2.3]
ruby: [2.7, '3.0']
include:
- rails_version: 5.2.4.4
ruby: 2.7
- rails_version: 6.0.3.4
ruby: 2.7
env:
RAILS_VERSION: ${{ matrix.rails_version }}
steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# -*- encoding : utf-8 -*-
# -*- coding: utf-8 -*-
# Written for use with Blacklight::Solr::Document::Marc, but you can use

# Written for use with Blacklight::Marc::DocumentExtension, but you can use
# it for your own custom Blacklight document Marc extension too -- just
# include this module in any document extension (or any other class)
# that provides a #to_marc returning a ruby-marc object. This module will add
# in export_as translation methods for a variety of formats.
module Blacklight::Solr::Document::MarcExport
module Blacklight::Marc::DocumentExport

def self.register_export_formats(document)
document.will_export_as(:xml)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# This extension would normally be registered using
# Blacklight::Solr::Document#use_extension. eg:
#
# SolrDocument.use_extension( Blacklight::Solr::Document::Marc ) { |document| my_logic_for_document_has_marc?( document ) }
# SolrDocument.use_extension( Blacklight::Marc::DocumentExtension ) { |document| my_logic_for_document_has_marc?( document ) }
#
# This extension also expects a :marc_source_field and :marc_format_type to
# be registered with the hosting classes extension_parameters. In an initializer
Expand All @@ -18,15 +18,16 @@
# SolrDocument.extension_parameters[:marc_format_type] = :marc21 # or :marcxml
require 'marc'

module Blacklight::Solr::Document::Marc
module Blacklight::Marc
module DocumentExtension

include Blacklight::Solr::Document::MarcExport # All our export_as stuff based on to_marc.
include Blacklight::Marc::DocumentExport # All our export_as stuff based on to_marc.

class UnsupportedMarcFormatType < RuntimeError; end

def self.extended(document)
# Register our exportable formats, we inherit these from MarcExport
Blacklight::Solr::Document::MarcExport.register_export_formats( document )
Blacklight::Marc::DocumentExport.register_export_formats( document )
end

# ruby-marc object
Expand Down Expand Up @@ -78,4 +79,5 @@ def _marc_format_type
self.class.extension_parameters[:marc_format_type]
end

end
end
18 changes: 7 additions & 11 deletions lib/blacklight/marc/engine.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
require "blacklight/marc"
require "rails"

module Blacklight::Marc
class Engine < Rails::Engine
config.autoload_paths += %W(
#{config.root}/app/presenters
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)

rake_tasks do
load "railties/solr_marc.rake"
end

initializer 'blacklight_marc.initialize' do |app|
require 'blacklight/solr/document'

Mime::Type.register_alias "text/plain", :refworks_marc_txt
Mime::Type.register_alias "text/plain", :openurl_kev
Mime::Type.register "application/x-endnote-refer", :endnote
Mime::Type.register "application/marc", :marc
Mime::Type.register "application/marcxml+xml", :marcxml,
["application/x-marc+xml", "application/x-marcxml+xml",
"application/marc+xml"]

# these are here for backwards compatibility with the old class names,
# which zeitwerk didn't care for
config.after_initialize do
Blacklight::Solr::Document::Marc = Blacklight::Marc::DocumentExtension
Blacklight::Solr::Document::MarcExport = Blacklight::Marc::DocumentExport
end
end
end
end
8 changes: 4 additions & 4 deletions lib/generators/blacklight/marc/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def add_marc_extension_to_solrdocument
# The following shows how to setup this blacklight document to display marc documents
extension_parameters[:marc_source_field] = :marc_ss
extension_parameters[:marc_format_type] = :marcxml
use_extension( Blacklight::Solr::Document::Marc) do |document|
document.key?( SolrDocument.extension_parameters[:marc_source_field] )
use_extension(Blacklight::Marc::DocumentExtension) do |document|
document.key?(SolrDocument.extension_parameters[:marc_source_field])
end
field_semantics.merge!(
field_semantics.merge!(
:title => "title_ssm",
:author => "author_ssm",
:language => "language_ssim",
Expand Down
1 change: 0 additions & 1 deletion spec/test_app_templates/Gemfile.extra
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
gem 'blacklight', github: 'projectblacklight/blacklight'
gem "traject", '~>3.0'
2 changes: 1 addition & 1 deletion spec/views/bookmarks/_endnote.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

RSpec.describe 'bookmarks/_endnote.html.erb' do
RSpec.describe 'bookmarks/_endnote' do
before do
allow(controller).to receive(:blacklight_config)
.and_return(CatalogController.blacklight_config)
Expand Down
2 changes: 1 addition & 1 deletion spec/views/bookmarks/_refworks.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

RSpec.describe 'bookmarks/_refworks.html.erb' do
RSpec.describe 'bookmarks/_refworks' do
before do
allow(controller).to receive(:blacklight_config)
.and_return(CatalogController.blacklight_config)
Expand Down
2 changes: 1 addition & 1 deletion spec/views/catalog/index.atom.builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
params.merge!( @params )
allow(view).to receive(:blacklight_config).and_return(@config)
allow(view).to receive(:search_field_options_for_select).and_return([])

allow(controller).to receive(:search_state_class).and_return(Blacklight::SearchState)
render :template => 'catalog/index', :formats => [:atom]

# We need to use rexml to test certain things that have_tag wont' test
Expand Down

0 comments on commit be6d8b5

Please sign in to comment.