Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorash wilson <smashwilson@gmail.com>2013-05-31 03:16:49 +0400
committerAsh Wilson <smashwilson@gmail.com>2013-08-26 02:58:41 +0400
commitc8a115c0e3a9c8242c2a422572d47a49e0cb2874 (patch)
tree5a36c3e0f364fdfb710e01090fc81b9676ea53c4 /spec/lib
parent2b36dee64485062c69779217d4a202e5ca1b67bd (diff)
Link issues from comments and automatically close them
Any mention of Issues, MergeRequests, or Commits via GitLab-flavored markdown references in descriptions, titles, or attached Notes creates a back-reference Note that links to the original referencer. Furthermore, pushing commits with commit messages that match a (configurable) regexp to a project's default branch will close any issues mentioned by GFM in the matched closing phrase. If accepting a merge request would close any Issues in this way, a banner is appended to the merge request's main panel to indicate this.
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/reference_extractor_spec.rb95
1 files changed, 95 insertions, 0 deletions
diff --git a/spec/lib/gitlab/reference_extractor_spec.rb b/spec/lib/gitlab/reference_extractor_spec.rb
new file mode 100644
index 00000000000..7d805f8c72a
--- /dev/null
+++ b/spec/lib/gitlab/reference_extractor_spec.rb
@@ -0,0 +1,95 @@
+require 'spec_helper'
+
+describe Gitlab::ReferenceExtractor do
+ it 'extracts username references' do
+ subject.analyze "this contains a @user reference"
+ subject.users.should == ["user"]
+ end
+
+ it 'extracts issue references' do
+ subject.analyze "this one talks about issue #1234"
+ subject.issues.should == ["1234"]
+ end
+
+ it 'extracts merge request references' do
+ subject.analyze "and here's !43, a merge request"
+ subject.merge_requests.should == ["43"]
+ end
+
+ it 'extracts snippet ids' do
+ subject.analyze "snippets like $12 get extracted as well"
+ subject.snippets.should == ["12"]
+ end
+
+ it 'extracts commit shas' do
+ subject.analyze "commit shas 98cf0ae3 are pulled out as Strings"
+ subject.commits.should == ["98cf0ae3"]
+ end
+
+ it 'extracts multiple references and preserves their order' do
+ subject.analyze "@me and @you both care about this"
+ subject.users.should == ["me", "you"]
+ end
+
+ it 'leaves the original note unmodified' do
+ text = "issue #123 is just the worst, @user"
+ subject.analyze text
+ text.should == "issue #123 is just the worst, @user"
+ end
+
+ it 'handles all possible kinds of references' do
+ accessors = Gitlab::Markdown::TYPES.map { |t| "#{t}s".to_sym }
+ subject.should respond_to(*accessors)
+ end
+
+ context 'with a project' do
+ let(:project) { create(:project_with_code) }
+
+ it 'accesses valid user objects on the project team' do
+ @u_foo = create(:user, username: 'foo')
+ @u_bar = create(:user, username: 'bar')
+ create(:user, username: 'offteam')
+
+ project.team << [@u_foo, :reporter]
+ project.team << [@u_bar, :guest]
+
+ subject.analyze "@foo, @baduser, @bar, and @offteam"
+ subject.users_for(project).should == [@u_foo, @u_bar]
+ end
+
+ it 'accesses valid issue objects' do
+ @i0 = create(:issue, project: project)
+ @i1 = create(:issue, project: project)
+
+ subject.analyze "##{@i0.iid}, ##{@i1.iid}, and #999."
+ subject.issues_for(project).should == [@i0, @i1]
+ end
+
+ it 'accesses valid merge requests' do
+ @m0 = create(:merge_request, source_project: project, target_project: project, source_branch: 'aaa')
+ @m1 = create(:merge_request, source_project: project, target_project: project, source_branch: 'bbb')
+
+ subject.analyze "!999, !#{@m1.iid}, and !#{@m0.iid}."
+ subject.merge_requests_for(project).should == [@m1, @m0]
+ end
+
+ it 'accesses valid snippets' do
+ @s0 = create(:project_snippet, project: project)
+ @s1 = create(:project_snippet, project: project)
+ @s2 = create(:project_snippet)
+
+ subject.analyze "$#{@s0.id}, $999, $#{@s2.id}, $#{@s1.id}"
+ subject.snippets_for(project).should == [@s0, @s1]
+ end
+
+ it 'accesses valid commits' do
+ commit = project.repository.commit("master")
+
+ subject.analyze "this references commits #{commit.sha[0..6]} and 012345"
+ extracted = subject.commits_for(project)
+ extracted.should have(1).item
+ extracted[0].sha.should == commit.sha
+ extracted[0].message.should == commit.message
+ end
+ end
+end