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
38ffb822
Commit
38ffb822
authored
Mar 26, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use NotificationService for handle notify logic when MR created
parent
58a1ed6d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
18 deletions
+33
-18
app/observers/merge_request_observer.rb
app/observers/merge_request_observer.rb
+1
-3
app/services/notification_service.rb
app/services/notification_service.rb
+11
-1
spec/observers/merge_request_observer_spec.rb
spec/observers/merge_request_observer_spec.rb
+5
-14
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+16
-0
No files found.
app/observers/merge_request_observer.rb
View file @
38ffb822
...
@@ -2,9 +2,7 @@ class MergeRequestObserver < ActiveRecord::Observer
...
@@ -2,9 +2,7 @@ class MergeRequestObserver < ActiveRecord::Observer
cattr_accessor
:current_user
cattr_accessor
:current_user
def
after_create
(
merge_request
)
def
after_create
(
merge_request
)
if
merge_request
.
assignee
&&
merge_request
.
assignee
!=
current_user
notification
.
new_merge_request
(
merge_request
,
current_user
)
Notify
.
delay
.
new_merge_request_email
(
merge_request
.
id
)
end
end
end
def
after_close
(
merge_request
,
transition
)
def
after_close
(
merge_request
,
transition
)
...
...
app/services/notification_service.rb
View file @
38ffb822
...
@@ -47,7 +47,7 @@ class NotificationService
...
@@ -47,7 +47,7 @@ class NotificationService
end
end
end
end
# When
we reassign
an issue we should send next emails:
# When
create
an issue we should send next emails:
#
#
# * issue assignee if his notification level is not Disabled
# * issue assignee if his notification level is not Disabled
#
#
...
@@ -56,4 +56,14 @@ class NotificationService
...
@@ -56,4 +56,14 @@ class NotificationService
Notify
.
delay
.
new_issue_email
(
issue
.
id
)
Notify
.
delay
.
new_issue_email
(
issue
.
id
)
end
end
end
end
# When create a merge request we should send next emails:
#
# * mr assignee if his notification level is not Disabled
#
def
new_merge_request
(
merge_request
,
current_user
)
if
merge_request
.
assignee
&&
merge_request
.
assignee
!=
current_user
Notify
.
delay
.
new_merge_request_email
(
merge_request
.
id
)
end
end
end
end
spec/observers/merge_request_observer_spec.rb
View file @
38ffb822
...
@@ -10,7 +10,8 @@ describe MergeRequestObserver do
...
@@ -10,7 +10,8 @@ describe MergeRequestObserver do
let
(
:closed_assigned_mr
)
{
create
(
:closed_merge_request
,
assignee:
assignee
,
author:
author
)
}
let
(
:closed_assigned_mr
)
{
create
(
:closed_merge_request
,
assignee:
assignee
,
author:
author
)
}
let
(
:closed_unassigned_mr
)
{
create
(
:closed_merge_request
,
author:
author
)
}
let
(
:closed_unassigned_mr
)
{
create
(
:closed_merge_request
,
author:
author
)
}
before
(
:each
)
{
subject
.
stub
(
:current_user
).
and_return
(
some_user
)
}
before
{
subject
.
stub
(
:current_user
).
and_return
(
some_user
)
}
before
{
subject
.
stub
(
notification:
mock
(
'NotificationService'
).
as_null_object
)
}
subject
{
MergeRequestObserver
.
instance
}
subject
{
MergeRequestObserver
.
instance
}
...
@@ -18,21 +19,11 @@ describe MergeRequestObserver do
...
@@ -18,21 +19,11 @@ describe MergeRequestObserver do
it
'is called when a merge request is created'
do
it
'is called when a merge request is created'
do
subject
.
should_receive
(
:after_create
)
subject
.
should_receive
(
:after_create
)
create
(
:merge_request
,
project:
create
(
:project
))
MergeRequest
.
observers
.
enable
:merge_request_observer
do
create
(
:merge_request
,
project:
create
(
:project
))
end
end
end
it
'sends an email to the assignee'
do
it
'trigger notification service'
do
Notify
.
should_receive
(
:new_merge_request_email
).
with
(
mr_mock
.
id
)
subject
.
should_receive
(
:notification
)
subject
.
after_create
(
mr_mock
)
end
it
'does not send an email to the assignee if assignee created the merge request'
do
subject
.
stub
(
:current_user
).
and_return
(
assignee
)
Notify
.
should_not_receive
(
:new_merge_request_email
)
subject
.
after_create
(
mr_mock
)
subject
.
after_create
(
mr_mock
)
end
end
end
end
...
...
spec/services/notification_service_spec.rb
View file @
38ffb822
...
@@ -44,4 +44,20 @@ describe NotificationService do
...
@@ -44,4 +44,20 @@ describe NotificationService do
end
end
end
end
end
end
describe
'Merge Requests'
do
let
(
:merge_request
)
{
create
:merge_request
,
assignee:
create
(
:user
)
}
describe
:new_merge_request
do
it
'should send email to merge_request assignee'
do
Notify
.
should_receive
(
:new_merge_request_email
).
with
(
merge_request
.
id
)
notification
.
new_merge_request
(
merge_request
,
merge_request
.
author
)
end
it
'should not send email to merge_request assignee if he is current_user'
do
Notify
.
should_not_receive
(
:new_merge_request_email
).
with
(
merge_request
.
id
)
notification
.
new_merge_request
(
merge_request
,
merge_request
.
assignee
)
end
end
end
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