From 7635afd0c4872e2552413b17b1a63bae76e62e45 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Wed, 16 Jan 2013 22:08:01 +0100 Subject: [PATCH] Use Urls for references in GFM --- lib/gitlab/markdown.rb | 10 +++++----- spec/helpers/gitlab_markdown_helper_spec.rb | 8 ++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb index d3f678cf..6fffc599 100644 --- a/lib/gitlab/markdown.rb +++ b/lib/gitlab/markdown.rb @@ -147,31 +147,31 @@ module Gitlab def reference_user(identifier) if member = @project.users_projects.joins(:user).where(users: { username: identifier }).first - link_to("@#{identifier}", project_team_member_path(@project, member), html_options.merge(class: "gfm gfm-team_member #{html_options[:class]}")) if member + link_to("@#{identifier}", project_team_member_url(@project, member), html_options.merge(class: "gfm gfm-team_member #{html_options[:class]}")) if member end end def reference_issue(identifier) if issue = @project.issues.where(id: identifier).first - link_to("##{identifier}", project_issue_path(@project, issue), html_options.merge(title: "Issue: #{issue.title}", class: "gfm gfm-issue #{html_options[:class]}")) + link_to("##{identifier}", project_issue_url(@project, issue), html_options.merge(title: "Issue: #{issue.title}", class: "gfm gfm-issue #{html_options[:class]}")) end end def reference_merge_request(identifier) if merge_request = @project.merge_requests.where(id: identifier).first - link_to("!#{identifier}", project_merge_request_path(@project, merge_request), html_options.merge(title: "Merge Request: #{merge_request.title}", class: "gfm gfm-merge_request #{html_options[:class]}")) + link_to("!#{identifier}", project_merge_request_url(@project, merge_request), html_options.merge(title: "Merge Request: #{merge_request.title}", class: "gfm gfm-merge_request #{html_options[:class]}")) end end def reference_snippet(identifier) if snippet = @project.snippets.where(id: identifier).first - link_to("$#{identifier}", project_snippet_path(@project, snippet), html_options.merge(title: "Snippet: #{snippet.title}", class: "gfm gfm-snippet #{html_options[:class]}")) + link_to("$#{identifier}", project_snippet_url(@project, snippet), html_options.merge(title: "Snippet: #{snippet.title}", class: "gfm gfm-snippet #{html_options[:class]}")) end end def reference_commit(identifier) if @project.valid_repo? && commit = @project.repository.commit(identifier) - link_to(identifier, project_commit_path(@project, commit), html_options.merge(title: CommitDecorator.new(commit).link_title, class: "gfm gfm-commit #{html_options[:class]}")) + link_to(identifier, project_commit_url(@project, commit), html_options.merge(title: CommitDecorator.new(commit).link_title, class: "gfm gfm-commit #{html_options[:class]}")) end end end diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index 497a5f17..7b51efdb 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -272,7 +272,7 @@ describe GitlabMarkdownHelper do groups[0].should match(/This should finally fix $/) # First issue link - groups[1].should match(/href="#{project_issue_path(project, issues[0])}"/) + groups[1].should match(/href="#{project_issue_url(project, issues[0])}"/) groups[1].should match(/##{issues[0].id}$/) # Internal commit link @@ -280,7 +280,7 @@ describe GitlabMarkdownHelper do groups[2].should match(/ and /) # Second issue link - groups[3].should match(/href="#{project_issue_path(project, issues[1])}"/) + groups[3].should match(/href="#{project_issue_url(project, issues[1])}"/) groups[3].should match(/##{issues[1].id}$/) # Trailing commit link @@ -339,5 +339,9 @@ describe GitlabMarkdownHelper do it "should leave inline code untouched" do markdown("\nDon't use `$#{snippet.id}` here.\n").should == "

Don't use $#{snippet.id} here.

\n" end + + it "should generate absolute urls for refs" do + markdown("##{issue.id}").should include(project_issue_url(project, issue)) + end end end