BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
356430c3
Commit
356430c3
authored
May 20, 2012
by
Robb Kidd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add method for an issue to know whether it is being closed
Update IssueObserver to create a Note on the issue its being closed.
parent
02924de3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
9 deletions
+55
-9
issue.rb
app/models/issue.rb
+4
-0
issue_observer.rb
app/models/issue_observer.rb
+1
-1
issue_observer_spec.rb
spec/models/issue_observer_spec.rb
+31
-8
issue_spec.rb
spec/models/issue_spec.rb
+19
-0
No files found.
app/models/issue.rb
View file @
356430c3
...
@@ -64,6 +64,10 @@ class Issue < ActiveRecord::Base
...
@@ -64,6 +64,10 @@ class Issue < ActiveRecord::Base
def
is_being_reassigned?
def
is_being_reassigned?
assignee_id_changed?
assignee_id_changed?
end
end
def
is_being_closed?
closed_changed?
&&
closed
end
end
end
# == Schema Information
# == Schema Information
#
#
...
...
app/models/issue_observer.rb
View file @
356430c3
...
@@ -7,6 +7,7 @@ class IssueObserver < ActiveRecord::Observer
...
@@ -7,6 +7,7 @@ class IssueObserver < ActiveRecord::Observer
def
after_change
(
issue
)
def
after_change
(
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?
end
end
def
send_reassigned_email
(
issue
)
def
send_reassigned_email
(
issue
)
...
@@ -16,5 +17,4 @@ class IssueObserver < ActiveRecord::Observer
...
@@ -16,5 +17,4 @@ class IssueObserver < ActiveRecord::Observer
Notify
.
reassigned_issue_email
(
recipient_id
,
issue
.
id
,
issue
.
assignee_id_was
)
Notify
.
reassigned_issue_email
(
recipient_id
,
issue
.
id
,
issue
.
assignee_id_was
)
end
end
end
end
end
end
spec/models/issue_observer_spec.rb
View file @
356430c3
...
@@ -26,18 +26,41 @@ describe IssueObserver do
...
@@ -26,18 +26,41 @@ describe IssueObserver do
end
end
context
'when an issue is changed'
do
context
'when an issue is changed'
do
it
'sends a reassigned email, if the issue is being reassigned'
do
before
(
:each
)
do
issue
.
should_receive
(
:is_being_reassigned?
).
and_return
(
true
)
issue
.
stub
(
:is_being_reassigned?
).
and_return
(
false
)
subject
.
should_receive
(
:send_reassigned_email
).
with
(
issue
)
issue
.
stub
(
:is_being_closed?
).
and_return
(
false
)
end
context
'a reassigned email'
do
it
'is sent if the issue is being reassigned'
do
issue
.
should_receive
(
:is_being_reassigned?
).
and_return
(
true
)
subject
.
should_receive
(
:send_reassigned_email
).
with
(
issue
)
subject
.
after_change
(
issue
)
end
it
'is not sent if the issue is not being reassigned'
do
issue
.
should_receive
(
:is_being_reassigned?
).
and_return
(
false
)
subject
.
should_not_receive
(
:send_reassigned_email
)
subject
.
after_change
(
issue
)
subject
.
after_change
(
issue
)
end
end
end
it
'does not send a reassigned email, if the issue was not reassigned'
do
context
'a status "closed" note'
do
issue
.
should_receive
(
:is_being_reassigned?
).
and_return
(
false
)
it
'is created if the issue is being closed'
do
subject
.
should_not_receive
(
:send_reassigned_email
)
issue
.
should_receive
(
:is_being_closed?
).
and_return
(
true
)
Note
.
should_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'closed'
)
subject
.
after_change
(
issue
)
end
subject
.
after_change
(
issue
)
it
'is not created if the issue is not being closed'
do
issue
.
should_receive
(
:is_being_closed?
).
and_return
(
false
)
Note
.
should_not_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'closed'
)
subject
.
after_change
(
issue
)
end
end
end
end
end
...
...
spec/models/issue_spec.rb
View file @
356430c3
...
@@ -36,6 +36,25 @@ describe Issue do
...
@@ -36,6 +36,25 @@ describe Issue do
end
end
end
end
describe
'#is_being_closed?'
do
it
'returns true if the closed attribute has changed and is now true'
do
subject
.
closed
=
true
subject
.
is_being_closed?
.
should
be_true
end
it
'returns false if the closed attribute has changed and is now false'
do
issue
=
Factory
.
create
(
:issue
,
:closed
=>
true
,
:author
=>
Factory
(
:user
),
:assignee
=>
Factory
(
:user
),
:project
=>
Factory
.
create
(
:project
))
issue
.
closed
=
false
issue
.
is_being_closed?
.
should
be_false
end
it
'returns false if the closed attribute has not changed'
do
subject
.
is_being_closed?
.
should
be_false
end
end
describe
"plus 1"
do
describe
"plus 1"
do
let
(
:project
)
{
Factory
(
:project
)
}
let
(
:project
)
{
Factory
(
:project
)
}
subject
{
subject
{
...
...
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