diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-26 15:10:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-26 15:10:28 +0300 |
commit | 6a0a4a80f740ccde8a1b4c6c757cb77286e0eec9 (patch) | |
tree | 673b9a5a8461b9be27efd02427fd9e4df2a39c6f /spec/lib | |
parent | c8a7e4ada117b968f841c2bb300fadc421cb3e98 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/checks/changes_access_spec.rb | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/spec/lib/gitlab/checks/changes_access_spec.rb b/spec/lib/gitlab/checks/changes_access_spec.rb index b6914a0a8f1..633c4baa931 100644 --- a/spec/lib/gitlab/checks/changes_access_spec.rb +++ b/spec/lib/gitlab/checks/changes_access_spec.rb @@ -174,6 +174,101 @@ RSpec.describe Gitlab::Checks::ChangesAccess do end end + describe '#single_change_accesses' do + let(:commits_for) { {} } + let(:expected_accesses) { [] } + + shared_examples '#single_change_access' do + before do + commits_for.each do |id, commits| + expect(subject) + .to receive(:commits_for) + .with(id) + .and_return(commits) + end + end + + it 'returns an array of SingleChangeAccess' do + # Commits are wrapped in a Gitlab::Lazy and thus need to be resolved + # first such that we can directly compare types. + actual_accesses = subject.single_change_accesses + .each { |access| access.instance_variable_set(:@commits, access.commits.to_a) } + + expect(actual_accesses).to match_array(expected_accesses) + end + end + + context 'with no changes' do + let(:changes) { [] } + + it_behaves_like '#single_change_access' + end + + context 'with a single change and no new commits' do + let(:commits_for) { { 'new' => [] } } + let(:changes) do + [ + { oldrev: 'old', newrev: 'new', ref: 'refs/heads/branch' } + ] + end + + let(:expected_accesses) do + [ + have_attributes(oldrev: 'old', newrev: 'new', ref: 'refs/heads/branch', commits: []) + ] + end + + it_behaves_like '#single_change_access' + end + + context 'with a single change and new commits' do + let(:commits_for) { { 'new' => [create_commit('new', [])] } } + let(:changes) do + [ + { oldrev: 'old', newrev: 'new', ref: 'refs/heads/branch' } + ] + end + + let(:expected_accesses) do + [ + have_attributes(oldrev: 'old', newrev: 'new', ref: 'refs/heads/branch', commits: [create_commit('new', [])]) + ] + end + + it_behaves_like '#single_change_access' + end + + context 'with multiple changes' do + let(:commits_for) do + { + 'a' => [create_commit('a', [])], + 'c' => [create_commit('c', [])], + 'd' => [] + } + end + + let(:changes) do + [ + { newrev: 'a', ref: 'refs/heads/a' }, + { oldrev: 'b', ref: 'refs/heads/b' }, + { oldrev: 'a', newrev: 'c', ref: 'refs/heads/c' }, + { newrev: 'd', ref: 'refs/heads/d' } + ] + end + + let(:expected_accesses) do + [ + have_attributes(newrev: 'a', ref: 'refs/heads/a', commits: [create_commit('a', [])]), + have_attributes(oldrev: 'b', ref: 'refs/heads/b', commits: []), + have_attributes(oldrev: 'a', newrev: 'c', ref: 'refs/heads/c', commits: [create_commit('c', [])]), + have_attributes(newrev: 'd', ref: 'refs/heads/d', commits: []) + ] + end + + it_behaves_like '#single_change_access' + end + end + def create_commit(id, parent_ids) Gitlab::Git::Commit.new(project.repository, { id: id, |