Commit 7dbbb6defeba71892230b20c5d1390f94ae1f719

Authored by Marin Jankovski
1 parent 70f828cd

Rename method to avoid clashes.

app/helpers/gitlab_markdown_helper.rb
... ... @@ -75,12 +75,12 @@ module GitlabMarkdownHelper
75 75 def new_link(path_with_namespace, string, ref)
76 76 [
77 77 path_with_namespace,
78   - path(string, ref),
  78 + path_with_ref(string, ref),
79 79 string
80 80 ].compact.join("/")
81 81 end
82 82  
83   - def path(string, ref)
  83 + def path_with_ref(string, ref)
84 84 if File.exists?(Rails.root.join(string))
85 85 "#{local_path(string)}/#{correct_ref(ref)}"
86 86 else
... ...
spec/helpers/gitlab_markdown_helper_spec.rb
... ... @@ -406,6 +406,30 @@ describe GitlabMarkdownHelper do
406 406 it "should generate absolute urls for emoji" do
407 407 markdown(":smile:").should include("src=\"#{url_to_image("emoji/smile")}")
408 408 end
  409 +
  410 + it "should handle relative urls for a file in master" do
  411 + actual = "[GitLab API doc](doc/api/README.md)\n"
  412 + expected = "<p><a href=\"/#{project.path_with_namespace}/blob/master/doc/api/README.md\">GitLab API doc</a></p>\n"
  413 + markdown(actual).should match(expected)
  414 + end
  415 +
  416 + it "should handle relative urls for a directory in master" do
  417 + actual = "[GitLab API doc](doc/api)\n"
  418 + expected = "<p><a href=\"/#{project.path_with_namespace}/tree/master/doc/api\">GitLab API doc</a></p>\n"
  419 + markdown(actual).should match(expected)
  420 + end
  421 +
  422 + it "should handle absolute urls" do
  423 + actual = "[GitLab](https://www.gitlab.com)\n"
  424 + expected = "<p><a href=\"https://www.gitlab.com\">GitLab</a></p>\n"
  425 + markdown(actual).should match(expected)
  426 + end
  427 +
  428 + it "should handle wiki urls" do
  429 + actual = "[Link](test/link)\n"
  430 + expected = "<p><a href=\"/#{project.path_with_namespace}/wikis/test/link\">Link</a></p>\n"
  431 + markdown(actual).should match(expected)
  432 + end
409 433 end
410 434  
411 435 describe "#render_wiki_content" do
... ...