Commit 4e7230a9 authored by Andreas Brandl's avatar Andreas Brandl

Use symbol keys consistently

parent cab79f74
......@@ -12,8 +12,8 @@ module Gitlab
attr_reader :order_by
def initialize(order_by: {}, lower_bounds: nil, per_page: DEFAULT_PAGE_SIZE, end_reached: false)
@order_by = order_by.with_indifferent_access
@lower_bounds = lower_bounds
@order_by = order_by.symbolize_keys
@lower_bounds = lower_bounds&.symbolize_keys
@per_page = per_page
@end_reached = end_reached
end
......@@ -34,7 +34,7 @@ module Gitlab
# Uses identical order_by/per_page information for the next page
def next(lower_bounds, end_reached)
dup.tap do |next_page|
next_page.lower_bounds = lower_bounds
next_page.lower_bounds = lower_bounds&.symbolize_keys
next_page.end_reached = end_reached
end
end
......
......@@ -44,9 +44,9 @@ module Gitlab
end
def validate_order!(rel)
present_order = rel.order_values.map { |val| [val.expr.name, val.direction] }.last(2).to_h
present_order = rel.order_values.map { |val| [val.expr.name.to_sym, val.direction] }.last(2).to_h
unless page.order_by.with_indifferent_access == present_order.with_indifferent_access
unless page.order_by == present_order
raise ArgumentError, "Page's order_by does not match the relation's order: #{present_order} vs #{page.order_by}"
end
end
......
......@@ -33,12 +33,12 @@ describe Gitlab::Pagination::Keyset::Page do
let(:page) { described_class.new(order_by: order_by, lower_bounds: lower_bounds, per_page: per_page, end_reached: end_reached) }
subject { page.next(new_lower_bounds, new_end_reached) }
let(:order_by) { {} }
let(:lower_bounds) { double }
let(:order_by) { { id: :desc } }
let(:lower_bounds) { { id: 42 } }
let(:per_page) { 10 }
let(:end_reached) { false }
let(:new_lower_bounds) { double }
let(:new_lower_bounds) { { id: 21 } }
let(:new_end_reached) { true }
it 'copies over order_by' do
......
......@@ -14,7 +14,7 @@ describe Gitlab::Pagination::Keyset::RequestContext do
it 'extracts order_by/sorting information' do
page = subject
expect(page.order_by).to eq('id' => :desc)
expect(page.order_by).to eq(id: :desc)
end
end
......@@ -24,7 +24,7 @@ describe Gitlab::Pagination::Keyset::RequestContext do
it 'extracts order_by/sorting information and adds tie breaker' do
page = subject
expect(page.order_by).to eq('created_at' => :desc, 'id' => :desc)
expect(page.order_by).to eq(created_at: :desc, id: :desc)
end
end
......@@ -34,7 +34,7 @@ describe Gitlab::Pagination::Keyset::RequestContext do
it 'defaults to tie breaker' do
page = subject
expect(page.order_by).to eq({ 'id' => :desc })
expect(page.order_by).to eq({ id: :desc })
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment