OSDN Git Service

Make changes to tests
[wvm/gitlab.git] / spec / lib / gitlab / reference_extractor_spec.rb
1 require 'spec_helper'
2
3 describe Gitlab::ReferenceExtractor do
4   it 'extracts username references' do
5     subject.analyze "this contains a @user reference"
6     subject.users.should == ["user"]
7   end
8
9   it 'extracts issue references' do
10     subject.analyze "this one talks about issue #1234"
11     subject.issues.should == ["1234"]
12   end
13
14   it 'extracts merge request references' do
15     subject.analyze "and here's !43, a merge request"
16     subject.merge_requests.should == ["43"]
17   end
18
19   it 'extracts snippet ids' do
20     subject.analyze "snippets like $12 get extracted as well"
21     subject.snippets.should == ["12"]
22   end
23
24   it 'extracts commit shas' do
25     subject.analyze "commit shas 98cf0ae3 are pulled out as Strings"
26     subject.commits.should == ["98cf0ae3"]
27   end
28
29   it 'extracts multiple references and preserves their order' do
30     subject.analyze "@me and @you both care about this"
31     subject.users.should == ["me", "you"]
32   end
33
34   it 'leaves the original note unmodified' do
35     text = "issue #123 is just the worst, @user"
36     subject.analyze text
37     text.should == "issue #123 is just the worst, @user"
38   end
39
40   it 'handles all possible kinds of references' do
41     accessors = Gitlab::Markdown::TYPES.map { |t| "#{t}s".to_sym }
42     subject.should respond_to(*accessors)
43   end
44
45   context 'with a project' do
46     let(:project) { create(:project) }
47
48     it 'accesses valid user objects on the project team' do
49       @u_foo = create(:user, username: 'foo')
50       @u_bar = create(:user, username: 'bar')
51       create(:user, username: 'offteam')
52
53       project.team << [@u_foo, :reporter]
54       project.team << [@u_bar, :guest]
55
56       subject.analyze "@foo, @baduser, @bar, and @offteam"
57       subject.users_for(project).should == [@u_foo, @u_bar]
58     end
59
60     it 'accesses valid issue objects' do
61       @i0 = create(:issue, project: project)
62       @i1 = create(:issue, project: project)
63
64       subject.analyze "##{@i0.iid}, ##{@i1.iid}, and #999."
65       subject.issues_for(project).should == [@i0, @i1]
66     end
67
68     it 'accesses valid merge requests' do
69       @m0 = create(:merge_request, source_project: project, target_project: project, source_branch: 'aaa')
70       @m1 = create(:merge_request, source_project: project, target_project: project, source_branch: 'bbb')
71
72       subject.analyze "!999, !#{@m1.iid}, and !#{@m0.iid}."
73       subject.merge_requests_for(project).should == [@m1, @m0]
74     end
75
76     it 'accesses valid snippets' do
77       @s0 = create(:project_snippet, project: project)
78       @s1 = create(:project_snippet, project: project)
79       @s2 = create(:project_snippet)
80
81       subject.analyze "$#{@s0.id}, $999, $#{@s2.id}, $#{@s1.id}"
82       subject.snippets_for(project).should == [@s0, @s1]
83     end
84
85     it 'accesses valid commits' do
86       commit = project.repository.commit("master")
87
88       subject.analyze "this references commits #{commit.sha[0..6]} and 012345"
89       extracted = subject.commits_for(project)
90       extracted.should have(1).item
91       extracted[0].sha.should == commit.sha
92       extracted[0].message.should == commit.message
93     end
94   end
95 end