diff --git a/TODO b/TODO index e386dc8..585d485 100644 --- a/TODO +++ b/TODO @@ -3,4 +3,5 @@ oh and generic transaction? not implemented i suspect REFACTOR ADAPTORS / STRATEGIES PASS CONNECTION TO STRATEGIES -WHERE ARE DATAMAPPER SPECS? \ No newline at end of file + +WRITE DATAMAPPER SPECS! \ No newline at end of file diff --git a/examples/features/example_multidb.feature b/examples/features/example_multidb.feature new file mode 100644 index 0000000..6906dc6 --- /dev/null +++ b/examples/features/example_multidb.feature @@ -0,0 +1,11 @@ +Feature: example + In order to test DataBase Cleaner + Here are some scenarios that rely on the DB being clean! + + Scenario: dirty the db + When I create a sneaky widget + Then I should see 1 sneaky widget + + Scenario: assume a clean db + When I create a sneaky widget + Then I should see 1 sneaky widget diff --git a/examples/features/step_definitions/example_steps.rb b/examples/features/step_definitions/example_steps.rb index 4b86681..1a3e28f 100644 --- a/examples/features/step_definitions/example_steps.rb +++ b/examples/features/step_definitions/example_steps.rb @@ -6,3 +6,11 @@ Then /^I should see 1 widget$/ do Widget.count.should == 1 end +When /^I create a sneaky widget$/ do + SneakyWidget.create! +end + +Then /^I should see 1 sneaky widget$/ do + SneakyWidget.count.should == 1 +end + diff --git a/examples/features/support/env.rb b/examples/features/support/env.rb index 076fc69..2d50903 100644 --- a/examples/features/support/env.rb +++ b/examples/features/support/env.rb @@ -1,12 +1,14 @@ require 'rubygems' +Bundler.setup require 'spec/expectations' +require 'ruby-debug' orm = ENV['ORM'] strategy = ENV['STRATEGY'] if orm && strategy - begin + begin require "#{File.dirname(__FILE__)}/../../lib/#{orm}_models" rescue LoadError raise "You don't have the #{orm} ORM installed" diff --git a/examples/lib/activerecord_models.rb b/examples/lib/activerecord_models.rb index de156ac..69c7b81 100644 --- a/examples/lib/activerecord_models.rb +++ b/examples/lib/activerecord_models.rb @@ -10,3 +10,8 @@ end class Widget < ActiveRecord::Base end + +class SneakyWidget < ActiveRecord::Base + set_table_name "widgets" + establish_connection(:adapter => "#{"jdbc" if defined?(JRUBY_VERSION)}sqlite3", :database => ":memory:") +end diff --git a/lib/database_cleaner/active_record/strategy.rb b/lib/database_cleaner/active_record/base.rb similarity index 57% rename from lib/database_cleaner/active_record/strategy.rb rename to lib/database_cleaner/active_record/base.rb index 7c744fa..a420149 100644 --- a/lib/database_cleaner/active_record/strategy.rb +++ b/lib/database_cleaner/active_record/base.rb @@ -1,5 +1,5 @@ -require 'database_cleaner/generic/strategy' - +require 'database_cleaner/generic/base' +require 'active_record/base' module DatabaseCleaner module ActiveRecord @@ -7,12 +7,12 @@ module DatabaseCleaner %w[truncation transaction] end - module Strategy - include ::DatabaseCleaner::Generic::Strategy + module Base + include ::DatabaseCleaner::Generic::Base def connection_klass #TODO, multiple connections... - #::ActiveRecord::Base + ::ActiveRecord::Base end end end diff --git a/lib/database_cleaner/active_record/transaction.rb b/lib/database_cleaner/active_record/transaction.rb index ec400df..bc55357 100644 --- a/lib/database_cleaner/active_record/transaction.rb +++ b/lib/database_cleaner/active_record/transaction.rb @@ -1,7 +1,7 @@ -require 'database_cleaner/active_record/strategy' +require 'database_cleaner/active_record/base' module DatabaseCleaner::ActiveRecord class Transaction - include ::DatabaseCleaner::ActiveRecord::Strategy + include ::DatabaseCleaner::ActiveRecord::Base def start if connection_klass.connection.respond_to?(:increment_open_transactions) diff --git a/lib/database_cleaner/active_record/truncation.rb b/lib/database_cleaner/active_record/truncation.rb index b80f3f0..3ffb341 100755 --- a/lib/database_cleaner/active_record/truncation.rb +++ b/lib/database_cleaner/active_record/truncation.rb @@ -1,7 +1,7 @@ require 'active_record/base' require 'active_record/connection_adapters/abstract_adapter' require "database_cleaner/generic/truncation" -require 'database_cleaner/active_record/strategy' +require 'database_cleaner/active_record/base' module ActiveRecord module ConnectionAdapters @@ -71,7 +71,7 @@ end module DatabaseCleaner::ActiveRecord class Truncation - include ::DatabaseCleaner::ActiveRecord::Strategy + include ::DatabaseCleaner::ActiveRecord::Base include ::DatabaseCleaner::Generic::Truncation def clean diff --git a/lib/database_cleaner/couch_potato/adaptor.rb b/lib/database_cleaner/couch_potato/base.rb similarity index 100% rename from lib/database_cleaner/couch_potato/adaptor.rb rename to lib/database_cleaner/couch_potato/base.rb diff --git a/lib/database_cleaner/data_mapper/adaptor.rb b/lib/database_cleaner/data_mapper/base.rb similarity index 100% rename from lib/database_cleaner/data_mapper/adaptor.rb rename to lib/database_cleaner/data_mapper/base.rb diff --git a/lib/database_cleaner/generic/strategy.rb b/lib/database_cleaner/generic/base.rb similarity index 96% rename from lib/database_cleaner/generic/strategy.rb rename to lib/database_cleaner/generic/base.rb index 906c1c6..d13077d 100644 --- a/lib/database_cleaner/generic/strategy.rb +++ b/lib/database_cleaner/generic/base.rb @@ -1,6 +1,6 @@ module ::DatabaseCleaner module Generic - module Strategy + module Base def self.included(base) base.extend(ClassMethods) diff --git a/lib/database_cleaner/mongo_mapper/adaptor.rb b/lib/database_cleaner/mongo_mapper/base.rb similarity index 100% rename from lib/database_cleaner/mongo_mapper/adaptor.rb rename to lib/database_cleaner/mongo_mapper/base.rb diff --git a/spec/database_cleaner/active_record/strategy_spec.rb b/spec/database_cleaner/active_record/base_spec.rb similarity index 80% rename from spec/database_cleaner/active_record/strategy_spec.rb rename to spec/database_cleaner/active_record/base_spec.rb index ff303fa..6e24775 100644 --- a/spec/database_cleaner/active_record/strategy_spec.rb +++ b/spec/database_cleaner/active_record/base_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'database_cleaner/active_record/strategy' +require 'database_cleaner/active_record/base' require 'database_cleaner/shared_strategy_spec' module DatabaseCleaner @@ -9,7 +9,7 @@ module DatabaseCleaner module ActiveRecord class ExampleStrategy - include ::DatabaseCleaner::ActiveRecord::Strategy + include ::DatabaseCleaner::ActiveRecord::Base end describe ExampleStrategy do diff --git a/spec/database_cleaner/active_record/truncation_spec.rb b/spec/database_cleaner/active_record/truncation_spec.rb index 00de9fe..6e19ffc 100644 --- a/spec/database_cleaner/active_record/truncation_spec.rb +++ b/spec/database_cleaner/active_record/truncation_spec.rb @@ -1,6 +1,6 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'database_cleaner/active_record/truncation' -require 'active_record' +require 'active_record/base' module ActiveRecord module ConnectionAdapters diff --git a/spec/database_cleaner/base_spec.rb b/spec/database_cleaner/base_spec.rb index 085bee1..830652e 100644 --- a/spec/database_cleaner/base_spec.rb +++ b/spec/database_cleaner/base_spec.rb @@ -15,10 +15,10 @@ module DatabaseCleaner #Cache all ORMs, we'll need them later but not now. before(:all) do - Temp_AR = ActiveRecord if defined?(::ActiveRecord) and not defined?(Temp_AR) - Temp_DM = DataMapper if defined?(::DataMapper) and not defined?(Temp_DM) - Temp_MM = MongoMapper if defined?(::MongoMapper) and not defined?(Temp_MM) - Temp_CP = CouchPotato if defined?(::CouchPotato) and not defined?(Temp_CP) + Temp_AR = ::ActiveRecord if defined?(::ActiveRecord) and not defined?(Temp_AR) + Temp_DM = ::DataMapper if defined?(::DataMapper) and not defined?(Temp_DM) + Temp_MM = ::MongoMapper if defined?(::MongoMapper) and not defined?(Temp_MM) + Temp_CP = ::CouchPotato if defined?(::CouchPotato) and not defined?(Temp_CP) end #Remove all ORM mocks and restore from cache diff --git a/spec/database_cleaner/generic/strategy_spec.rb b/spec/database_cleaner/generic/base_spec.rb similarity index 74% rename from spec/database_cleaner/generic/strategy_spec.rb rename to spec/database_cleaner/generic/base_spec.rb index af34241..714fbcc 100644 --- a/spec/database_cleaner/generic/strategy_spec.rb +++ b/spec/database_cleaner/generic/base_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' -require 'database_cleaner/generic/strategy' +require 'database_cleaner/generic/base' module ::DatabaseCleaner module Generic - class ExtendedStrategy - include Strategy + class ExampleStrategy + include ::DatabaseCleaner::Generic::Base end - describe ExtendedStrategy do + describe ExampleStrategy do context "class methods" do - subject { ExtendedStrategy } + subject { ExampleStrategy } its (:available_strategies) { should be_empty } end @@ -24,7 +24,7 @@ module ::DatabaseCleaner end it "should accept the desired database upon initalisation" do - eg = ExtendedStrategy.new :my_database + eg = ExampleStrategy.new :my_database eg.db.should == :my_database end end diff --git a/spec/database_cleaner/mongo_mapper/truncation_spec.rb b/spec/database_cleaner/mongo_mapper/truncation_spec.rb index b5aff63..1354eb9 100644 --- a/spec/database_cleaner/mongo_mapper/truncation_spec.rb +++ b/spec/database_cleaner/mongo_mapper/truncation_spec.rb @@ -23,10 +23,6 @@ module DatabaseCleaner #make these specs pend if orm not installed pending "Please install MongoMapper + Mongo to run these specs" unless defined?(::MongoMapper) && defined?(::Mongo) ::MongoMapper.connection.drop_database(@test_db) - - # TODO are these commented out in original? - #::MongoMapper.connection.db(TEST_DATABASE).collections.each {|c| c.remove } - #::MongoMapper.database = TEST_DATABASE end def ensure_counts(expected_counts)