mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
updated features
This commit is contained in:
parent
b8e30d46ea
commit
b12d4fd3c1
6 changed files with 40 additions and 16 deletions
|
@ -15,7 +15,13 @@ Then /^I should see ([\d]+) widget using datamapper$/ do |widget_count|
|
|||
end
|
||||
|
||||
When /^I create a widget in one db using datamapper$/ do
|
||||
DataMapperWidgetUsingDatabaseOne.create!
|
||||
begin
|
||||
DataMapperWidgetUsingDatabaseOne.create!
|
||||
rescue StandardError => e
|
||||
BREAK = e.backtrace
|
||||
debugger
|
||||
DataMapperWidgetUsingDatabaseOne.create!
|
||||
end
|
||||
end
|
||||
|
||||
When /^I create a widget in another db using datamapper$/ do
|
||||
|
|
|
@ -38,8 +38,17 @@ if orm && strategy
|
|||
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
|
||||
DatabaseCleaner[ orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym, {:connection => :one} ].strategy = strategy.to_sym
|
||||
DatabaseCleaner[ orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym, {:connection => :two} ].strategy = strategy.to_sym
|
||||
DatabaseCleaner.app_root = "#{File.dirname(__FILE__)}/../.."
|
||||
orm_sym = orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym
|
||||
|
||||
if orm_sym == :mongo_mapper
|
||||
DatabaseCleaner[ orm_sym, {:connection => 'database_cleaner_test_one'} ].strategy = strategy.to_sym
|
||||
DatabaseCleaner[ orm_sym, {:connection => 'database_cleaner_test_two'} ].strategy = strategy.to_sym
|
||||
else
|
||||
DatabaseCleaner[ orm_sym, {:connection => :one} ].strategy = strategy.to_sym
|
||||
DatabaseCleaner[ orm_sym, {:connection => :two} ].strategy = strategy.to_sym
|
||||
end
|
||||
|
||||
elsif another_orm
|
||||
DatabaseCleaner[ orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym ].strategy = strategy.to_sym
|
||||
DatabaseCleaner[ another_orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym ].strategy = strategy.to_sym
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
require 'active_record'
|
||||
databases_config = {
|
||||
"one" => {"adapter" => "#{"jdbc" if defined?(JRUBY_VERSION)}sqlite3", "database" => "#{DB_DIR}/activerecord_one.db"},
|
||||
"two" => {"adapter" => "#{"jdbc" if defined?(JRUBY_VERSION)}sqlite3", "database" => "#{DB_DIR}/activerecord_two.db"}
|
||||
}
|
||||
|
||||
File.open("#{File.dirname(__FILE__)}/../config/database.yml", 'w') do |file|
|
||||
file.write(YAML.dump(databases_config))
|
||||
end
|
||||
|
||||
["two","one"].each do |db|
|
||||
ActiveRecord::Base.establish_connection(:adapter => "#{"jdbc" if defined?(JRUBY_VERSION)}sqlite3", :database => "#{DB_DIR}/activerecord_#{db}.db")
|
||||
ActiveRecord::Base.establish_connection(databases_config[db])
|
||||
ActiveRecord::Base.connection.execute('DROP TABLE IF EXISTS "active_record_widgets"')
|
||||
ActiveRecord::Base.connection.execute('DROP TABLE IF EXISTS "active_record_widget_using_database_ones"')
|
||||
ActiveRecord::Base.connection.execute('DROP TABLE IF EXISTS "active_record_widget_using_database_twos"')
|
||||
|
@ -11,11 +19,11 @@ require 'active_record'
|
|||
t.string :name
|
||||
end
|
||||
|
||||
create_table :active_record_widget_usings_database_ones do |t|
|
||||
create_table :active_record_widget_using_database_ones do |t|
|
||||
t.string :name
|
||||
end
|
||||
|
||||
create_table :active_record_widget_usings_database_twos do |t|
|
||||
create_table :active_record_widget_using_database_twos do |t|
|
||||
t.string :name
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ require "dm-core"
|
|||
require "dm-validations"
|
||||
require "dm-aggregates"
|
||||
|
||||
DataMapper.setup(:default, "sqlite3:#{DB_DIR}/datamapper_one.db")
|
||||
DataMapper.setup(:default, "sqlite3:#{DB_DIR}/datamapper_default.db")
|
||||
DataMapper.setup(:one, "sqlite3:#{DB_DIR}/datamapper_one.db")
|
||||
DataMapper.setup(:two, "sqlite3:#{DB_DIR}/datamapper_two.db")
|
||||
|
||||
|
@ -22,10 +22,10 @@ class DataMapperWidgetUsingDatabaseOne
|
|||
def self.default_repository_name
|
||||
:one
|
||||
end
|
||||
|
||||
|
||||
property :id, Serial
|
||||
property :name, String
|
||||
|
||||
|
||||
end
|
||||
|
||||
class DataMapperWidgetUsingDatabaseTwo
|
||||
|
|
|
@ -18,8 +18,9 @@ end
|
|||
|
||||
class MongoMapperWidgetUsingDatabaseOne
|
||||
include MongoMapper::Document
|
||||
|
||||
database = 'database_cleaner_test_one'
|
||||
|
||||
connection = Mongo::Connection.new('127.0.0.1')
|
||||
set_database_name = 'database_cleaner_test_one'
|
||||
|
||||
key :id, Integer
|
||||
key :name, String
|
||||
|
@ -35,7 +36,8 @@ end
|
|||
class MongoMapperWidgetUsingDatabaseTwo
|
||||
include MongoMapper::Document
|
||||
|
||||
database = 'database_cleaner_test_two'
|
||||
connection = Mongo::Connection.new('127.0.0.1')
|
||||
set_database_name = 'database_cleaner_test_two'
|
||||
|
||||
key :id, Integer
|
||||
key :name, String
|
||||
|
|
|
@ -12,9 +12,8 @@ Feature: multiple database cleaning
|
|||
|
||||
Examples:
|
||||
| ORM | Strategy |
|
||||
| ActiveRecord | transaction |
|
||||
| ActiveRecord | truncation |
|
||||
| DataMapper | transaction |
|
||||
| DataMapper | truncation |
|
||||
# | MongoMapper | truncation |
|
||||
# | CouchPotato | truncation |
|
||||
# | ActiveRecord | transaction |
|
||||
# | MongoMapper | truncation |
|
||||
# | DataMapper | transaction | # Tickers are ugly...and betty don't like ugly... otherwise known as this is fubar
|
Loading…
Reference in a new issue