rm15701-add_link_field_project_identifier_substitution-trunk_r12406.diff

Mischa The Evil, 2013-12-15 01:27

Download (2 KB)

View differences:

lib/redmine/field_format.rb (working copy)
289 289
            url.gsub!('%value%') {value.to_s}
290 290
            url.gsub!('%id%') {customized.id.to_s}
291 291
            url.gsub!('%project_id%') {(customized.respond_to?(:project) ? customized.project.try(:id) : nil).to_s}
292
            url.gsub!('%project_identifier%') {(customized.respond_to?(:project) ? customized.project.try(:identifier) : nil).to_s}
292 293
            if custom_field.regexp.present?
293 294
              url.gsub!(%r{%m(\d+)%}) do
294 295
                m = $1.to_i
test/unit/lib/redmine/field_format/link_format_test.rb (working copy)
53 53
    assert_equal '<a href="http://foo/52">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
54 54
  end
55 55

  
56
  def test_link_field_should_substitute_project_identifier_in_url
57
    project = Project.new
58
    project.stubs(:identifier).returns('foo_project-00')
59
    object = Issue.new
60
    object.stubs(:project).returns(project)
61

  
62
    field = IssueCustomField.new(:field_format => 'link', :url_pattern => 'http://foo/%project_identifier%')
63
    custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
64

  
65
    assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
66
    assert_equal '<a href="http://foo/foo_project-00">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
67
  end
68

  
56 69
  def test_link_field_should_substitue_regexp_groups
57 70
    field = IssueCustomField.new(:field_format => 'link', :regexp => /^(.+)-(.+)$/, :url_pattern => 'http://foo/%m2%/%m1%')
58 71
    custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "56-142")