2012-06-21 23:25:23 -04: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 16:34:41 -05:00
|
|
|
|
2012-06-21 23:25:23 -04:00
|
|
|
belongs_to :alternative, :class_name => 'Contact'
|
|
|
|
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
|
|
|
|
2012-06-21 23:25:23 -04:00
|
|
|
def type; 'ContactSti' end
|
2010-04-29 20:39:52 -04:00
|
|
|
end
|