mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
152b85f06c
These new methods are used from the Active Record model layer to determine which relations are viable to back a model. These new methods allow us to change `conn.tables` in the future to only return tables and no views. Same for `conn.table_exists?`. The goal is to provide the following introspection methods on the connection: * `tables` * `table_exists?` * `views` * `view_exists?` * `data_sources` (views + tables) * `data_source_exists?` (views + tables)
41 lines
1 KiB
Ruby
41 lines
1 KiB
Ruby
module ContactFakeColumns
|
|
def self.extended(base)
|
|
base.class_eval do
|
|
establish_connection(:adapter => 'fake')
|
|
|
|
connection.data_sources = [table_name]
|
|
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 = {})
|
|
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
|