Skip to content

Commit

Permalink
changing from callnumber to call_number as much as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Dec 15, 2023
1 parent 54d7c12 commit 9db80e1
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 32 deletions.
12 changes: 6 additions & 6 deletions catalog-browse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CallnumberItem
class CallNumberItem
def initialize(browse_doc:, catalog_doc:, exact_match:)
@browse_doc = browse_doc
@catalog_doc = catalog_doc || {}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/utilities/browse_solr_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"),
Expand Down
5 changes: 4 additions & 1 deletion spec/models/callnumber_item_spec.rb
Original file line number Diff line number Diff line change
@@ -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"))
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/models/callnumber_list_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe CallnumberList do
describe CallNumberList do
before(:each) do
@browse_list = instance_double(BrowseList, original_reference: "callnumber")
end
Expand Down Expand Up @@ -46,7 +46,7 @@
end
end
end
describe CallnumberList::Error do
describe CallNumberList::Error do
before(:each) do
@params = {
original_reference: "OSU"
Expand Down
34 changes: 17 additions & 17 deletions spec/requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion views/call_number.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<tr <% if result.exact_match? %>class="exact-match"<% end %>>
<td>
<span <% if result.exact_match? %>class="strong"<% end %>>
<%= result.callnumber %>
<%= result.call_number %>
</span>
</td>
<td class="column-main">
Expand Down

0 comments on commit 9db80e1

Please sign in to comment.