summaryrefslogtreecommitdiff
path: root/spec/requests
diff options
context:
space:
mode:
authorJordan Ryan Reuter <jordan.reuter@scimedsolutions.com>2017-01-20 10:04:16 -0500
committerOswaldo Ferreira <oswaldo@gitlab.com>2017-03-07 22:56:30 -0300
commit473cab818aff034d072f0f6c8537a584bc5aa41c (patch)
tree1425966bf2f786870bbb2a613c31123aa1743c25 /spec/requests
parent2995f48ef3158252446c5e03c138feb6c1889941 (diff)
downloadgitlab-ce-473cab818aff034d072f0f6c8537a584bc5aa41c.tar.gz
Manually set total_count when paginating commits
`Kaminari.paginate_array` takes some options, most relevant of which is a `total_count` parameter. Using the `commit_count` for `total_count` lets us correctly treat the return of `Repository#commits` as a subset of all the commits we may wish to list. Addition of a new `Repository#commit_count_for_ref` method was necessarry to allow the user to start from an arbitrary ref. Ref #1381
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/commits_spec.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb
index 5190fcca2d1..1d298988f17 100644
--- a/spec/requests/api/commits_spec.rb
+++ b/spec/requests/api/commits_spec.rb
@@ -86,6 +86,43 @@ describe API::Commits, api: true do
expect(json_response.first["id"]).to eq("570e7b2abdd848b95f2f578043fc23bd6f6fd24d")
end
end
+
+ context 'pagination' do
+ it_behaves_like 'a paginated resources'
+
+ let(:page) { 0 }
+ let(:per_page) { 5 }
+ let(:ref_name) { 'master' }
+ let!(:request) do
+ get api("/projects/#{project.id}/repository/commits?page=#{page}&per_page=#{per_page}&ref_name=#{ref_name}", user)
+ end
+
+ it 'returns the commit count in the correct header' do
+ commit_count = project.repository.commit_count_for_ref(ref_name).to_s
+
+ expect(response.headers['X-Total']).to eq(commit_count)
+ end
+
+ context 'viewing the first page' do
+ it 'returns the first 5 commits' do
+ commit = project.repository.commit
+
+ expect(json_response.size).to eq(per_page)
+ expect(json_response.first['id']).to eq(commit.id)
+ end
+ end
+
+ context 'viewing the second page' do
+ let(:page) { 1 }
+
+ it 'returns the second 5 commits' do
+ commit = project.repository.commits('HEAD', offset: per_page * page).first
+
+ expect(json_response.size).to eq(per_page)
+ expect(json_response.first['id']).to eq(commit.id)
+ end
+ end
+ end
end
describe "Create a commit with multiple files and actions" do