database_cleaner/spec/support/data_mapper_helper.rb
2020-02-14 14:19:38 -06:00

35 lines
659 B
Ruby

require 'dm-core'
require 'dm-sqlite-adapter'
require 'database_cleaner/spec/database_helper'
class DataMapperHelper < DatabaseCleaner::Spec::DatabaseHelper
def setup
super
Kernel.const_set "User", Class.new
User.instance_eval do
include DataMapper::Resource
storage_names[:default] = 'users'
property :id, User::Serial
property :name, String
end
end
def teardown
Kernel.send :remove_const, "User" if defined?(User)
super
end
def connection
DataMapper.repository.adapter
end
private
def establish_connection(config = default_config)
DataMapper.setup(:default, config)
end
end