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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.md +8 -0
  4. data/Gemfile +0 -1
  5. data/lib/rom/sql/association.rb +5 -5
  6. data/lib/rom/sql/extensions/postgres/commands.rb +4 -4
  7. data/lib/rom/sql/extensions/rails_log_subscriber.rb +3 -1
  8. data/lib/rom/sql/gateway.rb +2 -0
  9. data/lib/rom/sql/migration/migrator.rb +1 -1
  10. data/lib/rom/sql/plugin/associates.rb +5 -3
  11. data/lib/rom/sql/plugin/pagination.rb +4 -4
  12. data/lib/rom/sql/relation.rb +1 -1
  13. data/lib/rom/sql/version.rb +1 -1
  14. data/rom-sql.gemspec +1 -1
  15. data/spec/integration/association/many_to_many_spec.rb +0 -1
  16. data/spec/integration/association/many_to_one/self_ref_spec.rb +3 -3
  17. data/spec/integration/association/many_to_one_spec.rb +0 -3
  18. data/spec/integration/association/one_to_many/self_ref_spec.rb +3 -3
  19. data/spec/integration/commands/create_spec.rb +43 -42
  20. data/spec/integration/commands/delete_spec.rb +12 -12
  21. data/spec/integration/commands/update_spec.rb +14 -19
  22. data/spec/integration/commands/upsert_spec.rb +1 -3
  23. data/spec/integration/plugins/associates/many_to_many_spec.rb +7 -7
  24. data/spec/integration/plugins/auto_wrap_spec.rb +7 -18
  25. data/spec/integration/schema/inferrer_spec.rb +0 -2
  26. data/spec/integration/sequel_api_spec.rb +0 -2
  27. data/spec/shared/users.rb +1 -0
  28. data/spec/shared/users_and_tasks.rb +4 -0
  29. data/spec/spec_helper.rb +17 -3
  30. data/spec/unit/attribute_spec.rb +0 -1
  31. data/spec/unit/relation/group_spec.rb +0 -1
  32. data/spec/unit/relation/inner_join_spec.rb +0 -2
  33. data/spec/unit/relation/left_join_spec.rb +0 -2
  34. data/spec/unit/relation/qualified_spec.rb +0 -2
  35. data/spec/unit/relation/right_join_spec.rb +0 -2
  36. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4f8bdb0d753d19b5bb7be8f3d9282312f634e5d
4
- data.tar.gz: dff2a952b88aa4457dc58adfc69a60e636a64527
3
+ metadata.gz: bc6edcd56b3aeda31a41f53c921aa2a79dd19ffc
4
+ data.tar.gz: d954520aa88474fcf6d61897ea0f1fed50e876ee
5
5
  SHA512:
