2018-02-28 05:22:04 -05:00
|
|
|
# coding: utf-8
|
2015-06-09 10:43:08 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Gitlab::ProjectSearchResults do
|
2016-03-17 16:48:19 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2015-06-09 10:43:08 -04:00
|
|
|
let(:query) { 'hello world' }
|
|
|
|
|
|
|
|
describe 'initialize with empty ref' do
|
2016-11-10 12:27:09 -05:00
|
|
|
let(:results) { described_class.new(user, project, query, '') }
|
2015-06-09 10:43:08 -04:00
|
|
|
|
|
|
|
it { expect(results.project).to eq(project) }
|
2015-10-14 19:14:24 -04:00
|
|
|
it { expect(results.query).to eq('hello world') }
|
2015-06-09 10:43:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'initialize with ref' do
|
|
|
|
let(:ref) { 'refs/heads/test' }
|
2016-11-10 12:27:09 -05:00
|
|
|
let(:results) { described_class.new(user, project, query, ref) }
|
2015-06-09 10:43:08 -04:00
|
|
|
|
|
|
|
it { expect(results.project).to eq(project) }
|
|
|
|
it { expect(results.repository_ref).to eq(ref) }
|
2015-10-14 19:14:24 -04:00
|
|
|
it { expect(results.query).to eq('hello world') }
|
2015-06-09 10:43:08 -04:00
|
|
|
end
|
2016-03-17 16:48:19 -04:00
|
|
|
|
2016-11-10 12:27:09 -05:00
|
|
|
describe 'blob search' do
|
2017-04-24 11:09:29 -04:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
|
|
|
|
subject(:results) { described_class.new(user, project, 'files').objects('blobs') }
|
|
|
|
|
|
|
|
context 'when repository is disabled' do
|
|
|
|
let(:project) { create(:project, :public, :repository, :repository_disabled) }
|
|
|
|
|
|
|
|
it 'hides blobs from members' do
|
|
|
|
project.add_reporter(user)
|
|
|
|
|
|
|
|
is_expected.to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'hides blobs from non-members' do
|
|
|
|
is_expected.to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when repository is internal' do
|
|
|
|
let(:project) { create(:project, :public, :repository, :repository_private) }
|
|
|
|
|
|
|
|
it 'finds blobs for members' do
|
|
|
|
project.add_reporter(user)
|
|
|
|
|
|
|
|
is_expected.not_to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'hides blobs from non-members' do
|
|
|
|
is_expected.to be_empty
|
|
|
|
end
|
|
|
|
end
|
2016-11-10 12:27:09 -05:00
|
|
|
|
|
|
|
it 'finds by name' do
|
2017-05-12 03:16:33 -04:00
|
|
|
expect(results.map(&:first)).to include('files/images/wm.svg')
|
2016-11-10 12:27:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds by content' do
|
|
|
|
blob = results.select { |result| result.first == "CHANGELOG" }.flatten.last
|
|
|
|
|
|
|
|
expect(blob.filename).to eq("CHANGELOG")
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'parsing results' do
|
|
|
|
let(:results) { project.repository.search_files_by_content('feature', 'master') }
|
|
|
|
let(:search_result) { results.first }
|
|
|
|
|
|
|
|
subject { described_class.parse_search_result(search_result) }
|
|
|
|
|
2017-04-03 13:31:52 -04:00
|
|
|
it "returns a valid FoundBlob" do
|
|
|
|
is_expected.to be_an Gitlab::SearchResults::FoundBlob
|
|
|
|
expect(subject.id).to be_nil
|
|
|
|
expect(subject.path).to eq('CHANGELOG')
|
2016-11-10 12:27:09 -05:00
|
|
|
expect(subject.filename).to eq('CHANGELOG')
|
|
|
|
expect(subject.basename).to eq('CHANGELOG')
|
|
|
|
expect(subject.ref).to eq('master')
|
|
|
|
expect(subject.startline).to eq(188)
|
|
|
|
expect(subject.data.lines[2]).to eq(" - Feature: Replace teams with group membership\n")
|
|
|
|
end
|
|
|
|
|
2018-01-15 09:49:27 -05:00
|
|
|
context 'when the matching filename contains a colon' do
|
2018-03-15 12:11:20 -04:00
|
|
|
let(:search_result) { "master:testdata/project::function1.yaml\x001\x00---\n" }
|
2018-01-15 09:49:27 -05:00
|
|
|
|
|
|
|
it 'returns a valid FoundBlob' do
|
|
|
|
expect(subject.filename).to eq('testdata/project::function1.yaml')
|
|
|
|
expect(subject.basename).to eq('testdata/project::function1')
|
|
|
|
expect(subject.ref).to eq('master')
|
|
|
|
expect(subject.startline).to eq(1)
|
2018-03-15 12:11:20 -04:00
|
|
|
expect(subject.data).to eq("---\n")
|
2018-01-15 09:49:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the matching content contains a number surrounded by colons' do
|
2018-03-15 12:11:20 -04:00
|
|
|
let(:search_result) { "master:testdata/foo.txt\x001\x00blah:9:blah" }
|
2018-01-15 09:49:27 -05:00
|
|
|
|
|
|
|
it 'returns a valid FoundBlob' do
|
|
|
|
expect(subject.filename).to eq('testdata/foo.txt')
|
|
|
|
expect(subject.basename).to eq('testdata/foo')
|
|
|
|
expect(subject.ref).to eq('master')
|
|
|
|
expect(subject.startline).to eq(1)
|
|
|
|
expect(subject.data).to eq('blah:9:blah')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-15 12:11:20 -04:00
|
|
|
context 'when the search result ends with an empty line' do
|
|
|
|
let(:results) { project.repository.search_files_by_content('Role models', 'master') }
|
|
|
|
|
|
|
|
it 'returns a valid FoundBlob that ends with an empty line' do
|
|
|
|
expect(subject.filename).to eq('files/markdown/ruby-style-guide.md')
|
|
|
|
expect(subject.basename).to eq('files/markdown/ruby-style-guide')
|
|
|
|
expect(subject.ref).to eq('master')
|
|
|
|
expect(subject.startline).to eq(1)
|
|
|
|
expect(subject.data).to eq("# Prelude\n\n> Role models are important. <br/>\n> -- Officer Alex J. Murphy / RoboCop\n\n")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-28 05:22:04 -05:00
|
|
|
context 'when the search returns non-ASCII data' do
|
|
|
|
context 'with UTF-8' do
|
2018-03-12 06:43:13 -04:00
|
|
|
let(:results) { project.repository.search_files_by_content('файл', 'master') }
|
2018-02-28 05:22:04 -05:00
|
|
|
|
|
|
|
it 'returns results as UTF-8' do
|
|
|
|
expect(subject.filename).to eq('encoding/russian.rb')
|
|
|
|
expect(subject.basename).to eq('encoding/russian')
|
|
|
|
expect(subject.ref).to eq('master')
|
|
|
|
expect(subject.startline).to eq(1)
|
2018-03-15 12:11:20 -04:00
|
|
|
expect(subject.data).to eq("Хороший файл\n")
|
2018-03-12 06:43:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with UTF-8 in the filename' do
|
|
|
|
let(:results) { project.repository.search_files_by_content('webhook', 'master') }
|
|
|
|
|
|
|
|
it 'returns results as UTF-8' do
|
|
|
|
expect(subject.filename).to eq('encoding/テスト.txt')
|
|
|
|
expect(subject.basename).to eq('encoding/テスト')
|
|
|
|
expect(subject.ref).to eq('master')
|
|
|
|
expect(subject.startline).to eq(3)
|
|
|
|
expect(subject.data).to include('WebHookの確認')
|
2018-02-28 05:22:04 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with ISO-8859-1' do
|
|
|
|
let(:search_result) { "master:encoding/iso8859.txt\x001\x00\xC4\xFC\nmaster:encoding/iso8859.txt\x002\x00\nmaster:encoding/iso8859.txt\x003\x00foo\n".force_encoding(Encoding::ASCII_8BIT) }
|
|
|
|
|
|
|
|
it 'returns results as UTF-8' do
|
|
|
|
expect(subject.filename).to eq('encoding/iso8859.txt')
|
|
|
|
expect(subject.basename).to eq('encoding/iso8859')
|
|
|
|
expect(subject.ref).to eq('master')
|
|
|
|
expect(subject.startline).to eq(1)
|
2018-03-15 12:11:20 -04:00
|
|
|
expect(subject.data).to eq("Äü\n\nfoo\n")
|
2018-02-28 05:22:04 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-10 12:27:09 -05:00
|
|
|
context "when filename has extension" do
|
2018-01-15 09:49:27 -05:00
|
|
|
let(:search_result) { "master:CONTRIBUTE.md\x005\x00- [Contribute to GitLab](#contribute-to-gitlab)\n" }
|
2016-11-10 12:27:09 -05:00
|
|
|
|
2017-04-03 13:31:52 -04:00
|
|
|
it { expect(subject.path).to eq('CONTRIBUTE.md') }
|
2016-11-10 12:27:09 -05:00
|
|
|
it { expect(subject.filename).to eq('CONTRIBUTE.md') }
|
|
|
|
it { expect(subject.basename).to eq('CONTRIBUTE') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when file under directory" do
|
2018-01-15 09:49:27 -05:00
|
|
|
let(:search_result) { "master:a/b/c.md\x005\x00a b c\n" }
|
2016-11-10 12:27:09 -05:00
|
|
|
|
2017-04-03 13:31:52 -04:00
|
|
|
it { expect(subject.path).to eq('a/b/c.md') }
|
2016-11-10 12:27:09 -05:00
|
|
|
it { expect(subject.filename).to eq('a/b/c.md') }
|
|
|
|
it { expect(subject.basename).to eq('a/b/c') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-24 11:09:29 -04:00
|
|
|
describe 'wiki search' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :public) }
|
2017-04-24 11:09:29 -04:00
|
|
|
let(:wiki) { build(:project_wiki, project: project) }
|
|
|
|
let!(:wiki_page) { wiki.create_page('Title', 'Content') }
|
|
|
|
|
|
|
|
subject(:results) { described_class.new(user, project, 'Content').objects('wiki_blobs') }
|
|
|
|
|
|
|
|
context 'when wiki is disabled' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :public, :wiki_disabled) }
|
2017-04-24 11:09:29 -04:00
|
|
|
|
|
|
|
it 'hides wiki blobs from members' do
|
|
|
|
project.add_reporter(user)
|
|
|
|
|
|
|
|
is_expected.to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'hides wiki blobs from non-members' do
|
|
|
|
is_expected.to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when wiki is internal' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :public, :wiki_private) }
|
2017-04-24 11:09:29 -04:00
|
|
|
|
2017-05-23 06:40:18 -04:00
|
|
|
it 'finds wiki blobs for guest' do
|
|
|
|
project.add_guest(user)
|
2017-04-24 11:09:29 -04:00
|
|
|
|
|
|
|
is_expected.not_to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'hides wiki blobs from non-members' do
|
|
|
|
is_expected.to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds by content' do
|
2018-01-15 09:49:27 -05:00
|
|
|
expect(results).to include("master:Title.md\x001\x00Content\n")
|
2017-04-24 11:09:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-22 05:25:04 -05:00
|
|
|
it 'does not list issues on private projects' do
|
|
|
|
issue = create(:issue, project: project)
|
|
|
|
|
|
|
|
results = described_class.new(user, project, issue.title)
|
|
|
|
|
|
|
|
expect(results.objects('issues')).not_to include issue
|
|
|
|
end
|
|
|
|
|
2016-03-17 16:48:19 -04:00
|
|
|
describe 'confidential issues' do
|
|
|
|
let(:query) { 'issue' }
|
|
|
|
let(:author) { create(:user) }
|
|
|
|
let(:assignee) { create(:user) }
|
|
|
|
let(:non_member) { create(:user) }
|
|
|
|
let(:member) { create(:user) }
|
|
|
|
let(:admin) { create(:admin) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :internal) }
|
2016-03-17 16:48:19 -04:00
|
|
|
let!(:issue) { create(:issue, project: project, title: 'Issue 1') }
|
|
|
|
let!(:security_issue_1) { create(:issue, :confidential, project: project, title: 'Security issue 1', author: author) }
|
2017-05-04 08:11:15 -04:00
|
|
|
let!(:security_issue_2) { create(:issue, :confidential, title: 'Security issue 2', project: project, assignees: [assignee]) }
|
2016-03-17 16:48:19 -04:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not list project confidential issues for non project members' do
|
2016-03-17 16:48:19 -04:00
|
|
|
results = described_class.new(non_member, project, query)
|
|
|
|
issues = results.objects('issues')
|
|
|
|
|
|
|
|
expect(issues).to include issue
|
|
|
|
expect(issues).not_to include security_issue_1
|
|
|
|
expect(issues).not_to include security_issue_2
|
2018-03-05 08:25:56 -05:00
|
|
|
expect(results.limited_issues_count).to eq 1
|
2016-03-17 16:48:19 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not list project confidential issues for project members with guest role' do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_guest(member)
|
2016-06-06 15:13:31 -04:00
|
|
|
|
|
|
|
results = described_class.new(member, project, query)
|
|
|
|
issues = results.objects('issues')
|
|
|
|
|
|
|
|
expect(issues).to include issue
|
|
|
|
expect(issues).not_to include security_issue_1
|
|
|
|
expect(issues).not_to include security_issue_2
|
2018-03-05 08:25:56 -05:00
|
|
|
expect(results.limited_issues_count).to eq 1
|
2016-06-06 15:13:31 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'lists project confidential issues for author' do
|
2016-03-17 16:48:19 -04:00
|
|
|
results = described_class.new(author, project, query)
|
|
|
|
issues = results.objects('issues')
|
|
|
|
|
|
|
|
expect(issues).to include issue
|
|
|
|
expect(issues).to include security_issue_1
|
|
|
|
expect(issues).not_to include security_issue_2
|
2018-03-05 08:25:56 -05:00
|
|
|
expect(results.limited_issues_count).to eq 2
|
2016-03-17 16:48:19 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'lists project confidential issues for assignee' do
|
2016-11-10 12:27:09 -05:00
|
|
|
results = described_class.new(assignee, project, query)
|
2016-03-17 16:48:19 -04:00
|
|
|
issues = results.objects('issues')
|
|
|
|
|
|
|
|
expect(issues).to include issue
|
|
|
|
expect(issues).not_to include security_issue_1
|
|
|
|
expect(issues).to include security_issue_2
|
2018-03-05 08:25:56 -05:00
|
|
|
expect(results.limited_issues_count).to eq 2
|
2016-03-17 16:48:19 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'lists project confidential issues for project members' do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(member)
|
2016-03-17 16:48:19 -04:00
|
|
|
|
|
|
|
results = described_class.new(member, project, query)
|
|
|
|
issues = results.objects('issues')
|
|
|
|
|
|
|
|
expect(issues).to include issue
|
|
|
|
expect(issues).to include security_issue_1
|
|
|
|
expect(issues).to include security_issue_2
|
2018-03-05 08:25:56 -05:00
|
|
|
expect(results.limited_issues_count).to eq 3
|
2016-03-17 16:48:19 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'lists all project issues for admin' do
|
2016-03-17 16:48:19 -04:00
|
|
|
results = described_class.new(admin, project, query)
|
|
|
|
issues = results.objects('issues')
|
|
|
|
|
|
|
|
expect(issues).to include issue
|
|
|
|
expect(issues).to include security_issue_1
|
|
|
|
expect(issues).to include security_issue_2
|
2018-03-05 08:25:56 -05:00
|
|
|
expect(results.limited_issues_count).to eq 3
|
2016-03-17 16:48:19 -04:00
|
|
|
end
|
|
|
|
end
|
2016-12-08 20:56:31 -05:00
|
|
|
|
|
|
|
describe 'notes search' do
|
|
|
|
it 'lists notes' do
|
2017-08-02 15:55:11 -04:00
|
|
|
project = create(:project, :public)
|
2016-12-08 20:56:31 -05:00
|
|
|
note = create(:note, project: project)
|
|
|
|
|
|
|
|
results = described_class.new(user, project, note.note)
|
|
|
|
|
|
|
|
expect(results.objects('notes')).to include note
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't list issue notes when access is restricted" do
|
2017-08-02 15:55:11 -04:00
|
|
|
project = create(:project, :public, :issues_private)
|
2016-12-08 20:56:31 -05:00
|
|
|
note = create(:note_on_issue, project: project)
|
|
|
|
|
|
|
|
results = described_class.new(user, project, note.note)
|
|
|
|
|
|
|
|
expect(results.objects('notes')).not_to include note
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't list merge_request notes when access is restricted" do
|
2017-08-02 15:55:11 -04:00
|
|
|
project = create(:project, :public, :merge_requests_private)
|
2016-12-08 20:56:31 -05:00
|
|
|
note = create(:note_on_merge_request, project: project)
|
|
|
|
|
|
|
|
results = described_class.new(user, project, note.note)
|
|
|
|
|
|
|
|
expect(results.objects('notes')).not_to include note
|
|
|
|
end
|
|
|
|
end
|
2016-12-08 09:54:45 -05:00
|
|
|
|
2018-03-05 08:25:56 -05:00
|
|
|
describe '#limited_notes_count' do
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:note) { create(:note_on_issue, project: project) }
|
|
|
|
let(:results) { described_class.new(user, project, note.note) }
|
|
|
|
|
|
|
|
context 'when count_limit is lower than total amount' do
|
|
|
|
before do
|
|
|
|
allow(results).to receive(:count_limit).and_return(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls note finder once to get the limited amount of notes' do
|
|
|
|
expect(results).to receive(:notes_finder).once.and_call_original
|
|
|
|
expect(results.limited_notes_count).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when count_limit is higher than total amount' do
|
|
|
|
it 'calls note finder multiple times to get the limited amount of notes' do
|
|
|
|
project = create(:project, :public)
|
|
|
|
note = create(:note_on_issue, project: project)
|
|
|
|
|
|
|
|
results = described_class.new(user, project, note.note)
|
|
|
|
|
|
|
|
expect(results).to receive(:notes_finder).exactly(4).times.and_call_original
|
|
|
|
expect(results.limited_notes_count).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-08 09:54:45 -05:00
|
|
|
# Examples for commit access level test
|
|
|
|
#
|
|
|
|
# params:
|
|
|
|
# * search_phrase
|
|
|
|
# * commit
|
|
|
|
#
|
|
|
|
shared_examples 'access restricted commits' do
|
|
|
|
context 'when project is internal' do
|
2017-01-24 18:42:12 -05:00
|
|
|
let(:project) { create(:project, :internal, :repository) }
|
2016-12-08 09:54:45 -05:00
|
|
|
|
|
|
|
it 'does not search if user is not authenticated' do
|
|
|
|
commits = described_class.new(nil, project, search_phrase).objects('commits')
|
|
|
|
|
|
|
|
expect(commits).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'searches if user is authenticated' do
|
|
|
|
commits = described_class.new(user, project, search_phrase).objects('commits')
|
|
|
|
|
|
|
|
expect(commits).to contain_exactly commit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project is private' do
|
|
|
|
let!(:creator) { create(:user, username: 'private-project-author') }
|
2017-01-24 18:42:12 -05:00
|
|
|
let!(:private_project) { create(:project, :private, :repository, creator: creator, namespace: creator.namespace) }
|
2016-12-08 09:54:45 -05:00
|
|
|
let(:team_master) do
|
|
|
|
user = create(:user, username: 'private-project-master')
|
2017-12-22 03:18:28 -05:00
|
|
|
private_project.add_master(user)
|
2016-12-08 09:54:45 -05:00
|
|
|
user
|
|
|
|
end
|
|
|
|
let(:team_reporter) do
|
|
|
|
user = create(:user, username: 'private-project-reporter')
|
2017-12-22 03:18:28 -05:00
|
|
|
private_project.add_reporter(user)
|
2016-12-08 09:54:45 -05:00
|
|
|
user
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not show commit to stranger' do
|
|
|
|
commits = described_class.new(nil, private_project, search_phrase).objects('commits')
|
|
|
|
|
|
|
|
expect(commits).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'team access' do
|
|
|
|
it 'shows commit to creator' do
|
|
|
|
commits = described_class.new(creator, private_project, search_phrase).objects('commits')
|
|
|
|
|
|
|
|
expect(commits).to contain_exactly commit
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows commit to master' do
|
|
|
|
commits = described_class.new(team_master, private_project, search_phrase).objects('commits')
|
|
|
|
|
|
|
|
expect(commits).to contain_exactly commit
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows commit to reporter' do
|
|
|
|
commits = described_class.new(team_reporter, private_project, search_phrase).objects('commits')
|
|
|
|
|
|
|
|
expect(commits).to contain_exactly commit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'commit search' do
|
|
|
|
context 'by commit message' do
|
2017-01-24 18:42:12 -05:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2016-12-08 09:54:45 -05:00
|
|
|
let(:commit) { project.repository.commit('59e29889be61e6e0e5e223bfa9ac2721d31605b8') }
|
|
|
|
let(:message) { 'Sorry, I did a mistake' }
|
|
|
|
|
|
|
|
it 'finds commit by message' do
|
|
|
|
commits = described_class.new(user, project, message).objects('commits')
|
|
|
|
|
|
|
|
expect(commits).to contain_exactly commit
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'handles when no commit match' do
|
|
|
|
commits = described_class.new(user, project, 'not really an existing description').objects('commits')
|
|
|
|
|
|
|
|
expect(commits).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'access restricted commits' do
|
|
|
|
let(:search_phrase) { message }
|
|
|
|
let(:commit) { project.repository.commit('59e29889be61e6e0e5e223bfa9ac2721d31605b8') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'by commit hash' do
|
2017-01-24 18:42:12 -05:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2016-12-08 09:54:45 -05:00
|
|
|
let(:commit) { project.repository.commit('0b4bc9a') }
|
2017-04-24 11:09:29 -04:00
|
|
|
|
2016-12-08 09:54:45 -05:00
|
|
|
commit_hashes = { short: '0b4bc9a', full: '0b4bc9a49b562e85de7cc9e834518ea6828729b9' }
|
|
|
|
|
|
|
|
commit_hashes.each do |type, commit_hash|
|
|
|
|
it "shows commit by #{type} hash id" do
|
|
|
|
commits = described_class.new(user, project, commit_hash).objects('commits')
|
|
|
|
|
|
|
|
expect(commits).to contain_exactly commit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'handles not existing commit hash correctly' do
|
|
|
|
commits = described_class.new(user, project, 'deadbeef').objects('commits')
|
|
|
|
|
|
|
|
expect(commits).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'access restricted commits' do
|
|
|
|
let(:search_phrase) { '0b4bc9a49' }
|
|
|
|
let(:commit) { project.repository.commit('0b4bc9a') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-06-09 10:43:08 -04:00
|
|
|
end
|