2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Diff::FileCollection::Compare do
|
2018-12-05 23:21:45 +05:30
|
|
|
include RepoHelpers
|
|
|
|
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:commit) { project.commit }
|
|
|
|
let(:start_commit) { sample_image_commit }
|
|
|
|
let(:head_commit) { sample_commit }
|
|
|
|
let(:raw_compare) do
|
|
|
|
Gitlab::Git::Compare.new(project.repository.raw_repository,
|
|
|
|
start_commit.id,
|
|
|
|
head_commit.id)
|
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
let(:diffable) { Compare.new(raw_compare, project) }
|
2023-03-04 22:38:38 +05:30
|
|
|
let(:diff_options) { {} }
|
2021-09-30 23:02:18 +05:30
|
|
|
let(:collection_default_args) do
|
|
|
|
{
|
|
|
|
project: diffable.project,
|
2023-03-04 22:38:38 +05:30
|
|
|
diff_options: diff_options,
|
2021-09-30 23:02:18 +05:30
|
|
|
diff_refs: diffable.diff_refs
|
|
|
|
}
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
it_behaves_like 'diff statistics' do
|
2018-12-05 23:21:45 +05:30
|
|
|
let(:stub_path) { '.gitignore' }
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
it_behaves_like 'sortable diff files' do
|
|
|
|
let(:unsorted_diff_files_paths) do
|
|
|
|
[
|
|
|
|
'.DS_Store',
|
|
|
|
'.gitignore',
|
|
|
|
'.gitmodules',
|
|
|
|
'Gemfile.zip',
|
|
|
|
'files/.DS_Store',
|
|
|
|
'files/ruby/popen.rb',
|
|
|
|
'files/ruby/regex.rb',
|
|
|
|
'files/ruby/version_info.rb',
|
|
|
|
'gitlab-shell'
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:sorted_diff_files_paths) do
|
|
|
|
[
|
|
|
|
'files/ruby/popen.rb',
|
|
|
|
'files/ruby/regex.rb',
|
|
|
|
'files/ruby/version_info.rb',
|
|
|
|
'files/.DS_Store',
|
|
|
|
'.DS_Store',
|
|
|
|
'.gitignore',
|
|
|
|
'.gitmodules',
|
|
|
|
'Gemfile.zip',
|
|
|
|
'gitlab-shell'
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
describe '#cache_key' do
|
|
|
|
subject(:cache_key) { described_class.new(diffable, **collection_default_args).cache_key }
|
|
|
|
|
|
|
|
it 'returns with head and base' do
|
|
|
|
expect(cache_key).to eq ['compare', head_commit.id, start_commit.id]
|
|
|
|
end
|
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
describe 'pagination methods' do
|
|
|
|
subject(:compare) { described_class.new(diffable, **collection_default_args) }
|
|
|
|
|
|
|
|
context 'when pagination options are not present' do
|
|
|
|
it 'returns default values' do
|
|
|
|
expect(compare.limit_value).to eq(Kaminari.config.default_per_page)
|
|
|
|
expect(compare.current_page).to eq(1)
|
|
|
|
expect(compare.next_page).to be_nil
|
|
|
|
expect(compare.prev_page).to be_nil
|
|
|
|
expect(compare.total_count).to be_nil
|
|
|
|
expect(compare.total_pages).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pagination options are present' do
|
|
|
|
let(:diff_options) { { page: 1, per_page: 10, count: 20 } }
|
|
|
|
|
|
|
|
it 'returns values based on options' do
|
|
|
|
expect(compare.limit_value).to eq(10)
|
|
|
|
expect(compare.current_page).to eq(1)
|
|
|
|
expect(compare.next_page).to eq(2)
|
|
|
|
expect(compare.prev_page).to be_nil
|
|
|
|
expect(compare.total_count).to eq(20)
|
|
|
|
expect(compare.total_pages).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|