move datamapper stuff back to its rightful place, fiddle with the gemfile slightly

This commit is contained in:
Jon Rowe 2010-05-31 14:57:52 +01:00
parent 23031933fa
commit 0ea001008a
5 changed files with 157 additions and 136 deletions

30
Gemfile
View file

@ -1,20 +1,30 @@
source "http://rubygems.org"
group :development do
gem "mysql"
gem 'sqlite3-ruby'
gem "rspec", "1.3.0"
gem "cucumber"
gem "jeweler"
gem "mongo"
gem "mongo_ext"
gem "bson_ext"
gem "mongo_mapper"
gem "datamapper"
gem "data_objects"
gem "do_sqlite3"
gem "couch_potato"
gem "activerecord"
gem "datamapper"
gem "data_objects"
gem "do_sqlite3"
gem "mongo_mapper"
gem "mongo"
gem "mongo_ext"
gem "couch_potato"
gem "bson_ext"
gem "rake"
gem "ruby-debug"
gem 'sqlite3-ruby'
gem "ZenTest"
gem "bundler"
gem "jeweler"
end

View file

@ -4,19 +4,19 @@ dependencies:
group:
- :development
version: ">= 0"
datamapper:
group:
- :development
version: ">= 0"
bson_ext:
group:
- :development
version: ">= 0"
datamapper:
group:
- :development
version: ">= 0"
mongo:
group:
- :development
version: ">= 0"
activerecord:
ZenTest:
group:
- :development
version: ">= 0"
@ -24,11 +24,7 @@ dependencies:
group:
- :development
version: ">= 0"
sqlite3-ruby:
group:
- :development
version: ">= 0"
mysql:
activerecord:
group:
- :development
version: ">= 0"
@ -40,10 +36,18 @@ dependencies:
group:
- :development
version: ">= 0"
mysql:
group:
- :development
version: ">= 0"
rake:
group:
- :development
version: ">= 0"
sqlite3-ruby:
group:
- :development
version: ">= 0"
rspec:
group:
- :development
@ -56,6 +60,10 @@ dependencies:
group:
- :development
version: ">= 0"
bundler:
group:
- :development
version: ">= 0"
cucumber:
group:
- :development
@ -67,6 +75,8 @@ dependencies:
specs:
- rake:
version: 0.8.7
- ZenTest:
version: 4.3.1
- activesupport:
version: 2.3.8
- activerecord:
@ -79,6 +89,8 @@ specs:
version: 1.0.1
- builder:
version: 2.1.2
- bundler:
version: 0.9.25
- columnize:
version: 0.3.1
- mime-types:
@ -157,7 +169,7 @@ specs:
version: 0.10.3
- sqlite3-ruby:
version: 1.2.5
hash: c37ee43fed255276a87c138cb08b2024ac62ae38
hash: e757b477472957856d90c7fa4141c6a69b4ad296
sources:
- Rubygems:
uri: http://rubygems.org

View file

@ -1,119 +1,4 @@
require 'database_cleaner/generic/base'
module DataMapper
module Adapters
class DataObjectsAdapter
def storage_names(repository = :default)
raise NotImplementedError
end
end
class MysqlAdapter < DataObjectsAdapter
# taken from http://github.com/godfat/dm-mapping/tree/master
def storage_names(repository = :default)
select 'SHOW TABLES'
end
def truncate_table(table_name)
execute("TRUNCATE TABLE #{quote_name(table_name)};")
end
# copied from activerecord
def disable_referential_integrity
old = select("SELECT @@FOREIGN_KEY_CHECKS;")
begin
execute("SET FOREIGN_KEY_CHECKS = 0;")
yield
ensure
execute("SET FOREIGN_KEY_CHECKS = #{old};")
end
end
end
class Sqlite3Adapter < DataObjectsAdapter
# taken from http://github.com/godfat/dm-mapping/tree/master
def storage_names(repository = :default)
# activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 177
sql = <<-SQL.compress_lines
SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
SQL
# activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 181
select sql
end
def truncate_table(table_name)
execute("DELETE FROM #{quote_name(table_name)};")
end
# this is a no-op copied from activerecord
# i didn't find out if/how this is possible
# activerecord also doesn't do more here
def disable_referential_integrity
yield
end
end
# FIXME
# i don't know if this works
# i basically just copied activerecord code to get a rough idea what they do.
# i don't have postgres available, so i won't be the one to write this.
# maybe codes below gets some postgres/datamapper user going, though.
class PostgresAdapter < DataObjectsAdapter
# taken from http://github.com/godfat/dm-mapping/tree/master
def storage_names(repository = :default)
sql = <<-SQL.compress_lines
SELECT table_name FROM "information_schema"."tables"
WHERE table_schema = current_schema()
SQL
select(sql)
end
def truncate_table(table_name)
execute("TRUNCATE TABLE #{quote_name(table_name)} CASCADE;")
end
# FIXME
# copied from activerecord
def supports_disable_referential_integrity?
version = select("SHOW server_version")[0][0].split('.')
(version[0].to_i >= 8 && version[1].to_i >= 1) ? true : false
rescue
return false
end
# FIXME
# copied unchanged from activerecord
def disable_referential_integrity(repository = :default)
if supports_disable_referential_integrity? then
execute(storage_names(repository).collect do |name|
"ALTER TABLE #{quote_name(name)} DISABLE TRIGGER ALL"
end.join(";"))
end
yield
ensure
if supports_disable_referential_integrity? then
execute(storage_names(repository).collect do |name|
"ALTER TABLE #{quote_name(name)} ENABLE TRIGGER ALL"
end.join(";"))
end
end
end
end
end
module DatabaseCleaner
module DataMapper
def self.available_strategies

View file

@ -1,7 +1,119 @@
require "database_cleaner/generic/truncation"
require 'database_cleaner/data_mapper/base'
module DataMapper
module Adapters
class DataObjectsAdapter
def storage_names(repository = :default)
raise NotImplementedError
end
end
class MysqlAdapter < DataObjectsAdapter
# taken from http://github.com/godfat/dm-mapping/tree/master
def storage_names(repository = :default)
select 'SHOW TABLES'
end
def truncate_table(table_name)
execute("TRUNCATE TABLE #{quote_name(table_name)};")
end
# copied from activerecord
def disable_referential_integrity
old = select("SELECT @@FOREIGN_KEY_CHECKS;")
begin
execute("SET FOREIGN_KEY_CHECKS = 0;")
yield
ensure
execute("SET FOREIGN_KEY_CHECKS = #{old};")
end
end
end
class Sqlite3Adapter < DataObjectsAdapter
# taken from http://github.com/godfat/dm-mapping/tree/master
def storage_names(repository = :default)
# activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 177
sql = <<-SQL.compress_lines
SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
SQL
# activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 181
select(sql)
end
def truncate_table(table_name)
execute("DELETE FROM #{quote_name(table_name)};")
end
# this is a no-op copied from activerecord
# i didn't find out if/how this is possible
# activerecord also doesn't do more here
def disable_referential_integrity
yield
end
end
# FIXME
# i don't know if this works
# i basically just copied activerecord code to get a rough idea what they do.
# i don't have postgres available, so i won't be the one to write this.
# maybe codes below gets some postgres/datamapper user going, though.
class PostgresAdapter < DataObjectsAdapter
# taken from http://github.com/godfat/dm-mapping/tree/master
def storage_names(repository = :default)
sql = <<-SQL.compress_lines
SELECT table_name FROM "information_schema"."tables"
WHERE table_schema = current_schema()
SQL
select(sql)
end
def truncate_table(table_name)
execute("TRUNCATE TABLE #{quote_name(table_name)} CASCADE;")
end
# FIXME
# copied from activerecord
def supports_disable_referential_integrity?
version = select("SHOW server_version")[0][0].split('.')
(version[0].to_i >= 8 && version[1].to_i >= 1) ? true : false
rescue
return false
end
# FIXME
# copied unchanged from activerecord
def disable_referential_integrity(repository = :default)
if supports_disable_referential_integrity? then
execute(storage_names(repository).collect do |name|
"ALTER TABLE #{quote_name(name)} DISABLE TRIGGER ALL"
end.join(";"))
end
yield
ensure
if supports_disable_referential_integrity? then
execute(storage_names(repository).collect do |name|
"ALTER TABLE #{quote_name(name)} ENABLE TRIGGER ALL"
end.join(";"))
end
end
end
end
end
module DatabaseCleaner

View file

@ -1,7 +1,9 @@
require "rubygems"
require "bundler"
Bundler.setup
require 'spec'
#require 'active_record'
#require 'mongo_mapper'