Skip to content

Commit

Permalink
fixed pagination for circ history to have default direction be DESC
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Aug 5, 2021
1 parent d29a081 commit 4b91933
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
12 changes: 11 additions & 1 deletion lib/pagination/pagination_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def page_number

private_constant :Page
private
def default_direction
'ASC'
end
def page(page)
url = path(page.offset)
Page.new(page: page, url: url)
Expand All @@ -52,7 +55,7 @@ def path(offset)
query = []
query.push("offset=#{offset}") if offset > 0
query.push("limit=#{@limit}") if @limit != 15
query.push("direction=#{@direction}") if @direction != 'ASC'
query.push("direction=#{@direction}") if @direction != default_direction
query.push("order_by=#{@order_by}") if @order_by != 'due_date'
query_string = query.join('&')
query_string = nil if query_string == ''
Expand All @@ -62,3 +65,10 @@ def path(offset)


end

class CirculationHistoryPaginationDecorator < PaginationDecorator
private
def default_direction
'DESC'
end
end
4 changes: 2 additions & 2 deletions models/items/circ_history/circ_history_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def self.for(uniqname:, offset: nil, limit: nil,
pagination_params[:limit] = limit unless limit.nil?
pagination_params[:current_offset] = offset unless offset.nil?
pagination_params[:order_by] = order_by unless order_by.nil?
pagination_params[:direction] = direction unless direction.nil?
CirculationHistoryItems.new(parsed_response: pr, pagination: PaginationDecorator.new(**pagination_params) )
direction.nil? ? pagination_params[:direction] = 'DESC' : pagination_params[:direction] = direction
CirculationHistoryItems.new(parsed_response: pr, pagination: CirculationHistoryPaginationDecorator.new(**pagination_params) )
else
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/models/items/circ_history/past_loans_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
@loan = loans["loans"].delete_at(0).to_json
end
it "requests loans sorted by title" do
stub_circ_history_get_request( url: 'users/emcard/loans', output: @loan, query: { "offset" => 1, "limit" => 1, "direction" => "DESC", "order_by" => "title"} )
loans = described_class.for(uniqname: 'emcard', offset: 1, limit: 1, direction: "DESC", order_by: "title")
expect(loans.pagination.next.url).to include("direction=DESC")
stub_circ_history_get_request( url: 'users/emcard/loans', output: @loan, query: { "offset" => 1, "limit" => 1, "direction" => "ASC", "order_by" => "title"} )
loans = described_class.for(uniqname: 'emcard', offset: 1, limit: 1, direction: "ASC", order_by: "title")
expect(loans.pagination.next.url).to include("direction=ASC")
expect(loans.pagination.next.url).to include("order_by=title")
end
end
Expand Down

0 comments on commit 4b91933

Please sign in to comment.