Skip to content

Commit

Permalink
move icon helpers to InstanceHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
renchap committed May 19, 2024
1 parent 2015db1 commit 4146080
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 43 deletions.
12 changes: 0 additions & 12 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,6 @@ def mascot_url
full_asset_url(instance_presenter.mascot&.file&.url || frontend_asset_path('images/elephant_ui_plane.svg'))
end

def instance_presenter
@instance_presenter ||= InstancePresenter.new
end

def favicon_path(size = '48')
instance_presenter.favicon&.file&.url(size)
end

def app_icon_path(size = '48')
instance_presenter.app_icon&.file&.url(size)
end

private

def storage_host_var
Expand Down
12 changes: 12 additions & 0 deletions app/helpers/instance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ def description_for_sign_up(invite = nil)
safe_join([description_prefix(invite), I18n.t('auth.description.suffix')], ' ')
end

def instance_presenter
@instance_presenter ||= InstancePresenter.new
end

def favicon_path(size = '48')
instance_presenter.favicon&.file&.url(size)
end

def app_icon_path(size = '48')
instance_presenter.app_icon&.file&.url(size)
end

private

def description_prefix(invite)
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/manifest_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ManifestSerializer < ActiveModel::Serializer
include ApplicationHelper
include InstanceHelper
include RoutingHelper
include ActionView::Helpers::TextHelper

Expand Down
1 change: 0 additions & 1 deletion app/serializers/rest/instance_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class ContactSerializer < ActiveModel::Serializer
end

include InstanceHelper
include ApplicationHelper
include RoutingHelper

attributes :domain, :title, :version, :source_url, :description,
Expand Down
29 changes: 0 additions & 29 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,33 +285,4 @@ def current_theme = 'default'
end
end
end

describe 'favicon' do
context 'when an icon exists' do
let!(:favicon) { Fabricate(:site_upload, var: 'favicon') }
let!(:app_icon) { Fabricate(:site_upload, var: 'app_icon') }

it 'returns the URL of the icon' do
expect(helper.favicon_path).to eq(favicon.file.url('48'))
expect(helper.app_icon_path).to eq(app_icon.file.url('48'))
end

it 'returns the URL of the icon with size parameter' do
expect(helper.favicon_path(16)).to eq(favicon.file.url('16'))
expect(helper.app_icon_path(16)).to eq(app_icon.file.url('16'))
end
end

context 'when an icon does not exist' do
it 'returns nil' do
expect(helper.favicon_path).to be_nil
expect(helper.app_icon_path).to be_nil
end

it 'returns nil with size parameter' do
expect(helper.favicon_path(16)).to be_nil
expect(helper.app_icon_path(16)).to be_nil
end
end
end
end
29 changes: 29 additions & 0 deletions spec/helpers/instance_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,33 @@
expect(helper.site_hostname).to eq 'example.com'
end
end

describe 'favicon' do
context 'when an icon exists' do
let!(:favicon) { Fabricate(:site_upload, var: 'favicon') }
let!(:app_icon) { Fabricate(:site_upload, var: 'app_icon') }

it 'returns the URL of the icon' do
expect(helper.favicon_path).to eq(favicon.file.url('48'))
expect(helper.app_icon_path).to eq(app_icon.file.url('48'))
end

it 'returns the URL of the icon with size parameter' do
expect(helper.favicon_path(16)).to eq(favicon.file.url('16'))
expect(helper.app_icon_path(16)).to eq(app_icon.file.url('16'))
end
end

context 'when an icon does not exist' do
it 'returns nil' do
expect(helper.favicon_path).to be_nil
expect(helper.app_icon_path).to be_nil
end

it 'returns nil with size parameter' do
expect(helper.favicon_path(16)).to be_nil
expect(helper.app_icon_path(16)).to be_nil
end
end
end
end

0 comments on commit 4146080

Please sign in to comment.