summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiyad Preukschas <riyad@informatik.uni-bremen.de>2012-10-05 00:25:40 +0200
committerRiyad Preukschas <riyad@informatik.uni-bremen.de>2012-10-10 01:31:36 +0200
commit6dc8c0eac28d826a4a58bcb3cdac070f3de2a10c (patch)
treed65d7d0e9978f4571d54f0454b9ca1fe822176c8
parent77bde9a0e41e9229357983d258eaea9d7ef67017 (diff)
downloadgitlab-ce-6dc8c0eac28d826a4a58bcb3cdac070f3de2a10c.tar.gz
Make MRs also count and display its commits' notes
-rw-r--r--app/models/merge_request.rb5
-rw-r--r--app/views/merge_requests/_merge_request.html.haml2
-rw-r--r--spec/models/merge_request_spec.rb15
3 files changed, 21 insertions, 1 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index b6392ce8f5d..5b3c37249fc 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -186,6 +186,11 @@ class MergeRequest < ActiveRecord::Base
patch_path
end
+
+ def mr_and_commit_notes
+ commit_ids = commits.map(&:id)
+ 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)
+ end
end
# == Schema Information
diff --git a/app/views/merge_requests/_merge_request.html.haml b/app/views/merge_requests/_merge_request.html.haml
index 9d94d670525..419419d2b0f 100644
--- a/app/views/merge_requests/_merge_request.html.haml
+++ b/app/views/merge_requests/_merge_request.html.haml
@@ -9,7 +9,7 @@
- if merge_request.notes.any?
%span.btn.small.disabled.grouped
%i.icon-comment
- = merge_request.notes.count
+ = merge_request.mr_and_commit_notes.count
%span.btn.small.disabled.grouped
= merge_request.source_branch
&rarr;
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 7a1f541f42b..91d404f79c0 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -35,4 +35,19 @@ describe MergeRequest do
it { should include_module(IssueCommonality) }
it { should include_module(Votes) }
end
+
+ describe "#mr_and_commit_notes" do
+ let!(:merge_request) { Factory.create(:merge_request) }
+
+ before do
+ merge_request.stub(:commits) { [merge_request.project.commit] }
+ Factory.create(:note, noteable: merge_request.commits.first)
+ Factory.create(:note, noteable: merge_request)
+ end
+
+ it "should include notes for commits" do
+ merge_request.commits.should_not be_empty
+ merge_request.mr_and_commit_notes.count.should == 2
+ end
+ end
end