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