Commit 4ecf30cd5b4731ed7735a658630729fd1c5fc993
1 parent
eb2f3a80
Exists in
spb-stable
and in
3 other branches
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 < ActiveRecord::Base | @@ -72,14 +72,20 @@ class Note < ActiveRecord::Base | ||
| 72 | # +noteable+ was referenced from +mentioner+, by including GFM in either +mentioner+'s description or an associated Note. | 72 | # +noteable+ was referenced from +mentioner+, by including GFM in either +mentioner+'s description or an associated Note. |
| 73 | # Create a system Note associated with +noteable+ with a GFM back-reference to +mentioner+. | 73 | # Create a system Note associated with +noteable+ with a GFM back-reference to +mentioner+. |
| 74 | def create_cross_reference_note(noteable, mentioner, author, project) | 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 | project: project, | 76 | project: project, |
| 79 | author: author, | 77 | author: author, |
| 80 | note: "_mentioned in #{mentioner.gfm_reference}_", | 78 | note: "_mentioned in #{mentioner.gfm_reference}_", |
| 81 | system: true | 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 | end | 89 | end |
| 84 | 90 | ||
| 85 | def create_assignee_change_note(noteable, project, author, assignee) | 91 | def create_assignee_change_note(noteable, project, author, assignee) |
spec/models/note_spec.rb
| @@ -250,6 +250,16 @@ describe Note do | @@ -250,6 +250,16 @@ describe Note do | ||
| 250 | its(:project) { should == project } | 250 | its(:project) { should == project } |
| 251 | its(:note) { should == "_mentioned in merge request !#{mergereq.iid}_" } | 251 | its(:note) { should == "_mentioned in merge request !#{mergereq.iid}_" } |
| 252 | end | 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 | end | 263 | end |
| 254 | 264 | ||
| 255 | describe '#cross_reference_exists?' do | 265 | describe '#cross_reference_exists?' do |