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
e558edd1
Commit
e558edd1
authored
Apr 26, 2016
by
Grzegorz Bizon
Committed by
Robert Speicher
May 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update specs to carry out changes in note factory
parent
21d0cddd
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
259 additions
and
131 deletions
+259
-131
features/steps/dashboard/todos.rb
features/steps/dashboard/todos.rb
+1
-1
features/steps/project/issues/issues.rb
features/steps/project/issues/issues.rb
+1
-1
spec/factories/notes.rb
spec/factories/notes.rb
+15
-6
spec/features/issues/note_polling_spec.rb
spec/features/issues/note_polling_spec.rb
+5
-1
spec/features/issues_spec.rb
spec/features/issues_spec.rb
+1
-1
spec/features/notes_on_merge_requests_spec.rb
spec/features/notes_on_merge_requests_spec.rb
+7
-3
spec/features/participants_autocomplete_spec.rb
spec/features/participants_autocomplete_spec.rb
+4
-2
spec/features/task_lists_spec.rb
spec/features/task_lists_spec.rb
+4
-1
spec/lib/gitlab/note_data_builder_spec.rb
spec/lib/gitlab/note_data_builder_spec.rb
+54
-17
spec/models/concerns/issuable_spec.rb
spec/models/concerns/issuable_spec.rb
+2
-5
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+7
-2
spec/models/note_spec.rb
spec/models/note_spec.rb
+8
-2
spec/models/project_services/hipchat_service_spec.rb
spec/models/project_services/hipchat_service_spec.rb
+90
-59
spec/models/project_services/slack_service_spec.rb
spec/models/project_services/slack_service_spec.rb
+45
-23
spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
.../merge_requests/merge_when_build_succeeds_service_spec.rb
+7
-3
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+8
-4
No files found.
features/steps/dashboard/todos.rb
View file @
e558edd1
...
...
@@ -20,7 +20,7 @@ class Spinach::Features::DashboardTodos < Spinach::FeatureSteps
step
'I have todos'
do
create
(
:todo
,
user:
current_user
,
project:
project
,
author:
mary_jane
,
target:
issue
,
action:
Todo
::
MENTIONED
)
create
(
:todo
,
user:
current_user
,
project:
project
,
author:
john_doe
,
target:
issue
,
action:
Todo
::
ASSIGNED
)
note
=
create
(
:note
,
author:
john_doe
,
noteable:
issue
,
note:
"
#{
current_user
.
to_reference
}
Wdyt?"
)
note
=
create
(
:note
,
author:
john_doe
,
noteable:
issue
,
note:
"
#{
current_user
.
to_reference
}
Wdyt?"
,
project:
project
)
create
(
:todo
,
user:
current_user
,
project:
project
,
author:
john_doe
,
target:
issue
,
action:
Todo
::
MENTIONED
,
note:
note
)
create
(
:todo
,
user:
current_user
,
project:
project
,
author:
john_doe
,
target:
merge_request
,
action:
Todo
::
ASSIGNED
)
end
...
...
features/steps/project/issues/issues.rb
View file @
e558edd1
...
...
@@ -348,7 +348,7 @@ class Spinach::Features::ProjectIssues < Spinach::FeatureSteps
step
'another user adds a comment with text "Yay!" to issue "Release 0.4"'
do
issue
=
Issue
.
find_by!
(
title:
'Release 0.4'
)
create
(
:note_on_issue
,
noteable:
issue
,
note:
'Yay!'
)
create
(
:note_on_issue
,
noteable:
issue
,
project:
project
,
note:
'Yay!'
)
end
step
'I should see a new comment with text "Yay!"'
do
...
...
spec/factories/notes.rb
View file @
e558edd1
...
...
@@ -9,7 +9,7 @@ FactoryGirl.define do
author
noteable
{
create
(
:issue
,
project:
project
)
}
factory
:note_on_issue
,
aliases:
[
:votable_note
]
factory
:note_on_issue
,
traits:
[
:on_issue
],
aliases:
[
:votable_note
]
factory
:note_on_commit
,
traits:
[
:on_commit
]
factory
:note_on_commit_diff
,
traits:
[
:on_commit
,
:on_diff
],
class:
LegacyDiffNote
factory
:note_on_merge_request
,
traits:
[
:on_merge_request
]
...
...
@@ -19,24 +19,33 @@ FactoryGirl.define do
factory
:downvote_note
,
traits:
[
:award
,
:downvote
]
factory
:upvote_note
,
traits:
[
:award
,
:upvote
]
trait
:on_issue
do
noteable_type
'Issue'
end
trait
:on_commit
do
noteable
nil
commit_id
RepoHelpers
.
sample_commit
.
id
noteable_type
"Commit"
end
trait
:on_diff
do
line_code
"0_184_184"
end
trait
:on_merge_request
do
noteable
{
create
(
:merge_request
,
project:
project
)
}
noteable_type
'MergeRequest'
noteable
do
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
end
end
trait
:on_project_snippet
do
noteable_type
'Snippet'
noteable
{
create
(
:snippet
,
project:
project
)
}
end
trait
:on_diff
do
line_code
"0_184_184"
end
trait
:system
do
system
true
end
...
...
spec/features/issues/note_polling_spec.rb
View file @
e558edd1
...
...
@@ -9,8 +9,12 @@ feature 'Issue notes polling' do
end
scenario
'Another user adds a comment to an issue'
,
js:
true
do
note
=
create
(
:note_on_issue
,
noteable:
issue
,
note:
'Looks good!'
)
note
=
create
(
:note_on_issue
,
noteable:
issue
,
project:
project
,
note:
'Looks good!'
)
page
.
execute_script
(
'notes.refresh();'
)
expect
(
page
).
to
have_selector
(
"#note_
#{
note
.
id
}
"
,
text:
'Looks good!'
)
end
end
spec/features/issues_spec.rb
View file @
e558edd1
...
...
@@ -125,7 +125,7 @@ describe 'Issues', feature: true do
describe
'Issue info'
do
it
'excludes award_emoji from comment count'
do
issue
=
create
(
:issue
,
author:
@user
,
assignee:
@user
,
project:
project
,
title:
'foobar'
)
create
(
:upvote_note
,
noteable:
issue
)
create
(
:upvote_note
,
noteable:
issue
,
project:
project
)
visit
namespace_project_issues_path
(
project
.
namespace
,
project
,
assignee_id:
@user
.
id
)
...
...
spec/features/notes_on_merge_requests_spec.rb
View file @
e558edd1
...
...
@@ -19,10 +19,14 @@ describe 'Comments', feature: true do
end
describe
'On a merge request'
,
js:
true
,
feature:
true
do
let!
(
:merge_request
)
{
create
(
:merge_request
)
}
let!
(
:project
)
{
merge_request
.
source_project
}
let!
(
:project
)
{
create
(
:project
)
}
let!
(
:merge_request
)
do
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
end
let!
(
:note
)
do
create
(
:note_on_merge_request
,
:with_attachment
,
project:
project
)
create
(
:note_on_merge_request
,
:with_attachment
,
noteable:
merge_request
,
project:
project
)
end
before
do
...
...
spec/features/participants_autocomplete_spec.rb
View file @
e558edd1
...
...
@@ -32,7 +32,8 @@ feature 'Member autocomplete', feature: true do
context
'adding a new note on a Issue'
,
js:
true
do
before
do
issue
=
create
(
:issue
,
author:
author
,
project:
project
)
create
(
:note
,
note:
'Ultralight Beam'
,
noteable:
issue
,
author:
participant
)
create
(
:note
,
note:
'Ultralight Beam'
,
noteable:
issue
,
project:
project
,
author:
participant
)
visit_issue
(
project
,
issue
)
end
...
...
@@ -47,7 +48,8 @@ feature 'Member autocomplete', feature: true do
context
'adding a new note on a Merge Request '
,
js:
true
do
before
do
merge
=
create
(
:merge_request
,
source_project:
project
,
target_project:
project
,
author:
author
)
create
(
:note
,
note:
'Ultralight Beam'
,
noteable:
merge
,
author:
participant
)
create
(
:note
,
note:
'Ultralight Beam'
,
noteable:
merge
,
project:
project
,
author:
participant
)
visit_merge_request
(
project
,
merge
)
end
...
...
spec/features/task_lists_spec.rb
View file @
e558edd1
...
...
@@ -75,7 +75,10 @@ feature 'Task Lists', feature: true do
describe
'for Notes'
do
let!
(
:issue
)
{
create
(
:issue
,
author:
user
,
project:
project
)
}
let!
(
:note
)
{
create
(
:note
,
note:
markdown
,
noteable:
issue
,
author:
user
)
}
let!
(
:note
)
do
create
(
:note
,
note:
markdown
,
noteable:
issue
,
project:
project
,
author:
user
)
end
it
'renders for note body'
do
visit_issue
(
project
,
issue
)
...
...
spec/lib/gitlab/note_data_builder_spec.rb
View file @
e558edd1
...
...
@@ -9,7 +9,8 @@ describe 'Gitlab::NoteDataBuilder', lib: true do
before
(
:each
)
do
expect
(
data
).
to
have_key
(
:object_attributes
)
expect
(
data
[
:object_attributes
]).
to
have_key
(
:url
)
expect
(
data
[
:object_attributes
][
:url
]).
to
eq
(
Gitlab
::
UrlBuilder
.
build
(
note
))
expect
(
data
[
:object_attributes
][
:url
])
.
to
eq
(
Gitlab
::
UrlBuilder
.
build
(
note
))
expect
(
data
[
:object_kind
]).
to
eq
(
'note'
)
expect
(
data
[
:user
]).
to
eq
(
user
.
hook_attrs
)
end
...
...
@@ -37,13 +38,21 @@ describe 'Gitlab::NoteDataBuilder', lib: true do
end
describe
'When asking for a note on issue'
do
let
(
:issue
)
{
create
(
:issue
,
created_at:
fixed_time
,
updated_at:
fixed_time
)
}
let
(
:note
)
{
create
(
:note_on_issue
,
noteable_id:
issue
.
id
,
project:
project
)
}
let
(
:issue
)
do
create
(
:issue
,
created_at:
fixed_time
,
updated_at:
fixed_time
,
project:
project
)
end
let
(
:note
)
do
create
(
:note_on_issue
,
noteable_id:
issue
.
id
,
project:
project
)
end
it
'returns the note and issue-specific data'
do
expect
(
data
).
to
have_key
(
:issue
)
expect
(
data
[
:issue
].
except
(
'updated_at'
)).
to
eq
(
issue
.
hook_attrs
.
except
(
'updated_at'
))
expect
(
data
[
:issue
][
'updated_at'
]).
to
be
>
issue
.
hook_attrs
[
'updated_at'
]
expect
(
data
[
:issue
].
except
(
'updated_at'
))
.
to
eq
(
issue
.
hook_attrs
.
except
(
'updated_at'
))
expect
(
data
[
:issue
][
'updated_at'
])
.
to
be
>
issue
.
hook_attrs
[
'updated_at'
]
end
include_examples
'project hook data'
...
...
@@ -51,13 +60,23 @@ describe 'Gitlab::NoteDataBuilder', lib: true do
end
describe
'When asking for a note on merge request'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
created_at:
fixed_time
,
updated_at:
fixed_time
)
}
let
(
:note
)
{
create
(
:note_on_merge_request
,
noteable_id:
merge_request
.
id
,
project:
project
)
}
let
(
:merge_request
)
do
create
(
:merge_request
,
created_at:
fixed_time
,
updated_at:
fixed_time
,
source_project:
project
)
end
let
(
:note
)
do
create
(
:note_on_merge_request
,
noteable_id:
merge_request
.
id
,
project:
project
)
end
it
'returns the note and merge request data'
do
expect
(
data
).
to
have_key
(
:merge_request
)
expect
(
data
[
:merge_request
].
except
(
'updated_at'
)).
to
eq
(
merge_request
.
hook_attrs
.
except
(
'updated_at'
))
expect
(
data
[
:merge_request
][
'updated_at'
]).
to
be
>
merge_request
.
hook_attrs
[
'updated_at'
]
expect
(
data
[
:merge_request
].
except
(
'updated_at'
))
.
to
eq
(
merge_request
.
hook_attrs
.
except
(
'updated_at'
))
expect
(
data
[
:merge_request
][
'updated_at'
])
.
to
be
>
merge_request
.
hook_attrs
[
'updated_at'
]
end
include_examples
'project hook data'
...
...
@@ -65,13 +84,22 @@ describe 'Gitlab::NoteDataBuilder', lib: true do
end
describe
'When asking for a note on merge request diff'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
created_at:
fixed_time
,
updated_at:
fixed_time
)
}
let
(
:note
)
{
create
(
:note_on_merge_request_diff
,
noteable_id:
merge_request
.
id
,
project:
project
)
}
let
(
:merge_request
)
do
create
(
:merge_request
,
created_at:
fixed_time
,
updated_at:
fixed_time
,
source_project:
project
)
end
let
(
:note
)
do
create
(
:note_on_merge_request_diff
,
noteable_id:
merge_request
.
id
,
project:
project
)
end
it
'returns the note and merge request diff data'
do
expect
(
data
).
to
have_key
(
:merge_request
)
expect
(
data
[
:merge_request
].
except
(
'updated_at'
)).
to
eq
(
merge_request
.
hook_attrs
.
except
(
'updated_at'
))
expect
(
data
[
:merge_request
][
'updated_at'
]).
to
be
>
merge_request
.
hook_attrs
[
'updated_at'
]
expect
(
data
[
:merge_request
].
except
(
'updated_at'
))
.
to
eq
(
merge_request
.
hook_attrs
.
except
(
'updated_at'
))
expect
(
data
[
:merge_request
][
'updated_at'
])
.
to
be
>
merge_request
.
hook_attrs
[
'updated_at'
]
end
include_examples
'project hook data'
...
...
@@ -79,13 +107,22 @@ describe 'Gitlab::NoteDataBuilder', lib: true do
end
describe
'When asking for a note on project snippet'
do
let!
(
:snippet
)
{
create
(
:project_snippet
,
created_at:
fixed_time
,
updated_at:
fixed_time
)
}
let!
(
:note
)
{
create
(
:note_on_project_snippet
,
noteable_id:
snippet
.
id
,
project:
project
)
}
let!
(
:snippet
)
do
create
(
:project_snippet
,
created_at:
fixed_time
,
updated_at:
fixed_time
,
project:
project
)
end
let!
(
:note
)
do
create
(
:note_on_project_snippet
,
noteable_id:
snippet
.
id
,
project:
project
)
end
it
'returns the note and project snippet data'
do
expect
(
data
).
to
have_key
(
:snippet
)
expect
(
data
[
:snippet
].
except
(
'updated_at'
)).
to
eq
(
snippet
.
hook_attrs
.
except
(
'updated_at'
))
expect
(
data
[
:snippet
][
'updated_at'
]).
to
be
>
snippet
.
hook_attrs
[
'updated_at'
]
expect
(
data
[
:snippet
].
except
(
'updated_at'
))
.
to
eq
(
snippet
.
hook_attrs
.
except
(
'updated_at'
))
expect
(
data
[
:snippet
][
'updated_at'
])
.
to
be
>
snippet
.
hook_attrs
[
'updated_at'
]
end
include_examples
'project hook data'
...
...
spec/models/concerns/issuable_spec.rb
View file @
e558edd1
...
...
@@ -189,7 +189,6 @@ describe Issue, "Issuable" do
let
(
:data
)
{
issue
.
to_hook_data
(
user
)
}
let
(
:project
)
{
issue
.
project
}
it
"returns correct hook data"
do
expect
(
data
[
:object_kind
]).
to
eq
(
"issue"
)
expect
(
data
[
:user
]).
to
eq
(
user
.
hook_attrs
)
...
...
@@ -230,10 +229,8 @@ describe Issue, "Issuable" do
describe
"votes"
do
before
do
author
=
create
:user
project
=
create
:empty_project
issue
.
notes
.
awards
.
create!
(
note:
"thumbsup"
,
author:
author
,
project:
project
)
issue
.
notes
.
awards
.
create!
(
note:
"thumbsdown"
,
author:
author
,
project:
project
)
issue
.
notes
.
awards
.
create!
(
note:
"thumbsup"
,
author:
user
,
project:
issue
.
project
)
issue
.
notes
.
awards
.
create!
(
note:
"thumbsdown"
,
author:
user
,
project:
issue
.
project
)
end
it
"returns correct values"
do
...
...
spec/models/merge_request_spec.rb
View file @
e558edd1
...
...
@@ -119,7 +119,9 @@ describe MergeRequest, models: true do
before
do
allow
(
merge_request
).
to
receive
(
:commits
)
{
[
merge_request
.
source_project
.
repository
.
commit
]
}
create
(
:note
,
commit_id:
merge_request
.
commits
.
first
.
id
,
noteable_type:
'Commit'
,
project:
merge_request
.
project
)
create
(
:note_on_commit
,
commit_id:
merge_request
.
commits
.
first
.
id
,
noteable_type:
'Commit'
,
project:
merge_request
.
project
)
create
(
:note
,
noteable:
merge_request
,
project:
merge_request
.
project
)
end
...
...
@@ -129,7 +131,10 @@ describe MergeRequest, models: true do
end
it
"should include notes for commits from target project as well"
do
create
(
:note
,
commit_id:
merge_request
.
commits
.
first
.
id
,
noteable_type:
'Commit'
,
project:
merge_request
.
target_project
)
create
(
:note_on_commit
,
commit_id:
merge_request
.
commits
.
first
.
id
,
noteable_type:
'Commit'
,
project:
merge_request
.
target_project
)
expect
(
merge_request
.
commits
).
not_to
be_empty
expect
(
merge_request
.
mr_and_commit_notes
.
count
).
to
eq
(
3
)
end
...
...
spec/models/note_spec.rb
View file @
e558edd1
...
...
@@ -202,12 +202,18 @@ describe Note, models: true do
let
(
:merge_request
)
{
create
:merge_request
}
it
"converts aliases to actual name"
do
note
=
create
(
:note
,
note:
":+1:"
,
noteable:
merge_request
)
note
=
create
(
:note
,
note:
":+1:"
,
noteable:
merge_request
,
project:
merge_request
.
project
)
expect
(
note
.
reload
.
note
).
to
eq
(
"thumbsup"
)
end
it
"is not an award emoji when comment is on a diff"
do
note
=
create
(
:note_on_merge_request_diff
,
note:
":blowfish:"
,
noteable:
merge_request
,
line_code:
"11d5d2e667e9da4f7f610f81d86c974b146b13bd_0_2"
)
note
=
create
(
:note_on_merge_request_diff
,
note:
":blowfish:"
,
noteable:
merge_request
,
project:
merge_request
.
project
,
line_code:
"11d5d2e667e9da4f7f610f81d86c974b146b13bd_0_2"
)
note
=
note
.
reload
expect
(
note
.
note
).
to
eq
(
":blowfish:"
)
...
...
spec/models/project_services/hipchat_service_spec.rb
View file @
e558edd1
...
...
@@ -176,86 +176,117 @@ describe HipchatService, models: true do
context
"Note events"
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
let
(
:snippet
)
{
create
(
:project_snippet
,
project:
project
)
}
let
(
:commit_note
)
{
create
(
:note_on_commit
,
author:
user
,
project:
project
,
commit_id:
project
.
repository
.
commit
.
id
,
note:
'a comment on a commit'
)
}
let
(
:merge_request_note
)
{
create
(
:note_on_merge_request
,
noteable_id:
merge_request
.
id
,
note:
"merge request note"
)
}
let
(
:issue_note
)
{
create
(
:note_on_issue
,
noteable_id:
issue
.
id
,
note:
"issue note"
)}
let
(
:snippet_note
)
{
create
(
:note_on_project_snippet
,
noteable_id:
snippet
.
id
,
note:
"snippet note"
)
}
it
"should call Hipchat API for commit comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
commit_note
,
user
)
hipchat
.
execute
(
data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
api_url
).
once
context
'when commit comment event triggered'
do
let
(
:commit_note
)
do
create
(
:note_on_commit
,
author:
user
,
project:
project
,
commit_id:
project
.
repository
.
commit
.
id
,
note:
'a comment on a commit'
)
end
it
"should call Hipchat API for commit comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
commit_note
,
user
)
hipchat
.
execute
(
data
)
message
=
hipchat
.
send
(
:create_message
,
data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
api_url
).
once
obj_attr
=
data
[
:object_attributes
]
commit_id
=
Commit
.
truncate_sha
(
data
[
:commit
][
:id
])
title
=
hipchat
.
send
(
:format_title
,
data
[
:commit
][
:message
])
message
=
hipchat
.
send
(
:create_message
,
data
)
expect
(
message
).
to
eq
(
"
#{
user
.
name
}
commented on "
\
"<a href=
\"
#{
obj_attr
[
:url
]
}
\"
>commit
#{
commit_id
}
</a> in "
\
"<a href=
\"
#{
project
.
web_url
}
\"
>
#{
project_name
}
</a>: "
\
"
#{
title
}
"
\
"<pre>a comment on a commit</pre>"
)
obj_attr
=
data
[
:object_attributes
]
commit_id
=
Commit
.
truncate_sha
(
data
[
:commit
][
:id
])
title
=
hipchat
.
send
(
:format_title
,
data
[
:commit
][
:message
])
expect
(
message
).
to
eq
(
"
#{
user
.
name
}
commented on "
\
"<a href=
\"
#{
obj_attr
[
:url
]
}
\"
>commit
#{
commit_id
}
</a> in "
\
"<a href=
\"
#{
project
.
web_url
}
\"
>
#{
project_name
}
</a>: "
\
"
#{
title
}
"
\
"<pre>a comment on a commit</pre>"
)
end
end
it
"should call Hipchat API for merge request comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
merge_request_note
,
user
)
hipchat
.
execute
(
data
)
context
'when merge request comment event triggered'
do
let
(
:merge_request
)
do
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
end
expect
(
WebMock
).
to
have_requested
(
:post
,
api_url
).
once
let
(
:merge_request_note
)
do
create
(
:note_on_merge_request
,
noteable_id:
merge_request
.
id
,
project:
project
,
note:
"merge request note"
)
end
message
=
hipchat
.
send
(
:create_message
,
data
)
it
"should call Hipchat API for merge request comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
merge_request_note
,
user
)
hipchat
.
execute
(
data
)
obj_attr
=
data
[
:object_attributes
]
merge_id
=
data
[
:merge_request
][
'iid'
]
title
=
data
[
:merge_request
][
'title'
]
expect
(
WebMock
).
to
have_requested
(
:post
,
api_url
).
once
expect
(
message
).
to
eq
(
"
#{
user
.
name
}
commented on "
\
"<a href=
\"
#{
obj_attr
[
:url
]
}
\"
>merge request !
#{
merge_id
}
</a> in "
\
"<a href=
\"
#{
project
.
web_url
}
\"
>
#{
project_name
}
</a>: "
\
"<b>
#{
title
}
</b>"
\
"<pre>merge request note</pre>"
)
message
=
hipchat
.
send
(
:create_message
,
data
)
obj_attr
=
data
[
:object_attributes
]
merge_id
=
data
[
:merge_request
][
'iid'
]
title
=
data
[
:merge_request
][
'title'
]
expect
(
message
).
to
eq
(
"
#{
user
.
name
}
commented on "
\
"<a href=
\"
#{
obj_attr
[
:url
]
}
\"
>merge request !
#{
merge_id
}
</a> in "
\
"<a href=
\"
#{
project
.
web_url
}
\"
>
#{
project_name
}
</a>: "
\
"<b>
#{
title
}
</b>"
\
"<pre>merge request note</pre>"
)
end
end
it
"should call Hipchat API for issue comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
issue_note
,
user
)
hipchat
.
execute
(
data
)
context
'when issue comment event triggered'
do
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue_note
)
do
create
(
:note_on_issue
,
noteable_id:
issue
.
id
,
project:
project
,
note:
"issue note"
)
end
message
=
hipchat
.
send
(
:create_message
,
data
)
it
"should call Hipchat API for issue comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
issue_note
,
user
)
hipchat
.
execute
(
data
)
obj_attr
=
data
[
:object_attributes
]
issue_id
=
data
[
:issue
][
'iid'
]
title
=
data
[
:issue
][
'title'
]
message
=
hipchat
.
send
(
:create_message
,
data
)
expect
(
message
).
to
eq
(
"
#{
user
.
name
}
commented on "
\
"<a href=
\"
#{
obj_attr
[
:url
]
}
\"
>issue #
#{
issue_id
}
</a> in "
\
"<a href=
\"
#{
project
.
web_url
}
\"
>
#{
project_name
}
</a>: "
\
"<b>
#{
title
}
</b>"
\
"<pre>issue note</pre>"
)
obj_attr
=
data
[
:object_attributes
]
issue_id
=
data
[
:issue
][
'iid'
]
title
=
data
[
:issue
][
'title'
]
expect
(
message
).
to
eq
(
"
#{
user
.
name
}
commented on "
\
"<a href=
\"
#{
obj_attr
[
:url
]
}
\"
>issue #
#{
issue_id
}
</a> in "
\
"<a href=
\"
#{
project
.
web_url
}
\"
>
#{
project_name
}
</a>: "
\
"<b>
#{
title
}
</b>"
\
"<pre>issue note</pre>"
)
end
end
it
"should call Hipchat API for snippet comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
snippet_note
,
user
)
hipchat
.
execute
(
data
)
context
'when snippet comment event triggered'
do
let
(
:snippet
)
{
create
(
:project_snippet
,
project:
project
)
}
let
(
:snippet_note
)
do
create
(
:note_on_project_snippet
,
noteable_id:
snippet
.
id
,
project:
project
,
note:
"snippet note"
)
end
expect
(
WebMock
).
to
have_requested
(
:post
,
api_url
).
once
it
"should call Hipchat API for snippet comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
snippet_note
,
user
)
hipchat
.
execute
(
data
)
message
=
hipchat
.
send
(
:create_message
,
data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
api_url
).
once
obj_attr
=
data
[
:object_attributes
]
snippet_id
=
data
[
:snippet
][
'id'
]
title
=
data
[
:snippet
][
'title'
]
message
=
hipchat
.
send
(
:create_message
,
data
)
expect
(
message
).
to
eq
(
"
#{
user
.
name
}
commented on "
\
"<a href=
\"
#{
obj_attr
[
:url
]
}
\"
>snippet #
#{
snippet_id
}
</a> in "
\
"<a href=
\"
#{
project
.
web_url
}
\"
>
#{
project_name
}
</a>: "
\
"<b>
#{
title
}
</b>"
\
"<pre>snippet note</pre>"
)
obj_attr
=
data
[
:object_attributes
]
snippet_id
=
data
[
:snippet
][
'id'
]
title
=
data
[
:snippet
][
'title'
]
expect
(
message
).
to
eq
(
"
#{
user
.
name
}
commented on "
\
"<a href=
\"
#{
obj_attr
[
:url
]
}
\"
>snippet #
#{
snippet_id
}
</a> in "
\
"<a href=
\"
#{
project
.
web_url
}
\"
>
#{
project_name
}
</a>: "
\
"<b>
#{
title
}
</b>"
\
"<pre>snippet note</pre>"
)
end
end
end
...
...
spec/models/project_services/slack_service_spec.rb
View file @
e558edd1
...
...
@@ -142,13 +142,6 @@ describe SlackService, models: true do
let
(
:slack
)
{
SlackService
.
new
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
let
(
:snippet
)
{
create
(
:project_snippet
,
project:
project
)
}
let
(
:commit_note
)
{
create
(
:note_on_commit
,
author:
user
,
project:
project
,
commit_id:
project
.
repository
.
commit
.
id
,
note:
'a comment on a commit'
)
}
let
(
:merge_request_note
)
{
create
(
:note_on_merge_request
,
noteable_id:
merge_request
.
id
,
note:
"merge request note"
)
}
let
(
:issue_note
)
{
create
(
:note_on_issue
,
noteable_id:
issue
.
id
,
note:
"issue note"
)}
let
(
:snippet_note
)
{
create
(
:note_on_project_snippet
,
noteable_id:
snippet
.
id
,
note:
"snippet note"
)
}
let
(
:webhook_url
)
{
'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685'
}
before
do
...
...
@@ -162,32 +155,61 @@ describe SlackService, models: true do
WebMock
.
stub_request
(
:post
,
webhook_url
)
end
it
"should call Slack API for commit comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
commit_note
,
user
)
slack
.
execute
(
data
)
context
'when commit comment event executed'
do
let
(
:commit_note
)
do
create
(
:note_on_commit
,
author:
user
,
project:
project
,
commit_id:
project
.
repository
.
commit
.
id
,
note:
'a comment on a commit'
)
end
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
it
"should call Slack API for commit comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
commit_note
,
user
)
slack
.
execute
(
data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
end
it
"should call Slack API for merge request comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
merge_request_note
,
user
)
slack
.
execute
(
data
)
context
'when merge request comment event executed'
do
let
(
:merge_request_note
)
do
create
(
:note_on_merge_request
,
project:
project
,
note:
"merge request note"
)
end
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
it
"should call Slack API for merge request comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
merge_request_note
,
user
)
slack
.
execute
(
data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
end
it
"should call Slack API for issue comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
issue_note
,
user
)
slack
.
execute
(
data
)
context
'when issue comment event executed'
do
let
(
:issue_note
)
do
create
(
:note_on_issue
,
project:
project
,
note:
"issue note"
)
end
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
it
"should call Slack API for issue comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
issue_note
,
user
)
slack
.
execute
(
data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
end
it
"should call Slack API for snippet comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
snippet_note
,
user
)
slack
.
execute
(
data
)
context
'when snippet comment event executed'
do
let
(
:snippet_note
)
do
create
(
:note_on_project_snippet
,
project:
project
,
note:
"snippet note"
)
end
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
it
"should call Slack API for snippet comment events"
do
data
=
Gitlab
::
NoteDataBuilder
.
build
(
snippet_note
,
user
)
slack
.
execute
(
data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
end
end
end
spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
View file @
e558edd1
require
'spec_helper'
describe
MergeRequests
::
MergeWhenBuildSucceedsService
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:
merge_request
)
{
create
(
:merge_reques
t
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:
project
)
{
create
(
:projec
t
)
}
let
(
:mr_merge_if_green_enabled
)
do
create
(
:merge_request
,
merge_when_build_succeeds:
true
,
merge_user:
user
,
...
...
@@ -10,11 +10,15 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
source_project:
project
,
target_project:
project
,
state:
"opened"
)
end
let
(
:project
)
{
create
(
:project
)
}
let
(
:ci_commit
)
{
create
(
:ci_commit_with_one_job
,
ref:
mr_merge_if_green_enabled
.
source_branch
,
project:
project
)
}
let
(
:service
)
{
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
project
,
user
,
commit_message:
'Awesome message'
)
}
describe
"#execute"
do
let
(
:merge_request
)
do
create
(
:merge_request
,
target_project:
project
,
source_project:
project
,
source_branch:
"feature"
,
target_branch:
'master'
)
end
context
'first time enabling'
do
before
do
allow
(
merge_request
).
to
receive
(
:ci_commit
).
and_return
(
ci_commit
)
...
...
spec/services/system_note_service_spec.rb
View file @
e558edd1
...
...
@@ -208,8 +208,10 @@ describe SystemNoteService, services: true do
end
describe
'.merge_when_build_succeeds'
do
let
(
:ci_commit
)
{
build
:ci_commit_without_jobs
}
let
(
:noteable
)
{
create
:merge_request
}
let
(
:ci_commit
)
{
build
(
:ci_commit_without_jobs
)}
let
(
:noteable
)
do
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
end
subject
{
described_class
.
merge_when_build_succeeds
(
noteable
,
project
,
author
,
noteable
.
last_commit
)
}
...
...
@@ -221,8 +223,10 @@ describe SystemNoteService, services: true do
end
describe
'.cancel_merge_when_build_succeeds'
do
let
(
:ci_commit
)
{
build
:ci_commit_without_jobs
}
let
(
:noteable
)
{
create
:merge_request
}
let
(
:ci_commit
)
{
build
(
:ci_commit_without_jobs
)
}
let
(
:noteable
)
do
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
end
subject
{
described_class
.
cancel_merge_when_build_succeeds
(
noteable
,
project
,
author
)
}
...
...
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