updated features

This commit is contained in:
Jon Rowe 2010-05-30 23:08:22 +01:00
parent b8e30d46ea
commit b12d4fd3c1
6 changed files with 40 additions and 16 deletions

View file

@ -15,7 +15,13 @@ Then /^I should see ([\d]+) widget using datamapper$/ do |widget_count|
end end
When /^I create a widget in one db using datamapper$/ do 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 end
When /^I create a widget in another db using datamapper$/ do When /^I create a widget in another db using datamapper$/ do

View file

@ -38,8 +38,17 @@ if orm && strategy
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 => :one} ].strategy = strategy.to_sym
DatabaseCleaner[ another_orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym, {:connection => :two} ].strategy = strategy.to_sym DatabaseCleaner[ another_orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym, {:connection => :two} ].strategy = strategy.to_sym
elsif multiple_db elsif multiple_db
DatabaseCleaner[ orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym, {:connection => :one} ].strategy = strategy.to_sym DatabaseCleaner.app_root = "#{File.dirname(__FILE__)}/../.."
DatabaseCleaner[ orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym, {:connection => :two} ].strategy = strategy.to_sym 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 elsif another_orm
DatabaseCleaner[ orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym ].strategy = strategy.to_sym 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 DatabaseCleaner[ another_orm.gsub(/(.)([A-Z]+)/,'\1_\2').downcase.to_sym ].strategy = strategy.to_sym

View file

@ -1,7 +1,15 @@
require 'active_record' 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| ["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_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_ones"')
ActiveRecord::Base.connection.execute('DROP TABLE IF EXISTS "active_record_widget_using_database_twos"') ActiveRecord::Base.connection.execute('DROP TABLE IF EXISTS "active_record_widget_using_database_twos"')
@ -11,11 +19,11 @@ require 'active_record'
t.string :name t.string :name
end end
create_table :active_record_widget_usings_database_ones do |t| create_table :active_record_widget_using_database_ones do |t|
t.string :name t.string :name
end end
create_table :active_record_widget_usings_database_twos do |t| create_table :active_record_widget_using_database_twos do |t|
t.string :name t.string :name
end end
end end

View file

@ -5,7 +5,7 @@ require "dm-core"
require "dm-validations" require "dm-validations"
require "dm-aggregates" 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(:one, "sqlite3:#{DB_DIR}/datamapper_one.db")
DataMapper.setup(:two, "sqlite3:#{DB_DIR}/datamapper_two.db") DataMapper.setup(:two, "sqlite3:#{DB_DIR}/datamapper_two.db")
@ -22,10 +22,10 @@ class DataMapperWidgetUsingDatabaseOne
def self.default_repository_name def self.default_repository_name
:one :one
end end
property :id, Serial property :id, Serial
property :name, String property :name, String
end end
class DataMapperWidgetUsingDatabaseTwo class DataMapperWidgetUsingDatabaseTwo

View file

@ -18,8 +18,9 @@ end
class MongoMapperWidgetUsingDatabaseOne class MongoMapperWidgetUsingDatabaseOne
include MongoMapper::Document 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 :id, Integer
key :name, String key :name, String
@ -35,7 +36,8 @@ end
class MongoMapperWidgetUsingDatabaseTwo class MongoMapperWidgetUsingDatabaseTwo
include MongoMapper::Document 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 :id, Integer
key :name, String key :name, String

View file

@ -12,9 +12,8 @@ Feature: multiple database cleaning
Examples: Examples:
| ORM | Strategy | | ORM | Strategy |
| ActiveRecord | transaction |
| ActiveRecord | truncation | | ActiveRecord | truncation |
| DataMapper | transaction |
| DataMapper | truncation | | DataMapper | truncation |
# | MongoMapper | truncation | # | ActiveRecord | transaction |
# | CouchPotato | truncation | # | MongoMapper | truncation |
# | DataMapper | transaction | # Tickers are ugly...and betty don't like ugly... otherwise known as this is fubar