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
|
||||
before do
|
||||
2.times { DmUser.create }
|
||||
2.times { User.create }
|
||||
end
|
||||
|
||||
describe "#truncate_table" do
|
||||
it "truncates the table" do
|
||||
connection.truncate_table(DmUser.storage_names[:default])
|
||||
expect(DmUser.count).to eq 0
|
||||
connection.truncate_table(User.storage_names[:default])
|
||||
expect(User.count).to eq 0
|
||||
end
|
||||
|
||||
it "resets AUTO_INCREMENT index of table" do
|
||||
connection.truncate_table(DmUser.storage_names[:default])
|
||||
expect(DmUser.create.id).to eq 1
|
||||
connection.truncate_table(User.storage_names[:default])
|
||||
expect(User.create.id).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,18 +2,27 @@ require 'dm-core'
|
|||
require 'dm-sqlite-adapter'
|
||||
require 'support/database_helper'
|
||||
|
||||
class ::DmUser
|
||||
include DataMapper::Resource
|
||||
|
||||
self.storage_names[:default] = 'users'
|
||||
|
||||
property :id, Serial
|
||||
property :name, String
|
||||
end
|
||||
|
||||
class DataMapperSQLite3Helper < DatabaseHelper
|
||||
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
|
||||
DataMapper.repository.adapter
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue