]> source.dussan.org Git - redmine.git/commitdiff
Adds #favicon_path and #favicon_url helpers.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 12 Jan 2014 09:58:07 +0000 (09:58 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 12 Jan 2014 09:58:07 +0000 (09:58 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@12661 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
test/unit/helpers/application_helper_test.rb

index 617a9029bc69d8c674cd6fdcf9ab3bd8c3130cf9..200bc1c2cadd8b581c268707f74dc8893fe320f7 100644 (file)
@@ -1270,8 +1270,21 @@ module ApplicationHelper
   end
 
   def favicon
-    fav_path = (current_theme && current_theme.favicon?) ? current_theme.favicon_path : '/favicon.ico'
-    "<link rel='shortcut icon' href='#{image_path(fav_path)}' />".html_safe
+    "<link rel='shortcut icon' href='#{favicon_path}' />".html_safe
+  end
+
+  # Returns the path to the favicon
+  def favicon_path
+    icon = (current_theme && current_theme.favicon?) ? current_theme.favicon_path : '/favicon.ico'
+    image_path(icon)
+  end
+
+  # Returns the full URL to the favicon
+  def favicon_url
+    # TODO: use #image_url introduced in Rails4
+    path = favicon_path
+    base = url_for(:controller => 'welcome', :action => 'index', :only_path => false)
+    base.sub(%r{/+$},'') + '/' + path.sub(%r{^/+},'')
   end
 
   def robot_exclusion_tag
index 82d55702ad9d845b3265de23fa22e2f196249c8b..00a1577571ca2b7c9b2186a2dff1f85f81587d1a 100644 (file)
@@ -1264,4 +1264,26 @@ RAW
     assert_equal '<h2>Foo &#187; Bar</h2>', title('Foo', 'Bar')
     assert_equal 'Bar - Foo - Redmine', html_title
   end
+
+  def test_favicon_path
+    assert_match %r{^/favicon\.ico}, favicon_path
+  end
+
+  def test_favicon_path_with_suburi
+    Redmine::Utils.relative_url_root = '/foo'
+    assert_match %r{^/foo/favicon\.ico}, favicon_path
+  ensure
+    Redmine::Utils.relative_url_root = ''
+  end
+
+  def test_favicon_url
+    assert_match %r{^http://test\.host/favicon\.ico}, favicon_url
+  end
+
+  def test_favicon_url_with_suburi
+    Redmine::Utils.relative_url_root = '/foo'
+    assert_match %r{^http://test\.host/foo/favicon\.ico}, favicon_url
+  ensure
+    Redmine::Utils.relative_url_root = ''
+  end
 end