diff --git a/catalog-browse.rb b/catalog-browse.rb index 4c3f7af..ae7cf8a 100644 --- a/catalog-browse.rb +++ b/catalog-browse.rb @@ -10,8 +10,8 @@ require_relative "lib/utilities/string_cleaner" require_relative "lib/models/browse_list" require_relative "lib/models/browse_list_presenter" -require_relative "lib/models/callnumber_list" -require_relative "lib/models/callnumber_item" +require_relative "lib/models/call_number_list" +require_relative "lib/models/call_number_item" require_relative "lib/models/author_list" require_relative "lib/models/author_item" require_relative "lib/models/subject_list" @@ -47,13 +47,13 @@ erb :authors, locals: {list: list} end get "/callnumber" do - callnumber = params[:query] - reference_id = params[:reference_id] || callnumber + call_number = params[:query] + reference_id = params[:reference_id] || call_number begin - list = CallnumberList.for(direction: params[:direction], reference_id: reference_id, num_rows_to_display: 20, original_reference: callnumber, banner_reference: params[:banner_reference]) + list = CallNumberList.for(direction: params[:direction], reference_id: reference_id, num_rows_to_display: 20, original_reference: call_number, banner_reference: params[:banner_reference]) rescue => e logger.error(e.message) - list = CallnumberList::Error.new(reference_id) + list = CallNumberList::Error.new(reference_id) end erb :call_number, locals: {list: list} end diff --git a/lib/models/callnumber_item.rb b/lib/models/call_number_item.rb similarity index 92% rename from lib/models/callnumber_item.rb rename to lib/models/call_number_item.rb index 99e456b..f98c912 100644 --- a/lib/models/callnumber_item.rb +++ b/lib/models/call_number_item.rb @@ -1,4 +1,4 @@ -class CallnumberItem +class CallNumberItem def initialize(browse_doc:, catalog_doc:, exact_match:) @browse_doc = browse_doc @catalog_doc = catalog_doc || {} @@ -13,6 +13,11 @@ def exact_match? !!@exact_match end + # for the view + def call_number + @browse_doc["callnumber"]&.strip + end + # for the view def callnumber @browse_doc["callnumber"]&.strip diff --git a/lib/models/callnumber_list.rb b/lib/models/call_number_list.rb similarity index 93% rename from lib/models/callnumber_list.rb rename to lib/models/call_number_list.rb index 18b8f40..5cd7738 100644 --- a/lib/models/callnumber_list.rb +++ b/lib/models/call_number_list.rb @@ -1,4 +1,4 @@ -class CallnumberList < BrowseListPresenter +class CallNumberList < BrowseListPresenter def self.for(direction:, reference_id:, num_rows_to_display:, original_reference:, banner_reference:) browse_list = BrowseList.for( direction: direction, @@ -37,7 +37,7 @@ def items exact_match = exact_matches.any?(browse_doc["id"]) banner_match = (banner_reference == browse_doc["id"]) banner_index = index if (exact_match || banner_match) && banner_index.nil? - CallnumberItem.new(browse_doc: browse_doc, catalog_doc: catalog_doc(browse_doc["bib_id"]), exact_match: exact_match) + CallNumberItem.new(browse_doc: browse_doc, catalog_doc: catalog_doc(browse_doc["bib_id"]), exact_match: exact_match) end banner_index.nil? ? my_items : my_items.insert(banner_index, match_notice) end @@ -53,7 +53,7 @@ def catalog_doc(bib_id) end end -class CallnumberList::Error < CallnumberList +class CallNumberList::Error < CallNumberList attr_reader :original_reference def initialize(original_reference = "") @original_reference = original_reference diff --git a/lib/utilities/browse_solr_client.rb b/lib/utilities/browse_solr_client.rb index 5a131e6..8df99a3 100644 --- a/lib/utilities/browse_solr_client.rb +++ b/lib/utilities/browse_solr_client.rb @@ -39,7 +39,7 @@ def browse(rows:, sort:, range:) @conn.public_send(:get, "#{@path_prefix}/select", query) end - def exact_matches(value: callnumber) + def exact_matches(value:) query = { q: @q, fq: %(#{@match_field}:"#{value}"), diff --git a/spec/models/callnumber_item_spec.rb b/spec/models/callnumber_item_spec.rb index 00470e2..3dbcc12 100644 --- a/spec/models/callnumber_item_spec.rb +++ b/spec/models/callnumber_item_spec.rb @@ -1,5 +1,5 @@ require_relative "../spec_helper" -describe CallnumberItem do +describe CallNumberItem do before(:each) do @catalog_doc = JSON.parse(fixture("zhizn_bib.json")) @index_doc = JSON.parse(fixture("zhizn_browse.json")) @@ -11,6 +11,9 @@ it "has false match_notice?" do expect(subject.match_notice?).to eq(false) end + it "shows call_number" do + expect(subject.call_number).to eq("PQ 1852 .B85 1992") + end it "shows callnumber" do expect(subject.callnumber).to eq("PQ 1852 .B85 1992") end diff --git a/spec/models/callnumber_list_spec.rb b/spec/models/callnumber_list_spec.rb index 564ae48..f0f5579 100644 --- a/spec/models/callnumber_list_spec.rb +++ b/spec/models/callnumber_list_spec.rb @@ -1,4 +1,4 @@ -describe CallnumberList do +describe CallNumberList do before(:each) do @browse_list = instance_double(BrowseList, original_reference: "callnumber") end @@ -46,7 +46,7 @@ end end end -describe CallnumberList::Error do +describe CallNumberList::Error do before(:each) do @params = { original_reference: "OSU" diff --git a/spec/requests_spec.rb b/spec/requests_spec.rb index 4ceb64c..0549211 100644 --- a/spec/requests_spec.rb +++ b/spec/requests_spec.rb @@ -2,8 +2,8 @@ describe "requests" do include Rack::Test::Methods before(:each) do - @callnumbers_core = S.call_number_collection - @authors_core = S.authority_collection + @call_number_collection = S.call_number_collection + @authority_collection = S.authority_collection end context "get /" do it "has status OK" do @@ -13,46 +13,46 @@ end context "get /callnumber" do it "for a successful query, returns status OK" do - stub_solr_get_request(url: "#{@callnumbers_core}/select", query: hash_including({fq: 'callnumber:"Thing"'}), output: fixture("biblio_results.json")) - stub_solr_get_request(url: "#{@callnumbers_core}/select", query: hash_including({sort: "id desc"}), output: fixture("callnumbers_before.json")) - stub_solr_get_request(url: "#{@callnumbers_core}/select", query: hash_including({fq: 'id:["Thing" TO *]'}), output: fixture("callnumbers_results.json")) + stub_solr_get_request(url: "#{@call_number_collection}/select", query: hash_including({fq: 'callnumber:"Thing"'}), output: fixture("biblio_results.json")) + stub_solr_get_request(url: "#{@call_number_collection}/select", query: hash_including({sort: "id desc"}), output: fixture("callnumbers_before.json")) + stub_solr_get_request(url: "#{@call_number_collection}/select", query: hash_including({fq: 'id:["Thing" TO *]'}), output: fixture("callnumbers_results.json")) stub_biblio_get_request(url: "biblio/select", query: hash_including({}), output: fixture("biblio_results_middle.json")) get "/callnumber", {query: "Thing"} expect(last_response.status).to eq(200) end it "for a network error, it still returns a successful response, but with an error message" do - stub_solr_get_request(url: "#{@callnumbers_core}/select", query: hash_including({fq: 'callnumber:"Thing"'}), no_return: true).to_timeout - stub_solr_get_request(url: "#{@callnumbers_core}/select", query: hash_including({sort: "id desc"}), no_return: true).to_timeout + stub_solr_get_request(url: "#{@call_number_collection}/select", query: hash_including({fq: 'callnumber:"Thing"'}), no_return: true).to_timeout + stub_solr_get_request(url: "#{@call_number_collection}/select", query: hash_including({sort: "id desc"}), no_return: true).to_timeout get "/callnumber", {query: "Thing"} expect(last_response.status).to eq(200) end end context "get /author" do it "returns status OK" do - stub_solr_get_request(url: "#{@authors_core}/select", query: hash_including({fq: 'term:"Thing"'}), output: fixture("author_exact_matches.json")) - stub_solr_get_request(url: "#{@authors_core}/select", query: hash_including({sort: "id desc"}), output: fixture("author_results.json")) - stub_solr_get_request(url: "#{@authors_core}/select", query: hash_including({fq: 'id:["Thing" TO *]'}), output: fixture("author_results.json")) + stub_solr_get_request(url: "#{@authority_collection}/select", query: hash_including({fq: 'term:"Thing"'}), output: fixture("author_exact_matches.json")) + stub_solr_get_request(url: "#{@authority_collection}/select", query: hash_including({sort: "id desc"}), output: fixture("author_results.json")) + stub_solr_get_request(url: "#{@authority_collection}/select", query: hash_including({fq: 'id:["Thing" TO *]'}), output: fixture("author_results.json")) get "/author", {query: "Thing"} expect(last_response.status).to eq(200) end it "for a network error, it still returns a successful response, but with an error message" do - stub_solr_get_request(url: "#{@authors_core}/select", query: hash_including({fq: 'term:"Thing"'}), no_return: true).to_timeout - stub_solr_get_request(url: "#{@authors_core}/select", query: hash_including({sort: "id desc"}), no_return: true).to_timeout + stub_solr_get_request(url: "#{@authority_collection}/select", query: hash_including({fq: 'term:"Thing"'}), no_return: true).to_timeout + stub_solr_get_request(url: "#{@authority_collection}/select", query: hash_including({sort: "id desc"}), no_return: true).to_timeout get "/author", {query: "Thing"} expect(last_response.status).to eq(200) end end context "get /subject" do it "returns status OK" do - stub_solr_get_request(url: "#{@authors_core}/select", query: hash_including({fq: 'term:"Thing"'}), output: fixture("author_exact_matches.json")) - stub_solr_get_request(url: "#{@authors_core}/select", query: hash_including({sort: "id desc"}), output: fixture("subject_results.json")) - stub_solr_get_request(url: "#{@authors_core}/select", query: hash_including({fq: 'id:["Thing" TO *]'}), output: fixture("subject_results.json")) + stub_solr_get_request(url: "#{@authority_collection}/select", query: hash_including({fq: 'term:"Thing"'}), output: fixture("author_exact_matches.json")) + stub_solr_get_request(url: "#{@authority_collection}/select", query: hash_including({sort: "id desc"}), output: fixture("subject_results.json")) + stub_solr_get_request(url: "#{@authority_collection}/select", query: hash_including({fq: 'id:["Thing" TO *]'}), output: fixture("subject_results.json")) get "/subject", {query: "Thing"} expect(last_response.status).to eq(200) end it "for a network error, it still returns a successful response, but with an error message" do - stub_solr_get_request(url: "#{@authors_core}/select", query: hash_including({fq: 'term:"Thing"'}), no_return: true).to_timeout - stub_solr_get_request(url: "#{@authors_core}/select", query: hash_including({sort: "id desc"}), no_return: true).to_timeout + stub_solr_get_request(url: "#{@authority_collection}/select", query: hash_including({fq: 'term:"Thing"'}), no_return: true).to_timeout + stub_solr_get_request(url: "#{@authority_collection}/select", query: hash_including({sort: "id desc"}), no_return: true).to_timeout get "/subject", {query: "Thing"} expect(last_response.status).to eq(200) end diff --git a/views/call_number.erb b/views/call_number.erb index abf8fa1..bea01da 100644 --- a/views/call_number.erb +++ b/views/call_number.erb @@ -18,7 +18,7 @@ class="exact-match"<% end %>> class="strong"<% end %>> - <%= result.callnumber %> + <%= result.call_number %>