6
- metadata.gz: 837cc9f183231b155420771c55408db56779aee6adb8d97c9ad378cbe82f4047774d93b764d064f5ecddfe3521081f02a91445d394ba6aa014e607382a69fd02
7
- data.tar.gz: 20c1e14423d4113a1aef6d03bd68a2e1a41232b562891fbf53b01b7ffea185e27d15d902c5bd72734f30b330e515ad2e6a831831d990694dc6c3226aedf786da
6
+ metadata.gz: 9f9f16bab1aef147b4956217362a1e08ec3f08dda74fc624c1e82622b6614e7bf557f8a47026f94dad182f4c34fe9fddebb3f33e876902355938f051a9c239f2
7
+ data.tar.gz: faa2da9349e0f26bfe53ed96a6e145a444a21ce100930191324650399d26a9aeeaa23ff1485b4cddc20532fda67e7667276bcd98ec460eecb7f0a1053f498347
@@ -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"
@@ -1,3 +1,11 @@
1
+ ## v1.2.2 2017-03-25
2
+
3
+ ### Changed
4
+
5
+ * Updated `dry-initializer` (flash-gordon)
6
+
7
+ [Compare v1.2.1...v1.2.2](https://github.com/rom-rb/rom-sql/compare/v1.2.1...v1.2.2)
8
+
1
9
  ## v1.2.1 2017-03-09
2
10
 
3
11
  ### Fixed
data/Gemfile CHANGED
@@ -10,7 +10,6 @@ group :test do
10
10
  gem 'pry', platforms: %i(jruby rbx)
11
11
  gem 'dry-struct'
12
12
  gem 'activesupport', '~> 5.0'
13
- gem 'rspec', '~> 3.1'
14
13
  gem 'codeclimate-test-reporter', require: false
15
14
  gem 'simplecov', require: false
16
15
 
@@ -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, reader: true, optional: true
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, reader: true, default: -> assoc { assoc.class.result }
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, reader: true, optional: true, default: -> assoc { assoc.target.to_sym }
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, reader: true, default: proc { nil }
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, reader: true, optional: true, default: proc { nil }
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, reader: true, default: -> c { c.class.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, reader: true, default: -> c { c.class.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, reader: true, default: -> c { c.class.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, reader: true, default: -> c { c.class.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
@@ -22,8 +22,10 @@ module ROM
22
22
  debug " #{name} #{sql} #{binds}"
23
23
  end
24
24
 
25
+ attr_reader :odd_or_even
26
+ private :odd_or_even
25
27
  def odd?
26
- @odd_or_even = !@odd_or_even
28
+ @odd_or_even = !odd_or_even
27
29
  end
28
30
  end
29
31
  end
@@ -23,6 +23,8 @@ module ROM
23
23
  attr_accessor :instance
24
24
  end
25
25
 
26
+ adapter :sql
27
+
26
28
  CONNECTION_EXTENSIONS = {
27
29
  postgres: %i(pg_array pg_json pg_enum pg_hstore)
28
30
  }.freeze
@@ -15,7 +15,7 @@ module ROM
15
15
 
16
16
  param :connection
17
17
 
18
- option :path, type: ROM::Types.Definition(Pathname), reader: true, default: proc { DEFAULT_PATH }
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, reader: true, optional: true, default: -> cmd { cmd.class.associations }
61
- option :configured_associations, reader: true, optional: true, default: proc { [] }
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, options.merge(associations: associations.merge(name => opts))
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, reader: true, default: proc { 1 }
14
- option :per_page, reader: true
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, reader: true, default: proc { |relation|
54
- Pager.new(relation.dataset, per_page: relation.class.per_page)
53
+ option :pager, default: -> {
54
+ Pager.new(dataset, per_page: self.class.per_page)
55
55
  }
56
56
  end
57
57
  end
@@ -112,7 +112,7 @@ module ROM
112
112
  names.map { |col| :"#{table}__#{col}" }
113
113
  end
114
114
 
115
- option :primary_key, reader: true, default: -> rel { rel.schema.primary_key_name }
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
  #
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module SQL
3
- VERSION = '1.2.1'.freeze
3
+ VERSION = '1.2.2'.freeze
4
4
  end
5
5
  end
@@ -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.1'
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'
@@ -7,7 +7,6 @@ RSpec.describe ROM::SQL::Association::ManyToMany do
7
7
  ROM::SQL::Association::ManyToMany.new(:tasks, :tags, through: :task_tags)
8
8
  }
9
9
 
10
- let(:tasks) { container.relations[:tasks] }
11
10
  let(:tags) { container.relations[:tags] }
12
11
 
13
12
  before do
@@ -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
- c1_id = relations[:categories].insert(name: 'C3', parent_id: p2_id)
29
- c2_id = relations[:categories].insert(name: 'C4', parent_id: p1_id)
30
- c3_id = relations[:categories].insert(name: 'C5', parent_id: p1_id)
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
@@ -1,7 +1,4 @@
1
1
  RSpec.describe ROM::SQL::Association::ManyToOne, helpers: true do
2
- let(:users) { container.relations[:users] }
3
- let(:tasks) { container.relations[:tasks] }
4
-
5
2
  with_adapters do
6
3
  context 'common name conventions' do
7
4
  include_context 'users and tasks'
@@ -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
- c1_id = relations[:categories].insert(name: 'C3', parent_id: p2_id)
34
- c2_id = relations[:categories].insert(name: 'C4', parent_id: p1_id)
35
- c3_id = relations[:categories].insert(name: 'C5', parent_id: p1_id)
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(:users) { commands[:users] }
7
- let(:tasks) { commands[:tasks] }
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 = users.create.transaction {
49
- users.create.call(name: 'Jane')
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 = users.create.transaction {
57
- users.create_many.call([{ name: 'Jane' }, { name: 'Jack' }])
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 = users.create.transaction {
67
- users.create.transaction {
68
- users.create.call(name: 'Jane')
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
- users.create.transaction {
79
- users.create.call(name: 'Jane')
80
- users.create.call(name: nil)
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 = users.create.transaction {
92
- users.create.call(name: 'Jane')
93
- users.create.call(name: 'John')
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
- users.create.transaction {
111
- users.create.call(name: 'Jane')
112
- users.create.call(name: 'Jane')
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
- users.create.transaction {
127
- users.create.call(name: 'John')
128
- users.create.transaction {
129
- users.create.call(name: 'Jane')
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 = users.try { users.create.call(name: 'Jane') }
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 = users.try do
169
- users.create_many.call([{ name: 'Jane' }, { name: 'Jack' }])
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
- users.try { users.create.call(name: nil) }
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
- users.try {
212
- users.create.call(name: 'Jane')
212
+ user_commands.try {
213
+ create_user.call(name: 'Jane')
213
214
  } >-> user {
214
- users.try { users.create.call(name: user[:name]) }
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
- tasks.try {
222
- tasks.create.call(user_id: 918_273_645)
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
- users.try { users.create.call(name: nil) }
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 = container.command(:users).create.execute(name: 'Jane')
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 = container.command(:users).create.execute([
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
- users.try {
295
- users.create.call(name: 'J')
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
- users.try {
303
- tasks.create.call(title: '')
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 { tasks.create.call(task) }
313
+ before { create_task.call(task) }
313
314
 
314
315
  it 'raises error without upsert marker' do
315
316
  expect {
316
- tasks.create.call(task)
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 { tasks.create.upsert(task) }.to_not raise_error
322
+ expect { create_task.upsert(task) }.to_not raise_error
322
323
  end
323
324
 
324
325
  it 'returns record data' do
325
- expect(tasks.create.upsert(task, constraint: :tasks_title_key, update: { user_id: nil })).to eql([
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
- subject(:users) { container.commands.users }
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
- container.relations.users.insert(id: 3, name: 'Jade')
21
- container.relations.users.insert(id: 4, name: 'John')
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
- users.delete.transaction do
28
- users.delete.by_name('Jade').call
27
+ delete_user.transaction do
28
+ delete_user.by_name('Jade').call
29
29
  end
30
- }.to change { container.relations.users.count }.by(-1)
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
- users.delete.transaction do
36
- users.delete.by_name('Jade').call
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 { container.relations.users.count }
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 = users.try { users.delete.by_name('Jade').call }
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 = users.delete.by_name('Jade')
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
- users.try { command.call }
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
- subject(:users) { container.command(:users) }
6
+ let(:update_user) { user_commands[:update] }
7
7
 
8
- let(:update) { container.commands[:users][:update] }
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
- relation.insert(name: 'Piotr')
40
- relation.insert(name: 'Jane')
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 = users.update.transaction do
46
- users.update.by_id(piotr[:id]).call(peter)
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
- users.update.transaction do
54
- users.update.by_id(piotr[:id]).call(peter)
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(relation.first[:name]).to eql('Piotr')
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 = users.try do
65
- users.update.by_id(piotr[:id]).call(peter)
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
- users.update.by_id(piotr[:id]).call(name: nil)
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 = users.update.by_name('Piotr').call(name: 'Pete')
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 = users.update.by_name(%w(Piotr Jane)).call(name: 'Josie')
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) { commands[:tasks][:create_or_update] }
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(:tasks) { container.commands[:tasks] }
5
- let(:tags) { container.commands[:tags] }
4
+ let(:create_tag) { tag_commands.create }
5
+ let(:create_task) { task_commands.create }
6
6
 
7
7
  let(:jane) do
8
- relations[:users].by_pk(relations[:users].insert(name: 'Jane')).one
8
+ users.by_pk(users.insert(name: 'Jane')).one
9
9
  end
10
10
 
11
11
  let(:john) do
12
- relations[:users].by_pk(relations[:users].insert(name: 'John')).one
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
- create_tags = tags[:create].with([{ name: 'red' }, { name: 'blue' }])
57
- create_task = tasks[:create].with(user_id: jane[:id], title: "Jade's task")
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 = create_tags >> create_task
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 } }
@@ -312,8 +312,6 @@ RSpec.describe 'Schema inference for common datatypes', seeds: false do
312
312
 
313
313
  describe 'inferring indices', oracle: false do
314
314
  before do |ex|
315
- ctx = self
316
-
317
315
  conn.create_table :test_inferrence do
318
316
  primary_key :id
319
317
  Integer :foo
@@ -3,8 +3,6 @@ require 'spec_helper'
3
3
  RSpec.describe 'Using legacy sequel api', :sqlite do
4
4
  include_context 'users'
5
5
 
6
- let(:users) { relations[:users] }
7
-
8
6
  before do
9
7
  conf.relation(:users) do
10
8
  include ROM::SQL::Relation::SequelAPI
@@ -6,6 +6,7 @@ RSpec.shared_context 'users' do
6
6
  end
7
7
 
8
8
  let(:users) { container.relations[:users] }
9
+ let(:user_commands) { container.commands[:users] }
9
10
 
10
11
  let(:jane_id) { 1 }
11
12
  let(:joe_id) { 2 }
@@ -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)
@@ -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')
@@ -3,7 +3,6 @@ require 'spec_helper'
3
3
  RSpec.describe ROM::SQL::Attribute, :postgres do
4
4
  include_context 'users and tasks'
5
5
 
6
- let(:users) { relations[:users] }
7
6
  let(:ds) { users.dataset }
8
7
 
9
8
  describe '#is' do
@@ -2,7 +2,6 @@ RSpec.describe ROM::Relation, '#group' do
2
2
  subject(:relation) { relations[:users] }
3
3
 
4
4
  let(:notes) { relations[:notes] }
5
- let(:tasks) { relations[:tasks] }
6
5
 
7
6
  include_context 'users and tasks'
8
7
 
@@ -1,8 +1,6 @@
1
1
  RSpec.describe ROM::Relation, '#inner_join' do
2
2
  subject(:relation) { relations[:users] }
3
3
 
4
- let(:tasks) { relations[:tasks] }
5
- let(:tags) { relations[:tags] }
6
4
  let(:puzzles) { relations[:puzzles] }
7
5
 
8
6
  include_context 'users and tasks'
@@ -1,8 +1,6 @@
1
1
  RSpec.describe ROM::Relation, '#left_join' do
2
2
  subject(:relation) { relations[:users] }
3
3
 
4
- let(:tasks) { relations[:tasks] }
5
-
6
4
  include_context 'users and tasks'
7
5
 
8
6
  with_adapters do
@@ -1,8 +1,6 @@
1
1
  RSpec.describe ROM::Relation, '#qualified' do
2
2
  subject(:relation) { relations[:users] }
3
3
 
4
- let(:tasks) { relations[:tasks] }
5
-
6
4
  include_context 'users and tasks'
7
5
 
8
6
  with_adapters do
@@ -1,8 +1,6 @@
1
1
  RSpec.describe ROM::Relation, '#right_join' do
2
2
  subject(:relation) { relations[:tasks] }
3
3
 
4
- let(:users) { relations[:users] }
5
-
6
4
  include_context 'users and tasks'
7
5
 
8
6
  with_adapters :postgres, :mysql do
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.1
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-09 00:00:00.000000000 Z
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.1'
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.1'
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.5.2
349
+ rubygems_version: 2.6.10
350
350
  signing_key:
351
351
  specification_version: 4
352
352
  summary: SQL databases support for ROM