diff --git a/app/models/note.rb b/app/models/note.rb index f4c0be3307fcae893b31dec8dc5f691143ec7d1a..48c03c9d587d48291774ccb96d48a8710b853cff 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -72,14 +72,20 @@ class Note < ActiveRecord::Base # +noteable+ was referenced from +mentioner+, by including GFM in either +mentioner+'s description or an associated Note. # Create a system Note associated with +noteable+ with a GFM back-reference to +mentioner+. def create_cross_reference_note(noteable, mentioner, author, project) - create({ - noteable: noteable, - commit_id: (noteable.sha if noteable.respond_to? :sha), + note_options = { project: project, author: author, note: "_mentioned in #{mentioner.gfm_reference}_", system: true - }, without_protection: true) + } + + if noteable.kind_of?(Commit) + note_options.merge!(noteable_type: 'Commit', commit_id: noteable.id) + else + note_options.merge!(noteable: noteable) + end + + create(note_options, without_protection: true) end def create_assignee_change_note(noteable, project, author, assignee) diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 7a00ee83ba4575fb8522d52cf84143e15a18b0ab..6be8a6a13f62bed16a7901cce10056435d6be106 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -250,6 +250,16 @@ describe Note do its(:project) { should == project } its(:note) { should == "_mentioned in merge request !#{mergereq.iid}_" } end + + context 'commit from issue' do + subject { Note.create_cross_reference_note(commit, issue, author, project) } + + it { should be_valid } + its(:noteable_type) { should == "Commit" } + its(:noteable_id) { should be_nil } + its(:commit_id) { should == commit.id } + its(:note) { should == "_mentioned in issue ##{issue.iid}_" } + end end describe '#cross_reference_exists?' do