diff options
author | Rémy Coutable <remy@rymai.me> | 2016-09-30 11:45:32 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-09-30 11:45:32 +0000 |
commit | a5972bbce689d27192683ad1b8475fb7756bf819 (patch) | |
tree | 8d6af9548bfa673f03373dbb36b2a4b36a91dd24 | |
parent | 6591b594d4907be0c235a9c05e40ac5bbb995d94 (diff) | |
parent | d16e1184befc0b724a7abccfdbe50b3fc8da4ed9 (diff) | |
download | gitlab-ce-a5972bbce689d27192683ad1b8475fb7756bf819.tar.gz |
Merge branch 'replace-alias_method_chain' into 'master'
Remove the "soon to be deprecated" `alias_method_chain` in favor of `Module#prepend`.
## Are there points in the code the reviewer needs to double check?
Double check whether the behavior of `attr_encrypted_no_db_connection` is still the desired one.
## Why was this MR needed?
The `alias_method_chain` becomes deprecated in Rails 5 in favor of the `Module#prepend` introduced in Ruby 2.0.
This MR prevents future deprecated warnings in light of a possible Rails version bump.
Closes #22302
See merge request !6570
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | config/initializers/attr_encrypted_no_db_connection.rb | 25 | ||||
-rw-r--r-- | config/initializers/postgresql_limit_fix.rb | 27 | ||||
-rw-r--r-- | lib/banzai/filter/task_list_filter.rb | 12 |
4 files changed, 35 insertions, 30 deletions
diff --git a/CHANGELOG b/CHANGELOG index 24c5a0409fc..12fcec03514 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,7 @@ v 8.13.0 (unreleased) - Allow the Koding integration to be configured through the API - Fix robots.txt disallowing access to groups starting with "s" (Matt Harrison) - Use a ConnectionPool for Rails.cache on Sidekiq servers + - Replace `alias_method_chain` with `Module#prepend` - Only update issuable labels if they have been changed - Take filters in account in issuable counters. !6496 - Revoke button in Applications Settings underlines on hover. diff --git a/config/initializers/attr_encrypted_no_db_connection.rb b/config/initializers/attr_encrypted_no_db_connection.rb index c668864089b..e007666b852 100644 --- a/config/initializers/attr_encrypted_no_db_connection.rb +++ b/config/initializers/attr_encrypted_no_db_connection.rb @@ -1,20 +1,21 @@ module AttrEncrypted module Adapters module ActiveRecord - def attribute_instance_methods_as_symbols_with_no_db_connection - # Use with_connection so the connection doesn't stay pinned to the thread. - connected = ::ActiveRecord::Base.connection_pool.with_connection(&:active?) rescue false - - if connected - # Call version from AttrEncrypted::Adapters::ActiveRecord - attribute_instance_methods_as_symbols_without_no_db_connection - else - # Call version from AttrEncrypted, i.e., `super` with regards to AttrEncrypted::Adapters::ActiveRecord - AttrEncrypted.instance_method(:attribute_instance_methods_as_symbols).bind(self).call + module DBConnectionQuerier + def attribute_instance_methods_as_symbols + # Use with_connection so the connection doesn't stay pinned to the thread. + connected = ::ActiveRecord::Base.connection_pool.with_connection(&:active?) rescue false + + if connected + # Call version from AttrEncrypted::Adapters::ActiveRecord + super + else + # Call version from AttrEncrypted, i.e., `super` with regards to AttrEncrypted::Adapters::ActiveRecord + AttrEncrypted.instance_method(:attribute_instance_methods_as_symbols).bind(self).call + end end end - - alias_method_chain :attribute_instance_methods_as_symbols, :no_db_connection + prepend DBConnectionQuerier end end end diff --git a/config/initializers/postgresql_limit_fix.rb b/config/initializers/postgresql_limit_fix.rb index 0cb3aaf4d24..4224d857e8a 100644 --- a/config/initializers/postgresql_limit_fix.rb +++ b/config/initializers/postgresql_limit_fix.rb @@ -1,5 +1,19 @@ if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter + module LimitFilter + def add_column(table_name, column_name, type, options = {}) + options.delete(:limit) if type == :text + super(table_name, column_name, type, options) + end + + def change_column(table_name, column_name, type, options = {}) + options.delete(:limit) if type == :text + super(table_name, column_name, type, options) + end + end + + prepend ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::LimitFilter + class TableDefinition def text(*args) options = args.extract_options! @@ -9,18 +23,5 @@ if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) column_names.each { |name| column(name, type, options) } end end - - def add_column_with_limit_filter(table_name, column_name, type, options = {}) - options.delete(:limit) if type == :text - add_column_without_limit_filter(table_name, column_name, type, options) - end - - def change_column_with_limit_filter(table_name, column_name, type, options = {}) - options.delete(:limit) if type == :text - change_column_without_limit_filter(table_name, column_name, type, options) - end - - alias_method_chain :add_column, :limit_filter - alias_method_chain :change_column, :limit_filter end end diff --git a/lib/banzai/filter/task_list_filter.rb b/lib/banzai/filter/task_list_filter.rb index 66608c9859c..4efbcaf5c7f 100644 --- a/lib/banzai/filter/task_list_filter.rb +++ b/lib/banzai/filter/task_list_filter.rb @@ -10,19 +10,21 @@ module Banzai # task_list gem. # # See https://github.com/github/task_list/pull/60 - class TaskListFilter < TaskList::Filter - def add_css_class_with_fix(node, *new_class_names) + module ClassNamesFilter + def add_css_class(node, *new_class_names) if new_class_names.include?('task-list') # Don't add class to all lists return elsif new_class_names.include?('task-list-item') - add_css_class_without_fix(node.parent, 'task-list') + super(node.parent, 'task-list') end - add_css_class_without_fix(node, *new_class_names) + super(node, *new_class_names) end + end - alias_method_chain :add_css_class, :fix + class TaskListFilter < TaskList::Filter + prepend ClassNamesFilter end end end |