diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3319ad2cb..8daa28178 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -741,7 +741,6 @@ RSpec/SubjectStub: Exclude: - 'spec/components/access_panels/sfx_component_spec.rb' - 'spec/controllers/concerns/callnumber_search_spec.rb' - - 'spec/models/barcode_search_spec.rb' - 'spec/models/concerns/solr_set_spec.rb' - 'spec/models/performance_alerts_spec.rb' - 'spec/models/search_builder_spec.rb' diff --git a/app/controllers/barcode_controller.rb b/app/controllers/barcode_controller.rb deleted file mode 100644 index 6089fd889..000000000 --- a/app/controllers/barcode_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class BarcodeController < ApplicationController - def show - render json: BarcodeSearch.new(params[:id]) - end -end diff --git a/app/models/barcode_search.rb b/app/models/barcode_search.rb deleted file mode 100644 index 22ac3345f..000000000 --- a/app/models/barcode_search.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -class BarcodeSearch - attr_reader :barcode - - def initialize(barcode) - @barcode = barcode - end - - def document_id - return if documents.blank? - - documents.first['id'] - end - - def as_json(*) - { barcode:, id: document_id } - end - - private - - def documents - response.dig('response', 'docs') || [] - end - - def response - @response ||= blacklight_solr.get('barcode', params: { n: barcode }) - end - - def blacklight_solr - Blacklight.default_index.connection - end -end diff --git a/config/routes.rb b/config/routes.rb index df0828bf4..7c181ed72 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,8 +26,6 @@ concern :marc_viewable, Blacklight::Marc::Routes::MarcViewable.new concern :range_searchable, BlacklightRangeLimit::Routes::RangeSearchable.new - resources :barcode, only: :show - resource :catalog, only: [:index], as: 'catalog', path: '/catalog', controller: 'catalog' do concerns :searchable concerns :range_searchable diff --git a/config/solr_configs/solrconfig.xml b/config/solr_configs/solrconfig.xml index 4f9de5ac2..acdbbeedc 100644 --- a/config/solr_configs/solrconfig.xml +++ b/config/solr_configs/solrconfig.xml @@ -1070,15 +1070,6 @@ - - - - explicit - id - {!field f=barcode_search v=$n} - - - diff --git a/spec/controllers/barcode_controller_spec.rb b/spec/controllers/barcode_controller_spec.rb deleted file mode 100644 index 8b8968e7c..000000000 --- a/spec/controllers/barcode_controller_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe BarcodeController do - describe 'routes' do - it 'is available at /barcode' do - request = { get: '/barcode/3610512345' } - expect(request).to route_to(controller: 'barcode', action: 'show', id: '3610512345') - end - end - - describe 'GET show' do - it 'renders the json returned by the BarcodeSearch class' do - json = { id: 'abc123', barcode: '3610512345' } - expect(BarcodeSearch).to receive(:new).with('3610512345').and_return(json) - - get :show, params: { id: '3610512345' } - - expect(response).to be_successful - response_json = response.parsed_body - expect(response_json['id']).to eq(json[:id]) - expect(response_json['barcode']).to eq(json[:barcode]) - end - end -end diff --git a/spec/models/barcode_search_spec.rb b/spec/models/barcode_search_spec.rb deleted file mode 100644 index 9c316f100..000000000 --- a/spec/models/barcode_search_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe BarcodeSearch do - subject { described_class.new(barcode) } - - let(:barcode) { '3610512345' } - let(:stub_response) do - { response: { docs: [{ id: 'abc123' }] } }.with_indifferent_access - end - let(:stub_no_docs_response) do - { response: { docs: [] } }.with_indifferent_access - end - - describe 'when the barcode search returns a document' do - before do - expect(subject).to receive_messages(response: stub_response) - end - - it 'gets the document id from the first document in the response' do - expect(subject.document_id).to eq('abc123') - end - - it 'has a json response that returns the barcode and id' do - expect(subject.as_json[:barcode]).to eq '3610512345' - expect(subject.as_json[:id]).to eq 'abc123' - end - end - - describe 'when the barcode search does not return a document' do - before do - expect(subject).to receive_messages(response: stub_no_docs_response) - end - - it 'returns nil for the document_id' do - expect(subject.document_id).to be_nil - end - end -end