extract favicon logic to lib class

This commit is contained in:
Alexis Reigel 2017-09-26 17:04:37 +02:00
parent 606b23dd39
commit a6f3f6b8cd
No known key found for this signature in database
GPG key ID: C728AF10972E97C0
5 changed files with 49 additions and 31 deletions

View file

@ -33,8 +33,4 @@ module AppearancesHelper
render 'shared/logo_type.svg'
end
end
def brand_favicon
brand_item&.favicon
end
end

View file

@ -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

23
lib/gitlab/favicon.rb Normal file
View file

@ -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

View file

@ -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'

View file

@ -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