From 01240a1836677b4a737ea1de816ae23be0c2c4b2 Mon Sep 17 00:00:00 2001 From: Tim Zallmann Date: Thu, 9 Nov 2017 17:35:12 +0100 Subject: Fixed Function + Test based on MR --- app/helpers/icons_helper.rb | 5 ++--- spec/helpers/icons_helper_spec.rb | 16 +++++++--------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index fcd41b798a1..c6a83f21ceb 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -1,6 +1,5 @@ module IconsHelper extend self - include Gitlab::CurrentSettings include FontAwesome::Rails::IconHelper # Creates an icon tag given icon name(s) and possible icon modifiers. @@ -27,14 +26,14 @@ module IconsHelper def sprite_icon_path # SVG Sprites currently don't work across domains, so in the case of a CDN # we have to set the current path deliberately to prevent addition of asset_host - sprite_base_url = ActionController::Base.asset_host.present? ? Gitlab.config.gitlab.url : nil + sprite_base_url = Gitlab.config.gitlab.url if ActionController::Base.asset_host ActionController::Base.helpers.image_path('icons.svg', host: sprite_base_url) end def sprite_icon(icon_name, size: nil, css_class: nil) css_classes = size ? "s#{size}" : "" css_classes << " #{css_class}" unless css_class.blank? - content_tag(:svg, content_tag(:use, "", { "xlink:href" => "#{sprite_icon_path()}##{icon_name}" } ), class: css_classes.empty? ? nil : css_classes) + content_tag(:svg, content_tag(:use, "", { "xlink:href" => "#{sprite_icon_path}##{icon_name}" } ), class: css_classes.empty? ? nil : css_classes) end def audit_icon(names, options = {}) diff --git a/spec/helpers/icons_helper_spec.rb b/spec/helpers/icons_helper_spec.rb index ddefc3862ae..fddda0cd627 100644 --- a/spec/helpers/icons_helper_spec.rb +++ b/spec/helpers/icons_helper_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe IconsHelper do + let(:icons_path) { ActionController::Base.helpers.image_path("icons.svg") } + describe 'icon' do it 'returns aria-hidden by default' do star = icon('star') @@ -18,8 +20,8 @@ describe IconsHelper do describe 'sprite_icon_path' do it 'returns relative path' do - expect(sprite_icon_path()) - .to eq icons_path() + expect(sprite_icon_path) + .to eq icons_path end context 'when an asset_host is set in the config it will return an absolute local URL' do @@ -41,17 +43,17 @@ describe IconsHelper do it 'returns svg icon html' do expect(sprite_icon(icon_name).to_s) - .to eq "" + .to eq "" end it 'returns svg icon html + size classes' do expect(sprite_icon(icon_name, size: 72).to_s) - .to eq "" + .to eq "" end it 'returns svg icon html + size classes + additional class' do expect(sprite_icon(icon_name, size: 72, css_class: 'icon-danger').to_s) - .to eq "" + .to eq "" end end @@ -160,8 +162,4 @@ describe IconsHelper do expect(file_type_icon_class('file', 0, 'CHANGELOG')).to eq 'file-text-o' end end - - def icons_path - ActionController::Base.helpers.image_path("icons.svg") - end end -- cgit v1.2.1