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 | 186 | |
187 | 187 | patch_path |
188 | 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 | 194 | end |
190 | 195 | |
191 | 196 | # == Schema Information | ... | ... |
app/views/merge_requests/_merge_request.html.haml
spec/models/merge_request_spec.rb
... | ... | @@ -35,4 +35,19 @@ describe MergeRequest do |
35 | 35 | it { should include_module(IssueCommonality) } |
36 | 36 | it { should include_module(Votes) } |
37 | 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 | 53 | end | ... | ... |