Skip to content
Snippets Groups Projects
Commit 0b890e4b authored by Igor Drozdov's avatar Igor Drozdov :two: Committed by Thong Kuah
Browse files

Clean up kwargs deprecation warnings paths

parent 0998b2da
No related branches found
No related tags found
1 merge request!62995[RUN ALL RSPEC] Clean up kwargs deprecation warnings paths
......@@ -53,10 +53,6 @@ def legacy?
endpoint_identifier == LEGACY_IDENTIFIER
end
def token_changed?
attribute_changed?(:token)
end
# Blank token assignment triggers token reset
def prevent_token_assignment
if token.present? && token_changed?
......
......@@ -27,6 +27,22 @@ def attribute_instance_methods_as_symbols
AttrEncrypted.instance_method(:attribute_instance_methods_as_symbols).bind(self).call
end
end
protected
# The attr_encrypted gem is not actively maintained
# At the same time it contains the code that raises kwargs deprecation warnings:
# https://github.com/attr-encrypted/attr_encrypted/blob/master/lib/attr_encrypted/adapters/active_record.rb#L65
#
def attr_encrypted(*attrs)
super
attr = attrs.first
redefine_method(:"#{attr}_changed?") do |**options|
attribute_changed?(attr, **options)
end
end
end
end
end
......
......@@ -55,11 +55,7 @@ def self.kwargs_warning
# one by one
def self.allowed_kwarg_warning_paths
%w[
activerecord-6.0.3.7/lib/active_record/migration.rb
activesupport-6.0.3.7/lib/active_support/cache.rb
activerecord-6.0.3.7/lib/active_record/relation.rb
asciidoctor-2.0.12/lib/asciidoctor/extensions.rb
attr_encrypted-3.1.0/lib/attr_encrypted/adapters/active_record.rb
gitlab-labkit-0.18.0/lib/labkit/correlation/grpc/client_interceptor.rb
]
end
......
......@@ -4,18 +4,20 @@
RSpec.describe 'GitLab monkey-patches to AttrEncrypted' do
describe '#attribute_instance_methods_as_symbols_available?' do
it 'returns false' do
expect(ActiveRecord::Base.__send__(:attribute_instance_methods_as_symbols_available?)).to be_falsy
end
it 'does not define virtual attributes' do
klass = Class.new(ActiveRecord::Base) do
let(:klass) do
Class.new(ActiveRecord::Base) do
# We need some sort of table to work on
self.table_name = 'projects'
attr_encrypted :foo
end
end
it 'returns false' do
expect(ActiveRecord::Base.__send__(:attribute_instance_methods_as_symbols_available?)).to be_falsy
end
it 'does not define virtual attributes' do
instance = klass.new
aggregate_failures do
......@@ -28,5 +30,11 @@
end
end
end
it 'calls attr_changed? method with kwargs' do
obj = klass.new
expect(obj.foo_changed?).to eq(false)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment