Commit 22802500 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch 'add-dispensable_render-method' into 'master'

Add dispensable_render methods

See merge request gitlab-org/gitlab!81546
parents 688ed72c 1780145c
...@@ -18,6 +18,28 @@ module ApplicationHelper ...@@ -18,6 +18,28 @@ module ApplicationHelper
end end
end end
def dispensable_render(...)
render(...)
rescue StandardError => error
if Feature.enabled?(:dispensable_render, default_enabled: :yaml)
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error)
nil
else
raise error
end
end
def dispensable_render_if_exists(...)
render_if_exists(...)
rescue StandardError => error
if Feature.enabled?(:dispensable_render, default_enabled: :yaml)
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error)
nil
else
raise error
end
end
def partial_exists?(partial) def partial_exists?(partial)
lookup_context.exists?(partial, [], true) lookup_context.exists?(partial, [], true)
end end
......
...@@ -3,23 +3,23 @@ ...@@ -3,23 +3,23 @@
= render "layouts/nav/sidebar/#{nav}" = render "layouts/nav/sidebar/#{nav}"
.content-wrapper.content-wrapper-margin{ class: "#{@content_wrapper_class}" } .content-wrapper.content-wrapper-margin{ class: "#{@content_wrapper_class}" }
.mobile-overlay .mobile-overlay
= render_if_exists 'layouts/header/verification_reminder' = dispensable_render_if_exists 'layouts/header/verification_reminder'
.alert-wrapper.gl-force-block-formatting-context .alert-wrapper.gl-force-block-formatting-context
= render 'shared/outdated_browser' = dispensable_render 'shared/outdated_browser'
= render_if_exists "layouts/header/licensed_user_count_threshold" = dispensable_render_if_exists "layouts/header/licensed_user_count_threshold"
= render_if_exists "layouts/header/token_expiry_notification" = dispensable_render_if_exists "layouts/header/token_expiry_notification"
= render "layouts/broadcast" = dispensable_render "layouts/broadcast"
= render "layouts/header/read_only_banner" = dispensable_render "layouts/header/read_only_banner"
= render "layouts/header/registration_enabled_callout" = dispensable_render "layouts/header/registration_enabled_callout"
= render "layouts/nav/classification_level_banner" = dispensable_render "layouts/nav/classification_level_banner"
= yield :flash_message = yield :flash_message
= render "shared/service_ping_consent" = dispensable_render "shared/service_ping_consent"
= render_two_factor_auth_recovery_settings_check = render_two_factor_auth_recovery_settings_check
= render_if_exists "layouts/header/ee_subscribable_banner" = dispensable_render_if_exists "layouts/header/ee_subscribable_banner"
= render_if_exists "layouts/header/seats_count_alert" = dispensable_render_if_exists "layouts/header/seats_count_alert"
= render_if_exists "shared/namespace_storage_limit_alert" = dispensable_render_if_exists "shared/namespace_storage_limit_alert"
= render_if_exists "shared/namespace_user_cap_reached_alert" = dispensable_render_if_exists "shared/namespace_user_cap_reached_alert"
= render_if_exists "shared/new_user_signups_cap_reached_alert" = dispensable_render_if_exists "shared/new_user_signups_cap_reached_alert"
= yield :page_level_alert = yield :page_level_alert
= yield :group_invite_members_banner = yield :group_invite_members_banner
- unless @hide_breadcrumbs - unless @hide_breadcrumbs
......
---
name: dispensable_render
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/81546
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/354337
milestone: '14.9'
type: development
group: group::activation
default_enabled: true
...@@ -517,4 +517,112 @@ RSpec.describe ApplicationHelper do ...@@ -517,4 +517,112 @@ RSpec.describe ApplicationHelper do
end end
end end
end end
describe '#dispensable_render' do
context 'when an error occurs in the template to be rendered' do
before do
allow(helper).to receive(:render).and_raise
end
it 'calls `track_and_raise_for_dev_exception`' do
expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
helper.dispensable_render
end
context 'for development environment' do
before do
stub_rails_env('development')
end
it 'raises an error' do
expect { helper.dispensable_render }.to raise_error(StandardError)
end
end
context 'for production environments' do
before do
stub_rails_env('production')
end
it 'returns nil' do
expect(helper.dispensable_render).to be_nil
end
context 'when the feature flag is disabled' do
before do
stub_feature_flags(dispensable_render: false)
end
it 'raises an error' do
expect { helper.dispensable_render }.to raise_error(StandardError)
end
end
end
end
context 'when no error occurs in the template to be rendered' do
before do
allow(helper).to receive(:render).and_return('foo')
end
it 'does not track or raise and returns the rendered content' do
expect(Gitlab::ErrorTracking).not_to receive(:track_and_raise_for_dev_exception)
expect(helper.dispensable_render).to eq('foo')
end
end
end
describe '#dispensable_render_if_exists' do
context 'when an error occurs in the template to be rendered' do
before do
allow(helper).to receive(:render_if_exists).and_raise
end
it 'calls `track_and_raise_for_dev_exception`' do
expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
helper.dispensable_render_if_exists
end
context 'for development environment' do
before do
stub_rails_env('development')
end
it 'raises an error' do
expect { helper.dispensable_render_if_exists }.to raise_error(StandardError)
end
end
context 'for production environments' do
before do
stub_rails_env('production')
end
it 'returns nil' do
expect(helper.dispensable_render_if_exists).to be_nil
end
context 'when the feature flag is disabled' do
before do
stub_feature_flags(dispensable_render: false)
end
it 'raises an error' do
expect { helper.dispensable_render_if_exists }.to raise_error(StandardError)
end
end
end
end
context 'when no error occurs in the template to be rendered' do
before do
allow(helper).to receive(:render_if_exists).and_return('foo')
end
it 'does not track or raise' do
expect(Gitlab::ErrorTracking).not_to receive(:track_and_raise_for_dev_exception)
expect(helper.dispensable_render_if_exists).to eq('foo')
end
end
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