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
diff options
context:
space:
mode:
authorVinnie Okada <vokada@mrvinn.com>2014-10-02 22:26:39 +0400
committerVinnie Okada <vokada@mrvinn.com>2014-10-03 21:30:20 +0400
commit2c46c4523fc8aa41cb60e4840af16fdd595f7dd2 (patch)
treeb178ae204f78e40aff7611b70a3a025f6e7befa9 /spec/lib/gitlab/reference_extractor_spec.rb
parent7edc1439fe11e396bb6327a3f50aca5dfe3c411c (diff)
Track projects in ReferenceExtractor
Store both the project and identifier of extracted references. This prevents `ReferenceExtractor` from returning objects in the wrong project for cross-project references.
Diffstat (limited to 'spec/lib/gitlab/reference_extractor_spec.rb')
-rw-r--r--spec/lib/gitlab/reference_extractor_spec.rb52
1 files changed, 28 insertions, 24 deletions
diff --git a/spec/lib/gitlab/reference_extractor_spec.rb b/spec/lib/gitlab/reference_extractor_spec.rb
index 99fed27c796..23867df39dd 100644
--- a/spec/lib/gitlab/reference_extractor_spec.rb
+++ b/spec/lib/gitlab/reference_extractor_spec.rb
@@ -2,45 +2,48 @@ require 'spec_helper'
describe Gitlab::ReferenceExtractor do
it 'extracts username references' do
- subject.analyze "this contains a @user reference"
- subject.users.should == ["user"]
+ subject.analyze('this contains a @user reference', nil)
+ subject.users.should == [{ project: nil, id: 'user' }]
end
it 'extracts issue references' do
- subject.analyze "this one talks about issue #1234"
- subject.issues.should == ["1234"]
+ subject.analyze('this one talks about issue #1234', nil)
+ subject.issues.should == [{ project: nil, id: '1234' }]
end
it 'extracts JIRA issue references' do
- Gitlab.config.gitlab.stub(:issues_tracker).and_return("jira")
- subject.analyze "this one talks about issue JIRA-1234"
- subject.issues.should == ["JIRA-1234"]
+ Gitlab.config.gitlab.stub(:issues_tracker).and_return('jira')
+ subject.analyze('this one talks about issue JIRA-1234', nil)
+ subject.issues.should == [{ project: nil, id: 'JIRA-1234' }]
end
it 'extracts merge request references' do
- subject.analyze "and here's !43, a merge request"
- subject.merge_requests.should == ["43"]
+ subject.analyze("and here's !43, a merge request", nil)
+ subject.merge_requests.should == [{ project: nil, id: '43' }]
end
it 'extracts snippet ids' do
- subject.analyze "snippets like $12 get extracted as well"
- subject.snippets.should == ["12"]
+ subject.analyze('snippets like $12 get extracted as well', nil)
+ subject.snippets.should == [{ project: nil, id: '12' }]
end
it 'extracts commit shas' do
- subject.analyze "commit shas 98cf0ae3 are pulled out as Strings"
- subject.commits.should == ["98cf0ae3"]
+ subject.analyze('commit shas 98cf0ae3 are pulled out as Strings', nil)
+ subject.commits.should == [{ project: nil, id: '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"]
+ subject.analyze('@me and @you both care about this', nil)
+ subject.users.should == [
+ { project: nil, id: 'me' },
+ { project: nil, id: '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"
+ text = 'issue #123 is just the worst, @user'
+ subject.analyze(text, nil)
+ text.should == 'issue #123 is just the worst, @user'
end
it 'handles all possible kinds of references' do
@@ -59,7 +62,7 @@ describe Gitlab::ReferenceExtractor do
project.team << [@u_foo, :reporter]
project.team << [@u_bar, :guest]
- subject.analyze "@foo, @baduser, @bar, and @offteam"
+ subject.analyze('@foo, @baduser, @bar, and @offteam', project)
subject.users_for(project).should == [@u_foo, @u_bar]
end
@@ -67,7 +70,7 @@ describe Gitlab::ReferenceExtractor do
@i0 = create(:issue, project: project)
@i1 = create(:issue, project: project)
- subject.analyze "##{@i0.iid}, ##{@i1.iid}, and #999."
+ subject.analyze("##{@i0.iid}, ##{@i1.iid}, and #999.", project)
subject.issues_for(project).should == [@i0, @i1]
end
@@ -75,7 +78,7 @@ describe Gitlab::ReferenceExtractor 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.analyze("!999, !#{@m1.iid}, and !#{@m0.iid}.", project)
subject.merge_requests_for(project).should == [@m1, @m0]
end
@@ -84,14 +87,15 @@ describe Gitlab::ReferenceExtractor do
@s1 = create(:project_snippet, project: project)
@s2 = create(:project_snippet)
- subject.analyze "$#{@s0.id}, $999, $#{@s2.id}, $#{@s1.id}"
+ subject.analyze("$#{@s0.id}, $999, $#{@s2.id}, $#{@s1.id}", project)
subject.snippets_for(project).should == [@s0, @s1]
end
it 'accesses valid commits' do
- commit = project.repository.commit("master")
+ commit = project.repository.commit('master')
- subject.analyze "this references commits #{commit.sha[0..6]} and 012345"
+ subject.analyze("this references commits #{commit.sha[0..6]} and 012345",
+ project)
extracted = subject.commits_for(project)
extracted.should have(1).item
extracted[0].sha.should == commit.sha