rom-sql 2.0.0.beta2 → 2.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -0
  3. data/lib/rom/plugins/relation/sql/postgres/explain.rb +54 -0
  4. data/lib/rom/sql.rb +1 -1
  5. data/lib/rom/sql/attribute.rb +17 -18
  6. data/lib/rom/sql/errors.rb +3 -0
  7. data/lib/rom/sql/extensions/mysql.rb +1 -1
  8. data/lib/rom/sql/extensions/mysql/type_builder.rb +28 -0
  9. data/lib/rom/sql/extensions/postgres.rb +3 -1
  10. data/lib/rom/sql/extensions/postgres/commands.rb +30 -13
  11. data/lib/rom/sql/extensions/postgres/{attributes_inferrer.rb → type_builder.rb} +24 -28
  12. data/lib/rom/sql/extensions/postgres/type_serializer.rb +39 -0
  13. data/lib/rom/sql/extensions/postgres/types.rb +24 -477
  14. data/lib/rom/sql/extensions/postgres/types/array.rb +163 -0
  15. data/lib/rom/sql/extensions/postgres/types/geometric.rb +135 -0
  16. data/lib/rom/sql/extensions/postgres/types/json.rb +235 -0
  17. data/lib/rom/sql/extensions/postgres/types/network.rb +15 -0
  18. data/lib/rom/sql/extensions/sqlite.rb +1 -1
  19. data/lib/rom/sql/extensions/sqlite/{attributes_inferrer.rb → type_builder.rb} +5 -5
  20. data/lib/rom/sql/extensions/sqlite/types.rb +8 -3
  21. data/lib/rom/sql/foreign_key.rb +17 -0
  22. data/lib/rom/sql/function.rb +86 -8
  23. data/lib/rom/sql/gateway.rb +26 -26
  24. data/lib/rom/sql/index.rb +4 -0
  25. data/lib/rom/sql/migration.rb +3 -3
  26. data/lib/rom/sql/migration/inline_runner.rb +9 -83
  27. data/lib/rom/sql/migration/migrator.rb +35 -12
  28. data/lib/rom/sql/migration/recorder.rb +21 -0
  29. data/lib/rom/sql/migration/runner.rb +115 -0
  30. data/lib/rom/sql/migration/schema_diff.rb +108 -53
  31. data/lib/rom/sql/migration/writer.rb +61 -0
  32. data/lib/rom/sql/relation.rb +2 -1
  33. data/lib/rom/sql/relation/reading.rb +63 -3
  34. data/lib/rom/sql/relation/writing.rb +38 -0
  35. data/lib/rom/sql/schema.rb +9 -3
  36. data/lib/rom/sql/schema/attributes_inferrer.rb +3 -119
  37. data/lib/rom/sql/schema/inferrer.rb +99 -18
  38. data/lib/rom/sql/schema/type_builder.rb +94 -0
  39. data/lib/rom/sql/type_dsl.rb +30 -0
  40. data/lib/rom/sql/type_extensions.rb +11 -6
  41. data/lib/rom/sql/type_serializer.rb +46 -0
  42. data/lib/rom/sql/types.rb +12 -0
  43. data/lib/rom/sql/version.rb +1 -1
  44. metadata +26 -244
  45. data/.codeclimate.yml +0 -15
  46. data/.gitignore +0 -17
  47. data/.rspec +0 -3
  48. data/.travis.yml +0 -39
  49. data/.yardopts +0 -2
  50. data/Gemfile +0 -33
  51. data/Guardfile +0 -24
  52. data/LICENSE.txt +0 -22
  53. data/Rakefile +0 -19
  54. data/circle.yml +0 -10
  55. data/lib/rom/sql/extensions/mysql/attributes_inferrer.rb +0 -10
  56. data/lib/rom/sql/relation/sequel_api.rb +0 -133
  57. data/log/.gitkeep +0 -0
  58. data/rom-sql.gemspec +0 -29
  59. data/spec/extensions/postgres/attribute_spec.rb +0 -217
  60. data/spec/extensions/postgres/integration_spec.rb +0 -59
  61. data/spec/extensions/postgres/types_spec.rb +0 -252
  62. data/spec/extensions/sqlite/types_spec.rb +0 -11
  63. data/spec/fixtures/migrations/20150403090603_create_carrots.rb +0 -8
  64. data/spec/integration/associations/many_to_many/custom_fks_spec.rb +0 -76
  65. data/spec/integration/associations/many_to_many/from_view_spec.rb +0 -88
  66. data/spec/integration/associations/many_to_many_spec.rb +0 -162
  67. data/spec/integration/associations/many_to_one/custom_fks_spec.rb +0 -64
  68. data/spec/integration/associations/many_to_one/from_view_spec.rb +0 -84
  69. data/spec/integration/associations/many_to_one/self_ref_spec.rb +0 -53
  70. data/spec/integration/associations/many_to_one_spec.rb +0 -117
  71. data/spec/integration/associations/one_to_many/custom_fks_spec.rb +0 -54
  72. data/spec/integration/associations/one_to_many/from_view_spec.rb +0 -57
  73. data/spec/integration/associations/one_to_many/self_ref_spec.rb +0 -54
  74. data/spec/integration/associations/one_to_many_spec.rb +0 -86
  75. data/spec/integration/associations/one_to_one_spec.rb +0 -69
  76. data/spec/integration/associations/one_to_one_through_spec.rb +0 -92
  77. data/spec/integration/auto_migrations/errors_spec.rb +0 -31
  78. data/spec/integration/auto_migrations/indexes_spec.rb +0 -253
  79. data/spec/integration/auto_migrations/managing_columns_spec.rb +0 -156
  80. data/spec/integration/auto_migrations/postgres/column_types_spec.rb +0 -63
  81. data/spec/integration/combine_with_spec.rb +0 -43
  82. data/spec/integration/commands/create_spec.rb +0 -304
  83. data/spec/integration/commands/delete_spec.rb +0 -84
  84. data/spec/integration/commands/update_spec.rb +0 -90
  85. data/spec/integration/commands/upsert_spec.rb +0 -83
  86. data/spec/integration/gateway_spec.rb +0 -107
  87. data/spec/integration/migration_spec.rb +0 -55
  88. data/spec/integration/plugins/associates/many_to_many_spec.rb +0 -69
  89. data/spec/integration/plugins/associates_spec.rb +0 -250
  90. data/spec/integration/plugins/auto_restrictions_spec.rb +0 -74
  91. data/spec/integration/relation_schema_spec.rb +0 -271
  92. data/spec/integration/schema/call_spec.rb +0 -24
  93. data/spec/integration/schema/inferrer/mysql_spec.rb +0 -45
  94. data/spec/integration/schema/inferrer/postgres_spec.rb +0 -203
  95. data/spec/integration/schema/inferrer/sqlite_spec.rb +0 -37
  96. data/spec/integration/schema/inferrer_spec.rb +0 -390
  97. data/spec/integration/schema/prefix_spec.rb +0 -16
  98. data/spec/integration/schema/qualified_spec.rb +0 -16
  99. data/spec/integration/schema/rename_spec.rb +0 -21
  100. data/spec/integration/schema/view_spec.rb +0 -29
  101. data/spec/integration/sequel_api_spec.rb +0 -36
  102. data/spec/integration/setup_spec.rb +0 -26
  103. data/spec/integration/support/active_support_notifications_spec.rb +0 -24
  104. data/spec/integration/support/rails_log_subscriber_spec.rb +0 -30
  105. data/spec/integration/wrap_spec.rb +0 -91
  106. data/spec/shared/accounts.rb +0 -48
  107. data/spec/shared/database_setup.rb +0 -70
  108. data/spec/shared/notes.rb +0 -23
  109. data/spec/shared/posts.rb +0 -34
  110. data/spec/shared/puppies.rb +0 -15
  111. data/spec/shared/relations.rb +0 -8
  112. data/spec/shared/users.rb +0 -32
  113. data/spec/shared/users_and_tasks.rb +0 -50
  114. data/spec/spec_helper.rb +0 -122
  115. data/spec/support/env_helper.rb +0 -25
  116. data/spec/support/helpers.rb +0 -24
  117. data/spec/support/oracle/create_users.sql +0 -7
  118. data/spec/support/oracle/set_sys_passwords.sql +0 -2
  119. data/spec/support/test_configuration.rb +0 -16
  120. data/spec/unit/attribute_spec.rb +0 -104
  121. data/spec/unit/function_spec.rb +0 -48
  122. data/spec/unit/gateway_spec.rb +0 -70
  123. data/spec/unit/logger_spec.rb +0 -14
  124. data/spec/unit/migration_tasks_spec.rb +0 -111
  125. data/spec/unit/migrator_spec.rb +0 -25
  126. data/spec/unit/order_dsl_spec.rb +0 -43
  127. data/spec/unit/plugin/associates_spec.rb +0 -94
  128. data/spec/unit/plugin/pagination_spec.rb +0 -91
  129. data/spec/unit/plugin/timestamp_spec.rb +0 -117
  130. data/spec/unit/projection_dsl_spec.rb +0 -110
  131. data/spec/unit/relation/assoc_spec.rb +0 -87
  132. data/spec/unit/relation/associations_spec.rb +0 -27
  133. data/spec/unit/relation/avg_spec.rb +0 -11
  134. data/spec/unit/relation/by_pk_spec.rb +0 -62
  135. data/spec/unit/relation/dataset_spec.rb +0 -50
  136. data/spec/unit/relation/distinct_spec.rb +0 -15
  137. data/spec/unit/relation/exclude_spec.rb +0 -11
  138. data/spec/unit/relation/exist_predicate_spec.rb +0 -25
  139. data/spec/unit/relation/exists_spec.rb +0 -18
  140. data/spec/unit/relation/fetch_spec.rb +0 -21
  141. data/spec/unit/relation/group_spec.rb +0 -61
  142. data/spec/unit/relation/having_spec.rb +0 -22
  143. data/spec/unit/relation/inner_join_spec.rb +0 -158
  144. data/spec/unit/relation/inspect_spec.rb +0 -11
  145. data/spec/unit/relation/instrument_spec.rb +0 -45
  146. data/spec/unit/relation/invert_spec.rb +0 -11
  147. data/spec/unit/relation/left_join_spec.rb +0 -55
  148. data/spec/unit/relation/lock_spec.rb +0 -93
  149. data/spec/unit/relation/map_spec.rb +0 -16
  150. data/spec/unit/relation/max_spec.rb +0 -11
  151. data/spec/unit/relation/min_spec.rb +0 -11
  152. data/spec/unit/relation/order_spec.rb +0 -51
  153. data/spec/unit/relation/pluck_spec.rb +0 -11
  154. data/spec/unit/relation/prefix_spec.rb +0 -29
  155. data/spec/unit/relation/primary_key_spec.rb +0 -27
  156. data/spec/unit/relation/project_spec.rb +0 -24
  157. data/spec/unit/relation/qualified_columns_spec.rb +0 -30
  158. data/spec/unit/relation/qualified_spec.rb +0 -25
  159. data/spec/unit/relation/read_spec.rb +0 -25
  160. data/spec/unit/relation/rename_spec.rb +0 -23
  161. data/spec/unit/relation/right_join_spec.rb +0 -57
  162. data/spec/unit/relation/select_append_spec.rb +0 -21
  163. data/spec/unit/relation/select_spec.rb +0 -40
  164. data/spec/unit/relation/sum_spec.rb +0 -11
  165. data/spec/unit/relation/union_spec.rb +0 -19
  166. data/spec/unit/relation/unique_predicate_spec.rb +0 -18
  167. data/spec/unit/relation/where_spec.rb +0 -133
  168. data/spec/unit/restriction_dsl_spec.rb +0 -34
  169. data/spec/unit/schema_spec.rb +0 -25
  170. data/spec/unit/types_spec.rb +0 -65
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::SQL::Associations::OneToMany, '#call' do
4
- include_context 'users'
5
-
6
- before do
7
- inferrable_relations.concat %i(puzzles)
8
- end
9
-
10
- subject(:assoc) do
11
- relations[:users].associations[:solved_puzzles]
12
- end
13
-
14
- with_adapters do
15
- before do
16
- conn.create_table(:puzzles) do
17
- primary_key :id
18
- foreign_key :author_id, :users, null: false
19
- foreign_key :solver_id, :users, null: true
20
- column :text, String, null: false
21
- end
22
-
23
- conf.relation(:puzzles) { schema(infer: true) }
24
-
25
- conf.relation(:users) do
26
- schema(infer: true) do
27
- associations do
28
- has_many :puzzles, as: :created_puzzles, foreign_key: :author_id
29
- has_many :puzzles, as: :solved_puzzles, foreign_key: :solver_id
30
- end
31
- end
32
- end
33
-
34
- relations[:puzzles].insert(author_id: joe_id, text: 'P1')
35
- relations[:puzzles].insert(author_id: joe_id, solver_id: jane_id, text: 'P2')
36
- end
37
-
38
- after do
39
- conn.drop_table(:puzzles)
40
- end
41
-
42
- it 'prepares joined relations using custom FK' do
43
- relation = assoc.()
44
-
45
- expect(relation.schema.map(&:to_sql_name)).
46
- to eql([Sequel.qualify(:puzzles, :id),
47
- Sequel.qualify(:puzzles, :author_id),
48
- Sequel.qualify(:puzzles, :solver_id),
49
- Sequel.qualify(:puzzles, :text)])
50
-
51
- expect(relation.first).to eql(id: 2, author_id: 2, solver_id: 1, text: 'P2')
52
- end
53
- end
54
- end
@@ -1,57 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::SQL::Associations::OneToMany, '#call' do
4
- include_context 'users'
5
-
6
- before do
7
- inferrable_relations.concat %i(puzzles)
8
- end
9
-
10
- subject(:assoc) do
11
- relations[:users].associations[:solved_puzzles]
12
- end
13
-
14
- with_adapters do
15
- before do
16
- conn.create_table(:puzzles) do
17
- primary_key :id
18
- foreign_key :user_id, :users, null: false
19
- column :text, String, null: false
20
- column :solved, TrueClass, null: false, default: false
21
- end
22
-
23
- conf.relation(:users) do
24
- schema(infer: true) do
25
- associations do
26
- has_many :puzzles
27
- has_many :puzzles, as: :solved_puzzles, view: :solved
28
- end
29
- end
30
- end
31
-
32
- conf.relation(:puzzles) do
33
- schema(infer: true)
34
-
35
- view(:solved, schema) do
36
- where(solved: true)
37
- end
38
- end
39
-
40
- relations[:puzzles].insert(user_id: joe_id, text: 'P1')
41
- relations[:puzzles].insert(user_id: joe_id, solved: true, text: 'P2')
42
- end
43
-
44
- it 'prepares joined relations using custom view' do
45
- relation = assoc.()
46
-
47
- expect(relation.schema.map(&:to_sql_name)).
48
- to eql([Sequel.qualify(:puzzles, :id),
49
- Sequel.qualify(:puzzles, :user_id),
50
- Sequel.qualify(:puzzles, :text),
51
- Sequel.qualify(:puzzles, :solved)])
52
-
53
- expect(relation.count).to be(1)
54
- expect(relation.first).to eql(id: 2, user_id: 2, solved: db_true, text: 'P2')
55
- end
56
- end
57
- end
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::SQL::Associations::OneToMany, '#call' do
4
- include_context 'database setup'
5
-
6
- before do
7
- inferrable_relations.concat %i(categories)
8
- end
9
-
10
- subject(:assoc) do
11
- relations[:categories].associations[:children]
12
- end
13
-
14
- with_adapters do
15
- before do
16
- conn.create_table(:categories) do
17
- primary_key :id
18
- foreign_key :parent_id, :categories, null: true
19
- column :name, String, null: false
20
- end
21
-
22
- conf.relation(:categories) do
23
- schema(infer: true) do
24
- associations do
25
- belongs_to :categories, as: :parent, foreign_key: :parent_id
26
- has_many :categories, as: :children, foreign_key: :parent_id
27
- end
28
- end
29
- end
30
-
31
- p1_id = relations[:categories].insert(name: 'P1')
32
- p2_id = relations[:categories].insert(name: 'P2')
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
- end
37
-
38
- it 'prepares joined relations using custom FK for a self-ref association' do
39
- relation = assoc.()
40
-
41
- expect(relation.schema.map(&:to_sql_name)).
42
- to eql([Sequel.qualify(:categories, :id),
43
- Sequel.qualify(:categories, :parent_id),
44
- Sequel.qualify(:categories, :name)])
45
-
46
- expect(relation.to_a).
47
- to eql([
48
- { id: 3, parent_id: 2, name: 'C3' },
49
- { id: 4, parent_id: 1, name: 'C4' },
50
- { id: 5, parent_id: 1, name: 'C5' }
51
- ])
52
- end
53
- end
54
- end
@@ -1,86 +0,0 @@
1
- RSpec.describe ROM::SQL::Associations::OneToMany, helpers: true do
2
- include_context 'users and tasks'
3
-
4
- subject(:assoc) do
5
- build_assoc(:one_to_many, :users, :tasks)
6
- end
7
-
8
- with_adapters do
9
- before do
10
- conf.relation(:tasks) do
11
- schema do
12
- attribute :id, ROM::SQL::Types::Serial
13
- attribute :user_id, ROM::SQL::Types::ForeignKey(:users)
14
- attribute :title, ROM::SQL::Types::String
15
- end
16
- end
17
- end
18
-
19
- describe '#result' do
20
- specify { expect(assoc.result).to be(:many) }
21
- end
22
-
23
- describe '#combine_keys' do
24
- specify { expect(assoc.combine_keys).to eql(id: :user_id) }
25
- end
26
-
27
- describe '#associate' do
28
- it 'merges FKs into tuples' do
29
- child = { name: 'Child' }
30
- parent = { id: 312, name: 'Parent '}
31
-
32
- expect(assoc.associate(child, parent)).to eql(user_id: 312, name: 'Child')
33
- end
34
- end
35
-
36
- describe '#call' do
37
- it 'prepares joined relations' do
38
- relation = assoc.()
39
-
40
- expect(relation.schema.map(&:name)).to eql(%i[id user_id title])
41
-
42
- expect(relation.order(tasks[:id].qualified).to_a).to eql([
43
- { id: 1, user_id: 2, title: "Joe's task" },
44
- { id: 2, user_id: 1, title: "Jane's task" }
45
- ])
46
-
47
- expect(relation.where(user_id: 1).to_a).to eql([
48
- { id: 2, user_id: 1, title: "Jane's task" }
49
- ])
50
-
51
- expect(relation.where(user_id: 2).to_a).to eql([
52
- { id: 1, user_id: 2, title: "Joe's task" }
53
- ])
54
- end
55
- end
56
-
57
- describe '#eager_load' do
58
- it 'preloads relation based on association' do
59
- relation = tasks.eager_load(assoc).call(users.call)
60
-
61
- expect(relation.to_a).to eql([
62
- { id: 1, user_id: 2, title: "Joe's task" },
63
- { id: 2, user_id: 1, title: "Jane's task" }
64
- ])
65
- end
66
-
67
- it 'maintains original relation' do
68
- relation = tasks.
69
- join(:task_tags, tag_id: :id).
70
- select_append(tasks.task_tags[:tag_id].qualified).
71
- eager_load(assoc).call(users.call)
72
-
73
- expect(relation.to_a).to eql([{ id: 1, user_id: 2, title: "Joe's task", tag_id: 1 }])
74
- end
75
-
76
- it 'respects custom order' do
77
- relation = tasks.
78
- order(tasks[:title].qualified).
79
- eager_load(assoc).call(users.call)
80
-
81
- expect(relation.to_a).
82
- to eql([{ id: 2, user_id: 1, title: "Jane's task" }, { id: 1, user_id: 2, title: "Joe's task" }])
83
- end
84
- end
85
- end
86
- end
@@ -1,69 +0,0 @@
1
- RSpec.describe ROM::SQL::Associations::OneToOne, helpers: true do
2
- include_context 'users'
3
- include_context 'accounts'
4
-
5
- subject(:assoc) do
6
- build_assoc(:one_to_one, :users, :accounts)
7
- end
8
-
9
- with_adapters do
10
- before do
11
- conn[:accounts].insert user_id: 1, number: '43', balance: -273.15.to_d
12
-
13
- conf.relation(:accounts) do
14
- schema do
15
- attribute :id, ROM::SQL::Types::Serial
16
- attribute :user_id, ROM::SQL::Types::ForeignKey(:users)
17
- attribute :number, ROM::SQL::Types::String
18
- attribute :balance, ROM::SQL::Types::Decimal
19
- end
20
- end
21
- end
22
-
23
- describe '#result' do
24
- specify { expect(assoc.result).to be(:one) }
25
- end
26
-
27
- describe '#combine_keys' do
28
- specify { expect(assoc.combine_keys).to eql(id: :user_id) }
29
- end
30
-
31
- describe '#call' do
32
- it 'prepares joined relations' do |example|
33
- relation = assoc.()
34
-
35
- expect(relation.schema.map(&:name)).to eql(%i[id user_id number balance])
36
-
37
- # TODO: this if clause should be removed when (and if) https://github.com/xerial/sqlite-jdbc/issues/112
38
- # will be resolved. See https://github.com/rom-rb/rom-sql/issues/49 for details
39
- if jruby? && sqlite?(example)
40
- expect(relation.to_a).
41
- to eql([{ id: 1, user_id: 1, number: '42', balance: 10_000 },
42
- { id: 2, user_id: 1, number: '43', balance: -273.15 }])
43
- else
44
- expect(relation.to_a).
45
- to eql([{ id: 1, user_id: 1, number: '42', balance: 10_000.to_d },
46
- { id: 2, user_id: 1, number: '43', balance: -273.15.to_d }])
47
- end
48
- end
49
- end
50
-
51
- describe '#eager_load' do
52
- it 'preloads relation based on association' do |example|
53
- relation = accounts.eager_load(assoc).call(users.call)
54
-
55
- # TODO: this if caluse should be removed when (and if) https://github.com/xerial/sqlite-jdbc/issues/112
56
- # will be resolved. See https://github.com/rom-rb/rom-sql/issues/49 for details
57
- if jruby? && sqlite?(example)
58
- expect(relation.to_a).
59
- to eql([{ id: 1, user_id: 1, number: '42', balance: 10_000 },
60
- { id: 2, user_id: 1, number: '43', balance: -273.15 }])
61
- else
62
- expect(relation.to_a).
63
- to eql([{ id: 1, user_id: 1, number: '42', balance: 10_000.to_d },
64
- { id: 2, user_id: 1, number: '43', balance: -273.15.to_d }])
65
- end
66
- end
67
- end
68
- end
69
- end
@@ -1,92 +0,0 @@
1
- RSpec.describe ROM::SQL::Associations::OneToOneThrough, helpers: true do
2
- include_context 'users'
3
- include_context 'accounts'
4
-
5
- subject(:assoc) do
6
- build_assoc(:one_to_one_through, :users, :cards, through: :accounts)
7
- end
8
-
9
- with_adapters do
10
- before do
11
- conf.relation(:accounts) do
12
- schema do
13
- attribute :id, ROM::SQL::Types::Serial
14
- attribute :user_id, ROM::SQL::Types::ForeignKey(:users)
15
- attribute :number, ROM::SQL::Types::String
16
- attribute :balance, ROM::SQL::Types::Decimal
17
-
18
- associations do
19
- one_to_many :cards
20
- one_to_many :subscriptions, through: :cards
21
- end
22
- end
23
- end
24
-
25
- conf.relation(:cards) do
26
- schema do
27
- attribute :id, ROM::SQL::Types::Serial
28
- attribute :account_id, ROM::SQL::Types::ForeignKey(:accounts)
29
- attribute :pan, ROM::SQL::Types::String
30
-
31
- associations do
32
- one_to_many :subscriptions
33
- end
34
- end
35
- end
36
-
37
- conf.relation(:subscriptions) do
38
- schema do
39
- attribute :id, ROM::SQL::Types::Serial
40
- attribute :card_id, ROM::SQL::Types::ForeignKey(:cards)
41
- attribute :service, ROM::SQL::Types::String
42
-
43
- associations do
44
- many_to_one :cards
45
- end
46
- end
47
- end
48
- end
49
-
50
- describe '#result' do
51
- specify { expect(assoc.result).to be(:one) }
52
- end
53
-
54
- describe '#combine_keys' do
55
- specify { expect(assoc.combine_keys).to eql(id: :user_id) }
56
- end
57
-
58
- describe '#call' do
59
- it 'prepares joined relations' do
60
- relation = assoc.()
61
-
62
- expect(relation.schema.map(&:name)).to eql(%i[id account_id pan user_id])
63
- expect(relation.to_a).to eql([id: 1, account_id: 1, pan: '*6789', user_id: 1])
64
- end
65
- end
66
-
67
- describe ':through another assoc' do
68
- subject(:assoc) do
69
- build_assoc(:one_to_one_through, :users, :subscriptions, through: :accounts)
70
- end
71
-
72
- let(:account_assoc) do
73
- build_assoc(:one_to_one_through, :accounts, :subscriptions, through: :cards)
74
- end
75
-
76
- it 'prepares joined relations through other association' do
77
- relation = assoc.()
78
-
79
- expect(relation.schema.map(&:name)).to eql(%i[id card_id service user_id])
80
- expect(relation.to_a).to eql([id: 1, card_id: 1, service: 'aws', user_id: 1])
81
- end
82
- end
83
-
84
- describe '#eager_load' do
85
- it 'preloads relation based on association' do
86
- relation = cards.eager_load(assoc).call(users.call)
87
-
88
- expect(relation.to_a).to eql([id: 1, account_id: 1, pan: '*6789', user_id: 1])
89
- end
90
- end
91
- end
92
- end
@@ -1,31 +0,0 @@
1
- RSpec.describe ROM::SQL::Gateway, :postgres do
2
- include_context 'database setup'
3
-
4
- subject(:gateway) { container.gateways[:default] }
5
-
6
- before do
7
- conn.drop_table?(:users)
8
- end
9
-
10
- describe 'unsupported conversions' do
11
- before do
12
- conf.relation(:users) do
13
- schema do
14
- attribute :id, ROM::SQL::Types::Serial
15
- attribute :name, ROM::SQL::Types::String
16
- end
17
- end
18
- end
19
-
20
- it 'raises an error' do
21
- conn.create_table :users do
22
- primary_key :id
23
- column :name, Integer, null: false
24
- end
25
-
26
- expect {
27
- gateway.auto_migrate!(conf)
28
- }.to raise_error(ROM::SQL::UnsupportedConversion, /Don't know how to convert/)
29
- end
30
- end
31
- end