Commit 4a3a5fe6 authored by Patrick Bajao's avatar Patrick Bajao

Show correct total number of commit diff's changes

Update the API endpoint to use the correct method for getting diff
of a commit to return correct X-Total in the response's header.

The said method uses the same limits as the ones used in the UI so
they'll be consistent.
parent 287e618b
---
title: Show correct total number of commit diff's changes
merge_request: 19424
author:
type: fixed
......@@ -169,7 +169,7 @@ module API
not_found! 'Commit' unless commit
raw_diffs = ::Kaminari.paginate_array(commit.raw_diffs.to_a)
raw_diffs = ::Kaminari.paginate_array(commit.diffs(expanded: true).diffs.to_a)
present paginate(raw_diffs), with: Entities::Diff
end
......
......@@ -1089,6 +1089,20 @@ describe API::Commits do
expect(json_response.first.keys).to include 'diff'
end
context 'when hard limits are lower than the number of files' do
before do
allow(Commit).to receive(:max_diff_options).and_return(max_files: 1)
end
it 'respects the limit' do
get api(route, current_user)
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response.size).to be <= 1
end
end
context 'when ref does not exist' do
let(:commit_id) { 'unknown' }
......
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