Commit a6f3f6b8 authored by Alexis Reigel's avatar Alexis Reigel

extract favicon logic to lib class

parent 606b23dd
......@@ -33,8 +33,4 @@ module AppearancesHelper
render 'shared/logo_type.svg'
end
end
def brand_favicon
brand_item&.favicon
end
end
......@@ -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
......
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
......@@ -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'
......
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment