diff options
author | Jordan Ryan Reuter <jordan.reuter@scimedsolutions.com> | 2017-01-20 18:04:16 +0300 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2017-03-08 04:56:30 +0300 |
commit | 473cab818aff034d072f0f6c8537a584bc5aa41c (patch) | |
tree | 1425966bf2f786870bbb2a613c31123aa1743c25 /spec/models/repository_spec.rb | |
parent | 2995f48ef3158252446c5e03c138feb6c1889941 (diff) |
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/models/repository_spec.rb')
-rw-r--r-- | spec/models/repository_spec.rb | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index eb992e1354e..45acdc52d08 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1042,7 +1042,7 @@ describe Repository, models: true do it 'expires the cache for all branches' do expect(cache).to receive(:expire). - at_least(repository.branches.length). + at_least(repository.branches.length * 2). times repository.expire_branch_cache @@ -1050,14 +1050,14 @@ describe Repository, models: true do it 'expires the cache for all branches when the root branch is given' do expect(cache).to receive(:expire). - at_least(repository.branches.length). + at_least(repository.branches.length * 2). times repository.expire_branch_cache(repository.root_ref) end it 'expires the cache for a specific branch' do - expect(cache).to receive(:expire).once + expect(cache).to receive(:expire).twice repository.expire_branch_cache('foo') end @@ -1742,6 +1742,21 @@ describe Repository, models: true do end end + describe '#commit_count_for_ref' do + context 'with a non-existing repository' do + it 'returns 0' do + expect(repository).to receive(:raw_repository).and_return(nil) + expect(repository.commit_count).to eq(0) + end + end + + context 'when searching for the root ref' do + it 'returns the same count as #commit_count' do + expect(repository.commit_count_for_ref(repository.root_ref)).to eq(repository.commit_count) + end + end + end + describe '#cache_method_output', caching: true do context 'with a non-existing repository' do let(:value) do |