Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
16e1076e
Commit
16e1076e
authored
Apr 03, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update tests.
parent
e33ddfeb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
48 deletions
+54
-48
spec/lib/gitlab/closing_issue_extractor_spec.rb
spec/lib/gitlab/closing_issue_extractor_spec.rb
+32
-30
spec/lib/gitlab/reference_extractor_spec.rb
spec/lib/gitlab/reference_extractor_spec.rb
+22
-18
No files found.
spec/lib/gitlab/closing_issue_extractor_spec.rb
View file @
16e1076e
...
@@ -5,126 +5,128 @@ describe Gitlab::ClosingIssueExtractor do
...
@@ -5,126 +5,128 @@ describe Gitlab::ClosingIssueExtractor do
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:iid1
)
{
issue
.
iid
}
let
(
:iid1
)
{
issue
.
iid
}
describe
:closed_by_message_in_project
do
subject
{
described_class
.
new
(
project
,
project
.
creator
)
}
describe
"#closed_by_message"
do
context
'with a single reference'
do
context
'with a single reference'
do
it
do
it
do
message
=
"Awesome commit (Closes #
#{
iid1
}
)"
message
=
"Awesome commit (Closes #
#{
iid1
}
)"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"Awesome commit (closes #
#{
iid1
}
)"
message
=
"Awesome commit (closes #
#{
iid1
}
)"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"Closed #
#{
iid1
}
"
message
=
"Closed #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"closed #
#{
iid1
}
"
message
=
"closed #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"Closing #
#{
iid1
}
"
message
=
"Closing #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"closing #
#{
iid1
}
"
message
=
"closing #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"Close #
#{
iid1
}
"
message
=
"Close #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"close #
#{
iid1
}
"
message
=
"close #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"Awesome commit (Fixes #
#{
iid1
}
)"
message
=
"Awesome commit (Fixes #
#{
iid1
}
)"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"Awesome commit (fixes #
#{
iid1
}
)"
message
=
"Awesome commit (fixes #
#{
iid1
}
)"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"Fixed #
#{
iid1
}
"
message
=
"Fixed #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"fixed #
#{
iid1
}
"
message
=
"fixed #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"Fixing #
#{
iid1
}
"
message
=
"Fixing #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"fixing #
#{
iid1
}
"
message
=
"fixing #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"Fix #
#{
iid1
}
"
message
=
"Fix #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"fix #
#{
iid1
}
"
message
=
"fix #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"Awesome commit (Resolves #
#{
iid1
}
)"
message
=
"Awesome commit (Resolves #
#{
iid1
}
)"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"Awesome commit (resolves #
#{
iid1
}
)"
message
=
"Awesome commit (resolves #
#{
iid1
}
)"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"Resolved #
#{
iid1
}
"
message
=
"Resolved #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"resolved #
#{
iid1
}
"
message
=
"resolved #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"Resolving #
#{
iid1
}
"
message
=
"Resolving #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"resolving #
#{
iid1
}
"
message
=
"resolving #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"Resolve #
#{
iid1
}
"
message
=
"Resolve #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
it
do
it
do
message
=
"resolve #
#{
iid1
}
"
message
=
"resolve #
#{
iid1
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
to
eq
([
issue
])
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
])
end
end
end
end
...
@@ -137,28 +139,28 @@ describe Gitlab::ClosingIssueExtractor do
...
@@ -137,28 +139,28 @@ describe Gitlab::ClosingIssueExtractor do
it
'fetches issues in single line message'
do
it
'fetches issues in single line message'
do
message
=
"Closes #
#{
iid1
}
and fix #
#{
iid2
}
"
message
=
"Closes #
#{
iid1
}
and fix #
#{
iid2
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
,
other_issue
])
to
eq
([
issue
,
other_issue
])
end
end
it
'fetches comma-separated issues references in single line message'
do
it
'fetches comma-separated issues references in single line message'
do
message
=
"Closes #
#{
iid1
}
, closes #
#{
iid2
}
"
message
=
"Closes #
#{
iid1
}
, closes #
#{
iid2
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
,
other_issue
])
to
eq
([
issue
,
other_issue
])
end
end
it
'fetches comma-separated issues numbers in single line message'
do
it
'fetches comma-separated issues numbers in single line message'
do
message
=
"Closes #
#{
iid1
}
, #
#{
iid2
}
and #
#{
iid3
}
"
message
=
"Closes #
#{
iid1
}
, #
#{
iid2
}
and #
#{
iid3
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
,
other_issue
,
third_issue
])
to
eq
([
issue
,
other_issue
,
third_issue
])
end
end
it
'fetches issues in multi-line message'
do
it
'fetches issues in multi-line message'
do
message
=
"Awesome commit (closes #
#{
iid1
}
)
\n
Also fixes #
#{
iid2
}
"
message
=
"Awesome commit (closes #
#{
iid1
}
)
\n
Also fixes #
#{
iid2
}
"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
,
other_issue
])
to
eq
([
issue
,
other_issue
])
end
end
...
@@ -166,7 +168,7 @@ describe Gitlab::ClosingIssueExtractor do
...
@@ -166,7 +168,7 @@ describe Gitlab::ClosingIssueExtractor do
message
=
"Awesome commit (closes #
#{
iid1
}
)
\n
"
\
message
=
"Awesome commit (closes #
#{
iid1
}
)
\n
"
\
"Also fixing issues #
#{
iid2
}
, #
#{
iid3
}
and #4"
"Also fixing issues #
#{
iid2
}
, #
#{
iid3
}
and #4"
expect
(
subject
.
closed_by_message
_in_project
(
message
,
project
)).
expect
(
subject
.
closed_by_message
(
message
)).
to
eq
([
issue
,
other_issue
,
third_issue
])
to
eq
([
issue
,
other_issue
,
third_issue
])
end
end
end
end
...
...
spec/lib/gitlab/reference_extractor_spec.rb
View file @
16e1076e
...
@@ -2,48 +2,48 @@ require 'spec_helper'
...
@@ -2,48 +2,48 @@ require 'spec_helper'
describe
Gitlab
::
ReferenceExtractor
do
describe
Gitlab
::
ReferenceExtractor
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
subject
{
Gitlab
::
ReferenceExtractor
.
new
(
project
)
}
subject
{
Gitlab
::
ReferenceExtractor
.
new
(
project
,
project
.
creator
)
}
it
'extracts username references'
do
it
'extracts username references'
do
subject
.
analyze
(
'this contains a @user reference'
)
subject
.
analyze
(
'this contains a @user reference'
)
expect
(
subject
.
users
).
to
eq
([{
project:
project
,
id:
'user'
}
])
expect
(
subject
.
references
[
:user
]).
to
eq
([[
project
,
'user'
]
])
end
end
it
'extracts issue references'
do
it
'extracts issue references'
do
subject
.
analyze
(
'this one talks about issue #1234'
)
subject
.
analyze
(
'this one talks about issue #1234'
)
expect
(
subject
.
issues
).
to
eq
([{
project:
project
,
id:
'1234'
}
])
expect
(
subject
.
references
[
:issue
]).
to
eq
([[
project
,
'1234'
]
])
end
end
it
'extracts JIRA issue references'
do
it
'extracts JIRA issue references'
do
subject
.
analyze
(
'this one talks about issue JIRA-1234'
)
subject
.
analyze
(
'this one talks about issue JIRA-1234'
)
expect
(
subject
.
issues
).
to
eq
([{
project:
project
,
id:
'JIRA-1234'
}
])
expect
(
subject
.
references
[
:issue
]).
to
eq
([[
project
,
'JIRA-1234'
]
])
end
end
it
'extracts merge request references'
do
it
'extracts merge request references'
do
subject
.
analyze
(
"and here's !43, a merge request"
)
subject
.
analyze
(
"and here's !43, a merge request"
)
expect
(
subject
.
merge_requests
).
to
eq
([{
project:
project
,
id:
'43'
}
])
expect
(
subject
.
references
[
:merge_request
]).
to
eq
([[
project
,
'43'
]
])
end
end
it
'extracts snippet ids'
do
it
'extracts snippet ids'
do
subject
.
analyze
(
'snippets like $12 get extracted as well'
)
subject
.
analyze
(
'snippets like $12 get extracted as well'
)
expect
(
subject
.
snippets
).
to
eq
([{
project:
project
,
id:
'12'
}
])
expect
(
subject
.
references
[
:snippet
]).
to
eq
([[
project
,
'12'
]
])
end
end
it
'extracts commit shas'
do
it
'extracts commit shas'
do
subject
.
analyze
(
'commit shas 98cf0ae3 are pulled out as Strings'
)
subject
.
analyze
(
'commit shas 98cf0ae3 are pulled out as Strings'
)
expect
(
subject
.
commits
).
to
eq
([{
project:
project
,
id:
'98cf0ae3'
}
])
expect
(
subject
.
references
[
:commit
]).
to
eq
([[
project
,
'98cf0ae3'
]
])
end
end
it
'extracts commit ranges'
do
it
'extracts commit ranges'
do
subject
.
analyze
(
'here you go, a commit range: 98cf0ae3...98cf0ae4'
)
subject
.
analyze
(
'here you go, a commit range: 98cf0ae3...98cf0ae4'
)
expect
(
subject
.
commit_ranges
).
to
eq
([{
project:
project
,
id:
'98cf0ae3...98cf0ae4'
}
])
expect
(
subject
.
references
[
:commit_range
]).
to
eq
([[
project
,
'98cf0ae3...98cf0ae4'
]
])
end
end
it
'extracts multiple references and preserves their order'
do
it
'extracts multiple references and preserves their order'
do
subject
.
analyze
(
'@me and @you both care about this'
)
subject
.
analyze
(
'@me and @you both care about this'
)
expect
(
subject
.
users
).
to
eq
([
expect
(
subject
.
references
[
:user
]
).
to
eq
([
{
project:
project
,
id:
'me'
}
,
[
project
,
'me'
]
,
{
project:
project
,
id:
'you'
}
[
project
,
'you'
]
])
])
end
end
...
@@ -70,7 +70,7 @@ describe Gitlab::ReferenceExtractor do
...
@@ -70,7 +70,7 @@ describe Gitlab::ReferenceExtractor do
it
'extracts issue references for invalid code blocks'
do
it
'extracts issue references for invalid code blocks'
do
subject
.
analyze
(
'test: ```this one talks about issue #1234```'
)
subject
.
analyze
(
'test: ```this one talks about issue #1234```'
)
expect
(
subject
.
issues
).
to
eq
([{
project:
project
,
id:
'1234'
}
])
expect
(
subject
.
references
[
:issue
]).
to
eq
([[
project
,
'1234'
]
])
end
end
it
'handles all possible kinds of references'
do
it
'handles all possible kinds of references'
do
...
@@ -78,16 +78,16 @@ describe Gitlab::ReferenceExtractor do
...
@@ -78,16 +78,16 @@ describe Gitlab::ReferenceExtractor do
expect
(
subject
).
to
respond_to
(
*
accessors
)
expect
(
subject
).
to
respond_to
(
*
accessors
)
end
end
it
'accesses valid user objects
on the project team
'
do
it
'accesses valid user objects'
do
@u_foo
=
create
(
:user
,
username:
'foo'
)
@u_foo
=
create
(
:user
,
username:
'foo'
)
@u_bar
=
create
(
:user
,
username:
'bar'
)
@u_bar
=
create
(
:user
,
username:
'bar'
)
create
(
:user
,
username:
'offteam'
)
@u_offteam
=
create
(
:user
,
username:
'offteam'
)
project
.
team
<<
[
@u_foo
,
:reporter
]
project
.
team
<<
[
@u_foo
,
:reporter
]
project
.
team
<<
[
@u_bar
,
:guest
]
project
.
team
<<
[
@u_bar
,
:guest
]
subject
.
analyze
(
'@foo, @baduser, @bar, and @offteam'
)
subject
.
analyze
(
'@foo, @baduser, @bar, and @offteam'
)
expect
(
subject
.
users
).
to
eq
([
@u_foo
,
@u_bar
])
expect
(
subject
.
users
).
to
eq
([
@u_foo
,
@u_bar
,
@u_offteam
])
end
end
it
'accesses valid issue objects'
do
it
'accesses valid issue objects'
do
...
@@ -139,11 +139,15 @@ describe Gitlab::ReferenceExtractor do
...
@@ -139,11 +139,15 @@ describe Gitlab::ReferenceExtractor do
end
end
context
'with a project with an underscore'
do
context
'with a project with an underscore'
do
let
(
:project
)
{
create
(
:project
,
path:
'test_project'
)
}
let
(
:other_project
)
{
create
(
:project
,
path:
'test_project'
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
other_project
)
}
before
do
other_project
.
team
<<
[
project
.
creator
,
:developer
]
end
it
'handles project issue references'
do
it
'handles project issue references'
do
subject
.
analyze
(
"this refers issue
#{
project
.
path_with_namespace
}
#
#{
issue
.
iid
}
"
)
subject
.
analyze
(
"this refers issue
#{
other_
project
.
path_with_namespace
}
#
#{
issue
.
iid
}
"
)
extracted
=
subject
.
issues
extracted
=
subject
.
issues
expect
(
extracted
.
size
).
to
eq
(
1
)
expect
(
extracted
.
size
).
to
eq
(
1
)
expect
(
extracted
).
to
eq
([
issue
])
expect
(
extracted
).
to
eq
([
issue
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment