diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-02-06 15:07:13 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-02-06 15:07:13 +0100 |
commit | a7420b77bd9b7038af3702d3665faab317048d3a (patch) | |
tree | eb96b3ec5c303aa6ea2573122586b397b1207fa9 /spec/lib | |
parent | 81eb5c7fd79897d63e733e99b8fc4424dc8ea38a (diff) | |
download | gitlab-ce-a7420b77bd9b7038af3702d3665faab317048d3a.tar.gz |
Add specs for standalone pagination for serializers
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/serializer/pagination_spec.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/lib/gitlab/serializer/pagination_spec.rb b/spec/lib/gitlab/serializer/pagination_spec.rb new file mode 100644 index 00000000000..43d9782c3b7 --- /dev/null +++ b/spec/lib/gitlab/serializer/pagination_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe Gitlab::Serializer::Pagination do + let(:request) { spy('request') } + let(:response) { spy('response') } + + before do + allow(request) + .to receive(:query_parameters) + .and_return(params) + end + + let(:pagination) { described_class.new(request, response) } + + describe '#paginate' do + subject { pagination.paginate(resource) } + + let(:resource) { User.all } + let(:params) { { page: 1, per_page: 2 } } + + context 'when a multiple resources are present in relation' do + before { create_list(:user, 3) } + + it 'correctly paginates the resource' do + expect(subject.count).to be 2 + end + + it 'appends relevant headers' do + expect(response).to receive(:[]=).with('X-Total', '3') + expect(response).to receive(:[]=).with('X-Total-Pages', '2') + expect(response).to receive(:[]=).with('X-Per-Page', '2') + + subject + end + end + + context 'when an invalid resource is about to be paginated' do + let(:resource) { create(:user) } + + it 'raises error' do + expect { subject }.to raise_error( + described_class::InvalidResourceError) + end + end + end +end |