rom-sql 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +16 -12
- data/CHANGELOG.md +23 -0
- data/Gemfile +11 -3
- data/README.md +1 -7
- data/lib/rom/sql.rb +4 -7
- data/lib/rom/sql/association.rb +1 -1
- data/lib/rom/sql/association/one_to_many.rb +44 -1
- data/lib/rom/sql/association/one_to_one.rb +1 -38
- data/lib/rom/sql/commands.rb +0 -3
- data/lib/rom/sql/commands/error_wrapper.rb +1 -1
- data/lib/rom/sql/errors.rb +4 -1
- data/lib/rom/sql/extensions.rb +19 -0
- data/lib/rom/sql/{support → extensions}/active_support_notifications.rb +0 -0
- data/lib/rom/sql/extensions/postgres.rb +3 -0
- data/lib/rom/sql/{commands/postgres.rb → extensions/postgres/commands.rb} +38 -0
- data/lib/rom/sql/extensions/postgres/inferrer.rb +64 -0
- data/lib/rom/sql/extensions/postgres/types.rb +65 -0
- data/lib/rom/sql/{support → extensions}/rails_log_subscriber.rb +0 -0
- data/lib/rom/sql/gateway.rb +15 -4
- data/lib/rom/sql/relation.rb +6 -2
- data/lib/rom/sql/relation/reading.rb +18 -0
- data/lib/rom/sql/schema/dsl.rb +7 -4
- data/lib/rom/sql/schema/inferrer.rb +44 -31
- data/lib/rom/sql/types.rb +5 -1
- data/lib/rom/sql/version.rb +1 -1
- data/rom-sql.gemspec +14 -13
- data/spec/extensions/postgres/inferrer_spec.rb +40 -0
- data/spec/extensions/postgres/integration_spec.rb +38 -0
- data/spec/extensions/postgres/types_spec.rb +115 -0
- data/spec/integration/association/many_to_many_spec.rb +2 -1
- data/spec/integration/association/one_to_one_spec.rb +6 -4
- data/spec/integration/combine_spec.rb +1 -1
- data/spec/integration/commands/create_spec.rb +46 -21
- data/spec/integration/commands/delete_spec.rb +13 -38
- data/spec/integration/commands/update_spec.rb +19 -41
- data/spec/integration/commands/upsert_spec.rb +1 -1
- data/spec/integration/gateway_spec.rb +5 -9
- data/spec/integration/migration_spec.rb +6 -7
- data/spec/integration/read_spec.rb +30 -38
- data/spec/integration/schema_inference_spec.rb +211 -49
- data/spec/integration/setup_spec.rb +5 -5
- data/spec/integration/support/active_support_notifications_spec.rb +4 -3
- data/spec/integration/support/rails_log_subscriber_spec.rb +5 -4
- data/spec/shared/database_setup.rb +21 -6
- data/spec/spec_helper.rb +44 -35
- data/spec/unit/association/one_to_many_spec.rb +20 -0
- data/spec/unit/association/one_to_one_spec.rb +23 -2
- data/spec/unit/association_errors_spec.rb +1 -1
- data/spec/unit/gateway_spec.rb +9 -8
- data/spec/unit/logger_spec.rb +1 -1
- data/spec/unit/migration_tasks_spec.rb +3 -3
- data/spec/unit/migrator_spec.rb +3 -2
- data/spec/unit/plugin/assoc_macros/combined_associations_spec.rb +1 -1
- data/spec/unit/plugin/assoc_macros/many_to_many_spec.rb +1 -1
- data/spec/unit/plugin/assoc_macros/many_to_one_spec.rb +1 -1
- data/spec/unit/plugin/assoc_macros/one_to_many_spec.rb +1 -1
- data/spec/unit/relation/associations_spec.rb +27 -0
- data/spec/unit/relation/avg_spec.rb +11 -0
- data/spec/unit/relation/by_pk_spec.rb +15 -0
- data/spec/unit/relation/dataset_spec.rb +48 -0
- data/spec/unit/relation/distinct_spec.rb +14 -0
- data/spec/unit/relation/exclude_spec.rb +13 -0
- data/spec/unit/relation/fetch_spec.rb +21 -0
- data/spec/unit/relation/having_spec.rb +20 -0
- data/spec/unit/relation/inner_join_spec.rb +22 -0
- data/spec/unit/relation/inspect_spec.rb +11 -0
- data/spec/unit/relation/invert_spec.rb +12 -0
- data/spec/unit/relation/left_join_spec.rb +16 -0
- data/spec/unit/relation/map_spec.rb +16 -0
- data/spec/unit/relation/max_spec.rb +11 -0
- data/spec/unit/relation/min_spec.rb +11 -0
- data/spec/unit/relation/pluck_spec.rb +11 -0
- data/spec/unit/relation/prefix_spec.rb +27 -0
- data/spec/unit/relation/primary_key_spec.rb +27 -0
- data/spec/unit/relation/project_spec.rb +22 -0
- data/spec/unit/relation/qualified_columns_spec.rb +27 -0
- data/spec/unit/relation/rename_spec.rb +21 -0
- data/spec/unit/relation/sum_spec.rb +11 -0
- data/spec/unit/relation/union_spec.rb +19 -0
- data/spec/unit/relation/unique_predicate_spec.rb +18 -0
- data/spec/unit/schema_spec.rb +1 -1
- data/spec/unit/types_spec.rb +4 -21
- metadata +79 -11
- data/lib/rom/sql/commands_ext/postgres.rb +0 -45
- data/lib/rom/sql/types/pg.rb +0 -26
- data/spec/unit/relation_spec.rb +0 -272
@@ -1,66 +1,228 @@
|
|
1
|
-
RSpec.describe 'Schema inference' do
|
1
|
+
RSpec.describe 'Schema inference for common datatypes' do
|
2
2
|
include_context 'database setup'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
String :text, null: false
|
10
|
-
Boolean :flag, null: false
|
11
|
-
Date :date
|
12
|
-
DateTime :datetime, null: false
|
13
|
-
Decimal :money, null: false
|
14
|
-
Bytea :data
|
15
|
-
end
|
4
|
+
let(:schema) { container.relations[dataset].schema }
|
5
|
+
|
6
|
+
def trunc_ts(time, drop_usec: false)
|
7
|
+
usec = drop_usec ? 0 : time.to_time.usec.floor
|
8
|
+
Time.mktime(time.year, time.month, time.day, time.hour, time.min, time.sec, usec)
|
16
9
|
end
|
17
10
|
|
18
|
-
|
11
|
+
with_adapters do |adapter|
|
12
|
+
describe 'inferring attributes' do
|
13
|
+
before do
|
14
|
+
dataset = self.dataset
|
15
|
+
conf.relation(dataset) do
|
16
|
+
schema(dataset, infer: true)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'for simple table' do
|
21
|
+
let(:dataset) { :users }
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
it 'can infer attributes for dataset' do
|
24
|
+
expect(schema.attributes).to eql(
|
25
|
+
id: ROM::SQL::Types::Serial.meta(name: :id),
|
26
|
+
name: ROM::SQL::Types::String.meta(name: :name)
|
27
|
+
)
|
28
|
+
end
|
25
29
|
end
|
26
|
-
end
|
27
30
|
|
28
|
-
|
29
|
-
|
31
|
+
context 'for a table with FKs' do
|
32
|
+
let(:dataset) { :tasks }
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
it 'can infer attributes for dataset' do
|
35
|
+
expect(schema.attributes).to eql(
|
36
|
+
id: ROM::SQL::Types::Serial.meta(name: :id),
|
37
|
+
title: ROM::SQL::Types::String.optional.meta(name: :title),
|
38
|
+
user_id: ROM::SQL::Types::Int.optional.meta(name: :user_id,
|
39
|
+
foreign_key: true,
|
40
|
+
relation: :users)
|
41
|
+
)
|
42
|
+
end
|
36
43
|
end
|
37
|
-
end
|
38
44
|
|
39
|
-
|
40
|
-
|
45
|
+
context 'for complex table' do
|
46
|
+
before do |example|
|
47
|
+
ctx = self
|
48
|
+
conn.drop_table?(:test_inferrence)
|
49
|
+
|
50
|
+
conn.create_table :test_inferrence do
|
51
|
+
primary_key :id
|
52
|
+
String :text, null: false
|
53
|
+
Boolean :flag, null: false
|
54
|
+
Date :date
|
55
|
+
DateTime :datetime, null: false
|
56
|
+
|
57
|
+
if ctx.postgres?(example)
|
58
|
+
Bytea :data
|
59
|
+
else
|
60
|
+
Blob :data
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
let(:dataset) { :test_inferrence }
|
41
66
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
67
|
+
it 'can infer attributes for dataset' do
|
68
|
+
expect(schema.attributes).to eql(
|
69
|
+
id: ROM::SQL::Types::Serial.meta(name: :id),
|
70
|
+
text: ROM::SQL::Types::String.meta(name: :text),
|
71
|
+
flag: ROM::SQL::Types::Bool.meta(name: :flag),
|
72
|
+
date: ROM::SQL::Types::Date.optional.meta(name: :date),
|
73
|
+
datetime: ROM::SQL::Types::Time.meta(name: :datetime),
|
74
|
+
data: ROM::SQL::Types::Blob.optional.meta(name: :data)
|
75
|
+
)
|
76
|
+
end
|
48
77
|
end
|
49
78
|
end
|
50
79
|
|
51
|
-
|
52
|
-
let(:
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
80
|
+
describe 'using commands with inferred schema' do
|
81
|
+
let(:relation) { container.relation(:people) }
|
82
|
+
|
83
|
+
before do
|
84
|
+
conn.drop_table?(:people)
|
85
|
+
|
86
|
+
conf.relation(:people) do
|
87
|
+
schema(dataset, infer: true)
|
88
|
+
end
|
89
|
+
|
90
|
+
conf.commands(:people) do
|
91
|
+
define(:create) do
|
92
|
+
result :one
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'inserting' do
|
98
|
+
let(:create) { commands[:people].create }
|
99
|
+
|
100
|
+
context "Sequel's types" do
|
101
|
+
before do
|
102
|
+
conn.create_table :people do
|
103
|
+
primary_key :id
|
104
|
+
String :name, null: false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it "doesn't coerce or check types on insert by default" do
|
109
|
+
result = create.call(name: Sequel.function(:upper, 'Jade'))
|
110
|
+
|
111
|
+
expect(result).to eql(id: 1, name: 'JADE')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'nullable columns' do
|
116
|
+
before do
|
117
|
+
conn.create_table :people do
|
118
|
+
primary_key :id
|
119
|
+
String :name, null: false
|
120
|
+
Integer :age, null: true
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'allows to insert records with nil value' do
|
125
|
+
result = create.call(name: 'Jade', age: nil)
|
126
|
+
|
127
|
+
expect(result).to eql(id: 1, name: 'Jade', age: nil)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'allows to omit nullable columns' do
|
131
|
+
result = create.call(name: 'Jade')
|
132
|
+
|
133
|
+
expect(result).to eql(id: 1, name: 'Jade', age: nil)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'columns with default value' do
|
138
|
+
before do
|
139
|
+
conn.create_table :people do
|
140
|
+
primary_key :id
|
141
|
+
String :name, null: false
|
142
|
+
Integer :age, null: false, default: 18
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'sets default value on missing key' do
|
147
|
+
result = create.call(name: 'Jade')
|
148
|
+
|
149
|
+
expect(result).to eql(id: 1, name: 'Jade', age: 18)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'raises an error on inserting nil value' do
|
153
|
+
expect { create.call(name: 'Jade', age: nil) }.to raise_error(ROM::SQL::NotNullConstraintError)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'coercions' do
|
158
|
+
context 'date' do
|
159
|
+
before do
|
160
|
+
conn.create_table :people do
|
161
|
+
primary_key :id
|
162
|
+
String :name, null: false
|
163
|
+
Date :birth_date, null: false
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'accetps Time' do
|
168
|
+
time = Time.iso8601('1970-01-01T06:00:00')
|
169
|
+
result = create.call(name: 'Jade', birth_date: time)
|
170
|
+
|
171
|
+
expect(result).to eql(id: 1, name: 'Jade', birth_date: Date.iso8601('1970-01-01T00:00:00'))
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
unless metadata[:sqlite] && defined? JRUBY_VERSION
|
176
|
+
context 'timestamp' do
|
177
|
+
before do
|
178
|
+
conn.create_table :people do
|
179
|
+
primary_key :id
|
180
|
+
String :name, null: false
|
181
|
+
Timestamp :created_at, null: false
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'accepts Date' do
|
186
|
+
date = Date.today
|
187
|
+
result = create.call(name: 'Jade', created_at: date)
|
188
|
+
|
189
|
+
expect(result).to eql(id: 1, name: 'Jade', created_at: date.to_time)
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'accepts Time' do |ex|
|
193
|
+
now = Time.now
|
194
|
+
result = create.call(name: 'Jade', created_at: now)
|
195
|
+
|
196
|
+
expected_time = trunc_ts(now, drop_usec: mysql?(ex))
|
197
|
+
expect(result).to eql(id: 1, name: 'Jade', created_at: expected_time)
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'accepts DateTime' do |ex|
|
201
|
+
now = DateTime.now
|
202
|
+
result = create.call(name: 'Jade', created_at: now)
|
203
|
+
|
204
|
+
expected_time = trunc_ts(now, drop_usec: mysql?(ex))
|
205
|
+
expect(result).to eql(id: 1, name: 'Jade', created_at: expected_time)
|
206
|
+
end
|
207
|
+
|
208
|
+
if !metadata[:mysql]
|
209
|
+
it 'accepts strings in RFC 2822' do
|
210
|
+
now = Time.now
|
211
|
+
result = create.call(name: 'Jade', created_at: now.rfc822)
|
212
|
+
|
213
|
+
expect(result).to eql(id: 1, name: 'Jade', created_at: trunc_ts(now, drop_usec: true))
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'accepts strings in RFC 3339' do
|
217
|
+
now = DateTime.now
|
218
|
+
result = create.call(name: 'Jade', created_at: now.rfc3339)
|
219
|
+
|
220
|
+
expect(result).to eql(id: 1, name: 'Jade', created_at: trunc_ts(now, drop_usec: true))
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
64
226
|
end
|
65
227
|
end
|
66
228
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
RSpec.describe 'ROM.container' do
|
1
|
+
RSpec.describe 'ROM.container', skip_tables: true do
|
2
2
|
include_context 'database setup'
|
3
3
|
|
4
4
|
with_adapters do
|
5
|
+
before do
|
6
|
+
conn.drop_table?(:dragons)
|
7
|
+
end
|
8
|
+
|
5
9
|
let(:rom) do
|
6
10
|
ROM.container(:sql, uri) do |conf|
|
7
11
|
conf.default.create_table(:dragons) do
|
@@ -11,10 +15,6 @@ RSpec.describe 'ROM.container' do
|
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
14
|
-
after do
|
15
|
-
rom.gateways[:default].drop_table(:dragons)
|
16
|
-
end
|
17
|
-
|
18
18
|
it 'creates tables within the setup block' do
|
19
19
|
expect(rom.relations[:dragons]).to be_kind_of(ROM::SQL::Relation)
|
20
20
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
RSpec.describe 'ActiveSupport::Notifications support', :postgres do
|
4
|
+
before do
|
5
|
+
ROM::SQL.load_extensions(:active_support_notifications, :rails_log_subscriber)
|
6
|
+
end
|
5
7
|
|
6
|
-
describe 'ActiveSupport::Notifications support' do
|
7
8
|
include_context 'database setup'
|
8
9
|
|
9
10
|
it 'works' do
|
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
require 'rom/sql/support/active_support_notifications'
|
4
|
-
require 'rom/sql/support/rails_log_subscriber'
|
5
|
-
|
6
3
|
require 'active_support/log_subscriber/test_helper'
|
7
4
|
|
8
|
-
describe 'Rails log subscriber' do
|
5
|
+
RSpec.describe 'Rails log subscriber', :postgres do
|
6
|
+
before do
|
7
|
+
ROM::SQL.load_extensions(:active_support_notifications, :rails_log_subscriber)
|
8
|
+
end
|
9
|
+
|
9
10
|
include ActiveSupport::LogSubscriber::TestHelper
|
10
11
|
|
11
12
|
include_context 'database setup'
|
@@ -1,9 +1,13 @@
|
|
1
1
|
shared_context 'database setup' do
|
2
|
-
let(:uri) do
|
3
|
-
|
4
|
-
|
2
|
+
let(:uri) do |example|
|
3
|
+
meta = example.metadata
|
4
|
+
adapters = ADAPTERS.select { |adapter| meta[adapter] }
|
5
|
+
|
6
|
+
case adapters.size
|
7
|
+
when 1 then DB_URIS.fetch(adapters.first)
|
8
|
+
when 0 then raise 'No adapter specified'
|
5
9
|
else
|
6
|
-
|
10
|
+
raise "Ambiguous adapter configuration, got #{adapters.inspect}"
|
7
11
|
end
|
8
12
|
end
|
9
13
|
|
@@ -17,27 +21,32 @@ shared_context 'database setup' do
|
|
17
21
|
%i(task_tags users_tasks tasks tags
|
18
22
|
subscriptions cards accounts
|
19
23
|
posts users
|
20
|
-
rabbits carrots
|
24
|
+
rabbits carrots
|
25
|
+
puppies schema_migrations
|
21
26
|
).each do |name|
|
22
27
|
conn.drop_table?(name)
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
26
31
|
before do |example|
|
32
|
+
ctx = self
|
27
33
|
conn.loggers << LOGGER
|
28
34
|
|
29
35
|
drop_tables
|
36
|
+
next if example.metadata[:skip_tables]
|
30
37
|
|
31
38
|
conn.create_table :users do
|
32
39
|
primary_key :id
|
33
40
|
String :name, null: false
|
34
|
-
check { char_length(name) > 2 } if postgres?(example)
|
41
|
+
check { char_length(name) > 2 } if ctx.postgres?(example)
|
35
42
|
end
|
36
43
|
|
37
44
|
conn.create_table :tasks do
|
38
45
|
primary_key :id
|
39
46
|
foreign_key :user_id, :users
|
40
47
|
String :title, unique: true
|
48
|
+
constraint(:title_length) { char_length(title) > 1 } if ctx.postgres?(example)
|
49
|
+
constraint(:title_length) { length(title) > 1 } if ctx.sqlite?(example)
|
41
50
|
end
|
42
51
|
|
43
52
|
conn.create_table :tags do
|
@@ -76,6 +85,12 @@ shared_context 'database setup' do
|
|
76
85
|
Integer :card_id
|
77
86
|
String :service
|
78
87
|
end
|
88
|
+
|
89
|
+
conn.create_table :puppies do
|
90
|
+
primary_key :id
|
91
|
+
String :name, null: false
|
92
|
+
TrueClass :cute, null: false, default: true
|
93
|
+
end
|
79
94
|
end
|
80
95
|
|
81
96
|
after do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'bundler'
|
4
2
|
Bundler.setup
|
5
3
|
|
6
|
-
if RUBY_ENGINE == 'ruby' &&
|
7
|
-
require '
|
8
|
-
|
4
|
+
if RUBY_ENGINE == 'ruby' && ENV['CI'] == 'true'
|
5
|
+
require 'simplecov'
|
6
|
+
SimpleCov.start do
|
7
|
+
add_filter '/spec/'
|
8
|
+
end
|
9
9
|
end
|
10
10
|
|
11
11
|
require 'rom-sql'
|
@@ -22,17 +22,20 @@ end
|
|
22
22
|
LOGGER = Logger.new(File.open('./log/test.log', 'a'))
|
23
23
|
|
24
24
|
if defined? JRUBY_VERSION
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
DB_URIS = {
|
26
|
+
sqlite: 'jdbc:sqlite:::memory',
|
27
|
+
postgres: 'jdbc:postgresql://localhost/rom_sql',
|
28
|
+
mysql: 'jdbc:mysql://localhost/rom_sql?user=root'
|
29
|
+
}
|
28
30
|
else
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
DB_URIS = {
|
32
|
+
sqlite: 'sqlite::memory',
|
33
|
+
postgres: 'postgres://localhost/rom_sql',
|
34
|
+
mysql: 'mysql2://root@localhost/rom_sql'
|
35
|
+
}
|
32
36
|
end
|
33
37
|
|
34
|
-
|
35
|
-
ADAPTERS = URIS.keys
|
38
|
+
ADAPTERS = DB_URIS.keys
|
36
39
|
PG_LTE_95 = ENV.fetch('PG_LTE_95', 'true') == 'true'
|
37
40
|
|
38
41
|
SPEC_ROOT = root = Pathname(__FILE__).dirname
|
@@ -44,38 +47,48 @@ Dir[root.join('support/**/*')].each { |f| require f }
|
|
44
47
|
require 'rom/support/deprecations'
|
45
48
|
ROM::Deprecations.set_logger!(root.join('../log/deprecations.log'))
|
46
49
|
|
47
|
-
|
48
|
-
if example
|
49
|
-
example.metadata[:adapter] == type
|
50
|
-
else
|
51
|
-
defined?(DB_URI) && DB_URI.include?(type.to_s)
|
52
|
-
end
|
53
|
-
end
|
50
|
+
ROM::SQL.load_extensions(:postgres)
|
54
51
|
|
55
|
-
|
56
|
-
|
52
|
+
require 'dry-types'
|
53
|
+
module Types
|
54
|
+
include Dry::Types.module
|
57
55
|
end
|
58
56
|
|
59
|
-
|
60
|
-
db?(
|
61
|
-
|
57
|
+
module ENVHelper
|
58
|
+
def db?(type, example)
|
59
|
+
example.metadata[type]
|
60
|
+
end
|
61
|
+
|
62
|
+
def postgres?(example)
|
63
|
+
db?(:postgres, example)
|
64
|
+
end
|
62
65
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
66
|
+
def mysql?(example)
|
67
|
+
db?(:mysql, example)
|
68
|
+
end
|
69
|
+
|
70
|
+
def sqlite?(example)
|
71
|
+
db?(:sqlite, example)
|
72
|
+
end
|
73
|
+
|
74
|
+
def jruby?
|
75
|
+
defined? JRUBY_VERSION
|
76
|
+
end
|
67
77
|
end
|
68
78
|
|
69
79
|
def with_adapters(*args, &block)
|
80
|
+
reset_adapter = { postgres: false, mysql: false, sqlite: false }
|
70
81
|
adapters = args.empty? || args[0] == :all ? ADAPTERS : args
|
71
82
|
|
72
83
|
adapters.each do |adapter|
|
73
|
-
context("with #{adapter}", adapter
|
84
|
+
context("with #{adapter}", **reset_adapter, adapter => true, &block)
|
74
85
|
end
|
75
86
|
end
|
76
87
|
|
77
88
|
RSpec.configure do |config|
|
78
|
-
config.disable_monkey_patching
|
89
|
+
config.disable_monkey_patching!
|
90
|
+
|
91
|
+
config.include ENVHelper
|
79
92
|
|
80
93
|
config.before(:suite) do
|
81
94
|
tmp_test_dir = TMP_PATH.join('test')
|
@@ -83,10 +96,6 @@ RSpec.configure do |config|
|
|
83
96
|
FileUtils.mkdir_p(tmp_test_dir)
|
84
97
|
end
|
85
98
|
|
86
|
-
config.around(adapter: :mysql) do |example|
|
87
|
-
with_adapter(:mysql) { example.run }
|
88
|
-
end
|
89
|
-
|
90
99
|
config.before do
|
91
100
|
module Test
|
92
101
|
end
|