torque-postgresql 2.0.3 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/torque/postgresql.rb +1 -0
  3. data/lib/torque/postgresql/adapter.rb +23 -0
  4. data/lib/torque/postgresql/adapter/database_statements.rb +2 -0
  5. data/lib/torque/postgresql/adapter/oid.rb +3 -1
  6. data/lib/torque/postgresql/adapter/oid/box.rb +2 -0
  7. data/lib/torque/postgresql/adapter/oid/circle.rb +2 -0
  8. data/lib/torque/postgresql/adapter/oid/enum.rb +5 -0
  9. data/lib/torque/postgresql/adapter/oid/enum_set.rb +2 -0
  10. data/lib/torque/postgresql/adapter/oid/interval.rb +2 -0
  11. data/lib/torque/postgresql/adapter/oid/line.rb +2 -0
  12. data/lib/torque/postgresql/adapter/oid/range.rb +2 -0
  13. data/lib/torque/postgresql/adapter/oid/segment.rb +2 -0
  14. data/lib/torque/postgresql/adapter/quoting.rb +2 -0
  15. data/lib/torque/postgresql/adapter/schema_creation.rb +8 -1
  16. data/lib/torque/postgresql/adapter/schema_definitions.rb +2 -0
  17. data/lib/torque/postgresql/adapter/schema_dumper.rb +9 -3
  18. data/lib/torque/postgresql/adapter/schema_statements.rb +2 -0
  19. data/lib/torque/postgresql/arel/infix_operation.rb +5 -1
  20. data/lib/torque/postgresql/arel/join_source.rb +2 -0
  21. data/lib/torque/postgresql/arel/nodes.rb +2 -0
  22. data/lib/torque/postgresql/arel/operations.rb +2 -0
  23. data/lib/torque/postgresql/arel/select_manager.rb +2 -0
  24. data/lib/torque/postgresql/arel/visitors.rb +6 -3
  25. data/lib/torque/postgresql/associations/association.rb +14 -3
  26. data/lib/torque/postgresql/associations/association_scope.rb +2 -0
  27. data/lib/torque/postgresql/associations/belongs_to_many_association.rb +168 -48
  28. data/lib/torque/postgresql/associations/builder/belongs_to_many.rb +8 -5
  29. data/lib/torque/postgresql/associations/builder/has_many.rb +2 -0
  30. data/lib/torque/postgresql/associations/preloader/association.rb +30 -1
  31. data/lib/torque/postgresql/attributes/builder.rb +3 -1
  32. data/lib/torque/postgresql/attributes/builder/enum.rb +10 -8
  33. data/lib/torque/postgresql/attributes/builder/period.rb +6 -4
  34. data/lib/torque/postgresql/attributes/enum.rb +6 -11
  35. data/lib/torque/postgresql/attributes/enum_set.rb +3 -1
  36. data/lib/torque/postgresql/attributes/lazy.rb +3 -1
  37. data/lib/torque/postgresql/attributes/period.rb +2 -0
  38. data/lib/torque/postgresql/autosave_association.rb +19 -16
  39. data/lib/torque/postgresql/auxiliary_statement.rb +2 -0
  40. data/lib/torque/postgresql/auxiliary_statement/settings.rb +2 -0
  41. data/lib/torque/postgresql/base.rb +11 -2
  42. data/lib/torque/postgresql/coder.rb +5 -3
  43. data/lib/torque/postgresql/collector.rb +2 -0
  44. data/lib/torque/postgresql/config.rb +5 -0
  45. data/lib/torque/postgresql/geometry_builder.rb +2 -0
  46. data/lib/torque/postgresql/i18n.rb +2 -0
  47. data/lib/torque/postgresql/inheritance.rb +2 -0
  48. data/lib/torque/postgresql/insert_all.rb +26 -0
  49. data/lib/torque/postgresql/migration/command_recorder.rb +2 -0
  50. data/lib/torque/postgresql/railtie.rb +2 -0
  51. data/lib/torque/postgresql/reflection.rb +2 -0
  52. data/lib/torque/postgresql/reflection/abstract_reflection.rb +13 -28
  53. data/lib/torque/postgresql/reflection/association_reflection.rb +24 -0
  54. data/lib/torque/postgresql/reflection/belongs_to_many_reflection.rb +2 -0
  55. data/lib/torque/postgresql/reflection/has_many_reflection.rb +2 -0
  56. data/lib/torque/postgresql/reflection/runtime_reflection.rb +2 -0
  57. data/lib/torque/postgresql/reflection/through_reflection.rb +2 -0
  58. data/lib/torque/postgresql/relation.rb +15 -11
  59. data/lib/torque/postgresql/relation/auxiliary_statement.rb +6 -1
  60. data/lib/torque/postgresql/relation/distinct_on.rb +2 -0
  61. data/lib/torque/postgresql/relation/inheritance.rb +2 -0
  62. data/lib/torque/postgresql/relation/merger.rb +2 -0
  63. data/lib/torque/postgresql/schema_cache.rb +2 -0
  64. data/lib/torque/postgresql/version.rb +3 -1
  65. data/spec/schema.rb +3 -2
  66. data/spec/tests/arel_spec.rb +3 -1
  67. data/spec/tests/belongs_to_many_spec.rb +139 -13
  68. data/spec/tests/enum_set_spec.rb +1 -1
  69. data/spec/tests/has_many_spec.rb +15 -1
  70. data/spec/tests/insert_all_spec.rb +89 -0
  71. data/spec/tests/table_inheritance_spec.rb +1 -1
  72. metadata +9 -6
