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