2013-05-30 19:16:49 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::ReferenceExtractor do
|
2015-03-27 07:58:23 -04:00
|
|
|
let(:project) { create(:project) }
|
2015-10-07 13:19:23 -04:00
|
|
|
subject { Gitlab::ReferenceExtractor.new(project, project.creator) }
|
2015-03-27 07:58:23 -04:00
|
|
|
|
2015-04-03 12:03:34 -04:00
|
|
|
it 'accesses valid user objects' do
|
2015-03-27 07:58:23 -04:00
|
|
|
@u_foo = create(:user, username: 'foo')
|
|
|
|
@u_bar = create(:user, username: 'bar')
|
2015-04-03 12:03:34 -04:00
|
|
|
@u_offteam = create(:user, username: 'offteam')
|
2013-05-30 19:16:49 -04:00
|
|
|
|
2015-03-27 07:58:23 -04:00
|
|
|
project.team << [@u_foo, :reporter]
|
|
|
|
project.team << [@u_bar, :guest]
|
2013-05-30 19:16:49 -04:00
|
|
|
|
2015-03-27 07:58:23 -04:00
|
|
|
subject.analyze('@foo, @baduser, @bar, and @offteam')
|
2015-04-03 12:03:34 -04:00
|
|
|
expect(subject.users).to eq([@u_foo, @u_bar, @u_offteam])
|
2015-03-27 07:58:23 -04:00
|
|
|
end
|
2013-05-30 19:16:49 -04:00
|
|
|
|
2015-06-02 07:17:11 -04:00
|
|
|
it 'ignores user mentions inside specific elements' do
|
|
|
|
@u_foo = create(:user, username: 'foo')
|
|
|
|
@u_bar = create(:user, username: 'bar')
|
|
|
|
@u_offteam = create(:user, username: 'offteam')
|
|
|
|
|
|
|
|
project.team << [@u_foo, :reporter]
|
|
|
|
project.team << [@u_bar, :guest]
|
|
|
|
|
|
|
|
subject.analyze(%Q{
|
2015-08-11 08:33:31 -04:00
|
|
|
Inline code: `@foo`
|
2015-06-02 07:17:11 -04:00
|
|
|
|
|
|
|
Code block:
|
|
|
|
|
|
|
|
```
|
|
|
|
@bar
|
|
|
|
```
|
2015-06-02 07:17:21 -04:00
|
|
|
|
2015-08-11 08:33:31 -04:00
|
|
|
Quote:
|
2015-06-02 07:17:21 -04:00
|
|
|
|
|
|
|
> @offteam
|
2015-06-02 07:17:11 -04:00
|
|
|
})
|
|
|
|
expect(subject.users).to eq([])
|
|
|
|
end
|
|
|
|
|
2015-03-27 07:58:23 -04:00
|
|
|
it 'accesses valid issue objects' do
|
|
|
|
@i0 = create(:issue, project: project)
|
|
|
|
@i1 = create(:issue, project: project)
|
2013-05-30 19:16:49 -04:00
|
|
|
|
2015-05-21 16:35:15 -04:00
|
|
|
subject.analyze("#{@i0.to_reference}, #{@i1.to_reference}, and #{Issue.reference_prefix}999.")
|
2015-03-27 07:58:23 -04:00
|
|
|
expect(subject.issues).to eq([@i0, @i1])
|
|
|
|
end
|
2013-05-30 19:16:49 -04:00
|
|
|
|
2015-03-27 07:58:23 -04:00
|
|
|
it 'accesses valid merge requests' do
|
2015-08-11 08:33:31 -04:00
|
|
|
@m0 = create(:merge_request, source_project: project, target_project: project, source_branch: 'markdown')
|
|
|
|
@m1 = create(:merge_request, source_project: project, target_project: project, source_branch: 'feature_conflict')
|
2013-05-30 19:16:49 -04:00
|
|
|
|
2015-03-27 07:58:23 -04:00
|
|
|
subject.analyze("!999, !#{@m1.iid}, and !#{@m0.iid}.")
|
|
|
|
expect(subject.merge_requests).to eq([@m1, @m0])
|
|
|
|
end
|
2013-05-30 19:16:49 -04:00
|
|
|
|
2015-04-15 14:02:36 -04:00
|
|
|
it 'accesses valid labels' do
|
|
|
|
@l0 = create(:label, title: 'one', project: project)
|
|
|
|
@l1 = create(:label, title: 'two', project: project)
|
|
|
|
@l2 = create(:label)
|
|
|
|
|
|
|
|
subject.analyze("~#{@l0.id}, ~999, ~#{@l2.id}, ~#{@l1.id}")
|
|
|
|
expect(subject.labels).to eq([@l0, @l1])
|
|
|
|
end
|
|
|
|
|
2015-03-27 07:58:23 -04:00
|
|
|
it 'accesses valid snippets' do
|
|
|
|
@s0 = create(:project_snippet, project: project)
|
|
|
|
@s1 = create(:project_snippet, project: project)
|
|
|
|
@s2 = create(:project_snippet)
|
2013-05-30 19:16:49 -04:00
|
|
|
|
2015-03-27 07:58:23 -04:00
|
|
|
subject.analyze("$#{@s0.id}, $999, $#{@s2.id}, $#{@s1.id}")
|
|
|
|
expect(subject.snippets).to eq([@s0, @s1])
|
|
|
|
end
|
2013-05-30 19:16:49 -04:00
|
|
|
|
2015-03-27 07:58:23 -04:00
|
|
|
it 'accesses valid commits' do
|
2015-04-21 09:13:40 -04:00
|
|
|
commit = project.commit('master')
|
2013-05-30 19:16:49 -04:00
|
|
|
|
2015-03-27 07:58:23 -04:00
|
|
|
subject.analyze("this references commits #{commit.sha[0..6]} and 012345")
|
|
|
|
extracted = subject.commits
|
|
|
|
expect(extracted.size).to eq(1)
|
|
|
|
expect(extracted[0].sha).to eq(commit.sha)
|
|
|
|
expect(extracted[0].message).to eq(commit.message)
|
|
|
|
end
|
2015-03-06 17:08:28 -05:00
|
|
|
|
2015-03-27 07:58:23 -04:00
|
|
|
it 'accesses valid commit ranges' do
|
2015-04-21 09:13:40 -04:00
|
|
|
commit = project.commit('master')
|
|
|
|
earlier_commit = project.commit('master~2')
|
2015-03-06 17:08:28 -05:00
|
|
|
|
2015-03-27 07:58:23 -04:00
|
|
|
subject.analyze("this references commits #{earlier_commit.sha[0..6]}...#{commit.sha[0..6]}")
|
2015-04-25 14:46:06 -04:00
|
|
|
|
2015-03-27 07:58:23 -04:00
|
|
|
extracted = subject.commit_ranges
|
|
|
|
expect(extracted.size).to eq(1)
|
2015-04-25 14:46:06 -04:00
|
|
|
expect(extracted.first).to be_kind_of(CommitRange)
|
|
|
|
expect(extracted.first.commit_from).to eq earlier_commit
|
|
|
|
expect(extracted.first.commit_to).to eq commit
|
2013-05-30 19:16:49 -04:00
|
|
|
end
|
2015-03-12 12:11:59 -04:00
|
|
|
|
|
|
|
context 'with a project with an underscore' do
|
2015-04-03 12:03:34 -04:00
|
|
|
let(:other_project) { create(:project, path: 'test_project') }
|
|
|
|
let(:issue) { create(:issue, project: other_project) }
|
|
|
|
|
|
|
|
before do
|
2015-10-07 13:19:23 -04:00
|
|
|
other_project.team << [project.creator, :developer]
|
2015-04-03 12:03:34 -04:00
|
|
|
end
|
2015-03-12 12:11:59 -04:00
|
|
|
|
|
|
|
it 'handles project issue references' do
|
2015-05-21 16:35:15 -04:00
|
|
|
subject.analyze("this refers issue #{issue.to_reference(project)}")
|
2015-03-27 07:58:23 -04:00
|
|
|
extracted = subject.issues
|
2015-03-12 12:11:59 -04:00
|
|
|
expect(extracted.size).to eq(1)
|
|
|
|
expect(extracted).to eq([issue])
|
|
|
|
end
|
|
|
|
end
|
2013-05-30 19:16:49 -04:00
|
|
|
end
|