Commit 6dc8c0eac28d826a4a58bcb3cdac070f3de2a10c
1 parent
77bde9a0
Exists in
master
and in
4 other branches
Make MRs also count and display its commits' notes
Showing
3 changed files
with
21 additions
and
1 deletions
Show diff stats
app/models/merge_request.rb
@@ -186,6 +186,11 @@ class MergeRequest < ActiveRecord::Base | @@ -186,6 +186,11 @@ class MergeRequest < ActiveRecord::Base | ||
186 | 186 | ||
187 | patch_path | 187 | patch_path |
188 | end | 188 | end |
189 | + | ||
190 | + def mr_and_commit_notes | ||
191 | + commit_ids = commits.map(&:id) | ||
192 | + Note.where("(noteable_type = 'MergeRequest' AND noteable_id = :mr_id) OR (noteable_type = 'Commit' AND noteable_id IN (:commit_ids))", mr_id: id, commit_ids: commit_ids) | ||
193 | + end | ||
189 | end | 194 | end |
190 | 195 | ||
191 | # == Schema Information | 196 | # == Schema Information |
app/views/merge_requests/_merge_request.html.haml
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | - if merge_request.notes.any? | 9 | - if merge_request.notes.any? |
10 | %span.btn.small.disabled.grouped | 10 | %span.btn.small.disabled.grouped |
11 | %i.icon-comment | 11 | %i.icon-comment |
12 | - = merge_request.notes.count | 12 | + = merge_request.mr_and_commit_notes.count |
13 | %span.btn.small.disabled.grouped | 13 | %span.btn.small.disabled.grouped |
14 | = merge_request.source_branch | 14 | = merge_request.source_branch |
15 | → | 15 | → |
spec/models/merge_request_spec.rb
@@ -35,4 +35,19 @@ describe MergeRequest do | @@ -35,4 +35,19 @@ describe MergeRequest do | ||
35 | it { should include_module(IssueCommonality) } | 35 | it { should include_module(IssueCommonality) } |
36 | it { should include_module(Votes) } | 36 | it { should include_module(Votes) } |
37 | end | 37 | end |
38 | + | ||
39 | + describe "#mr_and_commit_notes" do | ||
40 | + let!(:merge_request) { Factory.create(:merge_request) } | ||
41 | + | ||
42 | + before do | ||
43 | + merge_request.stub(:commits) { [merge_request.project.commit] } | ||
44 | + Factory.create(:note, noteable: merge_request.commits.first) | ||
45 | + Factory.create(:note, noteable: merge_request) | ||
46 | + end | ||
47 | + | ||
48 | + it "should include notes for commits" do | ||
49 | + merge_request.commits.should_not be_empty | ||
50 | + merge_request.mr_and_commit_notes.count.should == 2 | ||
51 | + end | ||
52 | + end | ||
38 | end | 53 | end |