Commit 2d00f2dfe41e1c3a4606f3e0d4657617b82ccb78
1 parent
8d8b8212
Exists in
master
and in
4 other branches
Added 'x notes' and +1 counters to issues and merge requests. Refs #549
Showing
6 changed files
with
52 additions
and
5 deletions
Show diff stats
app/models/merge_request.rb
| ... | ... | @@ -34,7 +34,7 @@ class MergeRequest < ActiveRecord::Base |
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | def validate_branches |
| 37 | - if target_branch == source_branch | |
| 37 | + if target_branch == source_branch | |
| 38 | 38 | errors.add :base, "You can not use same branch for source and target branches" |
| 39 | 39 | end |
| 40 | 40 | end |
| ... | ... | @@ -51,6 +51,11 @@ class MergeRequest < ActiveRecord::Base |
| 51 | 51 | def last_commit |
| 52 | 52 | project.commit(source_branch) |
| 53 | 53 | end |
| 54 | + | |
| 55 | + # Return the number of +1 comments (upvotes) | |
| 56 | + def upvotes | |
| 57 | + notes.select(&:upvote?).size | |
| 58 | + end | |
| 54 | 59 | end |
| 55 | 60 | # == Schema Information |
| 56 | 61 | # | ... | ... |
app/views/issues/_show.html.haml
app/views/issues/show.html.haml
| ... | ... | @@ -11,9 +11,13 @@ |
| 11 | 11 | - else |
| 12 | 12 | = link_to 'Close', project_issue_path(@project, @issue, :issue => {:closed => true }, :status_only => true), :method => :put, :class => "btn", :title => "Close Issue" |
| 13 | 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 | 15 | Edit |
| 16 | 16 | |
| 17 | + - if @issue.upvotes > 0 | |
| 18 | + %button.btn.success= "+#{@issue.upvotes}" | |
| 19 | + | |
| 20 | + | |
| 17 | 21 | .back_link |
| 18 | 22 | = link_to project_issues_path(@project) do |
| 19 | 23 | ← To issues list |
| ... | ... | @@ -36,9 +40,6 @@ |
| 36 | 40 | = image_tag gravatar_icon(@issue.assignee_email), :width => 16, :class => "lil_av" |
| 37 | 41 | %strong.author= link_to_issue_assignee(@issue) |
| 38 | 42 | |
| 39 | - - if @issue.upvotes > 0 | |
| 40 | - %span.label.success= "+#{@issue.upvotes}" | |
| 41 | - | |
| 42 | 43 | %hr |
| 43 | 44 | |
| 44 | 45 | %div= simple_format @issue.title | ... | ... |
app/views/merge_requests/_merge_request.html.haml
| ... | ... | @@ -5,6 +5,10 @@ |
| 5 | 5 | authored |
| 6 | 6 | = time_ago_in_words(merge_request.created_at) |
| 7 | 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 | 12 | .right |
| 9 | 13 | %span.label= merge_request.source_branch |
| 10 | 14 | → | ... | ... |
app/views/merge_requests/show.html.haml
| ... | ... | @@ -18,6 +18,9 @@ |
| 18 | 18 | = link_to edit_project_merge_request_path(@project, @merge_request), :class => "btn small" do |
| 19 | 19 | Edit |
| 20 | 20 | |
| 21 | + - if @merge_request.upvotes > 0 | |
| 22 | + %button.btn.success= "+#{@merge_request.upvotes}" | |
| 23 | + | |
| 21 | 24 | .back_link |
| 22 | 25 | = link_to project_merge_requests_path(@project) do |
| 23 | 26 | ← To merge requests | ... | ... |
spec/models/merge_request_spec.rb
| ... | ... | @@ -25,6 +25,38 @@ describe MergeRequest do |
| 25 | 25 | :author => Factory(:user), |
| 26 | 26 | :assignee => Factory(:user), |
| 27 | 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 | 60 | end |
| 29 | 61 | # == Schema Information |
| 30 | 62 | # | ... | ... |