Commit 2d00f2dfe41e1c3a4606f3e0d4657617b82ccb78

Authored by Ariejan de Vroom
1 parent 8d8b8212

Added 'x notes' and +1 counters to issues and merge requests. Refs #549

app/models/merge_request.rb
@@ -34,7 +34,7 @@ class MergeRequest < ActiveRecord::Base @@ -34,7 +34,7 @@ class MergeRequest < ActiveRecord::Base
34 34
35 35
36 def validate_branches 36 def validate_branches
37 - if target_branch == source_branch 37 + if target_branch == source_branch
38 errors.add :base, "You can not use same branch for source and target branches" 38 errors.add :base, "You can not use same branch for source and target branches"
39 end 39 end
40 end 40 end
@@ -51,6 +51,11 @@ class MergeRequest < ActiveRecord::Base @@ -51,6 +51,11 @@ class MergeRequest < ActiveRecord::Base
51 def last_commit 51 def last_commit
52 project.commit(source_branch) 52 project.commit(source_branch)
53 end 53 end
  54 +
  55 + # Return the number of +1 comments (upvotes)
  56 + def upvotes
  57 + notes.select(&:upvote?).size
  58 + end
54 end 59 end
55 # == Schema Information 60 # == Schema Information
56 # 61 #
app/views/issues/_show.html.haml
@@ -14,6 +14,8 @@ @@ -14,6 +14,8 @@
14 %span.label.important critical 14 %span.label.important critical
15 - if issue.today? 15 - if issue.today?
16 %span.label.success today 16 %span.label.success today
  17 + - if issue.notes.any?
  18 + %span.label= pluralize issue.notes.count, 'note'
17 - if issue.upvotes > 0 19 - if issue.upvotes > 0
18 %span.label.success= "+#{issue.upvotes}" 20 %span.label.success= "+#{issue.upvotes}"
19 21
app/views/issues/show.html.haml
@@ -11,9 +11,13 @@ @@ -11,9 +11,13 @@
11 - else 11 - else
12 = link_to 'Close', project_issue_path(@project, @issue, :issue => {:closed => true }, :status_only => true), :method => :put, :class => "btn", :title => "Close Issue" 12 = link_to 'Close', project_issue_path(@project, @issue, :issue => {:closed => true }, :status_only => true), :method => :put, :class => "btn", :title => "Close Issue"
13 - if can?(current_user, :admin_project, @project) || @issue.author == current_user 13 - if can?(current_user, :admin_project, @project) || @issue.author == current_user
14 - = link_to edit_project_issue_path(@project, @issue), :class => "btn small" do 14 + = link_to edit_project_issue_path(@project, @issue), :class => "btn" do
15 Edit 15 Edit
16 16
  17 + - if @issue.upvotes > 0
  18 + %button.btn.success= "+#{@issue.upvotes}"
  19 +
  20 +
17 .back_link 21 .back_link
18 = link_to project_issues_path(@project) do 22 = link_to project_issues_path(@project) do
19 ← To issues list 23 ← To issues list
@@ -36,9 +40,6 @@ @@ -36,9 +40,6 @@
36 = image_tag gravatar_icon(@issue.assignee_email), :width => 16, :class => "lil_av" 40 = image_tag gravatar_icon(@issue.assignee_email), :width => 16, :class => "lil_av"
37 %strong.author= link_to_issue_assignee(@issue) 41 %strong.author= link_to_issue_assignee(@issue)
38 42
39 - - if @issue.upvotes > 0  
40 - %span.label.success= "+#{@issue.upvotes}"  
41 -  
42 %hr 43 %hr
43 44
44 %div= simple_format @issue.title 45 %div= simple_format @issue.title
app/views/merge_requests/_merge_request.html.haml
@@ -5,6 +5,10 @@ @@ -5,6 +5,10 @@
5 authored 5 authored
6 = time_ago_in_words(merge_request.created_at) 6 = time_ago_in_words(merge_request.created_at)
7 ago 7 ago
  8 + - if merge_request.notes.any?
  9 + %span.label= pluralize merge_request.notes.count, 'note'
  10 + - if merge_request.upvotes > 0
  11 + %span.label.success= "+#{merge_request.upvotes}"
8 .right 12 .right
9 %span.label= merge_request.source_branch 13 %span.label= merge_request.source_branch
10 → 14 →
app/views/merge_requests/show.html.haml
@@ -18,6 +18,9 @@ @@ -18,6 +18,9 @@
18 = link_to edit_project_merge_request_path(@project, @merge_request), :class => "btn small" do 18 = link_to edit_project_merge_request_path(@project, @merge_request), :class => "btn small" do
19 Edit 19 Edit
20 20
  21 + - if @merge_request.upvotes > 0
  22 + %button.btn.success= "+#{@merge_request.upvotes}"
  23 +
21 .back_link 24 .back_link
22 = link_to project_merge_requests_path(@project) do 25 = link_to project_merge_requests_path(@project) do
23 ← To merge requests 26 ← To merge requests
spec/models/merge_request_spec.rb
@@ -25,6 +25,38 @@ describe MergeRequest do @@ -25,6 +25,38 @@ describe MergeRequest do
25 :author => Factory(:user), 25 :author => Factory(:user),
26 :assignee => Factory(:user), 26 :assignee => Factory(:user),
27 :project => Factory.create(:project)).should be_valid } 27 :project => Factory.create(:project)).should be_valid }
  28 +
  29 + describe "plus 1" do
  30 + let(:project) { Factory(:project) }
  31 + subject {
  32 + Factory.create(:merge_request,
  33 + :author => Factory(:user),
  34 + :assignee => Factory(:user),
  35 + :project => project)
  36 + }
  37 +
  38 + it "with no notes has a 0/0 score" do
  39 + subject.upvotes.should == 0
  40 + end
  41 +
  42 + it "should recognize non-+1 notes" do
  43 + subject.notes << Factory(:note, note: "No +1 here", project: Factory(:project, path: 'plusone', code: 'plusone'))
  44 + subject.should have(1).note
  45 + subject.notes.first.upvote?.should be_false
  46 + subject.upvotes.should == 0
  47 + end
  48 +
  49 + it "should recognize a single +1 note" do
  50 + subject.notes << Factory(:note, note: "+1 This is awesome", project: Factory(:project, path: 'plusone', code: 'plusone'))
  51 + subject.upvotes.should == 1
  52 + end
  53 +
  54 + it "should recognize a multiple +1 notes" do
  55 + subject.notes << Factory(:note, note: "+1 This is awesome", project: Factory(:project, path: 'plusone', code: 'plusone'))
  56 + subject.notes << Factory(:note, note: "+1 I want this", project: Factory(:project, path: 'plustwo', code: 'plustwo'))
  57 + subject.upvotes.should == 2
  58 + end
  59 + end
28 end 60 end
29 # == Schema Information 61 # == Schema Information
30 # 62 #