Skip to content

Commit 2874fc5

Browse files
committed
Prove that Fiber#new is creating new threads
1 parent 94cffaf commit 2874fc5

6 files changed

Lines changed: 131 additions & 9 deletions

File tree

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
--format documentation
22
--color
33
--require spec_helper
4+
--tag ~with_jdbc

Gemfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@ source "https://rubygems.org"
44
gemspec
55

66
gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
7-
gem "byebug"
7+
8+
group :cruby_only do
9+
gem "byebug"
10+
gem "mysql2"
11+
gem "pg"
12+
gem "sqlite3"
13+
end
14+
15+
group :development do
16+
gem "bundler"
17+
gem "rake"
18+
gem "rspec"
19+
end
820

921
group :test do
1022
gem "simplecov", require: false

database_cleaner-sequel.gemspec

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,4 @@ Gem::Specification.new do |spec|
2020

2121
spec.add_dependency "database_cleaner-core", "~>2.0.0"
2222
spec.add_dependency "sequel"
23-
24-
spec.add_development_dependency "bundler"
25-
spec.add_development_dependency "rake"
26-
spec.add_development_dependency "rspec"
27-
spec.add_development_dependency "mysql2"
28-
spec.add_development_dependency "pg"
29-
spec.add_development_dependency "sqlite3"
3023
end
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
require 'database_cleaner/sequel/transaction'
2+
require 'database_cleaner/spec'
3+
require 'sequel'
4+
require 'database_cleaner/spec/database_helper'
5+
require 'ostruct'
6+
7+
if RUBY_PLATFORM == 'java'
8+
require_relative '../../support/postgresql-42.3.0.jar'
9+
10+
class SequelHelper < DatabaseCleaner::Spec::DatabaseHelper
11+
private
12+
13+
def establish_connection(_config = default_config)
14+
@connection = ::Sequel.connect(
15+
# 'postgres://database_cleaner:database_cleaner@127.0.0.1:5433/database_cleaner_test'
16+
'jdbc:postgresql://127.0.0.1:5433/database_cleaner_test?user=database_cleaner&password=database_cleaner'
17+
)
18+
end
19+
end
20+
end
21+
22+
module DatabaseCleaner
23+
module Sequel
24+
RSpec.describe Transaction, :with_jdbc do
25+
it_should_behave_like "a database_cleaner strategy"
26+
27+
SequelHelper.with_all_dbs do |helper|
28+
next unless helper.db == :postgres
29+
30+
context "using a #{helper.db} connection" do
31+
around do |example|
32+
helper.setup
33+
example.run
34+
helper.teardown
35+
end
36+
37+
let(:connection) { helper.connection }
38+
39+
before { subject.db = connection }
40+
41+
context "cleaning" do
42+
it "should clean database" do
43+
subject.cleaning do
44+
connection[:users].insert
45+
expect(connection[:users].count).to eq(1)
46+
end
47+
48+
expect(connection[:users]).to be_empty
49+
end
50+
51+
it "should work with nested transaction" do
52+
subject.cleaning do
53+
begin
54+
connection.transaction do
55+
connection[:users].insert
56+
connection[:users].insert
57+
58+
expect(connection[:users].count).to eq(2)
59+
raise ::Sequel::Rollback
60+
end
61+
rescue
62+
end
63+
64+
connection[:users].insert
65+
expect(connection[:users].count).to eq(1)
66+
end
67+
68+
expect(connection[:users]).to be_empty
69+
end
70+
end
71+
72+
context "start/clean" do
73+
it "should clean database" do
74+
subject.start
75+
76+
connection[:users].insert
77+
expect(connection[:users].count).to eq(1)
78+
79+
subject.clean
80+
81+
expect(connection[:users]).to be_empty
82+
end
83+
84+
it "should work with nested transaction" do
85+
subject.start
86+
begin
87+
connection.transaction do
88+
connection[:users].insert
89+
connection[:users].insert
90+
91+
expect(connection[:users].count).to eq(2)
92+
raise ::Sequel::Rollback
93+
end
94+
rescue
95+
end
96+
97+
connection[:users].insert
98+
expect(connection[:users].count).to eq(1)
99+
100+
subject.clean
101+
102+
expect(connection[:users]).to be_empty
103+
end
104+
end
105+
end
106+
end
107+
108+
describe "start" do
109+
it "should start a transaction"
110+
end
111+
112+
describe "clean" do
113+
it "should finish a transaction"
114+
end
115+
end
116+
end
117+
end

spec/spec_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require "bundler/setup"
2-
require "byebug"
32

43
if ENV['COVERAGE'] == 'true'
54
require "simplecov"

spec/support/postgresql-42.3.0.jar

990 KB
Binary file not shown.

0 commit comments

Comments
 (0)