debian-mirror-gitlab/spec/finders/context_commits_finder_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
2 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe ContextCommitsFinder do
2020-03-13 15:44:24 +05:30
describe "#execute" do
let(:project) { create(:project, :repository) }
2022-10-11 01:57:18 +05:30
let(:merge_request) { create(:merge_request, source_branch: 'feature', target_branch: 'master') }
2020-03-13 15:44:24 +05:30
let(:commit) { create(:commit, id: '6d394385cf567f80a8fd85055db1ab4c5295806f') }
it 'filters commits by valid sha/commit message' do
params = { search: commit.id }
commits = described_class.new(project, merge_request, params).execute
expect(commits.length).to eq(1)
expect(commits[0].id).to eq(commit.id)
end
it 'returns nothing when searched by invalid sha/commit message' do
params = { search: 'zzz' }
commits = described_class.new(project, merge_request, params).execute
expect(commits).to be_empty
end
2022-10-11 01:57:18 +05:30
it 'returns commits based in author filter' do
2023-06-20 00:43:36 +05:30
params = { author: 'Job van der Voort' }
2022-10-11 01:57:18 +05:30
commits = described_class.new(project, merge_request, params).execute
expect(commits.length).to eq(1)
expect(commits[0].id).to eq('b83d6e391c22777fca1ed3012fce84f633d7fed0')
end
2023-06-20 00:43:36 +05:30
it 'returns commits based in committed before and after filter' do
params = { committed_before: 1471631400, committed_after: 1471458600 } # August 18, 2016 - # August 20, 2016
2022-10-11 01:57:18 +05:30
commits = described_class.new(project, merge_request, params).execute
2023-06-20 00:43:36 +05:30
expect(commits.length).to eq(2)
expect(commits[0].id).to eq('1b12f15a11fc6e62177bef08f47bc7b5ce50b141')
expect(commits[1].id).to eq('38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e')
2022-10-11 01:57:18 +05:30
end
2023-06-20 00:43:36 +05:30
it 'returns commits from target branch if no filter is applied' do
expect(project.repository).to receive(:commits).with(merge_request.target_branch, anything).and_call_original
2022-10-11 01:57:18 +05:30
2023-06-20 00:43:36 +05:30
commits = described_class.new(project, merge_request).execute
expect(commits.length).to eq(37)
2022-10-11 01:57:18 +05:30
expect(commits[0].id).to eq('b83d6e391c22777fca1ed3012fce84f633d7fed0')
2023-06-20 00:43:36 +05:30
expect(commits[1].id).to eq('498214de67004b1da3d820901307bed2a68a8ef6')
2022-10-11 01:57:18 +05:30
end
2020-03-13 15:44:24 +05:30
end
end