rails/activerecord/test/models/contact.rb
Jean Boussier 7263da542b Deprecate ConnectionPool#connection
Replaced by `#lease_connection` to better reflect what it does.

`ActiveRecord::Base#connection` is deprecated in the same way
but without a removal timeline nor a deprecation warning.

Inside the Active Record test suite, we do remove `Base.connection`
to ensure it's not used internally.

Some callsites have been converted to use `with_connection`,
some other have been more simply migrated to `lease_connection`
and will serve as a list of callsites to convert for
https://github.com/rails/rails/pull/50793
2024-03-01 14:32:55 +01:00

44 lines
1.1 KiB
Ruby

# frozen_string_literal: true
module ContactFakeColumns
def self.extended(base)
base.class_eval do
establish_connection(adapter: "fake")
lease_connection.data_sources = [table_name]
lease_connection.primary_keys = {
table_name => "id"
}
column :id, "integer"
column :name, "string"
column :age, "integer"
column :avatar, "binary"
column :created_at, "datetime"
column :awesome, "boolean"
column :preferences, "string"
column :alternative_id, "integer"
serialize :preferences
belongs_to :alternative, class_name: "Contact"
end
end
# mock out self.columns so no pesky db is needed for these tests
def column(name, sql_type = nil, options = {})
lease_connection.merge_column(table_name, name, sql_type, options)
end
end
class Contact < ActiveRecord::Base
extend ContactFakeColumns
end
class ContactSti < ActiveRecord::Base
extend ContactFakeColumns
column :type, "string"
def type; "ContactSti" end
end