torque-postgresql 2.0.1 → 2.0.6

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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/lib/torque/postgresql/adapter.rb +7 -0
  3. data/lib/torque/postgresql/adapter/database_statements.rb +2 -0
  4. data/lib/torque/postgresql/adapter/oid.rb +3 -1
  5. data/lib/torque/postgresql/adapter/oid/box.rb +2 -0
  6. data/lib/torque/postgresql/adapter/oid/circle.rb +2 -0
  7. data/lib/torque/postgresql/adapter/oid/enum.rb +2 -0
  8. data/lib/torque/postgresql/adapter/oid/enum_set.rb +2 -0
  9. data/lib/torque/postgresql/adapter/oid/interval.rb +2 -0
  10. data/lib/torque/postgresql/adapter/oid/line.rb +2 -0
  11. data/lib/torque/postgresql/adapter/oid/range.rb +2 -0
  12. data/lib/torque/postgresql/adapter/oid/segment.rb +2 -0
  13. data/lib/torque/postgresql/adapter/quoting.rb +2 -0
  14. data/lib/torque/postgresql/adapter/schema_creation.rb +8 -1
  15. data/lib/torque/postgresql/adapter/schema_definitions.rb +2 -0
  16. data/lib/torque/postgresql/adapter/schema_dumper.rb +11 -2
  17. data/lib/torque/postgresql/adapter/schema_statements.rb +2 -0
  18. data/lib/torque/postgresql/arel/infix_operation.rb +5 -1
  19. data/lib/torque/postgresql/arel/join_source.rb +2 -0
  20. data/lib/torque/postgresql/arel/nodes.rb +2 -0
  21. data/lib/torque/postgresql/arel/operations.rb +2 -0
  22. data/lib/torque/postgresql/arel/select_manager.rb +2 -0
  23. data/lib/torque/postgresql/arel/visitors.rb +6 -3
  24. data/lib/torque/postgresql/associations/association.rb +14 -3
  25. data/lib/torque/postgresql/associations/association_scope.rb +2 -0
  26. data/lib/torque/postgresql/associations/belongs_to_many_association.rb +164 -47
  27. data/lib/torque/postgresql/associations/builder/belongs_to_many.rb +8 -5
  28. data/lib/torque/postgresql/associations/builder/has_many.rb +2 -0
  29. data/lib/torque/postgresql/associations/preloader/association.rb +30 -1
  30. data/lib/torque/postgresql/attributes/builder.rb +3 -1
  31. data/lib/torque/postgresql/attributes/builder/enum.rb +5 -3
  32. data/lib/torque/postgresql/attributes/builder/period.rb +6 -4
  33. data/lib/torque/postgresql/attributes/enum.rb +5 -10
  34. data/lib/torque/postgresql/attributes/enum_set.rb +2 -0
  35. data/lib/torque/postgresql/attributes/lazy.rb +3 -1
  36. data/lib/torque/postgresql/attributes/period.rb +2 -0
  37. data/lib/torque/postgresql/autosave_association.rb +19 -16
  38. data/lib/torque/postgresql/auxiliary_statement.rb +2 -0
  39. data/lib/torque/postgresql/auxiliary_statement/settings.rb +2 -0
  40. data/lib/torque/postgresql/base.rb +5 -2
  41. data/lib/torque/postgresql/coder.rb +5 -3
  42. data/lib/torque/postgresql/collector.rb +2 -0
  43. data/lib/torque/postgresql/config.rb +5 -0
  44. data/lib/torque/postgresql/geometry_builder.rb +2 -0
  45. data/lib/torque/postgresql/i18n.rb +2 -0
  46. data/lib/torque/postgresql/inheritance.rb +2 -0
  47. data/lib/torque/postgresql/migration/command_recorder.rb +2 -0
  48. data/lib/torque/postgresql/railtie.rb +2 -0
  49. data/lib/torque/postgresql/reflection.rb +2 -0
  50. data/lib/torque/postgresql/reflection/abstract_reflection.rb +13 -28
  51. data/lib/torque/postgresql/reflection/association_reflection.rb +24 -0
  52. data/lib/torque/postgresql/reflection/belongs_to_many_reflection.rb +18 -4
  53. data/lib/torque/postgresql/reflection/has_many_reflection.rb +2 -0
  54. data/lib/torque/postgresql/reflection/runtime_reflection.rb +2 -0
  55. data/lib/torque/postgresql/reflection/through_reflection.rb +2 -0
  56. data/lib/torque/postgresql/relation.rb +15 -11
  57. data/lib/torque/postgresql/relation/auxiliary_statement.rb +6 -1
  58. data/lib/torque/postgresql/relation/distinct_on.rb +2 -0
  59. data/lib/torque/postgresql/relation/inheritance.rb +2 -0
  60. data/lib/torque/postgresql/relation/merger.rb +2 -0
  61. data/lib/torque/postgresql/schema_cache.rb +2 -0
  62. data/lib/torque/postgresql/version.rb +3 -1
  63. data/spec/schema.rb +3 -2
  64. data/spec/tests/arel_spec.rb +3 -1
  65. data/spec/tests/belongs_to_many_spec.rb +104 -12
  66. data/spec/tests/enum_set_spec.rb +1 -1
  67. data/spec/tests/has_many_spec.rb +25 -1
  68. data/spec/tests/table_inheritance_spec.rb +1 -1
  69. metadata +7 -7
