rom-sql 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +0 -1
- data/lib/rom/sql/association.rb +5 -5
- data/lib/rom/sql/extensions/postgres/commands.rb +4 -4
- data/lib/rom/sql/extensions/rails_log_subscriber.rb +3 -1
- data/lib/rom/sql/gateway.rb +2 -0
- data/lib/rom/sql/migration/migrator.rb +1 -1
- data/lib/rom/sql/plugin/associates.rb +5 -3
- data/lib/rom/sql/plugin/pagination.rb +4 -4
- data/lib/rom/sql/relation.rb +1 -1
- data/lib/rom/sql/version.rb +1 -1
- data/rom-sql.gemspec +1 -1
- data/spec/integration/association/many_to_many_spec.rb +0 -1
- data/spec/integration/association/many_to_one/self_ref_spec.rb +3 -3
- data/spec/integration/association/many_to_one_spec.rb +0 -3
- data/spec/integration/association/one_to_many/self_ref_spec.rb +3 -3
- data/spec/integration/commands/create_spec.rb +43 -42
- data/spec/integration/commands/delete_spec.rb +12 -12
- data/spec/integration/commands/update_spec.rb +14 -19
- data/spec/integration/commands/upsert_spec.rb +1 -3
- data/spec/integration/plugins/associates/many_to_many_spec.rb +7 -7
- data/spec/integration/plugins/auto_wrap_spec.rb +7 -18
- data/spec/integration/schema/inferrer_spec.rb +0 -2
- data/spec/integration/sequel_api_spec.rb +0 -2
- data/spec/shared/users.rb +1 -0
- data/spec/shared/users_and_tasks.rb +4 -0
- data/spec/spec_helper.rb +17 -3
- data/spec/unit/attribute_spec.rb +0 -1
- data/spec/unit/relation/group_spec.rb +0 -1
- data/spec/unit/relation/inner_join_spec.rb +0 -2
- data/spec/unit/relation/left_join_spec.rb +0 -2
- data/spec/unit/relation/qualified_spec.rb +0 -2
- data/spec/unit/relation/right_join_spec.rb +0 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc6edcd56b3aeda31a41f53c921aa2a79dd19ffc
|
4
|
+
data.tar.gz: d954520aa88474fcf6d61897ea0f1fed50e876ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f9f16bab1aef147b4956217362a1e08ec3f08dda74fc624c1e82622b6614e7bf557f8a47026f94dad182f4c34fe9fddebb3f33e876902355938f051a9c239f2
|
7
|
+
data.tar.gz: faa2da9349e0f26bfe53ed96a6e145a444a21ce100930191324650399d26a9aeeaa23ff1485b4cddc20532fda67e7667276bcd98ec460eecb7f0a1053f498347
|
data/.travis.yml
CHANGED
@@ -9,6 +9,7 @@ bundler_args: --without yard guard benchmarks tools
|
|
9
9
|
before_script:
|
10
10
|
- psql -c 'create database rom_sql;' -U postgres
|
11
11
|
- mysql -u root -e 'create database rom_sql;'
|
12
|
+
- rvm get master
|
12
13
|
after_success:
|
13
14
|
- '[ "${TRAVIS_JOB_NUMBER#*.}" = "1" ] && [ "$TRAVIS_BRANCH" = "master" ] && bundle exec codeclimate-test-reporter'
|
14
15
|
script: "bundle exec rake ci"
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/lib/rom/sql/association.rb
CHANGED
@@ -29,23 +29,23 @@ module ROM
|
|
29
29
|
|
30
30
|
# @!attribute [r] relation
|
31
31
|
# @return [Symbol] an optional relation identifier for the target
|
32
|
-
option :relation, Types::Strict::Symbol,
|
32
|
+
option :relation, Types::Strict::Symbol, optional: true
|
33
33
|
|
34
34
|
# @!attribute [r] result
|
35
35
|
# @return [Symbol] either :one or :many
|
36
|
-
option :result, Types::Strict::Symbol,
|
36
|
+
option :result, Types::Strict::Symbol, default: -> { self.class.result }
|
37
37
|
|
38
38
|
# @!attribute [r] as
|
39
39
|
# @return [Symbol] an optional association alias name
|
40
|
-
option :as, Types::Strict::Symbol,
|
40
|
+
option :as, Types::Strict::Symbol, default: -> { target.to_sym }
|
41
41
|
|
42
42
|
# @!attribute [r] foreign_key
|
43
43
|
# @return [Symbol] an optional association alias name
|
44
|
-
option :foreign_key, Types::Strict::Symbol, optional: true
|
44
|
+
option :foreign_key, Types::Optional::Strict::Symbol, optional: true
|
45
45
|
|
46
46
|
# @!attribute [r] view
|
47
47
|
# @return [Symbol] An optional view that should be used to extend assoc relation
|
48
|
-
option :view,
|
48
|
+
option :view, optional: true
|
49
49
|
|
50
50
|
alias_method :name, :as
|
51
51
|
|
@@ -69,19 +69,19 @@ module ROM
|
|
69
69
|
|
70
70
|
# @!attribute [r] constraint
|
71
71
|
# @return [Symbol] the name of the constraint expected to be violated
|
72
|
-
option :constraint,
|
72
|
+
option :constraint, default: -> { self.class.constraint }
|
73
73
|
|
74
74
|
# @!attribute [r] conflict_target
|
75
75
|
# @return [Object] the column or expression to handle a violation on
|
76
|
-
option :conflict_target,
|
76
|
+
option :conflict_target, default: -> { self.class.conflict_target }
|
77
77
|
|
78
78
|
# @!attribute [r] update_statement
|
79
79
|
# @return [Object] the update statement which will be executed in case of a violation
|
80
|
-
option :update_statement,
|
80
|
+
option :update_statement, default: -> { self.class.update_statement }
|
81
81
|
|
82
82
|
# @!attribute [r] update_where
|
83
83
|
# @return [Object] the WHERE clause to be added to the update
|
84
|
-
option :update_where,
|
84
|
+
option :update_where, default: -> { self.class.update_where }
|
85
85
|
|
86
86
|
# Tries to insert provided tuples and do an update (or nothing)
|
87
87
|
# when the inserted record violates a unique constraint and hence
|
data/lib/rom/sql/gateway.rb
CHANGED
@@ -15,7 +15,7 @@ module ROM
|
|
15
15
|
|
16
16
|
param :connection
|
17
17
|
|
18
|
-
option :path, type: ROM::Types.Definition(Pathname),
|
18
|
+
option :path, type: ROM::Types.Definition(Pathname), default: -> { DEFAULT_PATH }
|
19
19
|
|
20
20
|
# @api private
|
21
21
|
def run(options = {})
|
@@ -57,8 +57,8 @@ module ROM
|
|
57
57
|
|
58
58
|
associations Hash.new
|
59
59
|
|
60
|
-
option :associations,
|
61
|
-
option :configured_associations,
|
60
|
+
option :associations, default: -> { self.class.associations }
|
61
|
+
option :configured_associations, default: -> { EMPTY_ARRAY }
|
62
62
|
end
|
63
63
|
super
|
64
64
|
end
|
@@ -170,7 +170,9 @@ module ROM
|
|
170
170
|
# @api public
|
171
171
|
def with_association(name, opts = EMPTY_HASH)
|
172
172
|
self.class.build(
|
173
|
-
relation,
|
173
|
+
relation,
|
174
|
+
**options,
|
175
|
+
associations: associations.merge(name => opts)
|
174
176
|
)
|
175
177
|
end
|
176
178
|
|
@@ -10,8 +10,8 @@ module ROM
|
|
10
10
|
|
11
11
|
param :dataset
|
12
12
|
|
13
|
-
option :current_page,
|
14
|
-
option :per_page
|
13
|
+
option :current_page, default: -> { 1 }
|
14
|
+
option :per_page
|
15
15
|
|
16
16
|
def next_page
|
17
17
|
num = current_page + 1
|
@@ -50,8 +50,8 @@ module ROM
|
|
50
50
|
klass.class_eval do
|
51
51
|
defines :per_page
|
52
52
|
|
53
|
-
option :pager,
|
54
|
-
Pager.new(
|
53
|
+
option :pager, default: -> {
|
54
|
+
Pager.new(dataset, per_page: self.class.per_page)
|
55
55
|
}
|
56
56
|
end
|
57
57
|
end
|
data/lib/rom/sql/relation.rb
CHANGED
@@ -112,7 +112,7 @@ module ROM
|
|
112
112
|
names.map { |col| :"#{table}__#{col}" }
|
113
113
|
end
|
114
114
|
|
115
|
-
option :primary_key,
|
115
|
+
option :primary_key, default: -> { schema.primary_key_name }
|
116
116
|
|
117
117
|
# Return relation that will load associated tuples of this relation
|
118
118
|
#
|
data/lib/rom/sql/version.rb
CHANGED
data/rom-sql.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
|
22
22
|
spec.add_runtime_dependency 'dry-types', '~> 0.9', '>= 0.9.4'
|
23
23
|
spec.add_runtime_dependency 'dry-core', '~> 0.2', '>= 0.2.3'
|
24
|
-
spec.add_runtime_dependency 'rom', '~> 3.
|
24
|
+
spec.add_runtime_dependency 'rom', '~> 3.2'
|
25
25
|
|
26
26
|
spec.add_development_dependency 'bundler'
|
27
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
@@ -25,9 +25,9 @@ RSpec.describe ROM::SQL::Association::OneToMany, '#call' do
|
|
25
25
|
|
26
26
|
p1_id = relations[:categories].insert(name: 'P1')
|
27
27
|
p2_id = relations[:categories].insert(name: 'P2')
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
relations[:categories].insert(name: 'C3', parent_id: p2_id)
|
29
|
+
relations[:categories].insert(name: 'C4', parent_id: p1_id)
|
30
|
+
relations[:categories].insert(name: 'C5', parent_id: p1_id)
|
31
31
|
end
|
32
32
|
|
33
33
|
after do
|
@@ -30,9 +30,9 @@ RSpec.describe ROM::SQL::Association::OneToMany, '#call' do
|
|
30
30
|
|
31
31
|
p1_id = relations[:categories].insert(name: 'P1')
|
32
32
|
p2_id = relations[:categories].insert(name: 'P2')
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
relations[:categories].insert(name: 'C3', parent_id: p2_id)
|
34
|
+
relations[:categories].insert(name: 'C4', parent_id: p1_id)
|
35
|
+
relations[:categories].insert(name: 'C5', parent_id: p1_id)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'prepares joined relations using custom FK for a self-ref association' do
|
@@ -3,8 +3,9 @@ require 'dry-struct'
|
|
3
3
|
RSpec.describe 'Commands / Create', :postgres, seeds: false do
|
4
4
|
include_context 'relations'
|
5
5
|
|
6
|
-
let(:
|
7
|
-
let(:
|
6
|
+
let(:create_user) { user_commands.create }
|
7
|
+
let(:create_users) { user_commands.create_many }
|
8
|
+
let(:create_task) { task_commands.create }
|
8
9
|
|
9
10
|
before do |ex|
|
10
11
|
module Test
|
@@ -45,16 +46,16 @@ RSpec.describe 'Commands / Create', :postgres, seeds: false do
|
|
45
46
|
with_adapters do
|
46
47
|
describe '#transaction' do
|
47
48
|
it 'creates record if nothing was raised' do
|
48
|
-
result =
|
49
|
-
|
49
|
+
result = create_user.transaction {
|
50
|
+
create_user.call(name: 'Jane')
|
50
51
|
}
|
51
52
|
|
52
53
|
expect(result.value).to eql(id: 1, name: 'Jane')
|
53
54
|
end
|
54
55
|
|
55
56
|
it 'creates multiple records if nothing was raised' do
|
56
|
-
result =
|
57
|
-
|
57
|
+
result = create_user.transaction {
|
58
|
+
create_users.call([{ name: 'Jane' }, { name: 'Jack' }])
|
58
59
|
}
|
59
60
|
|
60
61
|
expect(result.value).to match_array([
|
@@ -63,9 +64,9 @@ RSpec.describe 'Commands / Create', :postgres, seeds: false do
|
|
63
64
|
end
|
64
65
|
|
65
66
|
it 'allows for nested transactions' do
|
66
|
-
result =
|
67
|
-
|
68
|
-
|
67
|
+
result = create_user.transaction {
|
68
|
+
create_user.transaction {
|
69
|
+
create_user.call(name: 'Jane')
|
69
70
|
}
|
70
71
|
}
|
71
72
|
|
@@ -75,9 +76,9 @@ RSpec.describe 'Commands / Create', :postgres, seeds: false do
|
|
75
76
|
it 'creates nothing if command error was raised' do
|
76
77
|
expect {
|
77
78
|
begin
|
78
|
-
|
79
|
-
|
80
|
-
|
79
|
+
create_user.transaction {
|
80
|
+
create_user.call(name: 'Jane')
|
81
|
+
create_user.call(name: nil)
|
81
82
|
}
|
82
83
|
rescue ROM::SQL::Error
|
83
84
|
end
|
@@ -88,9 +89,9 @@ RSpec.describe 'Commands / Create', :postgres, seeds: false do
|
|
88
89
|
expect {
|
89
90
|
passed = false
|
90
91
|
|
91
|
-
result =
|
92
|
-
|
93
|
-
|
92
|
+
result = create_user.transaction {
|
93
|
+
create_user.call(name: 'Jane')
|
94
|
+
create_user.call(name: 'John')
|
94
95
|
raise ROM::SQL::Rollback
|
95
96
|
} >-> _value {
|
96
97
|
passed = true
|
@@ -107,9 +108,9 @@ RSpec.describe 'Commands / Create', :postgres, seeds: false do
|
|
107
108
|
begin
|
108
109
|
passed = false
|
109
110
|
|
110
|
-
|
111
|
-
|
112
|
-
|
111
|
+
create_user.transaction {
|
112
|
+
create_user.call(name: 'Jane')
|
113
|
+
create_user.call(name: 'Jane')
|
113
114
|
} >-> _value {
|
114
115
|
passed = true
|
115
116
|
}
|
@@ -123,10 +124,10 @@ RSpec.describe 'Commands / Create', :postgres, seeds: false do
|
|
123
124
|
it 'creates nothing if anything was raised in any nested transaction' do
|
124
125
|
expect {
|
125
126
|
expect {
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
127
|
+
create_user.transaction {
|
128
|
+
create_user.call(name: 'John')
|
129
|
+
create_user.transaction {
|
130
|
+
create_user.call(name: 'Jane')
|
130
131
|
raise Exception
|
131
132
|
}
|
132
133
|
}
|
@@ -159,14 +160,14 @@ RSpec.describe 'Commands / Create', :postgres, seeds: false do
|
|
159
160
|
end
|
160
161
|
|
161
162
|
it 'returns a single tuple when result is set to :one' do
|
162
|
-
result =
|
163
|
+
result = user_commands.try { create_user.call(name: 'Jane') }
|
163
164
|
|
164
165
|
expect(result.value).to eql(id: 1, name: 'Jane')
|
165
166
|
end
|
166
167
|
|
167
168
|
it 'returns tuples when result is set to :many' do
|
168
|
-
result =
|
169
|
-
|
169
|
+
result = user_commands.try do
|
170
|
+
create_users.call([{ name: 'Jane' }, { name: 'Jack' }])
|
170
171
|
end
|
171
172
|
|
172
173
|
expect(result.value.to_a).to match_array([
|
@@ -176,7 +177,7 @@ RSpec.describe 'Commands / Create', :postgres, seeds: false do
|
|
176
177
|
|
177
178
|
it 're-raises not-null constraint violation error' do
|
178
179
|
expect {
|
179
|
-
|
180
|
+
user_commands.try { create_user.call(name: nil) }
|
180
181
|
}.to raise_error(ROM::SQL::NotNullConstraintError)
|
181
182
|
end
|
182
183
|
|
@@ -208,32 +209,32 @@ RSpec.describe 'Commands / Create', :postgres, seeds: false do
|
|
208
209
|
|
209
210
|
it 're-raises uniqueness constraint violation error' do
|
210
211
|
expect {
|
211
|
-
|
212
|
-
|
212
|
+
user_commands.try {
|
213
|
+
create_user.call(name: 'Jane')
|
213
214
|
} >-> user {
|
214
|
-
|
215
|
+
user_commands.try { create_user.call(name: user[:name]) }
|
215
216
|
}
|
216
217
|
}.to raise_error(ROM::SQL::UniqueConstraintError)
|
217
218
|
end
|
218
219
|
|
219
220
|
it 're-raises fk constraint violation error' do |ex|
|
220
221
|
expect {
|
221
|
-
|
222
|
-
|
222
|
+
task_commands.try {
|
223
|
+
create_task.call(user_id: 918_273_645)
|
223
224
|
}
|
224
225
|
}.to raise_error(ROM::SQL::ForeignKeyConstraintError)
|
225
226
|
end
|
226
227
|
|
227
228
|
it 're-raises database errors' do
|
228
229
|
expect {
|
229
|
-
|
230
|
+
user_commands.try { create_user.call(name: nil) }
|
230
231
|
}.to raise_error(ROM::SQL::NotNullConstraintError)
|
231
232
|
end
|
232
233
|
|
233
234
|
describe '#execute' do
|
234
235
|
context 'with a single record' do
|
235
236
|
it 'materializes the result' do
|
236
|
-
result =
|
237
|
+
result = create_user.execute(name: 'Jane')
|
237
238
|
expect(result).to eq([
|
238
239
|
{ id: 1, name: 'Jane' }
|
239
240
|
])
|
@@ -242,7 +243,7 @@ RSpec.describe 'Commands / Create', :postgres, seeds: false do
|
|
242
243
|
|
243
244
|
context 'with multiple records' do
|
244
245
|
it 'materializes the results' do
|
245
|
-
result =
|
246
|
+
result = create_user.execute([
|
246
247
|
{ name: 'Jane' },
|
247
248
|
{ name: 'John' }
|
248
249
|
])
|
@@ -291,16 +292,16 @@ RSpec.describe 'Commands / Create', :postgres, seeds: false do
|
|
291
292
|
describe '#call' do
|
292
293
|
it 're-raises check constraint violation error' do
|
293
294
|
expect {
|
294
|
-
|
295
|
-
|
295
|
+
user_commands.try {
|
296
|
+
create_user.call(name: 'J')
|
296
297
|
}
|
297
298
|
}.to raise_error(ROM::SQL::CheckConstraintError, /name/)
|
298
299
|
end
|
299
300
|
|
300
301
|
it 're-raises constraint violation error' do
|
301
302
|
expect {
|
302
|
-
|
303
|
-
|
303
|
+
user_commands.try {
|
304
|
+
create_task.call(title: '')
|
304
305
|
}
|
305
306
|
}.to raise_error(ROM::SQL::ConstraintError, /title/)
|
306
307
|
end
|
@@ -309,20 +310,20 @@ RSpec.describe 'Commands / Create', :postgres, seeds: false do
|
|
309
310
|
describe '#upsert' do
|
310
311
|
let(:task) { { title: 'task 1' } }
|
311
312
|
|
312
|
-
before {
|
313
|
+
before { create_task.call(task) }
|
313
314
|
|
314
315
|
it 'raises error without upsert marker' do
|
315
316
|
expect {
|
316
|
-
|
317
|
+
create_task.call(task)
|
317
318
|
}.to raise_error(ROM::SQL::UniqueConstraintError)
|
318
319
|
end
|
319
320
|
|
320
321
|
it 'raises no error for duplicated data' do
|
321
|
-
expect {
|
322
|
+
expect { create_task.upsert(task) }.to_not raise_error
|
322
323
|
end
|
323
324
|
|
324
325
|
it 'returns record data' do
|
325
|
-
expect(
|
326
|
+
expect(create_task.upsert(task, constraint: :tasks_title_key, update: { user_id: nil })).to eql([
|
326
327
|
id: 1, user_id: nil, title: 'task 1'
|
327
328
|
])
|
328
329
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
RSpec.describe 'Commands / Delete' do
|
2
2
|
include_context 'users and tasks'
|
3
3
|
|
4
|
-
|
4
|
+
let(:delete_user) { user_commands.delete }
|
5
5
|
|
6
6
|
with_adapters do
|
7
7
|
before do
|
@@ -17,45 +17,45 @@ RSpec.describe 'Commands / Delete' do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
users.insert(id: 3, name: 'Jade')
|
21
|
+
users.insert(id: 4, name: 'John')
|
22
22
|
end
|
23
23
|
|
24
24
|
describe '#transaction' do
|
25
25
|
it 'deletes in normal way if no error raised' do
|
26
26
|
expect {
|
27
|
-
|
28
|
-
|
27
|
+
delete_user.transaction do
|
28
|
+
delete_user.by_name('Jade').call
|
29
29
|
end
|
30
|
-
}.to change {
|
30
|
+
}.to change { users.count }.by(-1)
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'deletes nothing if error was raised' do
|
34
34
|
expect {
|
35
|
-
|
36
|
-
|
35
|
+
delete_user.transaction do
|
36
|
+
delete_user.by_name('Jade').call
|
37
37
|
raise ROM::SQL::Rollback
|
38
38
|
end
|
39
|
-
}.to_not change {
|
39
|
+
}.to_not change { users.count }
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
describe '#call' do
|
44
44
|
it 'deletes all tuples in a restricted relation' do
|
45
|
-
result =
|
45
|
+
result = user_commands.try { delete_user.by_name('Jade').call }
|
46
46
|
|
47
47
|
expect(result.value).to eql(id: 3, name: 'Jade')
|
48
48
|
end
|
49
49
|
|
50
50
|
it 're-raises database error' do
|
51
|
-
command =
|
51
|
+
command = delete_user.by_name('Jade')
|
52
52
|
|
53
53
|
expect(command.relation).to receive(:delete).and_raise(
|
54
54
|
Sequel::DatabaseError, 'totally wrong'
|
55
55
|
)
|
56
56
|
|
57
57
|
expect {
|
58
|
-
|
58
|
+
user_commands.try { command.call }
|
59
59
|
}.to raise_error(ROM::SQL::DatabaseError, /totally wrong/)
|
60
60
|
end
|
61
61
|
end
|
@@ -3,12 +3,9 @@ require 'dry-struct'
|
|
3
3
|
RSpec.describe 'Commands / Update', seeds: false do
|
4
4
|
include_context 'users'
|
5
5
|
|
6
|
-
|
6
|
+
let(:update_user) { user_commands[:update] }
|
7
7
|
|
8
|
-
let(:
|
9
|
-
|
10
|
-
let(:relation) { container.relations.users }
|
11
|
-
let(:piotr) { relation.by_name('Piotr').one }
|
8
|
+
let(:piotr) { users.by_name('Piotr').one }
|
12
9
|
let(:peter) { { name: 'Peter' } }
|
13
10
|
|
14
11
|
with_adapters do
|
@@ -36,55 +33,53 @@ RSpec.describe 'Commands / Update', seeds: false do
|
|
36
33
|
register :users, entity: -> tuples { tuples.map { |tuple| Test::User.new(tuple) } }
|
37
34
|
end
|
38
35
|
|
39
|
-
|
40
|
-
|
36
|
+
users.insert(name: 'Piotr')
|
37
|
+
users.insert(name: 'Jane')
|
41
38
|
end
|
42
39
|
|
43
40
|
context '#transaction' do
|
44
41
|
it 'update record if there was no errors' do
|
45
|
-
result =
|
46
|
-
|
42
|
+
result = update_user.transaction do
|
43
|
+
update_user.by_id(piotr[:id]).call(peter)
|
47
44
|
end
|
48
45
|
|
49
46
|
expect(result.value).to eq([{ id: 1, name: 'Peter' }])
|
50
47
|
end
|
51
48
|
|
52
49
|
it 'updates nothing if error was raised' do
|
53
|
-
|
54
|
-
|
50
|
+
update_user.transaction do
|
51
|
+
update_user.by_id(piotr[:id]).call(peter)
|
55
52
|
raise ROM::SQL::Rollback
|
56
53
|
end
|
57
54
|
|
58
|
-
expect(
|
55
|
+
expect(users.first[:name]).to eql('Piotr')
|
59
56
|
end
|
60
57
|
end
|
61
58
|
|
62
59
|
describe '#call' do
|
63
60
|
it 'updates relation tuples' do
|
64
|
-
result =
|
65
|
-
|
61
|
+
result = user_commands.try do
|
62
|
+
update_user.by_id(piotr[:id]).call(peter)
|
66
63
|
end
|
67
64
|
|
68
65
|
expect(result.value.to_a).to match_array([{ id: 1, name: 'Peter' }])
|
69
66
|
end
|
70
67
|
|
71
68
|
it 're-raises database errors' do |example|
|
72
|
-
pending 'why is it failing on travis?' if ENV['TRAVIS'] && mysql?(example) && !jruby?
|
73
|
-
|
74
69
|
expect {
|
75
|
-
|
70
|
+
update_user.by_id(piotr[:id]).call(name: nil)
|
76
71
|
}.to raise_error(ROM::SQL::NotNullConstraintError, /name/i)
|
77
72
|
end
|
78
73
|
|
79
74
|
it 'materializes single result' do
|
80
|
-
result =
|
75
|
+
result = update_user.by_name('Piotr').call(name: 'Pete')
|
81
76
|
expect(result).to eq([
|
82
77
|
{ id: 1, name: 'Pete' }
|
83
78
|
])
|
84
79
|
end
|
85
80
|
|
86
81
|
it 'materializes multiple results' do
|
87
|
-
result =
|
82
|
+
result = update_user.by_name(%w(Piotr Jane)).call(name: 'Josie')
|
88
83
|
expect(result).to eq([
|
89
84
|
{ id: 1, name: 'Josie' },
|
90
85
|
{ id: 2, name: 'Josie' }
|
@@ -1,10 +1,8 @@
|
|
1
1
|
RSpec.describe 'Commands / Postgres / Upsert', :postgres, seeds: false do
|
2
|
-
subject(:command) {
|
2
|
+
subject(:command) { task_commands[:create_or_update] }
|
3
3
|
|
4
4
|
include_context 'relations'
|
5
5
|
|
6
|
-
let(:tasks) { commands[:tasks] }
|
7
|
-
|
8
6
|
before do
|
9
7
|
conn.execute "ALTER TABLE tasks add CONSTRAINT tasks_title_key UNIQUE (title)"
|
10
8
|
|
@@ -1,15 +1,15 @@
|
|
1
1
|
RSpec.describe 'Plugins / :associates / with many-to-many', :sqlite, seeds: false do
|
2
2
|
include_context 'users and tasks'
|
3
3
|
|
4
|
-
let(:
|
5
|
-
let(:
|
4
|
+
let(:create_tag) { tag_commands.create }
|
5
|
+
let(:create_task) { task_commands.create }
|
6
6
|
|
7
7
|
let(:jane) do
|
8
|
-
|
8
|
+
users.by_pk(users.insert(name: 'Jane')).one
|
9
9
|
end
|
10
10
|
|
11
11
|
let(:john) do
|
12
|
-
|
12
|
+
users.by_pk(users.insert(name: 'John')).one
|
13
13
|
end
|
14
14
|
|
15
15
|
before do
|
@@ -53,10 +53,10 @@ RSpec.describe 'Plugins / :associates / with many-to-many', :sqlite, seeds: fals
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'associates a child with many parents' do
|
56
|
-
|
57
|
-
|
56
|
+
add_tags = create_tag.with([{ name: 'red' }, { name: 'blue' }])
|
57
|
+
add_task = create_task.with(user_id: jane[:id], title: "Jade's task")
|
58
58
|
|
59
|
-
command =
|
59
|
+
command = add_tags >> add_task
|
60
60
|
|
61
61
|
result = command.call
|
62
62
|
|
@@ -4,10 +4,6 @@ RSpec.describe 'Plugins / :auto_wrap' do
|
|
4
4
|
|
5
5
|
describe '#for_wrap' do
|
6
6
|
shared_context 'joined tuple' do
|
7
|
-
let(:name) do
|
8
|
-
users.name.relation
|
9
|
-
end
|
10
|
-
|
11
7
|
it 'returns joined tuples' do
|
12
8
|
task_with_user = tasks
|
13
9
|
.for_wrap({ id: :user_id }, name)
|
@@ -31,36 +27,29 @@ RSpec.describe 'Plugins / :auto_wrap' do
|
|
31
27
|
end
|
32
28
|
|
33
29
|
context 'when parent relation is registered under dataset name' do
|
34
|
-
subject(:tasks) { relations[:tasks] }
|
35
|
-
|
36
|
-
let(:users) { relations[:users] }
|
37
|
-
|
38
30
|
before do
|
39
31
|
conf.relation(:tasks) { schema(infer: true) }
|
40
32
|
conf.relation(:users) { schema(infer: true) }
|
41
33
|
end
|
42
34
|
|
43
|
-
include_context 'joined tuple'
|
35
|
+
include_context 'joined tuple' do
|
36
|
+
let(:name) { :users }
|
37
|
+
end
|
44
38
|
end
|
45
39
|
|
46
40
|
context 'when parent relation is registered under a custom name' do
|
47
|
-
subject(:tasks) { relations[:tasks] }
|
48
|
-
|
49
|
-
let(:users) { relations[:authors] }
|
50
|
-
|
51
41
|
before do
|
52
42
|
conf.relation(:tasks) { schema(infer: true) }
|
53
43
|
conf.relation(:authors) { schema(:users, infer: true) }
|
54
44
|
end
|
55
45
|
|
56
|
-
include_context 'joined tuple'
|
46
|
+
include_context 'joined tuple' do
|
47
|
+
let(:users) { relations[:authors] }
|
48
|
+
let(:name) { :authors}
|
49
|
+
end
|
57
50
|
end
|
58
51
|
|
59
52
|
context 'using association' do
|
60
|
-
subject(:tasks) { relations[:tasks] }
|
61
|
-
|
62
|
-
let(:users) { relations[:users] }
|
63
|
-
|
64
53
|
before do
|
65
54
|
conf.relation(:tasks) {
|
66
55
|
schema(infer: true) { associations { belongs_to :users, as: :assignee } }
|
data/spec/shared/users.rb
CHANGED
@@ -2,6 +2,10 @@ RSpec.shared_context 'users and tasks' do
|
|
2
2
|
include_context 'users'
|
3
3
|
|
4
4
|
let(:tasks) { container.relations[:tasks] }
|
5
|
+
let(:tags) { container.relations[:tags] }
|
6
|
+
|
7
|
+
let(:task_commands) { container.commands[:tasks] }
|
8
|
+
let(:tag_commands) { container.commands[:tags] }
|
5
9
|
|
6
10
|
before do
|
7
11
|
inferrable_relations.concat %i(tasks tags task_tags)
|
data/spec/spec_helper.rb
CHANGED
@@ -33,14 +33,14 @@ if defined? JRUBY_VERSION
|
|
33
33
|
DB_URIS = {
|
34
34
|
sqlite: 'jdbc:sqlite:::memory',
|
35
35
|
postgres: 'jdbc:postgresql://localhost/rom_sql',
|
36
|
-
mysql: 'jdbc:mysql://localhost/rom_sql?user=root',
|
36
|
+
mysql: 'jdbc:mysql://localhost/rom_sql?user=root&sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION',
|
37
37
|
oracle: ENV['ROM_USE_ORACLE'] ? fail('Setup Oracle for JRuby!') : nil
|
38
38
|
}
|
39
39
|
else
|
40
40
|
DB_URIS = {
|
41
41
|
sqlite: 'sqlite::memory',
|
42
42
|
postgres: 'postgres://localhost/rom_sql',
|
43
|
-
mysql: 'mysql2://root@localhost/rom_sql',
|
43
|
+
mysql: 'mysql2://root@localhost/rom_sql?sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION',
|
44
44
|
oracle: "oracle://#{ oracle_settings[:host] }:#{ oracle_settings[:port] }/" \
|
45
45
|
"#{ oracle_settings[:db_name] }?username=rom_sql&password=rom_sql&autosequence=true"
|
46
46
|
}
|
@@ -78,9 +78,23 @@ def with_adapters(*args, &block)
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
warning_api_available = RUBY_VERSION >= '2.4.0'
|
82
|
+
|
83
|
+
module SileneceWarnings
|
84
|
+
def warn(str)
|
85
|
+
if str['/sequel/'] || str['/rspec-core']
|
86
|
+
nil
|
87
|
+
else
|
88
|
+
super
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
Warning.extend(SileneceWarnings) if warning_api_available
|
94
|
+
|
81
95
|
RSpec.configure do |config|
|
82
96
|
config.disable_monkey_patching!
|
83
|
-
|
97
|
+
config.warnings = warning_api_available
|
84
98
|
|
85
99
|
config.before(:suite) do
|
86
100
|
tmp_test_dir = TMP_PATH.join('test')
|
data/spec/unit/attribute_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -84,14 +84,14 @@ dependencies:
|
|
84
84
|
requirements:
|
85
85
|
- - "~>"
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version: '3.
|
87
|
+
version: '3.2'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
92
|
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version: '3.
|
94
|
+
version: '3.2'
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
96
|
name: bundler
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -346,7 +346,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
346
346
|
version: '0'
|
347
347
|
requirements: []
|
348
348
|
rubyforge_project:
|
349
|
-
rubygems_version: 2.
|
349
|
+
rubygems_version: 2.6.10
|
350
350
|
signing_key:
|
351
351
|
specification_version: 4
|
352
352
|
summary: SQL databases support for ROM
|