mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
setup and teardown User class for DM tests.
This commit is contained in:
parent
ac54a9656f
commit
d1d9097448
2 changed files with 23 additions and 14 deletions
|
@ -14,18 +14,18 @@ RSpec.describe DatabaseCleaner::DataMapper::Truncation do
|
||||||
|
|
||||||
describe "DM connection adapter monkeypatches" do
|
describe "DM connection adapter monkeypatches" do
|
||||||
before do
|
before do
|
||||||
2.times { DmUser.create }
|
2.times { User.create }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#truncate_table" do
|
describe "#truncate_table" do
|
||||||
it "truncates the table" do
|
it "truncates the table" do
|
||||||
connection.truncate_table(DmUser.storage_names[:default])
|
connection.truncate_table(User.storage_names[:default])
|
||||||
expect(DmUser.count).to eq 0
|
expect(User.count).to eq 0
|
||||||
end
|
end
|
||||||
|
|
||||||
it "resets AUTO_INCREMENT index of table" do
|
it "resets AUTO_INCREMENT index of table" do
|
||||||
connection.truncate_table(DmUser.storage_names[:default])
|
connection.truncate_table(User.storage_names[:default])
|
||||||
expect(DmUser.create.id).to eq 1
|
expect(User.create.id).to eq 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,18 +2,27 @@ require 'dm-core'
|
||||||
require 'dm-sqlite-adapter'
|
require 'dm-sqlite-adapter'
|
||||||
require 'support/database_helper'
|
require 'support/database_helper'
|
||||||
|
|
||||||
class ::DmUser
|
|
||||||
include DataMapper::Resource
|
|
||||||
|
|
||||||
self.storage_names[:default] = 'users'
|
|
||||||
|
|
||||||
property :id, Serial
|
|
||||||
property :name, String
|
|
||||||
end
|
|
||||||
|
|
||||||
class DataMapperSQLite3Helper < DatabaseHelper
|
class DataMapperSQLite3Helper < DatabaseHelper
|
||||||
puts "DataMapper #{DataMapper::VERSION}, sqlite3"
|
puts "DataMapper #{DataMapper::VERSION}, sqlite3"
|
||||||
|
|
||||||
|
def setup
|
||||||
|
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
|
||||||
|
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
Kernel.send :remove_const, "User" if defined?(User)
|
||||||
|
end
|
||||||
|
|
||||||
def connection
|
def connection
|
||||||
DataMapper.repository.adapter
|
DataMapper.repository.adapter
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue