2012-06-22 03:25:23 +00:00
|
|
|
module ContactFakeColumns
|
|
|
|
def self.extended(base)
|
|
|
|
base.class_eval do
|
|
|
|
establish_connection(:adapter => 'fake')
|
|
|
|
|
|
|
|
connection.tables = [table_name]
|
|
|
|
connection.primary_keys = {
|
|
|
|
table_name => 'id'
|
|
|
|
}
|
|
|
|
|
|
|
|
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 21:34:41 +00:00
|
|
|
|
2012-06-22 03:25:23 +00:00
|
|
|
belongs_to :alternative, :class_name => 'Contact'
|
|
|
|
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 = {})
|
|
|
|
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
|
|
|
|
column :type, :string
|
2010-04-30 00:39:52 +00:00
|
|
|
|
2012-06-22 03:25:23 +00:00
|
|
|
def type; 'ContactSti' end
|
2010-04-30 00:39:52 +00:00
|
|
|
end
|