2008-06-01 14:12:40 -04:00
|
|
|
ActiveRecord::Base.establish_connection(
|
|
|
|
:adapter => 'sqlite3',
|
|
|
|
:database => File.join(File.dirname(__FILE__), 'test.db')
|
|
|
|
)
|
|
|
|
|
|
|
|
class CreateSchema < ActiveRecord::Migration
|
|
|
|
def self.up
|
|
|
|
create_table :users, :force => true do |t|
|
|
|
|
t.string :first_name
|
|
|
|
t.string :last_name
|
|
|
|
t.string :email
|
|
|
|
t.boolean :admin, :default => false
|
|
|
|
end
|
|
|
|
|
|
|
|
create_table :posts, :force => true do |t|
|
2008-07-08 10:05:47 -04:00
|
|
|
t.string :name
|
2008-06-01 14:12:40 -04:00
|
|
|
t.integer :author_id
|
|
|
|
end
|
2008-11-24 18:11:40 -05:00
|
|
|
|
|
|
|
create_table :business, :force => true do |t|
|
|
|
|
t.string :name
|
|
|
|
t.integer :owner_id
|
|
|
|
end
|
2008-06-01 14:12:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
CreateSchema.suppress_messages { CreateSchema.migrate(:up) }
|
|
|
|
|
|
|
|
class User < ActiveRecord::Base
|
|
|
|
validates_presence_of :first_name, :last_name, :email
|
|
|
|
has_many :posts, :foreign_key => 'author_id'
|
|
|
|
end
|
|
|
|
|
2008-11-24 18:11:40 -05:00
|
|
|
class Business < ActiveRecord::Base
|
|
|
|
validates_presence_of :name, :owner_id
|
|
|
|
belongs_to :owner, :class_name => 'User'
|
|
|
|
end
|
|
|
|
|
2008-06-01 14:12:40 -04:00
|
|
|
class Post < ActiveRecord::Base
|
2008-07-08 10:05:47 -04:00
|
|
|
validates_presence_of :name, :author_id
|
2008-06-01 14:12:40 -04:00
|
|
|
belongs_to :author, :class_name => 'User'
|
|
|
|
end
|