Commit 89a03a3453c988bc15fe837aefaa1c2b2d215ace
1 parent
5d9f2e7d
Exists in
master
and in
4 other branches
1/ rspec'ed
2/ @commit.safe_message as an argument 3/ preserve in helper 4/ spaces around operators
Showing
3 changed files
with
78 additions
and
10 deletions
Show diff stats
app/helpers/commits_helper.rb
| ... | ... | @@ -20,26 +20,27 @@ module CommitsHelper |
| 20 | 20 | def more_commits_link |
| 21 | 21 | offset = params[:offset] || 0 |
| 22 | 22 | limit = params[:limit] || 100 |
| 23 | - link_to "More", project_commits_path(@project, :offset => offset.to_i + limit.to_i, :limit => limit), | |
| 23 | + link_to "More", project_commits_path(project, :offset => offset.to_i + limit.to_i, :limit => limit), | |
| 24 | 24 | :remote => true, :class => "lite_button vm", :style => "text-align:center; width:930px; ", :id => "more-commits-link" |
| 25 | 25 | end |
| 26 | 26 | |
| 27 | - def commit_msg_with_link_to_issues | |
| 28 | - out = "" | |
| 29 | - @commit.safe_message.split(/(#[0-9]+)/m).each do |m| | |
| 27 | + def commit_msg_with_link_to_issues(project, message) | |
| 28 | + return '' unless message | |
| 29 | + out = '' | |
| 30 | + message.split(/(#[0-9]+)/m).each do |m| | |
| 30 | 31 | if m =~ /(#([0-9]+))/m |
| 31 | 32 | begin |
| 32 | 33 | issue = Issue.find($2) |
| 33 | - raise Exception('Issue not belonging to current project, not creating link !') unless issue.project_id == @project.id | |
| 34 | - out+=link_to($1, project_issue_path(@project, $2)) | |
| 34 | + raise Exception('Issue not belonging to current project, not creating link !') unless issue.project_id == project.id | |
| 35 | + out += link_to($1, project_issue_path(project, $2)) | |
| 35 | 36 | rescue |
| 36 | - out+=$1 | |
| 37 | + out += $1 | |
| 37 | 38 | end |
| 38 | 39 | else |
| 39 | - out+= m | |
| 40 | + out += m | |
| 40 | 41 | end |
| 41 | 42 | end |
| 42 | - out | |
| 43 | + preserve out | |
| 43 | 44 | end |
| 44 | 45 | |
| 45 | 46 | end | ... | ... |
app/views/commits/show.html.haml
| ... | ... | @@ -0,0 +1,67 @@ |
| 1 | +require "spec_helper" | |
| 2 | +include Haml::Helpers | |
| 3 | + | |
| 4 | +describe CommitsHelper do | |
| 5 | + | |
| 6 | + before do | |
| 7 | + @project = Factory :project | |
| 8 | + @other_project = Factory :project, :path => "OtherPath", :code => "OtherCode" | |
| 9 | + @fake_user = Factory :user | |
| 10 | + @valid_issue = Factory :issue, :assignee => @fake_user, :author => @fake_user, :project => @project | |
| 11 | + @invalid_issue = Factory :issue, :assignee => @fake_user, :author => @fake_user, :project => @other_project | |
| 12 | + end | |
| 13 | + | |
| 14 | + it "should provides return message untouched if no issue number present" do | |
| 15 | + message = "Dummy message without issue number" | |
| 16 | + | |
| 17 | + commit_msg_with_link_to_issues(@project, message).should eql message | |
| 18 | + end | |
| 19 | + | |
| 20 | + it "should returns message handled by preserve" do | |
| 21 | + message = "My brand new | |
| 22 | + Commit on multiple | |
| 23 | + lines !" | |
| 24 | + | |
| 25 | + #\n are converted to 
 as specified in preserve_rspec | |
| 26 | + expected = "My brand new
 Commit on multiple
 lines !" | |
| 27 | + | |
| 28 | + commit_msg_with_link_to_issues(@project, message).should eql expected | |
| 29 | + end | |
| 30 | + | |
| 31 | + it "should returns empty string if message undefined" do | |
| 32 | + commit_msg_with_link_to_issues(@project, nil).should eql '' | |
| 33 | + end | |
| 34 | + | |
| 35 | + it "should returns link_to issue for one valid issue in message" do | |
| 36 | + issue_id = @valid_issue.id | |
| 37 | + message = "One commit message ##{issue_id}" | |
| 38 | + expected = "One commit message <a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a>" | |
| 39 | + | |
| 40 | + commit_msg_with_link_to_issues(@project, message).should eql expected | |
| 41 | + end | |
| 42 | + | |
| 43 | + it "should returns message untouched for one invalid issue in message" do | |
| 44 | + issue_id = @invalid_issue.id | |
| 45 | + message = "One commit message ##{issue_id}" | |
| 46 | + | |
| 47 | + commit_msg_with_link_to_issues(@project, message).should eql message | |
| 48 | + end | |
| 49 | + | |
| 50 | + it "should handle multiple issue references in commit message" do | |
| 51 | + issue_id = @valid_issue.id | |
| 52 | + invalid_issue_id = @invalid_issue.id | |
| 53 | + | |
| 54 | + message = "One big commit message with a valid issue ##{issue_id} and an invalid one ##{invalid_issue_id}. | |
| 55 | + We reference valid ##{issue_id} multiple times (##{issue_id}) as the invalid ##{invalid_issue_id} is also | |
| 56 | + referenced another time (##{invalid_issue_id})" | |
| 57 | + | |
| 58 | + expected = "One big commit message with a valid issue <a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a>"+ | |
| 59 | + " and an invalid one ##{invalid_issue_id}.
 "+ | |
| 60 | + "We reference valid <a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a> multiple times "+ | |
| 61 | + "(<a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a>) "+ | |
| 62 | + "as the invalid ##{invalid_issue_id} is also
 referenced another time (##{invalid_issue_id})" | |
| 63 | + | |
| 64 | + commit_msg_with_link_to_issues(@project, message).should eql expected | |
| 65 | + end | |
| 66 | + | |
| 67 | +end | |
| 0 | 68 | \ No newline at end of file | ... | ... |