Skip to content

Commit

Permalink
Merge pull request #194 from mlibrary/illiad-pagination
Browse files Browse the repository at this point in the history
ILLiad Pagination
  • Loading branch information
erinesullivan authored Jul 22, 2021
2 parents 38b32a9 + ee41e1c commit 8e1a7ee
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 82 deletions.
6 changes: 3 additions & 3 deletions my_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ def dev_login?
end

get '/interlibrary-loan' do
interlibrary_loans = InterlibraryLoans.for(uniqname: session[:uniqname])
interlibrary_loans = InterlibraryLoans.for(uniqname: session[:uniqname], limit: params["limit"], offset: params["offset"], count: nil)

erb :'current-checkouts/interlibrary-loan', :locals => { interlibrary_loans: interlibrary_loans }
end
get '/scans-and-electronic-items' do
document_delivery = DocumentDelivery.for(uniqname: session[:uniqname])
document_delivery = DocumentDelivery.for(uniqname: session[:uniqname], limit: params["limit"], offset: params["offset"], count: nil)

erb :'current-checkouts/scans-and-electronic-items', :locals => { document_delivery: document_delivery }
end
Expand Down Expand Up @@ -232,7 +232,7 @@ def dev_login?


get '/interlibrary-loan' do
interlibrary_loan_requests = InterlibraryLoanRequests.for(uniqname: session[:uniqname])
interlibrary_loan_requests = InterlibraryLoanRequests.for(uniqname: session[:uniqname], limit: params["limit"], offset: params["offset"], count: nil)

erb :'pending-requests/interlibrary-loan', :locals => { interlibrary_loan_requests: interlibrary_loan_requests }
end
Expand Down
91 changes: 25 additions & 66 deletions spec/models/items/interlibrary_loan/document_delivery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
require 'json'

describe DocumentDelivery do
let(:query){{"$filter" => "RequestType eq 'Article' and TransactionStatus eq 'Delivered to Web'", "$top" => '15'}}
context "one loan" do
before(:each) do
requests = JSON.parse(File.read('./spec/fixtures/illiad_requests.json'))
body = [requests[3]].to_json
stub_illiad_get_request(url: "Transaction/UserRequests/testhelp", body: body, query: {"$filter" =>"RequestType eq 'Article' and TransactionStatus eq 'Delivered to Web'"})
stub_illiad_get_request(url: "Transaction/UserRequests/testhelp", body: body, query: query)
end
subject do
DocumentDelivery.for(uniqname: 'testhelp')
DocumentDelivery.for(uniqname: 'testhelp', count: 25)
end
context "#count" do
it "returns total request item count" do
expect(subject.count).to eq(1)
expect(subject.count).to eq(25)
end
end
context "#each" do
Expand All @@ -32,74 +33,32 @@
end
context "#item_text" do
it "returns 'item' if there is only one loan, or 'items' if there is not" do
expect(subject.item_text).to eq('item')
expect(subject.item_text).to eq('items')
end
end
end
end

