mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Refactor
This commit is contained in:
parent
57c11963fb
commit
8da9150a1b
17 changed files with 52 additions and 29 deletions
3
TODO
3
TODO
|
@ -3,4 +3,5 @@ oh and generic transaction? not implemented i suspect
|
|||
|
||||
REFACTOR ADAPTORS / STRATEGIES
|
||||
PASS CONNECTION TO STRATEGIES
|
||||
WHERE ARE DATAMAPPER SPECS?
|
||||
|
||||
WRITE DATAMAPPER SPECS!
|
11
examples/features/example_multidb.feature
Normal file
11
examples/features/example_multidb.feature
Normal file
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module ::DatabaseCleaner
|
||||
module Generic
|
||||
module Strategy
|
||||
module Base
|
||||
|
||||
def self.included(base)
|
||||
base.extend(ClassMethods)
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue