Skip to content

Instantly share code, notes, and snippets.

@zw963
Created December 30, 2021 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zw963/43f165e5a3a471e0550c8eb0cf64289b to your computer and use it in GitHub Desktop.
Save zw963/43f165e5a3a471e0550c8eb0cf64289b to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem 'pg'
gem 'sequel'
gem 'minitest'
gem 'minitest-hooks'
end
system("sudo -u postgres dropdb --if-exists check_sequel_db")
system("sudo -u postgres createdb check_sequel_db")
DB_URL="postgres://postgres:postgres@localhost:5432/check_sequel_db"
DB = Sequel.connect(DB_URL)
DB.create_table(:insiders, :ignore_index_errors=>true) do
primary_key :id
String :name, :text=>true, :null=>false, unique: true
end
class Insider < Sequel::Model
end
ENV['RACK_ENV'] = 'test'
require 'minitest/autorun'
require 'minitest/pride'
require 'minitest/hooks/default'
class Minitest::HooksSpec
def around
DB.transaction(:rollback=>:always, :savepoint=>true, :auto_savepoint=>true){super}
end
def around_all
DB.transaction(:rollback=>:always){super}
end
end
require 'logger'
LOGGER = Logger.new($stdout)
DB.loggers << LOGGER
describe 'routes/insiders/show' do
it 'should failed' do
insider = Insider.create(name: 'a')
assert 1, Insider.count
end
it 'should succss' do
insider = Insider.create(name: 'a')
assert 1, Insider.count
end
end
# Following is logs
# I, [2021-12-31T03:13:04.126132 #842563] INFO -- : (0.000227s) BEGIN
# I, [2021-12-31T03:13:04.126518 #842563] INFO -- : (0.000229s) SAVEPOINT autopoint_1
# I, [2021-12-31T03:13:04.127615 #842563] INFO -- : (0.000404s) SAVEPOINT autopoint_2
# I, [2021-12-31T03:13:04.129117 #842563] INFO -- : (0.000895s) INSERT INTO "insiders" ("name") VALUES ('a') RETURNING *
# I, [2021-12-31T03:13:04.129463 #842563] INFO -- : (0.000177s) RELEASE SAVEPOINT autopoint_2
# I, [2021-12-31T03:13:04.130092 #842563] INFO -- : (0.000344s) SELECT count(*) AS "count" FROM "insiders" LIMIT 1
# I, [2021-12-31T03:13:04.130352 #842563] INFO -- : (0.000148s) ROLLBACK TO SAVEPOINT autopoint_1
# .I, [2021-12-31T03:13:04.130616 #842563] INFO -- : (0.000101s) SAVEPOINT autopoint_1
# I, [2021-12-31T03:13:04.130927 #842563] INFO -- : (0.000150s) SAVEPOINT autopoint_2
# I, [2021-12-31T03:13:04.131253 #842563] INFO -- : (0.000181s) INSERT INTO "insiders" ("name") VALUES ('a') RETURNING *
# I, [2021-12-31T03:13:04.131467 #842563] INFO -- : (0.000141s) RELEASE SAVEPOINT autopoint_2
# I, [2021-12-31T03:13:04.131701 #842563] INFO -- : (0.000171s) SELECT count(*) AS "count" FROM "insiders" LIMIT 1
# I, [2021-12-31T03:13:04.131932 #842563] INFO -- : (0.000157s) ROLLBACK TO SAVEPOINT autopoint_1
# I, [2021-12-31T03:13:04.132153 #842563] INFO -- : (0.000159s) ROLLBACK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment