diff --git a/.gitignore b/.gitignore index f6ff313..5d0dbeb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,6 @@ coverage pkg .bundle bundled_gems/ +vendor/ examples/db/*.db examples/config/database.yml diff --git a/Gemfile b/Gemfile old mode 100644 new mode 100755 index 1b24676..a82ffc1 --- a/Gemfile +++ b/Gemfile @@ -1,20 +1,20 @@ source "http://rubygems.org" group :development do gem "mysql" - gem "json_pure", "1.2.0" + gem "json_pure", "1.4.3" gem "rspec", "1.3.0" - gem "cucumber" + gem "cucumber", "0.8.1" gem "activerecord" - gem "datamapper", "0.10.2" - gem "data_objects" - gem "do_sqlite3" + gem "datamapper", "1.0.0" + gem "dm-migrations", "1.0.0" + gem "dm-sqlite-adapter", "1.0.0" # mongo requirements - gem "mongo", "1.0.2" + gem "mongo", "1.0.1" gem "mongo_ext", "0.19.3" - gem "bson", "1.0.2" + gem "bson_ext", "1.0.1" gem "mongoid", "1.9.0" #mongoid requires active support <= 2.3.5 diff --git a/Gemfile.lock b/Gemfile.lock index 1ce6b11..38de565 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,11 +11,15 @@ dependencies: datamapper: group: - :development - version: = 0.10.2 + version: = 1.0.0 mongo: group: - :development - version: = 1.0.2 + version: = 1.0.1 + bson_ext: + group: + - :development + version: = 1.0.1 ZenTest: group: - :development @@ -36,10 +40,6 @@ dependencies: group: - :development version: ">= 0" - data_objects: - group: - - :development - version: ">= 0" rake: group: - :development @@ -56,14 +56,14 @@ dependencies: group: - :development version: = 1.3.0 - bson: - group: - - :development - version: = 1.0.2 jeweler: group: - :development version: ">= 0" + dm-sqlite-adapter: + group: + - :development + version: = 1.0.0 bundler: group: - :development @@ -75,19 +75,19 @@ dependencies: cucumber: group: - :development - version: ">= 0" + version: = 0.8.1 json_pure: group: - :development - version: = 1.2.0 + version: = 1.4.3 + dm-migrations: + group: + - :development + version: = 1.0.0 activesupport: group: - :development version: <= 2.3.5 - do_sqlite3: - group: - - :development - version: ">= 0" specs: - rake: version: 0.8.7 @@ -99,10 +99,10 @@ specs: version: 2.3.5 - addressable: version: 2.1.2 -- bcrypt-ruby: - version: 2.1.2 - bson: - version: 1.0.2 + version: 1.0.1 +- bson_ext: + version: 1.0.1 - builder: version: 2.1.2 - bundler: @@ -121,46 +121,52 @@ specs: version: 0.2.31 - diff-lcs: version: 1.1.2 +- trollop: + version: 1.16.2 +- gherkin: + version: 2.0.1 - json_pure: - version: 1.2.0 -- polyglot: - version: 0.3.1 + version: 1.4.3 - term-ansicolor: version: 1.0.5 -- treetop: - version: 1.4.8 - cucumber: - version: 0.6.4 + version: 0.8.1 - data_objects: version: 0.10.2 - extlib: version: 0.9.15 - dm-core: - version: 0.10.2 + version: 1.0.0 - dm-aggregates: - version: 0.10.2 -- dm-constraints: - version: 0.10.2 + version: 1.0.0 - dm-migrations: - version: 0.10.2 + version: 1.0.0 +- dm-constraints: + version: 1.0.0 - fastercsv: version: 1.5.3 - dm-serializer: - version: 0.10.2 + version: 1.0.0 - dm-timestamps: - version: 0.10.2 + version: 1.0.0 +- dm-transactions: + version: 1.0.0 - stringex: version: 1.1.0 - uuidtools: version: 2.1.1 - dm-types: - version: 0.10.2 + version: 1.0.0 - dm-validations: - version: 0.10.2 + version: 1.0.0 - datamapper: - version: 0.10.2 + version: 1.0.0 +- dm-do-adapter: + version: 1.0.0 - do_sqlite3: version: 0.10.2 +- dm-sqlite-adapter: + version: 1.0.0 - durran-validatable: version: 2.0.1 - gemcutter: @@ -176,7 +182,7 @@ specs: - linecache: version: "0.43" - mongo: - version: 1.0.2 + version: 1.0.1 - mongo_ext: version: 0.19.3 - plucky: @@ -200,11 +206,11 @@ specs: version: 1.3.0 - tzinfo: version: 0.3.22 -hash: 8e87490eff1e76efe5e75a0c7380657e6d50ed93 +hash: dabca3250327bd882a442aa36e3708f62eed0a76 sources: - Git: uri: git://github.com/JonRowe/mongomapper.git git: git://github.com/JonRowe/mongomapper.git - ref: c93703c266085ad021a0d9987f7efa0ebd82b5ea + ref: 1bae62df3aea1870a948972c95d7198ddd8f39aa - Rubygems: uri: http://rubygems.org diff --git a/examples/features/datamapper/multiple_db_datamapper.feature b/examples/features/datamapper/multiple_db_datamapper.feature deleted file mode 100644 index a718431..0000000 --- a/examples/features/datamapper/multiple_db_datamapper.feature +++ /dev/null @@ -1,23 +0,0 @@ -Feature: example - In order to test DataBase Cleaner - Here are some scenarios that rely on the DB being clean! - - Background: - Given I have setup database cleaner to clean multiple databases using datamapper - - Scenario: dirty the db - When I create a widget in one db using datamapper - And I create a widget in another db using datamapper - Then I should see 1 widget in one db using datamapper - And I should see 1 widget in another db using datamapper - - Scenario: assume a clean db - When I create a widget in one db using datamapper - Then I should see 1 widget in one db using datamapper - And I should see 0 widget in another db using datamapper - - Scenario: assume a clean db - When I create a widget in another db using datamapper - Then I should see 0 widget in one db using datamapper - And I should see 1 widget in another db using datamapper - diff --git a/examples/features/datamapper/single_db.feature b/examples/features/datamapper/single_db.feature deleted file mode 100644 index e69de29..0000000 diff --git a/examples/features/step_definitions/mongoid_steps.rb b/examples/features/step_definitions/mongoid_steps.rb new file mode 100644 index 0000000..474ef33 --- /dev/null +++ b/examples/features/step_definitions/mongoid_steps.rb @@ -0,0 +1,23 @@ +When /^I create a widget using mongoid$/ do + MongoidWidget.create!( :id => rand(1000)+1000) +end + +Then /^I should see ([\d]+) widget using mongoid$/ do |widget_count| + MongoidWidget.count.should == widget_count.to_i +end + +When /^I create a widget in one db using mongoid$/ do + MongoidWidgetUsingDatabaseOne.create! +end + +When /^I create a widget in another db using mongoid$/ do + MongoidWidgetUsingDatabaseTwo.create! +end + +Then /^I should see ([\d]+) widget in one db using mongoid$/ do |widget_count| + MongoidWidgetUsingDatabaseOne.count.should == widget_count.to_i +end + +Then /^I should see ([\d]+) widget in another db using mongoid$/ do |widget_count| + MongoidWidgetUsingDatabaseTwo.count.should == widget_count.to_i +end \ No newline at end of file diff --git a/examples/features/support/env.rb b/examples/features/support/env.rb index 632a344..6115903 100644 --- a/examples/features/support/env.rb +++ b/examples/features/support/env.rb @@ -1,5 +1,9 @@ +#Hilarious as it seems, this is necessary so bundle exec cucumber works for mongoid cukeage (I'm assuming mongomapper is automatically present because its a git repo) +Object.send(:remove_const, 'MongoMapper') if defined?(::MongoMapper) + require 'rubygems' require 'bundler' + Bundler.setup require 'spec/expectations' require 'ruby-debug' @@ -34,10 +38,7 @@ if orm && strategy - if multiple_db && another_orm - DatabaseCleaner[ orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym, {:connection => :one} ].strategy = strategy.to_sym - DatabaseCleaner[ another_orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym, {:connection => :two} ].strategy = strategy.to_sym - elsif multiple_db + if multiple_db DatabaseCleaner.app_root = "#{File.dirname(__FILE__)}/../.." orm_sym = orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym diff --git a/examples/lib/couchpotato_models.rb b/examples/lib/couchpotato_models.rb index e7ddc14..03b3cc3 100644 --- a/examples/lib/couchpotato_models.rb +++ b/examples/lib/couchpotato_models.rb @@ -1,5 +1,5 @@ require 'couch_potato' -require 'json/pure' +require 'json/pure' unless defined? ::JSON ::CouchPotato::Config.database_name = 'couch_potato_test' class CouchPotatoWidget diff --git a/examples/lib/datamapper_models.rb b/examples/lib/datamapper_models.rb index 9054195..896f347 100644 --- a/examples/lib/datamapper_models.rb +++ b/examples/lib/datamapper_models.rb @@ -1,7 +1,12 @@ require "dm-core" +require "dm-transactions" + +#Datamapper 1.0 requires you to require dm-migrations to automigrate +require "dm-migrations" # only to please activerecord API used in database_cleaner/examples/features/step_definitions # yes, i know that's lazy ... + require "dm-validations" require "dm-aggregates" diff --git a/examples/lib/mongoid_models.rb b/examples/lib/mongoid_models.rb index f014234..9066cdc 100644 --- a/examples/lib/mongoid_models.rb +++ b/examples/lib/mongoid_models.rb @@ -9,15 +9,41 @@ end #::MongoMapper.connection = Mongo::Connection.new('127.0.0.1') #::MongoMapper.database = 'database_cleaner_test' -class Widget +class MongoidWidget include Mongoid::Document field :id, :type => Integer field :name class << self - #mongomapper doesn't seem to provide this... + #mongoid doesn't seem to provide this... def create!(*args) new(*args).save! end end end + +class MongoidWidgetUsingDatabaseOne + include Mongoid::Document + field :id, :type => Integer + field :name + + class << self + #mongoid doesn't seem to provide this... + def create!(*args) + new(*args).save! + end + end +end + +class MongoidWidgetUsingDatabaseTwo + include Mongoid::Document + field :id, :type => Integer + field :name + + class << self + #mongoid doesn't seem to provide this... + def create!(*args) + new(*args).save! + end + end +end \ No newline at end of file diff --git a/features/cleaning_multiple_orms.feature b/features/cleaning_multiple_orms.feature index 3607a65..ded7064 100644 --- a/features/cleaning_multiple_orms.feature +++ b/features/cleaning_multiple_orms.feature @@ -13,7 +13,17 @@ Feature: database cleaning using multiple ORMs | ORM1 | ORM2 | | ActiveRecord | DataMapper | | ActiveRecord | MongoMapper | + | ActiveRecord | Mongoid | + | ActiveRecord | CouchPotato | + | DataMapper | ActiveRecord | | DataMapper | MongoMapper | + | DataMapper | Mongoid | | DataMapper | CouchPotato | + | MongoMapper | ActiveRecord | + | MongoMapper | DataMapper | + | MongoMapper | Mongoid | | MongoMapper | CouchPotato | | CouchPotato | ActiveRecord | + | CouchPotato | DataMapper | + | CouchPotato | MongoMapper | + | CouchPotato | Mongoid | diff --git a/features/step_definitions/database_cleaner_steps.rb b/features/step_definitions/database_cleaner_steps.rb index bdf7f2b..1663d0a 100644 --- a/features/step_definitions/database_cleaner_steps.rb +++ b/features/step_definitions/database_cleaner_steps.rb @@ -4,7 +4,7 @@ Given /^I am using (ActiveRecord|DataMapper|MongoMapper|Mongoid|CouchPotato)$/ d @feature_runner.orm = orm end -Given /^I am using (ActiveRecord|DataMapper|MongoMapper|CouchPotato) and (ActiveRecord|DataMapper|MongoMapper|CouchPotato)$/ do |orm1,orm2| +Given /^I am using (ActiveRecord|DataMapper|MongoMapper|CouchPotato|Mongoid) and (ActiveRecord|DataMapper|MongoMapper|CouchPotato|Mongoid)$/ do |orm1,orm2| @feature_runner = FeatureRunner.new @feature_runner.orm = orm1 @feature_runner.another_orm = orm2 diff --git a/features/support/feature_runner.rb b/features/support/feature_runner.rb index 120f22f..9482b76 100644 --- a/features/support/feature_runner.rb +++ b/features/support/feature_runner.rb @@ -13,11 +13,22 @@ class FeatureRunner def go(feature) full_dir ||= File.expand_path(File.dirname(__FILE__) + "/../../examples/") Dir.chdir(full_dir) do - + + ENV['ORM'] = orm - ENV['ANOTHER_ORM'] = another_orm if another_orm - ENV['MULTIPLE_DBS'] = "true" if multiple_databases ENV['STRATEGY'] = strategy + + if another_orm + ENV['ANOTHER_ORM'] = another_orm + else + ENV['ANOTHER_ORM'] = nil + end + + if multiple_databases + ENV['MULTIPLE_DBS'] = "true" + else + ENV['MULTIPLE_DBS'] = nil + end self.output = `#{"jruby -S " if defined?(JRUBY_VERSION)}cucumber features/#{feature}.feature` diff --git a/lib/database_cleaner/data_mapper/truncation.rb b/lib/database_cleaner/data_mapper/truncation.rb index 9292a0a..58fb565 100644 --- a/lib/database_cleaner/data_mapper/truncation.rb +++ b/lib/database_cleaner/data_mapper/truncation.rb @@ -36,6 +36,7 @@ module DataMapper end + class Sqlite3Adapter < DataObjectsAdapter # taken from http://github.com/godfat/dm-mapping/tree/master @@ -62,7 +63,32 @@ module DataMapper end end + + class SqliteAdapter < 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 diff --git a/spec/database_cleaner/base_spec.rb b/spec/database_cleaner/base_spec.rb index 962d4b1..4fbef92 100644 --- a/spec/database_cleaner/base_spec.rb +++ b/spec/database_cleaner/base_spec.rb @@ -58,6 +58,7 @@ module DatabaseCleaner Object.const_set('ActiveRecord','Actively mocking records.') Object.const_set('DataMapper', 'Mapping data mocks') Object.const_set('MongoMapper', 'Mapping mock mongos') + Object.const_set('Mongoid', 'Mongoid mock') Object.const_set('CouchPotato', 'Couching mock potatos') cleaner.orm.should == :active_record @@ -66,6 +67,7 @@ module DatabaseCleaner it "should detect DataMapper second" do Object.const_set('DataMapper', 'Mapping data mocks') Object.const_set('MongoMapper', 'Mapping mock mongos') + Object.const_set('Mongoid', 'Mongoid mock') Object.const_set('CouchPotato', 'Couching mock potatos') cleaner.orm.should == :data_mapper @@ -73,11 +75,19 @@ module DatabaseCleaner it "should detect MongoMapper third" do Object.const_set('MongoMapper', 'Mapping mock mongos') + Object.const_set('Mongoid', 'Mongoid mock') Object.const_set('CouchPotato', 'Couching mock potatos') cleaner.orm.should == :mongo_mapper end + + it "should detect Mongoid fourth" do + Object.const_set('Mongoid', 'Mongoid mock') + Object.const_set('CouchPotato', 'Couching mock potatos') + cleaner.orm.should == :mongoid + end + it "should detect CouchPotato last" do Object.const_set('CouchPotato', 'Couching mock potatos')