2021-08-02 11:08:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe '0_log_deprecations' do
|
2022-07-06 08:08:36 -04:00
|
|
|
def setup_other_deprecations
|
2022-07-18 08:08:41 -04:00
|
|
|
Warning.process(__FILE__) { :default }
|
2022-07-06 08:08:36 -04:00
|
|
|
end
|
|
|
|
|
2021-08-02 11:08:56 -04:00
|
|
|
def load_initializer
|
|
|
|
load Rails.root.join('config/initializers/0_log_deprecations.rb')
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:env_var) { '1' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_env('GITLAB_LOG_DEPRECATIONS', env_var)
|
2022-07-06 08:08:36 -04:00
|
|
|
setup_other_deprecations
|
2021-08-02 11:08:56 -04:00
|
|
|
load_initializer
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
ActiveSupport::Notifications.unsubscribe('deprecation.rails')
|
|
|
|
end
|
|
|
|
|
2022-07-18 08:08:41 -04:00
|
|
|
around do |example|
|
|
|
|
# reset state changed by initializer
|
|
|
|
Warning.clear(&example)
|
|
|
|
end
|
|
|
|
|
2022-07-06 08:08:36 -04:00
|
|
|
describe 'Ruby deprecations' do
|
2021-08-02 11:08:56 -04:00
|
|
|
context 'when catching deprecations through Kernel#warn' do
|
|
|
|
it 'also logs them to deprecation logger' do
|
|
|
|
expect(Gitlab::DeprecationJsonLogger).to receive(:info).with(
|
|
|
|
message: 'ABC gem is deprecated',
|
|
|
|
source: 'ruby'
|
|
|
|
)
|
|
|
|
|
|
|
|
expect { warn('ABC gem is deprecated') }.to output.to_stderr
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-06 08:08:36 -04:00
|
|
|
describe 'other messages from Kernel#warn' do
|
2021-08-02 11:08:56 -04:00
|
|
|
it 'does not log them to deprecation logger' do
|
|
|
|
expect(Gitlab::DeprecationJsonLogger).not_to receive(:info)
|
|
|
|
|
|
|
|
expect { warn('Sure is hot today') }.to output.to_stderr
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when disabled via environment' do
|
|
|
|
let(:env_var) { '0' }
|
|
|
|
|
|
|
|
it 'does not log them to deprecation logger' do
|
|
|
|
expect(Gitlab::DeprecationJsonLogger).not_to receive(:info)
|
|
|
|
|
|
|
|
expect { warn('ABC gem is deprecated') }.to output.to_stderr
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-06 08:08:36 -04:00
|
|
|
describe 'Rails deprecations' do
|
2021-08-02 11:08:56 -04:00
|
|
|
it 'logs them to deprecation logger' do
|
|
|
|
expect(Gitlab::DeprecationJsonLogger).to receive(:info).with(
|
|
|
|
message: match(/^DEPRECATION WARNING: ABC will be removed/),
|
|
|
|
source: 'rails'
|
|
|
|
)
|
|
|
|
|
|
|
|
expect { ActiveSupport::Deprecation.warn('ABC will be removed') }.to output.to_stderr
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when disabled via environment' do
|
|
|
|
let(:env_var) { '0' }
|
|
|
|
|
|
|
|
it 'does not log them to deprecation logger' do
|
|
|
|
expect(Gitlab::DeprecationJsonLogger).not_to receive(:info)
|
|
|
|
|
|
|
|
expect { ActiveSupport::Deprecation.warn('ABC will be removed') }.to output.to_stderr
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|