Skip to content

Instantly share code, notes, and snippets.

@botandrose
Created January 30, 2020 12:51
Show Gist options
  • Save botandrose/5dc4c20e5f3d63cee191cbf336f3a542 to your computer and use it in GitHub Desktop.
Save botandrose/5dc4c20e5f3d63cee191cbf336f3a542 to your computer and use it in GitHub Desktop.
Attempt to reproduce database cleaner bug
require "active_record"
require "database_cleaner"
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
ActiveRecord::Schema.define do
create_table :models do |t|
t.string :name
end
end
class Model < ActiveRecord::Base
end
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with :truncation
DatabaseCleaner.strategy = :transaction
Model.create! name: "test"
end
config.around do |example|
DatabaseCleaner.start
example.run
DatabaseCleaner.clean
end
end
RSpec.describe do
it "works" do
expect(Model.first.name).to eq "test"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment