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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
b973fc4a
Commit
b973fc4a
authored
Feb 05, 2015
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add note cross reference specs, remove repetition.
parent
a7ae2679
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
20 deletions
+98
-20
app/models/project_services/jira_service.rb
app/models/project_services/jira_service.rb
+4
-4
spec/models/note_spec.rb
spec/models/note_spec.rb
+79
-10
spec/services/git_push_service_spec.rb
spec/services/git_push_service_spec.rb
+6
-6
spec/support/repo_helpers.rb
spec/support/repo_helpers.rb
+9
-0
No files found.
app/models/project_services/jira_service.rb
View file @
b973fc4a
...
...
@@ -57,7 +57,7 @@ class JiraService < IssueTrackerService
def
create_cross_reference_note
(
mentioned
,
noteable
,
author
)
issue_name
=
mentioned
.
id
project
=
self
.
project
noteable_name
=
noteable
.
class
.
name
.
downcase
.
to_sym
noteable_name
=
noteable
.
class
.
name
.
underscore
.
downcase
.
to_sym
noteable_id
=
if
noteable
.
is_a?
(
Commit
)
noteable
.
id
else
...
...
@@ -161,7 +161,7 @@ class JiraService < IssueTrackerService
"
#{
self
.
class
.
name
}
ERROR:
#{
result
}
. Hostname:
#{
url
}
."
else
case
result
.
code
when
201
when
201
,
200
"
#{
self
.
class
.
name
}
SUCCESS 201: Sucessfully posted to
#{
url
}
."
when
401
"
#{
self
.
class
.
name
}
ERROR 401: Unauthorized. Check the
#{
self
.
username
}
credentials and JIRA access permissions and try again."
...
...
@@ -170,8 +170,8 @@ class JiraService < IssueTrackerService
end
end
Rails
.
logger
.
info
(
message
)
message
Rails
.
logger
.
info
(
message
)
message
end
def
server_url
...
...
spec/models/note_spec.rb
View file @
b973fc4a
...
...
@@ -209,26 +209,80 @@ describe Note do
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:mergereq
)
{
create
(
:merge_request
,
:simple
,
target_project:
project
,
source_project:
project
)
}
let
(
:commit
)
{
project
.
repository
.
commit
}
let
(
:jira_issue
)
{
JiraIssue
.
new
(
"JIRA-1"
,
project
)}
let
(
:jira_tracker
)
{
project
.
create_jira_service
if
project
.
jira_service
.
nil?
}
let
(
:api_mention_url
)
{
'http://jira.example/rest/api/2/issue/JIRA-1/comment'
}
# Test all of {issue, merge request, commit} in both the referenced and referencing
# roles, to ensure that the correct information can be inferred from any argument.
context
'issue from a merge request'
do
subject
{
Note
.
create_cross_reference_note
(
issue
,
mergereq
,
author
,
project
)
}
context
'in default issue tracker'
do
subject
{
Note
.
create_cross_reference_note
(
issue
,
mergereq
,
author
,
project
)
}
it
{
should
be_valid
}
its
(
:noteable
)
{
should
==
issue
}
its
(
:project
)
{
should
==
issue
.
project
}
its
(
:author
)
{
should
==
author
}
its
(
:note
)
{
should
==
"_mentioned in merge request !
#{
mergereq
.
iid
}
_"
}
end
it
{
should
be_valid
}
its
(
:noteable
)
{
should
==
issue
}
its
(
:project
)
{
should
==
issue
.
project
}
its
(
:author
)
{
should
==
author
}
its
(
:note
)
{
should
==
"_mentioned in merge request !
#{
mergereq
.
iid
}
_"
}
context
'in JIRA issue tracker'
do
before
do
jira_service_settings
WebMock
.
stub_request
(
:post
,
api_mention_url
)
end
after
do
jira_tracker
.
destroy!
end
subject
{
Note
.
create_cross_reference_note
(
jira_issue
,
mergereq
,
author
,
project
)
}
it
{
should
==
jira_status_message
}
end
end
context
'issue from a commit'
do
subject
{
Note
.
create_cross_reference_note
(
issue
,
commit
,
author
,
project
)
}
context
'in default issue tracker'
do
subject
{
Note
.
create_cross_reference_note
(
issue
,
commit
,
author
,
project
)
}
it
{
should
be_valid
}
its
(
:noteable
)
{
should
==
issue
}
its
(
:note
)
{
should
==
"_mentioned in commit
#{
commit
.
sha
}
_"
}
it
{
should
be_valid
}
its
(
:noteable
)
{
should
==
issue
}
its
(
:note
)
{
should
==
"_mentioned in commit
#{
commit
.
sha
}
_"
}
end
context
'in JIRA issue tracker'
do
before
do
jira_service_settings
WebMock
.
stub_request
(
:post
,
api_mention_url
)
end
after
do
jira_tracker
.
destroy!
end
subject
{
Note
.
create_cross_reference_note
(
jira_issue
,
commit
,
author
,
project
)
}
it
{
should
==
jira_status_message
}
end
end
context
'issue from an isue'
do
context
'in JIRA issue tracker'
do
before
do
jira_service_settings
WebMock
.
stub_request
(
:post
,
api_mention_url
)
end
after
do
jira_tracker
.
destroy!
end
subject
{
Note
.
create_cross_reference_note
(
jira_issue
,
issue
,
author
,
project
)
}
it
{
should
==
jira_status_message
}
end
end
context
'merge request from an issue'
do
...
...
@@ -386,4 +440,19 @@ describe Note do
let
(
:backref_text
)
{
issue
.
gfm_reference
}
let
(
:set_mentionable_text
)
{
->
(
txt
)
{
subject
.
note
=
txt
}
}
end
def
jira_service_settings
properties
=
{
"title"
=>
"JIRA tracker"
,
"project_url"
=>
"http://jira.example/issues/?jql=project=A"
,
"issues_url"
=>
"http://jira.example/browse/JIRA-1"
,
"new_issue_url"
=>
"http://jira.example/secure/CreateIssue.jspa"
}
jira_tracker
.
update_attributes
(
properties:
properties
,
active:
true
)
end
def
jira_status_message
"JiraService SUCCESS 201: Sucessfully posted to
#{
api_mention_url
}
."
end
end
spec/services/git_push_service_spec.rb
View file @
b973fc4a
...
...
@@ -270,15 +270,15 @@ describe GitPushService do
it
"should initiate one api call to jira server to close the issue"
do
message
=
{
'update'
=>
{
'comment'
=>
[{
'add'
=>
{
'body'
=>
"Issue solved with http://localhost/
#{
project
.
path_with_namespace
}
/commit/
#{
closing_commit
.
id
}
"
update:
{
comment:
[{
add:
{
body:
"Issue solved with http://localhost/
#{
project
.
path_with_namespace
}
/commit/
#{
closing_commit
.
id
}
"
}
}]
},
'transition'
=>
{
'id'
=>
'2'
transition:
{
id:
'2'
}
}.
to_json
...
...
spec/support/repo_helpers.rb
View file @
b973fc4a
...
...
@@ -96,4 +96,13 @@ eos
commits:
commits
)
end
def
jira_properties
{
"title"
=>
"JIRA tracker"
,
"project_url"
=>
"http://jira.example/issues/?jql=project=A"
,
"issues_url"
=>
"http://jira.example/browse/JIRA-1"
,
"new_issue_url"
=>
"http://jira.example/secure/CreateIssue.jspa"
}
end
end
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