2017-07-09 17:41:28 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2012-06-22 03:25:23 +00:00
|
|
|
module ContactFakeColumns
|
|
|
|
def self.extended(base)
|
|
|
|
base.class_eval do
|
2016-08-06 17:37:57 +00:00
|
|
|
establish_connection(adapter: "fake")
|
2012-06-22 03:25:23 +00:00
|
|
|
|
2024-03-01 11:18:50 +00:00
|
|
|
lease_connection.data_sources = [table_name]
|
|
|
|
lease_connection.primary_keys = {
|
2016-08-06 16:26:20 +00:00
|
|
|
table_name => "id"
|
2012-06-22 03:25:23 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 11:10:15 +00:00
|
|
|
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"
|
2012-06-22 03:25:23 +00:00
|
|
|
|
|
|
|
serialize :preferences
|
2011-02-04 21:34:41 +00:00
|
|
|
|
2016-08-06 17:37:57 +00:00
|
|
|
belongs_to :alternative, class_name: "Contact"
|
2012-06-22 03:25:23 +00:00
|
|
|
end
|
|
|
|
end
|
2011-02-01 19:30:09 +00:00
|
|
|
|
2007-09-20 23:22:30 +00:00
|
|
|
# mock out self.columns so no pesky db is needed for these tests
|
2012-06-22 03:25:23 +00:00
|
|
|
def column(name, sql_type = nil, options = {})
|
2024-03-01 11:18:50 +00:00
|
|
|
lease_connection.merge_column(table_name, name, sql_type, options)
|
2007-09-20 23:22:30 +00:00
|
|
|
end
|
2012-06-22 03:25:23 +00:00
|
|
|
end
|
2007-09-20 23:22:30 +00:00
|
|
|
|
2012-06-22 03:25:23 +00:00
|
|
|
class Contact < ActiveRecord::Base
|
|
|
|
extend ContactFakeColumns
|
|
|
|
end
|
2008-01-18 07:27:03 +00:00
|
|
|
|
2012-06-22 03:25:23 +00:00
|
|
|
class ContactSti < ActiveRecord::Base
|
|
|
|
extend ContactFakeColumns
|
2019-04-08 11:10:15 +00:00
|
|
|
column :type, "string"
|
2010-04-30 00:39:52 +00:00
|
|
|
|
2016-08-06 16:26:20 +00:00
|
|
|
def type; "ContactSti" end
|
2010-04-30 00:39:52 +00:00
|
|
|
end
|