changed activerecord / datamapper to sqlite in order to facilitate the testing of multiple databases

This commit is contained in:
Jon Rowe 2010-05-18 07:50:20 +01:00
parent efed6b01bf
commit 7ee7654c48
2 changed files with 23 additions and 8 deletions

View File

@ -1,15 +1,28 @@
require 'active_record'
db_dir = "#{File.dirname(__FILE__)}/../db"
ActiveRecord::Base.establish_connection(:adapter => "#{"jdbc" if defined?(JRUBY_VERSION)}sqlite3", :database => ":memory:")
ActiveRecord::Base.establish_connection(:adapter => "#{"jdbc" if defined?(JRUBY_VERSION)}sqlite3", :database => "#{db_dir}/activerecord_one.db")
class SchemeInfo < ActiveRecord::Base
end
ActiveRecord::Schema.define(:version => 1) do
create_table :widgets do |t|
t.string :name
# check to see if the schema needs resetting (when using file based db)
begin
result = ActiveRecord::Base.connection.execute("SELECT version FROM schema_migrations")
raise StandardError unless result.first["version"] == "1"
rescue
ActiveRecord::Schema.define(:version => 1) do
create_table :widgets do |t|
t.string :name
end
create_table :another_widgets do |t|
t.string :name
end
end
create_table :another_widgets do |t|
t.string :name
end
end
unless defined? Widget

View File

@ -5,7 +5,9 @@ require "dm-core"
require "dm-validations"
require "dm-aggregates"
DataMapper.setup(:default, "sqlite3::memory:")
db_dir = "#{File.dirname(__FILE__)}/../db"
DataMapper.setup(:default, "sqlite3:#{db_dir}/datamapper_one.db")
class MapperWidget
include DataMapper::Resource