describe DocumentDeliveryItem do
before(:each) do
item = JSON.parse(File.read("./spec/fixtures/illiad_requests.json"))[3]
item["PhotoItemAuthor"] = "B. Authorwoman"
@delivery = item
end
subject do
DocumentDeliveryItem.new(@delivery)
end
context "#title" do
it "returns title string" do
expect(subject.title).to eq("A Book About Things: Chapter One")
end
end
context "#author" do
it "returns author string" do
expect(subject.author).to eq("A. Authorman; B. Authorwoman")
end
end
context "#illiad_id" do
it "returns the ILLiad transaction ID" do
expect(subject.illiad_id).to eq(3298028)
end
end
context "#illiad_url" do
it "returns ILLIAD url based on action number, form number, and if the form is actually type" do
expect(subject.illiad_url(42, 1887, true)).to eq("https://ill.lib.umich.edu/illiad/illiad.dll?Action=42&Type=1887&Value=3298028")
end
end
context "#url_transaction" do
it "returns url to the ILLiad transaction" do
expect(subject.url_transaction).to eq("https://ill.lib.umich.edu/illiad/illiad.dll?Action=10&Form=72&Value=3298028")
end
end
context "#url_cancel_request" do
it "returns url to cancel the ILLiad transaction request" do
expect(subject.url_cancel_request).to eq("https://ill.lib.umich.edu/illiad/illiad.dll?Action=21&Type=10&Value=3298028")
end
end
context "#url_request_renewal" do
it "returns url to the form to request a renewal of the ILLiad transaction" do
expect(subject.url_request_renewal).to eq("https://ill.lib.umich.edu/illiad/illiad.dll?Action=11&Form=71&Value=3298028")
end
end
context "#creation_date" do
it "returns creation date string" do
expect(subject.creation_date).to eq("03/09/21")
end
end
context "#expiration_date" do
it "returns expiration date string" do
expect(subject.expiration_date).to eq('')
context "no count given" do
before(:each) do
requests = JSON.parse(File.read('./spec/fixtures/illiad_requests.json'))
body = [requests[3]].to_json
stub_illiad_get_request(url: 'Transaction/UserRequests/testhelp', body: body, query: {'$filter': query['$filter']})
end
end
context "#transaction_date" do
it "returns transaction date string" do
expect(subject.transaction_date).to eq("03/09/21")
subject do
DocumentDelivery.for(uniqname: 'testhelp', limit: '1', count: nil)
end
end
context "#renewable?" do
it "returns a boolean" do
expect(subject.renewable?).to eq(false)
context "#count" do
it "returns total number of transactions" do
expect(subject.count).to eq(1)
end
end
context "#each" do
it "returns limit number of Loan objects" do
items = ''
subject.each do |item|
items = items + item.class.name
end
expect(items).to eq("DocumentDeliveryItem"*1)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
require 'json'

describe InterlibraryLoanRequests do
let(:query){{"$filter" => "TransactionStatus ne 'Request Finished' and TransactionStatus ne 'Cancelled by ILL Staff' and TransactionStatus ne 'Cancelled by Customer' and TransactionStatus ne 'Delivered to Web' and TransactionStatus ne 'Checked Out to Customer' and ProcessType eq 'Borrowing'", "$top" => '15'}}
context "two requests" do
before(:each) do
filter = "TransactionStatus ne 'Request Finished' and TransactionStatus ne 'Cancelled by ILL Staff' and TransactionStatus ne 'Cancelled by Customer' and TransactionStatus ne 'Delivered to Web' and TransactionStatus ne 'Checked Out to Customer' and ProcessType eq 'Borrowing'"
requests = JSON.parse(File.read('./spec/fixtures/illiad_requests.json'))
requests.delete_at(0)
requests[2]["TransactionStatus"] = "Request Has Been Submitted to ILL"
requests[3]["TransactionStatus"] = "Awaiting Request Processing"
stub_illiad_get_request(url: 'Transaction/UserRequests/testhelp', body: requests.to_json, query: {"$filter" => filter})
stub_illiad_get_request(url: 'Transaction/UserRequests/testhelp', body: requests.to_json, query: query)
end
subject do
InterlibraryLoanRequests.for(uniqname: 'testhelp')
InterlibraryLoanRequests.for(uniqname: 'testhelp', count: 25)
end
context "#count" do
it "returns total request item count" do
expect(subject.count).to eq(4)
expect(subject.count).to eq(25)
end
end
context "#each" do
Expand All @@ -39,4 +39,30 @@
end
end
end
context "no count given" do
before(:each) do
requests = JSON.parse(File.read('./spec/fixtures/illiad_requests.json'))
requests.delete_at(0)
requests[2]["TransactionStatus"] = "Request Has Been Submitted to ILL"
requests[3]["TransactionStatus"] = "Awaiting Request Processing"
stub_illiad_get_request(url: 'Transaction/UserRequests/testhelp', body: requests.to_json, query: {'$filter': query['$filter']})
end
subject do
InterlibraryLoanRequests.for(uniqname: 'testhelp', limit: '1', count: nil)
end
context "#count" do
it "returns total number of transactions" do
expect(subject.count).to eq(4)
end
end
context "#each" do
it "returns limit number of Loan objects" do
items = ''
subject.each do |item|
items = items + item.class.name
end
expect(items).to eq("InterlibraryLoanRequest"*1)
end
end
end
end
35 changes: 29 additions & 6 deletions spec/models/items/interlibrary_loan/interlibrary_loans_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
require 'json'

describe InterlibraryLoans do
let(:query){{"$filter" => "RequestType eq 'Loan' and TransactionStatus eq 'Checked Out to Customer' and ProcessType eq 'Borrowing'", "$top" => '15'}}
context "one loan" do
before(:each) do
body = [ JSON.parse(File.read('./spec/fixtures/illiad_requests.json'))[0] ].to_json
filter = "RequestType eq 'Loan' and TransactionStatus eq 'Checked Out to Customer' and ProcessType eq 'Borrowing'"
stub_illiad_get_request(url: 'Transaction/UserRequests/testhelp', body: body, query: {"$filter" => filter})
stub_illiad_get_request(url: 'Transaction/UserRequests/testhelp', body: body, query: query)
end
subject do
InterlibraryLoans.for(uniqname: 'testhelp')
InterlibraryLoans.for(uniqname: 'testhelp', count: 25)
end
context "#count" do
it "returns total request item count" do
expect(subject.count).to eq(1)
expect(subject.count).to eq(25)
end
end
context "#each" do
Expand All @@ -22,7 +22,7 @@
subject.each do |item|
items = items + item.class.name
end
expect(items).to eq('InterlibraryLoan')
expect(items).to eq('InterlibraryLoan'*1)
end
end
context "#empty?" do
Expand All @@ -32,7 +32,30 @@
end
context "#item_text" do
it "returns 'item' if there is only one loan, or 'items' if there is not" do
expect(subject.item_text).to eq('item')
expect(subject.item_text).to eq('items')
end
end
end
context "no count given" do
before(:each) do
body = [ JSON.parse(File.read('./spec/fixtures/illiad_requests.json'))[0] ].to_json
stub_illiad_get_request(url: 'Transaction/UserRequests/testhelp', body: body, query: {'$filter': query['$filter']})
end
subject do
InterlibraryLoans.for(uniqname: 'testhelp', limit: '1', count: nil)
end
context "#count" do
it "returns total number of transactions" do
expect(subject.count).to eq(1)
end
end
context "#each" do
it "returns limit number of Loan objects" do
items = ''
subject.each do |item|
items = items + item.class.name
end
expect(items).to eq("InterlibraryLoan"*1)
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion views/current-checkouts/interlibrary-loan.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<table>
<caption>
<div class="caption-flex">
<p>Showing <span class="strong"><%= interlibrary_loans.count %></span> <%= interlibrary_loans.item_text %></p>
<p>Showing <span class="strong"><%= interlibrary_loans.pagination.first %></span> - <span class="strong"><%= interlibrary_loans.pagination.last %></span> of <span class="strong"><%= interlibrary_loans.count %></span> <%= interlibrary_loans.item_text %></p>
</div>
</caption>
<thead>
Expand Down Expand Up @@ -46,4 +46,6 @@
</table>
</div>

<%= erb :'components/pagination', locals: {pagination: interlibrary_loans.pagination, count: interlibrary_loans.count} %>
<% end %>
4 changes: 3 additions & 1 deletion views/current-checkouts/scans-and-electronic-items.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<table>
<caption>
<div class="caption-flex">
<p>Showing <span class="strong"><%= document_delivery.count %></span> <%= document_delivery.item_text %></p>
<p>Showing <span class="strong"><%= document_delivery.pagination.first %></span> - <span class="strong"><%= document_delivery.pagination.last %></span> of <span class="strong"><%= document_delivery.count %></span> <%= document_delivery.item_text %></p>
</div>
</caption>
<thead>
Expand Down Expand Up @@ -42,4 +42,6 @@
</table>
</div>

<%= erb :'components/pagination', locals: {pagination: document_delivery.pagination, count: document_delivery.count} %>
<% end %>
4 changes: 3 additions & 1 deletion views/pending-requests/interlibrary-loan.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<table>
<caption>
<div class="caption-flex">
<p>Showing <span class="strong"><%= interlibrary_loan_requests.count %></span> <%= interlibrary_loan_requests.item_text %></p>
<p>Showing <span class="strong"><%= interlibrary_loan_requests.pagination.first %></span> - <span class="strong"><%= interlibrary_loan_requests.pagination.last %></span> of <span class="strong"><%= interlibrary_loan_requests.count %></span> <%= interlibrary_loan_requests.item_text %></p>
</div>
</caption>
<thead>
Expand Down Expand Up @@ -37,4 +37,6 @@
</table>
</div>

<%= erb :'components/pagination', locals: {pagination: interlibrary_loan_requests.pagination, count: interlibrary_loan_requests.count} %>
<% end %>

0 comments on commit 8e1a7ee

Please sign in to comment.