Commit 4ecf30cd5b4731ed7735a658630729fd1c5fc993

Authored by Dmitriy Zaporozhets
1 parent eb2f3a80

Fix bug with cross-reference note on commit

It should not set noteable_id if noteable_type is Commit
We have Note#commit_id for this

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing 2 changed files with 20 additions and 4 deletions   Show diff stats
app/models/note.rb
... ... @@ -72,14 +72,20 @@ class Note &lt; ActiveRecord::Base
72 72 # +noteable+ was referenced from +mentioner+, by including GFM in either +mentioner+'s description or an associated Note.
73 73 # Create a system Note associated with +noteable+ with a GFM back-reference to +mentioner+.
74 74 def create_cross_reference_note(noteable, mentioner, author, project)
75   - create({
76   - noteable: noteable,
77   - commit_id: (noteable.sha if noteable.respond_to? :sha),
  75 + note_options = {
78 76 project: project,
79 77 author: author,
80 78 note: "_mentioned in #{mentioner.gfm_reference}_",
81 79 system: true
82   - }, without_protection: true)
  80 + }
  81 +
  82 + if noteable.kind_of?(Commit)
  83 + note_options.merge!(noteable_type: 'Commit', commit_id: noteable.id)
  84 + else
  85 + note_options.merge!(noteable: noteable)
  86 + end
  87 +
  88 + create(note_options, without_protection: true)
83 89 end
84 90  
85 91 def create_assignee_change_note(noteable, project, author, assignee)
... ...
spec/models/note_spec.rb
... ... @@ -250,6 +250,16 @@ describe Note do
250 250 its(:project) { should == project }
251 251 its(:note) { should == "_mentioned in merge request !#{mergereq.iid}_" }
252 252 end
  253 +
  254 + context 'commit from issue' do
  255 + subject { Note.create_cross_reference_note(commit, issue, author, project) }
  256 +
  257 + it { should be_valid }
  258 + its(:noteable_type) { should == "Commit" }
  259 + its(:noteable_id) { should be_nil }
  260 + its(:commit_id) { should == commit.id }
  261 + its(:note) { should == "_mentioned in issue ##{issue.iid}_" }
  262 + end
253 263 end
254 264  
255 265 describe '#cross_reference_exists?' do
... ...