diff --git a/bug_report_templates/test-ransack-scope-and-column-same-name.rb b/bug_report_templates/test-ransack-scope-and-column-same-name.rb index a8f0334b..27655dd9 100644 --- a/bug_report_templates/test-ransack-scope-and-column-same-name.rb +++ b/bug_report_templates/test-ransack-scope-and-column-same-name.rb @@ -39,7 +39,7 @@ # Display versions. message = "Running test case with Ruby #{RUBY_VERSION}, Active Record #{ ::ActiveRecord::VERSION::STRING}, Arel #{Arel::VERSION} and #{ - ::ActiveRecord::Base.connection.adapter_name}" + ::ActiveRecord::Base.adapter_class::ADAPTER_NAME}" line = '=' * message.length puts line, message, line diff --git a/bug_report_templates/test-ransacker-arel-present-predicate.rb b/bug_report_templates/test-ransacker-arel-present-predicate.rb index 690ad1ca..eefad098 100644 --- a/bug_report_templates/test-ransacker-arel-present-predicate.rb +++ b/bug_report_templates/test-ransacker-arel-present-predicate.rb @@ -37,7 +37,7 @@ # Display versions. message = "Running test case with Ruby #{RUBY_VERSION}, Active Record #{ ::ActiveRecord::VERSION::STRING}, Arel #{Arel::VERSION} and #{ - ::ActiveRecord::Base.connection.adapter_name}" + ::ActiveRecord::Base.adapter_class::ADAPTER_NAME}" line = '=' * message.length puts line, message, line diff --git a/lib/ransack/adapters/active_record/context.rb b/lib/ransack/adapters/active_record/context.rb index e28fd812..10e315a2 100644 --- a/lib/ransack/adapters/active_record/context.rb +++ b/lib/ransack/adapters/active_record/context.rb @@ -15,7 +15,7 @@ def type_for(attr) relation = attr.arel_attribute.relation name = attr.arel_attribute.name.to_s table = relation.respond_to?(:table_name) ? relation.table_name : relation.name - schema_cache = self.klass.connection.schema_cache + schema_cache = self.klass.connection_pool.schema_cache unless schema_cache.send(:data_source_exists?, table) raise "No table named #{table} exists." end diff --git a/lib/ransack/constants.rb b/lib/ransack/constants.rb index 027e87be..809ec322 100644 --- a/lib/ransack/constants.rb +++ b/lib/ransack/constants.rb @@ -161,7 +161,7 @@ module Constants module_function # replace % \ to \% \\ def escape_wildcards(unescaped) - case ActiveRecord::Base.connection.adapter_name + case ActiveRecord::Base.adapter_class::ADAPTER_NAME when "Mysql2".freeze # Necessary for MySQL unescaped.to_s.gsub(/([\\%_])/, '\\\\\\1') diff --git a/lib/ransack/nodes/condition.rb b/lib/ransack/nodes/condition.rb index 0dc01eb0..77d0ed44 100644 --- a/lib/ransack/nodes/condition.rb +++ b/lib/ransack/nodes/condition.rb @@ -257,7 +257,7 @@ def arel_predicate_for_attribute(attr) end def attr_value_for_attribute(attr) - return attr.attr if ActiveRecord::Base.connection.adapter_name == "PostgreSQL" + return attr.attr if ActiveRecord::Base.adapter_class::ADAPTER_NAME == "PostgreSQL" predicate.case_insensitive ? attr.attr.lower : attr.attr rescue diff --git a/spec/helpers/ransack_helper.rb b/spec/helpers/ransack_helper.rb index f80e883c..4fb50fdf 100644 --- a/spec/helpers/ransack_helper.rb +++ b/spec/helpers/ransack_helper.rb @@ -1,9 +1,9 @@ module RansackHelper def quote_table_name(table) - ActiveRecord::Base.connection.quote_table_name(table) + ActiveRecord::Base.lease_connection.quote_table_name(table) end def quote_column_name(column) - ActiveRecord::Base.connection.quote_column_name(column) + ActiveRecord::Base.lease_connection.quote_column_name(column) end end diff --git a/spec/ransack/adapters/active_record/base_spec.rb b/spec/ransack/adapters/active_record/base_spec.rb index 433db347..f87383d4 100644 --- a/spec/ransack/adapters/active_record/base_spec.rb +++ b/spec/ransack/adapters/active_record/base_spec.rb @@ -277,7 +277,7 @@ module ActiveRecord describe '#ransacker' do # For infix tests def self.sane_adapter? - case ::ActiveRecord::Base.connection.adapter_name + case ::ActiveRecord::Base.adapter_class::ADAPTER_NAME when 'SQLite3', 'PostgreSQL' true else @@ -379,7 +379,7 @@ def self.sane_adapter? context 'searching by underscores' do # when escaping is supported right in LIKE expression without adding extra expressions def self.simple_escaping? - case ::ActiveRecord::Base.connection.adapter_name + case ::ActiveRecord::Base.adapter_class::ADAPTER_NAME when 'Mysql2', 'PostgreSQL' true else diff --git a/spec/ransack/configuration_spec.rb b/spec/ransack/configuration_spec.rb index 9d232143..2244e18d 100644 --- a/spec/ransack/configuration_spec.rb +++ b/spec/ransack/configuration_spec.rb @@ -188,7 +188,7 @@ module Ransack end end - it "PG's sort option", if: ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" do + it "PG's sort option", if: ::ActiveRecord::Base.adapter_class::ADAPTER_NAME == "PostgreSQL" do default = Ransack.options.clone Ransack.configure { |c| c.postgres_fields_sort_option = :nulls_first } diff --git a/spec/ransack/predicate_spec.rb b/spec/ransack/predicate_spec.rb index cf84e200..3cb2d9a1 100644 --- a/spec/ransack/predicate_spec.rb +++ b/spec/ransack/predicate_spec.rb @@ -157,7 +157,7 @@ module Ransack describe 'cont' do it_has_behavior 'wildcard escaping', :name_cont, - (case ActiveRecord::Base.connection.adapter_name + (case ActiveRecord::Base.adapter_class::ADAPTER_NAME when "PostGIS", "PostgreSQL" /"people"."name" ILIKE '%\\%\\.\\_\\\\%'/ when "Mysql2" @@ -177,7 +177,7 @@ module Ransack describe 'not_cont' do it_has_behavior 'wildcard escaping', :name_not_cont, - (case ActiveRecord::Base.connection.adapter_name + (case ActiveRecord::Base.adapter_class::ADAPTER_NAME when "PostGIS", "PostgreSQL" /"people"."name" NOT ILIKE '%\\%\\.\\_\\\\%'/ when "Mysql2" @@ -197,7 +197,7 @@ module Ransack describe 'i_cont' do it_has_behavior 'wildcard escaping', :name_i_cont, - (case ActiveRecord::Base.connection.adapter_name + (case ActiveRecord::Base.adapter_class::ADAPTER_NAME when "PostGIS" /LOWER\("people"."name"\) ILIKE '%\\%\\.\\_\\\\%'/ when "PostgreSQL" @@ -219,7 +219,7 @@ module Ransack describe 'not_i_cont' do it_has_behavior 'wildcard escaping', :name_not_i_cont, - (case ActiveRecord::Base.connection.adapter_name + (case ActiveRecord::Base.adapter_class::ADAPTER_NAME when "PostGIS" /LOWER\("people"."name"\) NOT ILIKE '%\\%\\.\\_\\\\%'/ when "PostgreSQL" @@ -324,14 +324,14 @@ module Ransack @s.awesome_true = true field = "#{quote_table_name("people")}.#{quote_column_name("awesome")}" expect(@s.result.to_sql).to match /#{field} = #{ - ActiveRecord::Base.connection.quoted_true}/ + ActiveRecord::Base.lease_connection.quoted_true}/ end it 'generates an inequality condition for boolean true' do @s.awesome_true = false field = "#{quote_table_name("people")}.#{quote_column_name("awesome")}" expect(@s.result.to_sql).to match /#{field} != #{ - ActiveRecord::Base.connection.quoted_true}/ + ActiveRecord::Base.lease_connection.quoted_true}/ end end @@ -340,14 +340,14 @@ module Ransack @s.awesome_not_true = true field = "#{quote_table_name("people")}.#{quote_column_name("awesome")}" expect(@s.result.to_sql).to match /#{field} != #{ - ActiveRecord::Base.connection.quoted_true}/ + ActiveRecord::Base.lease_connection.quoted_true}/ end it 'generates an equality condition for boolean true' do @s.awesome_not_true = false field = "#{quote_table_name("people")}.#{quote_column_name("awesome")}" expect(@s.result.to_sql).to match /#{field} = #{ - ActiveRecord::Base.connection.quoted_true}/ + ActiveRecord::Base.lease_connection.quoted_true}/ end end @@ -356,14 +356,14 @@ module Ransack @s.awesome_false = true field = "#{quote_table_name("people")}.#{quote_column_name("awesome")}" expect(@s.result.to_sql).to match /#{field} = #{ - ActiveRecord::Base.connection.quoted_false}/ + ActiveRecord::Base.lease_connection.quoted_false}/ end it 'generates an inequality condition for boolean false' do @s.awesome_false = false field = "#{quote_table_name("people")}.#{quote_column_name("awesome")}" expect(@s.result.to_sql).to match /#{field} != #{ - ActiveRecord::Base.connection.quoted_false}/ + ActiveRecord::Base.lease_connection.quoted_false}/ end end @@ -372,14 +372,14 @@ module Ransack @s.awesome_not_false = true field = "#{quote_table_name("people")}.#{quote_column_name("awesome")}" expect(@s.result.to_sql).to match /#{field} != #{ - ActiveRecord::Base.connection.quoted_false}/ + ActiveRecord::Base.lease_connection.quoted_false}/ end it 'generates an equality condition for boolean false' do @s.awesome_not_false = false field = "#{quote_table_name("people")}.#{quote_column_name("awesome")}" expect(@s.result.to_sql).to match /#{field} = #{ - ActiveRecord::Base.connection.quoted_false}/ + ActiveRecord::Base.lease_connection.quoted_false}/ end end diff --git a/spec/ransack/search_spec.rb b/spec/ransack/search_spec.rb index 26433199..5a7d5070 100644 --- a/spec/ransack/search_spec.rb +++ b/spec/ransack/search_spec.rb @@ -666,7 +666,7 @@ def remove_quotes_and_backticks(str) end.to raise_error(Ransack::InvalidSearchError, "Invalid argument (Integer) supplied to sorts=") end - it "PG's sort option", if: ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" do + it "PG's sort option", if: ::ActiveRecord::Base.adapter_class::ADAPTER_NAME == "PostgreSQL" do default = Ransack.options.clone s = Search.new(Person, s: 'name asc') @@ -687,7 +687,7 @@ def remove_quotes_and_backticks(str) Ransack.options = default end - it "PG's sort option with double name", if: ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" do + it "PG's sort option with double name", if: ::ActiveRecord::Base.adapter_class::ADAPTER_NAME == "PostgreSQL" do default = Ransack.options.clone s = Search.new(Person, s: 'doubled_name asc') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 18facc43..6c93f275 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -35,7 +35,7 @@ config.before(:suite) do message = "Running Ransack specs with #{ - ActiveRecord::Base.connection.adapter_name + ActiveRecord::Base.adapter_class::ADAPTER_NAME }, Active Record #{::ActiveRecord::VERSION::STRING}, Arel #{Arel::VERSION } and Ruby #{RUBY_VERSION}" line = '=' * message.length diff --git a/spec/support/schema.rb b/spec/support/schema.rb index 02e5b4a1..66433a47 100644 --- a/spec/support/schema.rb +++ b/spec/support/schema.rb @@ -40,6 +40,8 @@ ) end +ActiveRecord.permanent_connection_checkout = :disallowed + # This is just a test app with no sensitive data, so we explicitly allowlist all # attributes and associations for search. In general, end users should # explicitly authorize each model, but this shows a way to configure the @@ -382,7 +384,7 @@ class OperationHistory < Base module Schema def self.create s = ::ActiveRecord::Schema.new - s.instance_variable_set(:@connection, SubDB::Base.connection) + s.instance_variable_set(:@connection, SubDB::Base.lease_connection) s.verbose = false s.define({}) do create_table :operation_histories, force: true do |t|