Commit 65d34388 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'bug/noteable_id' into 'master'

Fix bug with cross-reference note on commit

Fixes #1018
parents c03df58e 4ecf30cd
...@@ -72,14 +72,20 @@ class Note < ActiveRecord::Base ...@@ -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. # +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+. # Create a system Note associated with +noteable+ with a GFM back-reference to +mentioner+.
def create_cross_reference_note(noteable, mentioner, author, project) def create_cross_reference_note(noteable, mentioner, author, project)
create({ note_options = {
noteable: noteable,
commit_id: (noteable.sha if noteable.respond_to? :sha),
project: project, project: project,
author: author, author: author,
note: "_mentioned in #{mentioner.gfm_reference}_", note: "_mentioned in #{mentioner.gfm_reference}_",
system: true 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 end
def create_assignee_change_note(noteable, project, author, assignee) def create_assignee_change_note(noteable, project, author, assignee)
......
...@@ -250,6 +250,16 @@ describe Note do ...@@ -250,6 +250,16 @@ describe Note do
its(:project) { should == project } its(:project) { should == project }
its(:note) { should == "_mentioned in merge request !#{mergereq.iid}_" } its(:note) { should == "_mentioned in merge request !#{mergereq.iid}_" }
end 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 end
describe '#cross_reference_exists?' do describe '#cross_reference_exists?' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment