Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ def rss_feed
auto_discovery_link_tag :rss, events_path(format: :xml), title: 'Event-Feed'
end

def label_logo_asset(label_id = Whitelabel[:label_id])
asset_with_fallback("labels/#{label_id}.png", fallback: 'logo.png')
end

def icon(type)
path = image_path Whitelabel.label ? "labels/#{Whitelabel[:label_id]}.ico" : 'favicon.ico'
path = image_path favicon_asset
tag.link rel: type, href: path
end

Expand Down Expand Up @@ -93,6 +97,26 @@ def user_name(user)

private

def favicon_asset
return 'favicon.ico' unless Whitelabel.label

asset_with_fallback("labels/#{Whitelabel[:label_id]}.ico", fallback: 'favicon.ico')
end

def asset_with_fallback(logical_path, fallback:)
return logical_path if asset_file_exists?(logical_path)

fallback
end

def asset_file_exists?(logical_path)
[
Rails.root.join('app/assets/images', logical_path),
Rails.root.join('public', logical_path),
Rails.root.join('public/images', logical_path)
].any?(&:exist?)
end

def markdown_parser
@markdown_parser ||= Redcarpet::Markdown.new Redcarpet::Render::Safe, autolink: true, space_after_headers: true
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/application/_headline.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ header.d-none.d-xl-block
- else
.col-lg-2.text-center
= link_to(root_path, title: title) do
=image_tag("labels/#{Whitelabel[:label_id]}.png", title: title, id: :logo)
= image_tag(label_logo_asset, title: title, id: :logo)

.col-lg-10
= link_to(root_path, id: :title, title: title) do
Expand Down
2 changes: 1 addition & 1 deletion app/views/application/_nav.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
nav.navbar.sticky-top.navbar-expand-lg.navbar-light.bg-light#nav
.label.navbar-brand
= link_to(root_path(anchor: :on_ruby), class: 'navbar-brand ps-4') do
= image_tag("labels/#{Whitelabel[:label_id]}.png", title: title, class: "d-inline-block align-bottom label")
= image_tag(label_logo_asset, title: title, class: "d-inline-block align-bottom label")
.d-none.d-sm-inline.d-md-inline.d-lg-none= I18n.tw('name')

button.navbar-toggler.border-0(type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation")
Expand Down
2 changes: 1 addition & 1 deletion app/views/labels/index.slim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ section.mt-4
- subtitle = t("label.#{label.label_id}.subtitle")
.card
.text-center
span.image= image_tag("labels/#{label.label_id}.png", alt: name, style: "max-height:100px;padding-top:10px")
span.image= image_tag(label_logo_asset(label.label_id), alt: name, style: "max-height:100px;padding-top:10px")
.card-body
h5.card-title= title

Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
module OnRuby
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.0
config.load_defaults 6.1

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
Expand Down
38 changes: 0 additions & 38 deletions config/initializers/new_framework_defaults_5_2.rb

This file was deleted.

45 changes: 0 additions & 45 deletions config/initializers/new_framework_defaults_6_0.rb

This file was deleted.

67 changes: 0 additions & 67 deletions config/initializers/new_framework_defaults_6_1.rb

This file was deleted.

6 changes: 3 additions & 3 deletions spec/controllers/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@
context 'POST :email_login' do
it 'sends the email and redirect to index', :aggregate_failures do
expect { post :email_login, params: { email: 'user@example.org' } }
.to have_enqueued_job(ActionMailer::DeliveryJob)
.to have_enqueued_job(ActionMailer::MailDeliveryJob)

expect(response).to redirect_to(root_path)
end

it 'does not send the email if param missing', :aggregate_failures do
expect { post :email_login }
.not_to have_enqueued_job(ActionMailer::DeliveryJob)
.not_to have_enqueued_job(ActionMailer::MailDeliveryJob)
expect(response).to have_http_status(:unprocessable_entity)
end

it 'does not send the email looks bad', :aggregate_failures do
expect { post :email_login, params: { email: 'user@org' } }
.not_to have_enqueued_job(ActionMailer::DeliveryJob)
.not_to have_enqueued_job(ActionMailer::MailDeliveryJob)
expect(response).to have_http_status(:unprocessable_entity)
end
end
Expand Down
26 changes: 26 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,30 @@
.to include('&lt;script&gt;alert(&quot;xss&quot;);&lt;/script&gt;')
end
end

describe '#browser_icon' do
it 'falls back to the default favicon when the whitelabel icon is missing' do
allow(Whitelabel).to receive(:label).and_return(instance_double(Whitelabel))
allow(Whitelabel).to receive(:[]).with(:label_id).and_return('tokio')

expect(helper.browser_icon).to include('href="/assets/favicon')
end

it 'uses the whitelabel favicon when it exists' do
allow(Whitelabel).to receive(:label).and_return(instance_double(Whitelabel))
allow(Whitelabel).to receive(:[]).with(:label_id).and_return('berlin')

expect(helper.browser_icon).to include('labels/berlin')
end
end

describe '#label_logo_asset' do
it 'falls back to the default logo when the whitelabel logo is missing' do
expect(helper.label_logo_asset('tokio')).to eq('logo.png')
end

it 'uses the whitelabel logo when it exists' do
expect(helper.label_logo_asset('berlin')).to eq('labels/berlin.png')
end
end
end
Loading