Skip to content

Instantly share code, notes, and snippets.

@ismasan
Created November 4, 2008 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ismasan/22227 to your computer and use it in GitHub Desktop.
Save ismasan/22227 to your computer and use it in GitHub Desktop.
# Create ActiveRecord schemas on the fly for AR extensions testing
#
ActiveRecord::Base.establish_connection(
:adapter=>'sqlite3',
:dbfile=> File.join(File.dirname(__FILE__),'..','spec','db','test.db')
)
# define a migration
class TestSchema < ActiveRecord::Migration
def self.up
create_table :items do |t|
t.string :title
t.string :slug
t.string :permalink
t.boolean :published
t.integer :category_id
t.timestamps
end
end
def self.down
drop_table :items
end
end
namespace :db do
desc "Create test schema"
task :create => :destroy do
# run the migration
TestSchema.migrate(:up)
end
desc "Destroy test schema"
task :destroy do
TestSchema.migrate(:down)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment