summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexis Reigel <mail@koffeinfrei.org>2017-09-26 17:04:37 +0200
committerAlexis Reigel <mail@koffeinfrei.org>2018-06-05 16:20:19 +0200
commita6f3f6b8cd2e79acbc824c401435284635071e1a (patch)
tree45155dd3a0efe1071a1aa7313ac26fc7db616aa8
parent606b23dd39bc67b01a52bb189dd938fba87badd2 (diff)
downloadgitlab-ce-a6f3f6b8cd2e79acbc824c401435284635071e1a.tar.gz
extract favicon logic to lib class
-rw-r--r--app/helpers/appearances_helper.rb4
-rw-r--r--app/helpers/page_layout_helper.rb6
-rw-r--r--lib/gitlab/favicon.rb23
-rw-r--r--spec/helpers/page_layout_helper_spec.rb22
-rw-r--r--spec/lib/gitlab/favicon_spec.rb25
5 files changed, 49 insertions, 31 deletions
diff --git a/app/helpers/appearances_helper.rb b/app/helpers/appearances_helper.rb
index 52ee8aec4ad..f48db024e3f 100644
--- a/app/helpers/appearances_helper.rb
+++ b/app/helpers/appearances_helper.rb
@@ -33,8 +33,4 @@ module AppearancesHelper
render 'shared/logo_type.svg'
end
end
-
- def brand_favicon
- brand_item&.favicon
- end
end
diff --git a/app/helpers/page_layout_helper.rb b/app/helpers/page_layout_helper.rb
index b9b0e08cde5..c3dd204181d 100644
--- a/app/helpers/page_layout_helper.rb
+++ b/app/helpers/page_layout_helper.rb
@@ -39,11 +39,7 @@ module PageLayoutHelper
end
def favicon
- return brand_favicon.default.url if brand_favicon
- return 'favicon-yellow.ico' if Gitlab::Utils.to_boolean(ENV['CANARY'])
- return 'favicon-blue.ico' if Rails.env.development?
-
- 'favicon.ico'
+ Gitlab::Favicon.default
end
def page_image
diff --git a/lib/gitlab/favicon.rb b/lib/gitlab/favicon.rb
new file mode 100644
index 00000000000..27150f8d1ea
--- /dev/null
+++ b/lib/gitlab/favicon.rb
@@ -0,0 +1,23 @@
+module Gitlab
+ class Favicon
+ class << self
+ def default
+ return appearance_favicon.default.url if appearance_favicon
+ return 'favicon-yellow.ico' if Gitlab::Utils.to_boolean(ENV['CANARY'])
+ return 'favicon-blue.ico' if Rails.env.development?
+
+ 'favicon.ico'
+ end
+
+ private
+
+ def appearance
+ @appearance ||= Appearance.current
+ end
+
+ def appearance_favicon
+ appearance&.favicon
+ end
+ end
+ end
+end
diff --git a/spec/helpers/page_layout_helper_spec.rb b/spec/helpers/page_layout_helper_spec.rb
index 53ecf25612f..cf98eed27f1 100644
--- a/spec/helpers/page_layout_helper_spec.rb
+++ b/spec/helpers/page_layout_helper_spec.rb
@@ -40,28 +40,6 @@ describe PageLayoutHelper do
end
end
- describe 'favicon' do
- it 'defaults to favicon.ico' do
- allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('production'))
- expect(helper.favicon).to eq 'favicon.ico'
- end
-
- it 'has blue favicon for development' do
- allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('development'))
- expect(helper.favicon).to eq 'favicon-blue.ico'
- end
-
- it 'has yellow favicon for canary' do
- stub_env('CANARY', 'true')
- expect(helper.favicon).to eq 'favicon-yellow.ico'
- end
-
- it 'uses the custom favicon if an favicon appearance is present' do
- create :appearance, favicon: fixture_file_upload(Rails.root.join('spec/fixtures/dk.png'))
- expect(helper.favicon).to match %r{/uploads/-/system/appearance/favicon/\d+/default_dk.ico}
- end
- end
-
describe 'page_image' do
it 'defaults to the GitLab logo' do
expect(helper.page_image).to match_asset_path 'assets/gitlab_logo.png'
diff --git a/spec/lib/gitlab/favicon_spec.rb b/spec/lib/gitlab/favicon_spec.rb
new file mode 100644
index 00000000000..51a8ed47abf
--- /dev/null
+++ b/spec/lib/gitlab/favicon_spec.rb
@@ -0,0 +1,25 @@
+require 'rails_helper'
+
+RSpec.describe Gitlab::Favicon do
+ describe '.default' do
+ it 'defaults to favicon.ico' do
+ allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('production'))
+ expect(described_class.default).to eq 'favicon.ico'
+ end
+
+ it 'has blue favicon for development' do
+ allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('development'))
+ expect(described_class.default).to eq 'favicon-blue.ico'
+ end
+
+ it 'has yellow favicon for canary' do
+ stub_env('CANARY', 'true')
+ expect(described_class.favicon).to eq 'favicon-yellow.ico'
+ end
+
+ it 'uses the custom favicon if a favicon appearance is present' do
+ create :appearance, favicon: fixture_file_upload(Rails.root.join('spec/fixtures/dk.png'))
+ expect(described_class.default).to match %r{/uploads/-/system/appearance/favicon/\d+/default_dk.ico}
+ end
+ end
+end