mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Added a schema to test with
This commit is contained in:
parent
00479742db
commit
8e63972e6b
2 changed files with 32 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
*.swp
|
*.swp
|
||||||
|
test.db
|
||||||
|
|
|
@ -5,3 +5,34 @@ require 'activerecord'
|
||||||
require 'factory_girl'
|
require 'factory_girl'
|
||||||
require 'shoulda'
|
require 'shoulda'
|
||||||
|
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table :posts, :force => true do |t|
|
||||||
|
t.string :title
|
||||||
|
t.integer :author_id
|
||||||
|
end
|
||||||
|
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
|
||||||
|
|
||||||
|
class Post < ActiveRecord::Base
|
||||||
|
validates_presence_of :title, :author_id
|
||||||
|
belongs_to :author, :class_name => 'User'
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue