]> source.dussan.org Git - redmine.git/commitdiff
Add project identifier substitution option to the URL-pattern property of link format...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 15 Dec 2013 08:53:02 +0000 (08:53 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 15 Dec 2013 08:53:02 +0000 (08:53 +0000)
Patch by Mischa The Evil.

git-svn-id: http://svn.redmine.org/redmine/trunk@12413 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/field_format.rb
test/unit/lib/redmine/field_format/link_format_test.rb

index ac27831be37734ee3678f8f4811ca813275b85af..799fcf610453309ae151f66acba711137e4fe6dc 100644 (file)
@@ -289,6 +289,7 @@ module Redmine
             url.gsub!('%value%') {value.to_s}
             url.gsub!('%id%') {customized.id.to_s}
             url.gsub!('%project_id%') {(customized.respond_to?(:project) ? customized.project.try(:id) : nil).to_s}
+            url.gsub!('%project_identifier%') {(customized.respond_to?(:project) ? customized.project.try(:identifier) : nil).to_s}
             if custom_field.regexp.present?
               url.gsub!(%r{%m(\d+)%}) do
                 m = $1.to_i
index 339d984aa84304ca68e26ec5ff335f2220d0e06c..04f702728231d0f8c49806a1e053cd1b12e7b65b 100644 (file)
@@ -53,6 +53,19 @@ class Redmine::LinkFieldFormatTest < ActionView::TestCase
     assert_equal '<a href="http://foo/52">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
   end
 
+  def test_link_field_should_substitute_project_identifier_in_url
+    project = Project.new
+    project.stubs(:identifier).returns('foo_project-00')
+    object = Issue.new
+    object.stubs(:project).returns(project)
+
+    field = IssueCustomField.new(:field_format => 'link', :url_pattern => 'http://foo/%project_identifier%')
+    custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
+
+    assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
+    assert_equal '<a href="http://foo/foo_project-00">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
+  end
+
   def test_link_field_should_substitute_regexp_groups
     field = IssueCustomField.new(:field_format => 'link', :regexp => /^(.+)-(.+)$/, :url_pattern => 'http://foo/%m2%/%m1%')
     custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "56-142")