summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/note.rb12
-rw-r--r--app/observers/issue_observer.rb5
-rw-r--r--spec/models/note_spec.rb31
3 files changed, 48 insertions, 0 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index 48b36bcafdf..67755f44148 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -82,6 +82,18 @@ class Note < ActiveRecord::Base
}, without_protection: true)
end
+ def create_assignee_change_note(noteable, project, author, assignee)
+ body = assignee.nil? ? '_Assignee removed_' : "_Reassigned to @#{assignee.username}_"
+
+ create({
+ noteable: noteable,
+ project: project,
+ author: author,
+ note: body,
+ system: true
+ }, without_protection: true)
+ end
+
def discussions_from_notes(notes)
discussion_ids = []
discussions = []
diff --git a/app/observers/issue_observer.rb b/app/observers/issue_observer.rb
index 1575cf0f19f..6ef13eb5d5e 100644
--- a/app/observers/issue_observer.rb
+++ b/app/observers/issue_observer.rb
@@ -19,6 +19,7 @@ class IssueObserver < BaseObserver
def after_update(issue)
if issue.is_being_reassigned?
notification.reassigned_issue(issue, current_user)
+ create_assignee_note(issue)
end
issue.notice_added_references(issue.project, current_user)
@@ -32,6 +33,10 @@ class IssueObserver < BaseObserver
Note.create_status_change_note(issue, issue.project, current_user, issue.state, current_commit)
end
+ def create_assignee_note(issue)
+ Note.create_assignee_change_note(issue, issue.project, current_user, issue.assignee)
+ end
+
def execute_hooks(issue)
issue.project.execute_hooks(issue.to_hook_data, :issue_hooks)
end
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 55b264ce8cf..b86603dd4ac 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -180,6 +180,31 @@ describe Note do
end
end
+ describe '#create_assignee_change_note' do
+ let(:project) { create(:project) }
+ let(:thing) { create(:issue, project: project) }
+ let(:author) { create(:user) }
+ let(:assignee) { create(:user) }
+
+ subject { Note.create_assignee_change_note(thing, project, author, assignee) }
+
+ context 'creates and saves a Note' do
+ it { should be_a Note }
+ its(:id) { should_not be_nil }
+ end
+
+ its(:noteable) { should == thing }
+ its(:project) { should == thing.project }
+ its(:author) { should == author }
+ its(:note) { should =~ /Reassigned to @#{assignee.username}/ }
+
+ context 'assignee is removed' do
+ let(:assignee) { nil }
+
+ its(:note) { should =~ /Assignee removed/ }
+ end
+ end
+
describe '#create_cross_reference_note' do
let(:project) { create(:project_with_code) }
let(:author) { create(:user) }
@@ -252,6 +277,7 @@ describe Note do
let(:issue) { create(:issue, project: project) }
let(:other) { create(:issue, project: project) }
let(:author) { create(:user) }
+ let(:assignee) { create(:user) }
it 'should recognize user-supplied notes as non-system' do
@note = create(:note_on_issue)
@@ -267,6 +293,11 @@ describe Note do
@note = Note.create_cross_reference_note(issue, other, author, project)
@note.should be_system
end
+
+ it 'should identify assignee-change notes as system notes' do
+ @note = Note.create_assignee_change_note(issue, project, author, assignee)
+ @note.should be_system
+ end
end
describe :authorization do