@@ -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
 
@@ -21,6 +21,11 @@ RSpec.describe 'HasMany' do
21
21
  expect(subject._reflections).to include('texts')
22
22
  end
23
23
 
24
+ it 'has correct foreign key' do
25
+ item = subject._reflections['texts']
26
+ expect(item.foreign_key).to be_eql('user_id')
27
+ end
28
+
24
29
  it 'loads associated records' do
25
30
  expect(subject.texts.to_sql).to match(Regexp.new(<<-SQL.squish))
26
31
  SELECT "texts"\\.\\* FROM "texts" WHERE \\(?"texts"\\."user_id" = #{subject.id}\\)?
@@ -210,6 +215,11 @@ RSpec.describe 'HasMany' do
210
215
  expect(subject._reflections).to include('videos')
211
216
  end
212
217
 
218
+ it 'has correct foreign key' do
219
+ item = subject._reflections['videos']
220
+ expect(item.foreign_key).to be_eql('tag_ids')
221
+ end
222
+
213
223
  it 'loads associated records' do
214
224
  expect(subject.videos.to_sql).to match(Regexp.new(<<-SQL.squish))
215
225
  SELECT "videos"\\.\\* FROM "videos"
@@ -281,6 +291,20 @@ RSpec.describe 'HasMany' do
281
291
  expect(record.tag_ids).to be_eql([subject.id])
282
292
  end
283
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
+
284
308
  it 'can concat records' do
285
309
  FactoryBot.create(:video, tag_ids: [subject.id])
286
310
  expect(subject.videos.size).to be_eql(1)
@@ -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.1
4
+ version: 2.0.6
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-08 00:00:00.000000000 Z
11
+ date: 2021-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -333,10 +333,9 @@ test_files:
333
333
  - spec/factories/videos.rb
334
334
  - spec/tests/geometric_builder_spec.rb
335
335
  - spec/tests/range_spec.rb
336
+ - spec/tests/arel_spec.rb
336
337
  - spec/tests/enum_spec.rb
337
- - spec/tests/auxiliary_statement_spec.rb
338
- - spec/tests/has_many_spec.rb
339
- - spec/tests/table_inheritance_spec.rb
338
+ - spec/tests/period_spec.rb
340
339
  - spec/tests/coder_spec.rb
341
340
  - spec/tests/collector_spec.rb
342
341
  - spec/tests/distinct_on_spec.rb
@@ -344,10 +343,11 @@ test_files:
344
343
  - spec/tests/lazy_spec.rb
345
344
  - spec/tests/quoting_spec.rb
346
345
  - spec/tests/relation_spec.rb
347
- - spec/tests/arel_spec.rb
346
+ - spec/tests/auxiliary_statement_spec.rb
348
347
  - spec/tests/enum_set_spec.rb
348
+ - spec/tests/has_many_spec.rb
349
349
  - spec/tests/belongs_to_many_spec.rb
350
- - spec/tests/period_spec.rb
350
+ - spec/tests/table_inheritance_spec.rb
351
351
  - spec/mocks/cache_query.rb
352
352
  - spec/mocks/create_table.rb
353
353
  - spec/en.yml