summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorCedric Gatay <cedric@gatay.fr>2011-12-26 23:22:15 +0100
committerCedric Gatay <cedric@gatay.fr>2011-12-27 00:37:27 +0100
commit89a03a3453c988bc15fe837aefaa1c2b2d215ace (patch)
tree0848d3dae0c41b41c0fa2065d98d548d377338f4 /spec
parent5d9f2e7d1582cce02648c54c373083fc8c1f70c8 (diff)
downloadgitlab-ce-89a03a3453c988bc15fe837aefaa1c2b2d215ace.tar.gz
1/ rspec'ed
2/ @commit.safe_message as an argument 3/ preserve in helper 4/ spaces around operators
Diffstat (limited to 'spec')
-rw-r--r--spec/helpers/commit_helper_spec.rb67
1 files changed, 67 insertions, 0 deletions
diff --git a/spec/helpers/commit_helper_spec.rb b/spec/helpers/commit_helper_spec.rb
new file mode 100644
index 00000000000..747a28a35b9
--- /dev/null
+++ b/spec/helpers/commit_helper_spec.rb
@@ -0,0 +1,67 @@
+require "spec_helper"
+include Haml::Helpers
+
+describe CommitsHelper do
+
+ before do
+ @project = Factory :project
+ @other_project = Factory :project, :path => "OtherPath", :code => "OtherCode"
+ @fake_user = Factory :user
+ @valid_issue = Factory :issue, :assignee => @fake_user, :author => @fake_user, :project => @project
+ @invalid_issue = Factory :issue, :assignee => @fake_user, :author => @fake_user, :project => @other_project
+ end
+
+ it "should provides return message untouched if no issue number present" do
+ message = "Dummy message without issue number"
+
+ commit_msg_with_link_to_issues(@project, message).should eql message
+ end
+
+ it "should returns message handled by preserve" do
+ message = "My brand new
+ Commit on multiple
+ lines !"
+
+ #\n are converted to &#x000A as specified in preserve_rspec
+ expected = "My brand new&#x000A; Commit on multiple&#x000A; lines !"
+
+ commit_msg_with_link_to_issues(@project, message).should eql expected
+ end
+
+ it "should returns empty string if message undefined" do
+ commit_msg_with_link_to_issues(@project, nil).should eql ''
+ end
+
+ it "should returns link_to issue for one valid issue in message" do
+ issue_id = @valid_issue.id
+ message = "One commit message ##{issue_id}"
+ expected = "One commit message <a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a>"
+
+ commit_msg_with_link_to_issues(@project, message).should eql expected
+ end
+
+ it "should returns message untouched for one invalid issue in message" do
+ issue_id = @invalid_issue.id
+ message = "One commit message ##{issue_id}"
+
+ commit_msg_with_link_to_issues(@project, message).should eql message
+ end
+
+ it "should handle multiple issue references in commit message" do
+ issue_id = @valid_issue.id
+ invalid_issue_id = @invalid_issue.id
+
+ message = "One big commit message with a valid issue ##{issue_id} and an invalid one ##{invalid_issue_id}.
+ We reference valid ##{issue_id} multiple times (##{issue_id}) as the invalid ##{invalid_issue_id} is also
+ referenced another time (##{invalid_issue_id})"
+
+ expected = "One big commit message with a valid issue <a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a>"+
+ " and an invalid one ##{invalid_issue_id}.&#x000A; "+
+ "We reference valid <a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a> multiple times "+
+ "(<a href=\"/#{@project.code}/issues/#{issue_id}\">##{issue_id}</a>) "+
+ "as the invalid ##{invalid_issue_id} is also&#x000A; referenced another time (##{invalid_issue_id})"
+
+ commit_msg_with_link_to_issues(@project, message).should eql expected
+ end
+
+end \ No newline at end of file