mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Merge pull request #304 from DatabaseCleaner/fixes_cucumber_failures
Fixes cucumber failures
This commit is contained in:
commit
a1ac42cf41
5 changed files with 32 additions and 26 deletions
|
@ -3,8 +3,7 @@ rvm:
|
|||
- 1.9.3
|
||||
- 2.0.0
|
||||
- 2.1.0
|
||||
# TODO: make this work with the regular rake command
|
||||
script: "bundle exec rake spec"
|
||||
script: "bundle exec rake"
|
||||
gemfile:
|
||||
- Gemfile
|
||||
before_script:
|
||||
|
|
|
@ -30,9 +30,6 @@ if orm && strategy
|
|||
require "#{File.dirname(__FILE__)}/../../lib/#{another_orm.downcase}_models"
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
if multiple_db
|
||||
DatabaseCleaner.app_root = "#{File.dirname(__FILE__)}/../.."
|
||||
orm_sym = orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
require 'mongoid'
|
||||
|
||||
Mongoid.configure do |config|
|
||||
name = 'database_cleaner_test'
|
||||
config.connect_to(name)
|
||||
config.master = Mongo::Connection.new.db('database_cleaner_test')
|
||||
end
|
||||
|
||||
|
||||
#::MongoMapper.connection = Mongo::Connection.new('127.0.0.1')
|
||||
#::MongoMapper.database = 'database_cleaner_test'
|
||||
|
||||
class MongoidWidget
|
||||
include Mongoid::Document
|
||||
field :id, :type => Integer
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
require 'neo4j-core'
|
||||
DatabaseCleaner[:neo4j, :connection => {:type => :server_db, :path => 'http://localhost:7474'}]
|
||||
|
||||
class Neo4jWidget < Neo4j::Node
|
||||
def self.create!(*args)
|
||||
|
|
|
@ -43,7 +43,37 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
module DatabaseCleaner::ActiveRecord
|
||||
module SelectiveTruncation
|
||||
def tables_to_truncate(connection)
|
||||
if information_schema_exists?(connection)
|
||||
(@only || tables_with_new_rows(connection)) - @tables_to_exclude
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def tables_with_new_rows(connection)
|
||||
@db_name ||= connection.instance_variable_get('@config')[:database]
|
||||
result = connection.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = '#{@db_name}' AND table_rows > 0")
|
||||
result.map{ |row| row[0] } - ['schema_migrations']
|
||||
end
|
||||
|
||||
def information_schema_exists? connection
|
||||
@information_schema_exists ||=
|
||||
begin
|
||||
connection.execute("SELECT * FROM information_schema.tables")
|
||||
true
|
||||
rescue
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Deletion < Truncation
|
||||
if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
||||
include SelectiveTruncation
|
||||
end
|
||||
|
||||
def clean
|
||||
connection = connection_class.connection
|
||||
connection.disable_referential_integrity do
|
||||
|
@ -54,17 +84,3 @@ module DatabaseCleaner::ActiveRecord
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
||||
class DatabaseCleaner::ActiveRecord::Deletion
|
||||
def tables_to_truncate(connection)
|
||||
(@only || tables_with_new_rows(connection)) - @tables_to_exclude
|
||||
end
|
||||
|
||||
def tables_with_new_rows(connection)
|
||||
@db_name ||= connection.instance_variable_get('@config')[:database]
|
||||
result = connection.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = '#{@db_name}' AND table_rows > 0")
|
||||
result.map{ |row| row[0] } - ['schema_migrations']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue