Permalink
Browse files

move datamapper stuff back to its rightful place, fiddle with the gem…

…file slightly
  • Loading branch information...
1 parent 2303193 commit 0ea001008a2435df68e103ecebf7f27092d0dc83 @JonRowe JonRowe committed May 31, 2010
Showing with 153 additions and 132 deletions.
  1. +19 −9 Gemfile
  2. +20 −8 Gemfile.lock
  3. +0 −115 lib/database_cleaner/data_mapper/base.rb
  4. +112 −0 lib/database_cleaner/data_mapper/truncation.rb
  5. +2 −0 spec/spec_helper.rb
View
28 Gemfile
@@ -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 "activerecord"
+
gem "datamapper"
- gem "data_objects"
- gem "do_sqlite3"
+ gem "data_objects"
+ gem "do_sqlite3"
+
+ gem "mongo_mapper"
+ gem "mongo"
+ gem "mongo_ext"
+
gem "couch_potato"
- gem "activerecord"
+ gem "bson_ext"
+
gem "rake"
gem "ruby-debug"
+ gem 'sqlite3-ruby'
+
+ gem "ZenTest"
+
+ gem "bundler"
+ gem "jeweler"
end
View
28 Gemfile.lock
@@ -4,46 +4,50 @@ dependencies:
group:
- :development
version: ">= 0"
- datamapper:
+ bson_ext:
group:
- :development
version: ">= 0"
- bson_ext:
+ datamapper:
group:
- :development
version: ">= 0"
mongo:
group:
- :development
version: ">= 0"
- activerecord:
+ ZenTest:
group:
- :development
version: ">= 0"
mongo_mapper:
group:
- :development
version: ">= 0"
- sqlite3-ruby:
+ activerecord:
group:
- :development
version: ">= 0"
- mysql:
+ mongo_ext:
group:
- :development
version: ">= 0"
- mongo_ext:
+ data_objects:
group:
- :development
version: ">= 0"
- data_objects:
+ 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
115 lib/database_cleaner/data_mapper/base.rb
@@ -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
112 lib/database_cleaner/data_mapper/truncation.rb
@@ -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
2 spec/spec_helper.rb
@@ -1,7 +1,9 @@
require "rubygems"
+
require "bundler"
Bundler.setup
+
require 'spec'
#require 'active_record'
#require 'mongo_mapper'

0 comments on commit 0ea0010

Please sign in to comment.