From 2d00f2dfe41e1c3a4606f3e0d4657617b82ccb78 Mon Sep 17 00:00:00 2001 From: Ariejan de Vroom Date: Thu, 15 Mar 2012 00:51:03 +0200 Subject: [PATCH] Added 'x notes' and +1 counters to issues and merge requests. Refs #549 --- app/models/merge_request.rb | 7 +++- app/views/issues/_show.html.haml | 2 ++ app/views/issues/show.html.haml | 9 +++--- .../merge_requests/_merge_request.html.haml | 4 +++ app/views/merge_requests/show.html.haml | 3 ++ spec/models/merge_request_spec.rb | 32 +++++++++++++++++++ 6 files changed, 52 insertions(+), 5 deletions(-) diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index cd44a25f..9bbbcd47 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -34,7 +34,7 @@ class MergeRequest < ActiveRecord::Base def validate_branches - if target_branch == source_branch + if target_branch == source_branch errors.add :base, "You can not use same branch for source and target branches" end end @@ -51,6 +51,11 @@ class MergeRequest < ActiveRecord::Base def last_commit project.commit(source_branch) end + + # Return the number of +1 comments (upvotes) + def upvotes + notes.select(&:upvote?).size + end end # == Schema Information # diff --git a/app/views/issues/_show.html.haml b/app/views/issues/_show.html.haml index 505fa81e..7b25579f 100644 --- a/app/views/issues/_show.html.haml +++ b/app/views/issues/_show.html.haml @@ -14,6 +14,8 @@ %span.label.important critical - if issue.today? %span.label.success today + - if issue.notes.any? + %span.label= pluralize issue.notes.count, 'note' - if issue.upvotes > 0 %span.label.success= "+#{issue.upvotes}" diff --git a/app/views/issues/show.html.haml b/app/views/issues/show.html.haml index fc0d3498..4769c075 100644 --- a/app/views/issues/show.html.haml +++ b/app/views/issues/show.html.haml @@ -11,9 +11,13 @@ - else = link_to 'Close', project_issue_path(@project, @issue, :issue => {:closed => true }, :status_only => true), :method => :put, :class => "btn", :title => "Close Issue" - if can?(current_user, :admin_project, @project) || @issue.author == current_user - = link_to edit_project_issue_path(@project, @issue), :class => "btn small" do + = link_to edit_project_issue_path(@project, @issue), :class => "btn" do Edit + - if @issue.upvotes > 0 + %button.btn.success= "+#{@issue.upvotes}" + + .back_link = link_to project_issues_path(@project) do ← To issues list @@ -36,9 +40,6 @@ = image_tag gravatar_icon(@issue.assignee_email), :width => 16, :class => "lil_av" %strong.author= link_to_issue_assignee(@issue) - - if @issue.upvotes > 0 - %span.label.success= "+#{@issue.upvotes}" - %hr %div= simple_format @issue.title diff --git a/app/views/merge_requests/_merge_request.html.haml b/app/views/merge_requests/_merge_request.html.haml index 1b8166c5..4b3470f9 100644 --- a/app/views/merge_requests/_merge_request.html.haml +++ b/app/views/merge_requests/_merge_request.html.haml @@ -5,6 +5,10 @@ authored = time_ago_in_words(merge_request.created_at) ago + - if merge_request.notes.any? + %span.label= pluralize merge_request.notes.count, 'note' + - if merge_request.upvotes > 0 + %span.label.success= "+#{merge_request.upvotes}" .right %span.label= merge_request.source_branch → diff --git a/app/views/merge_requests/show.html.haml b/app/views/merge_requests/show.html.haml index e725c198..9c601962 100644 --- a/app/views/merge_requests/show.html.haml +++ b/app/views/merge_requests/show.html.haml @@ -18,6 +18,9 @@ = link_to edit_project_merge_request_path(@project, @merge_request), :class => "btn small" do Edit + - if @merge_request.upvotes > 0 + %button.btn.success= "+#{@merge_request.upvotes}" + .back_link = link_to project_merge_requests_path(@project) do ← To merge requests diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index f6b4cbc8..63996e2e 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -25,6 +25,38 @@ describe MergeRequest do :author => Factory(:user), :assignee => Factory(:user), :project => Factory.create(:project)).should be_valid } + + describe "plus 1" do + let(:project) { Factory(:project) } + subject { + Factory.create(:merge_request, + :author => Factory(:user), + :assignee => Factory(:user), + :project => project) + } + + it "with no notes has a 0/0 score" do + subject.upvotes.should == 0 + end + + it "should recognize non-+1 notes" do + subject.notes << Factory(:note, note: "No +1 here", project: Factory(:project, path: 'plusone', code: 'plusone')) + subject.should have(1).note + subject.notes.first.upvote?.should be_false + subject.upvotes.should == 0 + end + + it "should recognize a single +1 note" do + subject.notes << Factory(:note, note: "+1 This is awesome", project: Factory(:project, path: 'plusone', code: 'plusone')) + subject.upvotes.should == 1 + end + + it "should recognize a multiple +1 notes" do + subject.notes << Factory(:note, note: "+1 This is awesome", project: Factory(:project, path: 'plusone', code: 'plusone')) + subject.notes << Factory(:note, note: "+1 I want this", project: Factory(:project, path: 'plustwo', code: 'plustwo')) + subject.upvotes.should == 2 + end + end end # == Schema Information #