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
Tatuya Kamada
gitlab-ce
Commits
2cb0a62f
Commit
2cb0a62f
authored
Aug 29, 2012
by
Alex Denisov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Notification sends to issue author and assignee if issue being reopened or closed
parent
4d655321
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
9 deletions
+76
-9
app/observers/issue_observer.rb
app/observers/issue_observer.rb
+14
-2
spec/observers/issue_observer_spec.rb
spec/observers/issue_observer_spec.rb
+62
-7
No files found.
app/observers/issue_observer.rb
View file @
2cb0a62f
...
@@ -9,8 +9,20 @@ class IssueObserver < ActiveRecord::Observer
...
@@ -9,8 +9,20 @@ class IssueObserver < ActiveRecord::Observer
def
after_update
(
issue
)
def
after_update
(
issue
)
send_reassigned_email
(
issue
)
if
issue
.
is_being_reassigned?
send_reassigned_email
(
issue
)
if
issue
.
is_being_reassigned?
Note
.
create_status_change_note
(
issue
,
current_user
,
'closed'
)
if
issue
.
is_being_closed?
Note
.
create_status_change_note
(
issue
,
current_user
,
'reopened'
)
if
issue
.
is_being_reopened?
if
issue
.
is_being_closed?
Note
.
create_status_change_note
(
issue
,
current_user
,
'closed'
)
[
issue
.
author
,
issue
.
assignee
].
compact
.
each
do
|
recipient
|
Notify
.
issue_status_changed_email
(
recipient
.
id
,
issue
.
id
,
'closed'
,
current_user
)
end
end
if
issue
.
is_being_reopened?
Note
.
create_status_change_note
(
issue
,
current_user
,
'reopened'
)
[
issue
.
author
,
issue
.
assignee
].
compact
.
each
do
|
recipient
|
Notify
.
issue_status_changed_email
(
recipient
.
id
,
issue
.
id
,
'reopened'
,
current_user
)
end
end
end
end
protected
protected
...
...
spec/observers/issue_observer_spec.rb
View file @
2cb0a62f
...
@@ -3,7 +3,8 @@ require 'spec_helper'
...
@@ -3,7 +3,8 @@ require 'spec_helper'
describe
IssueObserver
do
describe
IssueObserver
do
let
(
:some_user
)
{
double
(
:user
,
id:
1
)
}
let
(
:some_user
)
{
double
(
:user
,
id:
1
)
}
let
(
:assignee
)
{
double
(
:user
,
id:
2
)
}
let
(
:assignee
)
{
double
(
:user
,
id:
2
)
}
let
(
:issue
)
{
double
(
:issue
,
id:
42
,
assignee:
assignee
)
}
let
(
:author
)
{
double
(
:user
,
id:
3
)
}
let
(
:issue
)
{
double
(
:issue
,
id:
42
,
assignee:
assignee
,
author:
author
)
}
before
(
:each
)
{
subject
.
stub
(
:current_user
).
and_return
(
some_user
)
}
before
(
:each
)
{
subject
.
stub
(
:current_user
).
and_return
(
some_user
)
}
...
@@ -67,36 +68,90 @@ describe IssueObserver do
...
@@ -67,36 +68,90 @@ describe IssueObserver do
end
end
end
end
context
'a status "closed"
note
'
do
context
'a status "closed"'
do
it
'is created if the issue is being closed'
do
it
'
note
is created if the issue is being closed'
do
issue
.
should_receive
(
:is_being_closed?
).
and_return
(
true
)
issue
.
should_receive
(
:is_being_closed?
).
and_return
(
true
)
Note
.
should_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'closed'
)
Note
.
should_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'closed'
)
subject
.
after_update
(
issue
)
subject
.
after_update
(
issue
)
end
end
it
'is not created if the issue is not being closed'
do
it
'
note
is not created if the issue is not being closed'
do
issue
.
should_receive
(
:is_being_closed?
).
and_return
(
false
)
issue
.
should_receive
(
:is_being_closed?
).
and_return
(
false
)
Note
.
should_not_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'closed'
)
Note
.
should_not_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'closed'
)
subject
.
after_update
(
issue
)
subject
.
after_update
(
issue
)
end
end
it
'notification is delivered if the issue being closed'
do
issue
.
stub
(
:is_being_closed?
).
and_return
(
true
)
Notify
.
should_receive
(
:issue_status_changed_email
).
twice
Note
.
should_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'closed'
)
subject
.
after_update
(
issue
)
end
it
'notification is not delivered if the issue not being closed'
do
issue
.
stub
(
:is_being_closed?
).
and_return
(
false
)
Notify
.
should_not_receive
(
:issue_status_changed_email
)
Note
.
should_not_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'closed'
)
subject
.
after_update
(
issue
)
end
it
'notification is delivered only to author if the issue being closed'
do
issue_without_assignee
=
double
(
:issue
,
id:
42
,
author:
author
,
assignee:
nil
)
issue_without_assignee
.
stub
(
:is_being_reassigned?
).
and_return
(
false
)
issue_without_assignee
.
stub
(
:is_being_closed?
).
and_return
(
true
)
issue_without_assignee
.
stub
(
:is_being_reopened?
).
and_return
(
false
)
Notify
.
should_receive
(
:issue_status_changed_email
).
once
Note
.
should_receive
(
:create_status_change_note
).
with
(
issue_without_assignee
,
some_user
,
'closed'
)
subject
.
after_update
(
issue_without_assignee
)
end
end
end
context
'a status "reopened"
note
'
do
context
'a status "reopened"'
do
it
'is created if the issue is being reopened'
do
it
'
note
is created if the issue is being reopened'
do
issue
.
should_receive
(
:is_being_reopened?
).
and_return
(
true
)
issue
.
should_receive
(
:is_being_reopened?
).
and_return
(
true
)
Note
.
should_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'reopened'
)
Note
.
should_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'reopened'
)
subject
.
after_update
(
issue
)
subject
.
after_update
(
issue
)
end
end
it
'is not created if the issue is not being reopened'
do
it
'
note
is not created if the issue is not being reopened'
do
issue
.
should_receive
(
:is_being_reopened?
).
and_return
(
false
)
issue
.
should_receive
(
:is_being_reopened?
).
and_return
(
false
)
Note
.
should_not_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'reopened'
)
Note
.
should_not_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'reopened'
)
subject
.
after_update
(
issue
)
subject
.
after_update
(
issue
)
end
end
it
'notification is delivered if the issue being reopened'
do
issue
.
stub
(
:is_being_reopened?
).
and_return
(
true
)
Notify
.
should_receive
(
:issue_status_changed_email
).
twice
Note
.
should_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'reopened'
)
subject
.
after_update
(
issue
)
end
it
'notification is not delivered if the issue not being reopened'
do
issue
.
stub
(
:is_being_reopened?
).
and_return
(
false
)
Notify
.
should_not_receive
(
:issue_status_changed_email
)
Note
.
should_not_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'reopened'
)
subject
.
after_update
(
issue
)
end
it
'notification is delivered only to author if the issue being reopened'
do
issue_without_assignee
=
double
(
:issue
,
id:
42
,
author:
author
,
assignee:
nil
)
issue_without_assignee
.
stub
(
:is_being_reassigned?
).
and_return
(
false
)
issue_without_assignee
.
stub
(
:is_being_closed?
).
and_return
(
false
)
issue_without_assignee
.
stub
(
:is_being_reopened?
).
and_return
(
true
)
Notify
.
should_receive
(
:issue_status_changed_email
).
once
Note
.
should_receive
(
:create_status_change_note
).
with
(
issue_without_assignee
,
some_user
,
'reopened'
)
subject
.
after_update
(
issue_without_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