@@ -48,7 +48,7 @@ RSpec.describe 'Enum' do
48
48
  expect(dump_io.string).to match checker
49
49
  end
50
50
 
51
- it 'can have a default value as an array of symbols' do
51
+ xit 'can have a default value as an array of symbols' do
52
52
  dump_io = StringIO.new
53
53
  checker = /t\.enum +"types", +default: \[:A, :B\], +array: true, +subtype: :types/
54
54
  ActiveRecord::SchemaDumper.dump(connection, dump_io)
@@ -5,7 +5,7 @@ RSpec.describe 'HasMany' do
5
5
  let(:builder) { ActiveRecord::Associations::Builder::HasMany }
6
6
 
7
7
  it 'adds the array option' do
8
- expect(builder.send(:valid_options, [])).to include(:array)
8
+ expect(builder.send(:valid_options, {})).to include(:array)
9
9
  end
10
10
  end
11
11
 
@@ -291,6 +291,20 @@ RSpec.describe 'HasMany' do
291
291
  expect(record.tag_ids).to be_eql([subject.id])
292
292
  end
293
293
 
294
+ it 'can perist after accessed in after_create' do
295
+ other.belongs_to_many(:tags)
296
+ other.after_create { self.tags.to_a }
297
+
298
+ video = FactoryBot.create(:video)
299
+ subject.videos << video
300
+
301
+ expect(subject.reload.videos.size).to eql(1)
302
+ expect(video.reload.tags.size).to eql(1)
303
+
304
+ other.reset_callbacks(:create)
305
+ other._reflections = {}
306
+ end
307
+
294
308
  it 'can concat records' do
295
309
  FactoryBot.create(:video, tag_ids: [subject.id])
296
310
  expect(subject.videos.size).to be_eql(1)
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'InsertAll' do
4
+ context 'on executing' do
5
+ before do
6
+ ActiveRecord::InsertAll.send(:public, :to_sql)
7
+ allow_any_instance_of(ActiveRecord::InsertAll).to receive(:execute, &:to_sql)
8
+ end
9
+
10
+ subject { Tag }
11
+
12
+ let(:entries) { [{ name: 'A' }, { name: 'B' }] }
13
+
14
+ it 'does not mess with insert_all' do
15
+ result = subject.insert_all(entries)
16
+ expect(result.squish).to be_eql(<<~SQL.squish)
17
+ INSERT INTO "tags" ("name") VALUES ('A'), ('B')
18
+ ON CONFLICT DO NOTHING RETURNING "id"
19
+ SQL
20
+
21
+ result = subject.insert_all(entries, returning: %i[name])
22
+ expect(result.squish).to be_eql(<<~SQL.squish)
23
+ INSERT INTO "tags" ("name") VALUES ('A'), ('B')
24
+ ON CONFLICT DO NOTHING RETURNING "name"
25
+ SQL
26
+
27
+ result = subject.insert_all(entries, returning: %i[id name])
28
+ expect(result.squish).to be_eql(<<~SQL.squish)
29
+ INSERT INTO "tags" ("name") VALUES ('A'), ('B')
30
+ ON CONFLICT DO NOTHING RETURNING "id","name"
31
+ SQL
32
+ end
33
+
34
+ it 'does not mess with insert_all!' do
35
+ result = subject.insert_all!(entries)
36
+ expect(result.squish).to be_eql(<<~SQL.squish)
37
+ INSERT INTO "tags" ("name") VALUES ('A'), ('B') RETURNING "id"
38
+ SQL
39
+
40
+ result = subject.insert_all!(entries, returning: %i[name])
41
+ expect(result.squish).to be_eql(<<~SQL.squish)
42
+ INSERT INTO "tags" ("name") VALUES ('A'), ('B') RETURNING "name"
43
+ SQL
44
+ end
45
+
46
+ it 'does not mess with upsert without where' do
47
+ result = subject.upsert_all(entries)
48
+ expect(result.squish).to be_eql(<<~SQL.squish)
49
+ INSERT INTO "tags" ("name") VALUES ('A'), ('B')
50
+ ON CONFLICT ("id") DO UPDATE SET "name"=excluded."name"
51
+ RETURNING "id"
52
+ SQL
53
+
54
+ result = subject.upsert_all(entries, returning: %i[name])
55
+ expect(result.squish).to be_eql(<<~SQL.squish)
56
+ INSERT INTO "tags" ("name") VALUES ('A'), ('B')
57
+ ON CONFLICT ("id") DO UPDATE SET "name"=excluded."name"
58
+ RETURNING "name"
59
+ SQL
60
+ end
61
+
62
+ it 'does add the where condition without the returning clause' do
63
+ result = subject.upsert_all(entries, returning: false, where: '1=1')
64
+ expect(result.squish).to be_eql(<<~SQL.squish)
65
+ INSERT INTO "tags" ("name") VALUES ('A'), ('B')
66
+ ON CONFLICT ("id") DO UPDATE SET "name"=excluded."name"
67
+ WHERE 1=1
68
+ SQL
69
+ end
70
+
71
+ it 'does add the where condition with the returning clause' do
72
+ result = subject.upsert_all(entries, where: '1=1')
73
+ expect(result.squish).to be_eql(<<~SQL.squish)
74
+ INSERT INTO "tags" ("name") VALUES ('A'), ('B')
75
+ ON CONFLICT ("id") DO UPDATE SET "name"=excluded."name"
76
+ WHERE 1=1 RETURNING "id"
77
+ SQL
78
+ end
79
+
80
+ xit 'dows work with model-based where clause' do
81
+ result = subject.upsert_all(entries, where: Tag.where(name: 'C'))
82
+ expect(result.squish).to be_eql(<<~SQL.squish)
83
+ INSERT INTO "tags" ("name") VALUES ('A'), ('B')
84
+ ON CONFLICT ("id") DO UPDATE SET "name"=excluded."name"
85
+ WHERE "tags"."name" = 'C' RETURNING "id"
86
+ SQL
87
+ end
88
+ end
89
+ end
@@ -66,7 +66,7 @@ RSpec.describe 'TableInheritance' do
66
66
 
