Commit d8058520 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'jej/fix-scim-pagination-integer-handling' into 'master'

SCIM pagination startIndex handles string input

See merge request gitlab-org/gitlab!19331
parents 51e1569b 9739eea3
......@@ -5,10 +5,16 @@ module ScimPaginatable
class_methods do
def scim_paginate(start_index:, count:)
one_based_index = [start_index.presence || 1, 1].max
one_based_index = [start_index.to_i, 1].max
zero_based_index = one_based_index - 1
offset(zero_based_index).limit(count)
scim_paginate_with_offset_and_limit(offset: zero_based_index, limit: count.to_i)
end
private
def scim_paginate_with_offset_and_limit(offset:, limit:)
offset(offset).limit(limit)
end
end
end
---
title: SCIM pagination startIndex handles string input
merge_request: 19331
author:
type: fixed
......@@ -59,7 +59,7 @@ describe ::EE::API::Helpers::ScimPagination do
end
it 'uses a 1-based index' do
query = { startIndex: 1 }
query = { startIndex: '1' }
result = pagination_class.new(query).scim_paginate(resource)
......
......@@ -16,9 +16,21 @@ describe ScimPaginatable do
end
it 'translates a 1-based index to an offset of 0' do
expect(paginatable_class).to receive(:offset).with(0).and_return(double(limit: double))
expect(paginatable_class).to receive(:scim_paginate_with_offset_and_limit).with(offset: 0, limit: count)
paginatable_class.scim_paginate(start_index: start_index, count: count)
paginatable_class.scim_paginate(start_index: 1, count: count)
end
it 'handles string input' do
expect(paginatable_class).to receive(:scim_paginate_with_offset_and_limit).with(offset: start_index - 1, limit: count)
paginatable_class.scim_paginate(start_index: start_index.to_s, count: count.to_s)
end
it 'defaults to offset of 0' do
expect(paginatable_class).to receive(:scim_paginate_with_offset_and_limit).with(offset: 0, limit: count)
paginatable_class.scim_paginate(start_index: '', count: count)
end
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