rom-sql 1.3.5 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -7
  3. data/Gemfile +7 -5
  4. data/lib/rom/plugins/relation/sql/auto_restrictions.rb +11 -17
  5. data/lib/rom/sql.rb +3 -2
  6. data/lib/rom/sql/associations.rb +5 -0
  7. data/lib/rom/sql/associations/core.rb +20 -0
  8. data/lib/rom/sql/associations/many_to_many.rb +83 -0
  9. data/lib/rom/sql/associations/many_to_one.rb +55 -0
  10. data/lib/rom/sql/associations/one_to_many.rb +31 -0
  11. data/lib/rom/sql/{association → associations}/one_to_one.rb +3 -2
  12. data/lib/rom/sql/{association → associations}/one_to_one_through.rb +3 -2
  13. data/lib/rom/sql/associations/self_ref.rb +39 -0
  14. data/lib/rom/sql/attribute.rb +44 -54
  15. data/lib/rom/sql/errors.rb +2 -0
  16. data/lib/rom/sql/extensions/mysql.rb +1 -1
  17. data/lib/rom/sql/extensions/mysql/attributes_inferrer.rb +10 -0
  18. data/lib/rom/sql/extensions/postgres.rb +1 -1
  19. data/lib/rom/sql/extensions/postgres/{inferrer.rb → attributes_inferrer.rb} +4 -4
  20. data/lib/rom/sql/extensions/postgres/types.rb +9 -19
  21. data/lib/rom/sql/extensions/sqlite.rb +1 -1
  22. data/lib/rom/sql/extensions/sqlite/{inferrer.rb → attributes_inferrer.rb} +2 -2
  23. data/lib/rom/sql/gateway.rb +29 -30
  24. data/lib/rom/sql/index.rb +13 -0
  25. data/lib/rom/sql/migration.rb +10 -0
  26. data/lib/rom/sql/migration/inline_runner.rb +86 -0
  27. data/lib/rom/sql/migration/migrator.rb +17 -0
  28. data/lib/rom/sql/migration/schema_diff.rb +177 -0
  29. data/lib/rom/sql/plugin/associates.rb +11 -45
  30. data/lib/rom/sql/plugin/pagination.rb +4 -4
  31. data/lib/rom/sql/relation.rb +22 -42
  32. data/lib/rom/sql/relation/reading.rb +3 -3
  33. data/lib/rom/sql/schema.rb +14 -21
  34. data/lib/rom/sql/schema/associations_dsl.rb +7 -6
  35. data/lib/rom/sql/schema/attributes_inferrer.rb +164 -0
  36. data/lib/rom/sql/schema/inferrer.rb +40 -141
  37. data/lib/rom/sql/type_extensions.rb +44 -0
  38. data/lib/rom/sql/version.rb +1 -1
  39. data/lib/rom/sql/wrap.rb +25 -0
  40. data/rom-sql.gemspec +2 -2
  41. data/spec/integration/{association → associations}/many_to_many/custom_fks_spec.rb +4 -2
  42. data/spec/integration/{association → associations}/many_to_many/from_view_spec.rb +2 -2
  43. data/spec/integration/{association → associations}/many_to_many_spec.rb +25 -30
  44. data/spec/integration/{association → associations}/many_to_one/custom_fks_spec.rb +5 -3
  45. data/spec/integration/{association → associations}/many_to_one/from_view_spec.rb +3 -3
  46. data/spec/integration/{association → associations}/many_to_one/self_ref_spec.rb +2 -2
  47. data/spec/integration/{association → associations}/many_to_one_spec.rb +20 -38
  48. data/spec/integration/{association → associations}/one_to_many/custom_fks_spec.rb +4 -2
  49. data/spec/integration/{association → associations}/one_to_many/from_view_spec.rb +2 -2
  50. data/spec/integration/{association → associations}/one_to_many/self_ref_spec.rb +2 -2
  51. data/spec/integration/{association → associations}/one_to_many_spec.rb +24 -11
  52. data/spec/integration/{association → associations}/one_to_one_spec.rb +13 -9
  53. data/spec/integration/{association → associations}/one_to_one_through_spec.rb +15 -11
  54. data/spec/integration/auto_migrations/errors_spec.rb +31 -0
  55. data/spec/integration/auto_migrations/indexes_spec.rb +109 -0
  56. data/spec/integration/auto_migrations/managing_columns_spec.rb +156 -0
  57. data/spec/integration/auto_migrations/postgres/column_types_spec.rb +63 -0
  58. data/spec/integration/commands/create_spec.rb +2 -4
  59. data/spec/integration/commands/delete_spec.rb +2 -2
  60. data/spec/integration/commands/update_spec.rb +2 -0
  61. data/spec/integration/graph_spec.rb +9 -3
  62. data/spec/integration/plugins/associates_spec.rb +16 -55
  63. data/spec/integration/plugins/auto_restrictions_spec.rb +0 -11
  64. data/spec/integration/relation_schema_spec.rb +49 -25
  65. data/spec/integration/schema/inferrer/postgres_spec.rb +1 -1
  66. data/spec/integration/schema/inferrer_spec.rb +7 -18
  67. data/spec/integration/setup_spec.rb +4 -0
  68. data/spec/integration/{plugins/auto_wrap_spec.rb → wrap_spec.rb} +13 -36
  69. data/spec/shared/accounts.rb +4 -0
  70. data/spec/shared/database_setup.rb +2 -1
  71. data/spec/shared/notes.rb +2 -0
  72. data/spec/shared/posts.rb +2 -0
  73. data/spec/shared/puppies.rb +2 -0
  74. data/spec/shared/relations.rb +2 -2
  75. data/spec/shared/users.rb +2 -0
  76. data/spec/shared/users_and_tasks.rb +4 -0
  77. data/spec/spec_helper.rb +3 -6
  78. data/spec/support/helpers.rb +11 -8
  79. data/spec/support/test_configuration.rb +16 -0
  80. data/spec/unit/plugin/associates_spec.rb +5 -10
  81. data/spec/unit/plugin/pagination_spec.rb +9 -9
  82. data/spec/unit/plugin/timestamp_spec.rb +9 -9
  83. data/spec/unit/relation/dataset_spec.rb +7 -5
  84. data/spec/unit/relation/inner_join_spec.rb +2 -15
  85. data/spec/unit/relation/primary_key_spec.rb +1 -1
  86. data/spec/unit/schema_spec.rb +6 -4
  87. metadata +65 -70
  88. data/lib/rom/plugins/relation/sql/auto_combine.rb +0 -71
  89. data/lib/rom/plugins/relation/sql/auto_wrap.rb +0 -62
  90. data/lib/rom/sql/association.rb +0 -103
  91. data/lib/rom/sql/association/many_to_many.rb +0 -119
  92. data/lib/rom/sql/association/many_to_one.rb +0 -73
  93. data/lib/rom/sql/association/name.rb +0 -78
  94. data/lib/rom/sql/association/one_to_many.rb +0 -60
  95. data/lib/rom/sql/extensions/mysql/inferrer.rb +0 -10
  96. data/lib/rom/sql/qualified_attribute.rb +0 -53
  97. data/lib/rom/sql/schema/dsl.rb +0 -75
  98. data/spec/unit/association/many_to_many_spec.rb +0 -89
  99. data/spec/unit/association/many_to_one_spec.rb +0 -81
  100. data/spec/unit/association/name_spec.rb +0 -68
  101. data/spec/unit/association/one_to_many_spec.rb +0 -82
  102. data/spec/unit/association/one_to_one_spec.rb +0 -83
  103. data/spec/unit/association/one_to_one_through_spec.rb +0 -69
@@ -1,83 +0,0 @@
1
- RSpec.describe ROM::SQL::Association::OneToOne, helpers: true do
2
- subject(:assoc) do
3
- ROM::SQL::Association::OneToOne.new(source, target, options)
4
- end
5
-
6
- let(:options) { {} }
7
-
8
- let(:users) { double(:users, primary_key: :id) }
9
- let(:tasks) { double(:tasks) }
10
- let(:avatars) { double(:avatars) }
11
-
12
- describe '#associate' do
13
- let(:source) { :users }
14
- let(:target) { :avatar }
15
-
16
- let(:relations) do
17
- { users: users, avatar: avatars }
18
- end
19
-
20
- it 'returns child tuple with FK set' do
21
- expect(avatars).to receive(:foreign_key).with(:users).and_return(:user_id)
22
-
23
- avatar_tuple = { url: 'http://rom-rb.org/images/logo.svg' }
24
- user_tuple = { id: 3 }
25
-
26
- expect(assoc.associate(relations, avatar_tuple, user_tuple)).to eql(
27
- user_id: 3, url: 'http://rom-rb.org/images/logo.svg'
28
- )
29
- end
30
- end
31
-
32
- shared_examples_for 'one-to-one association' do
33
- describe '#combine_keys' do
34
- it 'returns a hash with combine keys' do
35
- expect(tasks).to receive(:foreign_key).with(:users).and_return(:user_id)
36
-
37
- expect(assoc.combine_keys(relations)).to eql(id: :user_id)
38
- end
39
- end
40
- end
41
-
42
- context 'with default names' do
43
- let(:source) { :users }
44
- let(:target) { :tasks }
45
-
46
- let(:relations) do
47
- { users: users, tasks: tasks }
48
- end
49
-
50
- it_behaves_like 'one-to-one association'
51
-
52
- describe '#join_keys' do
53
- it 'returns a hash with combine keys' do
54
- expect(tasks).to receive(:foreign_key).with(:users).and_return(:user_id)
55
-
56
- expect(assoc.join_keys(relations)).to eql(
57
- qualified_attribute(:users, :id) => qualified_attribute(:tasks, :user_id)
58
- )
59
- end
60
- end
61
- end
62
-
63
- context 'with custom relation names' do
64
- let(:source) { assoc_name(:users, :people) }
65
- let(:target) { assoc_name(:tasks, :user_tasks) }
66
-
67
- let(:relations) do
68
- { users: users, tasks: tasks }
69
- end
70
-
71
- it_behaves_like 'one-to-one association'
72
-
73
- describe '#join_keys' do
74
- it 'returns a hash with combine keys' do
75
- expect(tasks).to receive(:foreign_key).with(:users).and_return(:user_id)
76
-
77
- expect(assoc.join_keys(relations)).to eql(
78
- qualified_attribute(:people, :id) => qualified_attribute(:user_tasks, :user_id)
79
- )
80
- end
81
- end
82
- end
83
- end
@@ -1,69 +0,0 @@
1
- RSpec.describe ROM::SQL::Association::OneToOneThrough, helpers: true do
2
- subject(:assoc) do
3
- ROM::SQL::Association::OneToOneThrough.new(source, target, options)
4
- end
5
-
6
- let(:options) { { through: :tasks_tags } }
7
-
8
- let(:tags) { double(:tags, primary_key: :id) }
9
- let(:tasks) { double(:tasks, primary_key: :id) }
10
- let(:tasks_tags) { double(:tasks, primary_key: [:task_id, :tag_id]) }
11
-
12
- let(:source) { :tasks }
13
- let(:target) { :tags }
14
-
15
- describe '#result' do
16
- it 'is :one' do
17
- expect(assoc.result).to be(:one)
18
- end
19
- end
20
-
21
- shared_examples_for 'many-to-many association' do
22
- describe '#combine_keys' do
23
- it 'returns a hash with combine keys' do
24
- expect(tasks_tags).to receive(:foreign_key).with(:tasks).and_return(:tag_id)
25
-
26
- expect(assoc.combine_keys(relations)).to eql(id: :tag_id)
27
- end
28
- end
29
- end
30
-
31
- context 'with default names' do
32
- let(:relations) do
33
- { tasks: tasks, tags: tags, tasks_tags: tasks_tags }
34
- end
35
-
36
- it_behaves_like 'many-to-many association'
37
-
38
- describe '#join_keys' do
39
- it 'returns a hash with combine keys' do
40
- expect(tasks_tags).to receive(:foreign_key).with(:tasks).and_return(:tag_id)
41
-
42
- expect(assoc.join_keys(relations)).to eql(
43
- qualified_attribute(:tasks, :id) => qualified_attribute(:tasks_tags, :tag_id)
44
- )
45
- end
46
- end
47
- end
48
-
49
- context 'with custom relation names' do
50
- let(:source) { assoc_name(:tasks, :user_tasks) }
51
- let(:target) { assoc_name(:tags, :user_tags) }
52
-
53
- let(:relations) do
54
- { tasks: tasks, tags: tags, tasks_tags: tasks_tags }
55
- end
56
-
57
- it_behaves_like 'many-to-many association'
58
-
59
- describe '#join_keys' do
60
- it 'returns a hash with combine keys' do
61
- expect(tasks_tags).to receive(:foreign_key).with(:tasks).and_return(:tag_id)
62
-
63
- expect(assoc.join_keys(relations)).to eql(
64
- qualified_attribute(:user_tasks, :id) => qualified_attribute(:tasks_tags, :tag_id)
65
- )
66
- end
67
- end
68
- end
69
- end