diff --git a/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb b/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb index d163ce9..90fa3e4 100644 --- a/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb +++ b/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb @@ -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 diff --git a/spec/support/data_mapper/sqlite3_helper.rb b/spec/support/data_mapper/sqlite3_helper.rb index 46279cb..762285f 100644 --- a/spec/support/data_mapper/sqlite3_helper.rb +++ b/spec/support/data_mapper/sqlite3_helper.rb @@ -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