2018-05-05 15:44:02 -04:00
|
|
|
require 'dm-core'
|
|
|
|
require 'dm-sqlite-adapter'
|
2018-05-23 13:38:23 -04:00
|
|
|
require 'database_cleaner/spec/database_helper'
|
2018-05-05 15:44:02 -04:00
|
|
|
|
2018-05-23 13:38:23 -04:00
|
|
|
class DataMapperHelper < DatabaseCleaner::Spec::DatabaseHelper
|
2018-05-05 15:53:09 -04:00
|
|
|
def setup
|
2018-05-22 09:39:18 -04:00
|
|
|
super
|
|
|
|
|
2018-05-05 15:53:09 -04:00
|
|
|
Kernel.const_set "User", Class.new
|
|
|
|
User.instance_eval do
|
|
|
|
include DataMapper::Resource
|
2018-05-05 15:44:02 -04:00
|
|
|
|
2018-05-05 15:53:09 -04:00
|
|
|
storage_names[:default] = 'users'
|
2018-05-05 15:44:02 -04:00
|
|
|
|
2018-05-05 15:53:09 -04:00
|
|
|
property :id, User::Serial
|
|
|
|
property :name, String
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
Kernel.send :remove_const, "User" if defined?(User)
|
2018-05-22 09:39:18 -04:00
|
|
|
|
|
|
|
super
|
2018-05-05 15:53:09 -04:00
|
|
|
end
|
2018-05-05 15:44:02 -04:00
|
|
|
|
|
|
|
def connection
|
|
|
|
DataMapper.repository.adapter
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def establish_connection(config = default_config)
|
|
|
|
DataMapper.setup(:default, config)
|
|
|
|
end
|
|
|
|
end
|