67
67
  it 'allows empty-body create table operation' do
68
68
  sql = connection.create_table(:activity_posts, inherits: :activities)
69
- result = 'CREATE TABLE "activity_posts" ()'
69
+ result = "CREATE TABLE \"activity_posts\" ()"
70
70
  result << ' INHERITS ( "activities" )'
71
71
  expect(sql).to eql(result)
72
72
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torque-postgresql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-26 00:00:00.000000000 Z
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -221,6 +221,7 @@ files:
221
221
  - lib/torque/postgresql/geometry_builder.rb
222
222
  - lib/torque/postgresql/i18n.rb
223
223
  - lib/torque/postgresql/inheritance.rb
224
+ - lib/torque/postgresql/insert_all.rb
224
225
  - lib/torque/postgresql/migration.rb
225
226
  - lib/torque/postgresql/migration/command_recorder.rb
226
227
  - lib/torque/postgresql/railtie.rb
@@ -277,6 +278,7 @@ files:
277
278
  - spec/tests/enum_spec.rb
278
279
  - spec/tests/geometric_builder_spec.rb
279
280
  - spec/tests/has_many_spec.rb
281
+ - spec/tests/insert_all_spec.rb
280
282
  - spec/tests/interval_spec.rb
281
283
  - spec/tests/lazy_spec.rb
282
284
  - spec/tests/period_spec.rb
@@ -333,8 +335,10 @@ test_files:
333
335
  - spec/factories/videos.rb
334
336
  - spec/tests/geometric_builder_spec.rb
335
337
  - spec/tests/range_spec.rb
338
+ - spec/tests/arel_spec.rb
339
+ - spec/tests/insert_all_spec.rb
336
340
  - spec/tests/enum_spec.rb
337
- - spec/tests/auxiliary_statement_spec.rb
341
+ - spec/tests/period_spec.rb
338
342
  - spec/tests/coder_spec.rb
339
343
  - spec/tests/collector_spec.rb
340
344
  - spec/tests/distinct_on_spec.rb
@@ -342,11 +346,10 @@ test_files:
342
346
  - spec/tests/lazy_spec.rb
343
347
  - spec/tests/quoting_spec.rb
344
348
  - spec/tests/relation_spec.rb
345
- - spec/tests/arel_spec.rb
349
+ - spec/tests/auxiliary_statement_spec.rb
346
350
  - spec/tests/enum_set_spec.rb
347
- - spec/tests/belongs_to_many_spec.rb
348
351
  - spec/tests/has_many_spec.rb
349
- - spec/tests/period_spec.rb
352
+ - spec/tests/belongs_to_many_spec.rb
350
353
  - spec/tests/table_inheritance_spec.rb
351
354
  - spec/mocks/cache_query.rb
352
355
  - spec/mocks/create_table.rb