rom-sql 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/.travis.yml +12 -7
  4. data/CHANGELOG.md +28 -0
  5. data/Gemfile +6 -9
  6. data/README.md +5 -4
  7. data/circle.yml +10 -0
  8. data/lib/rom/plugins/relation/sql/auto_combine.rb +16 -3
  9. data/lib/rom/plugins/relation/sql/auto_wrap.rb +3 -2
  10. data/lib/rom/sql/association.rb +75 -0
  11. data/lib/rom/sql/association/many_to_many.rb +86 -0
  12. data/lib/rom/sql/association/many_to_one.rb +60 -0
  13. data/lib/rom/sql/association/name.rb +70 -0
  14. data/lib/rom/sql/association/one_to_many.rb +9 -0
  15. data/lib/rom/sql/association/one_to_one.rb +46 -0
  16. data/lib/rom/sql/association/one_to_one_through.rb +9 -0
  17. data/lib/rom/sql/commands.rb +2 -0
  18. data/lib/rom/sql/commands/create.rb +2 -2
  19. data/lib/rom/sql/commands/delete.rb +0 -1
  20. data/lib/rom/sql/commands/postgres.rb +76 -0
  21. data/lib/rom/sql/commands/update.rb +6 -3
  22. data/lib/rom/sql/commands_ext/postgres.rb +17 -0
  23. data/lib/rom/sql/gateway.rb +23 -15
  24. data/lib/rom/sql/header.rb +7 -1
  25. data/lib/rom/sql/plugin/assoc_macros.rb +3 -3
  26. data/lib/rom/sql/plugin/associates.rb +50 -9
  27. data/lib/rom/sql/qualified_attribute.rb +53 -0
  28. data/lib/rom/sql/relation.rb +76 -25
  29. data/lib/rom/sql/relation/reading.rb +138 -35
  30. data/lib/rom/sql/relation/writing.rb +21 -0
  31. data/lib/rom/sql/schema.rb +35 -0
  32. data/lib/rom/sql/schema/associations_dsl.rb +68 -0
  33. data/lib/rom/sql/schema/dsl.rb +27 -0
  34. data/lib/rom/sql/schema/inferrer.rb +80 -0
  35. data/lib/rom/sql/support/active_support_notifications.rb +27 -17
  36. data/lib/rom/sql/types.rb +11 -0
  37. data/lib/rom/sql/types/pg.rb +26 -0
  38. data/lib/rom/sql/version.rb +1 -1
  39. data/rom-sql.gemspec +4 -2
  40. data/spec/integration/association/many_to_many_spec.rb +137 -0
  41. data/spec/integration/association/many_to_one_spec.rb +110 -0
  42. data/spec/integration/association/one_to_many_spec.rb +58 -0
  43. data/spec/integration/association/one_to_one_spec.rb +57 -0
  44. data/spec/integration/association/one_to_one_through_spec.rb +90 -0
  45. data/spec/integration/combine_spec.rb +24 -24
  46. data/spec/integration/commands/create_spec.rb +215 -168
  47. data/spec/integration/commands/delete_spec.rb +88 -46
  48. data/spec/integration/commands/update_spec.rb +141 -60
  49. data/spec/integration/commands/upsert_spec.rb +83 -0
  50. data/spec/integration/gateway_spec.rb +9 -17
  51. data/spec/integration/migration_spec.rb +3 -5
  52. data/spec/integration/plugins/associates_spec.rb +168 -0
  53. data/spec/integration/plugins/auto_wrap_spec.rb +46 -0
  54. data/spec/integration/read_spec.rb +80 -77
  55. data/spec/integration/relation_schema_spec.rb +180 -0
  56. data/spec/integration/schema_inference_spec.rb +67 -0
  57. data/spec/integration/setup_spec.rb +22 -0
  58. data/spec/{support → integration/support}/active_support_notifications_spec.rb +0 -0
  59. data/spec/{support → integration/support}/rails_log_subscriber_spec.rb +0 -0
  60. data/spec/shared/database_setup.rb +46 -8
  61. data/spec/shared/relations.rb +8 -0
  62. data/spec/shared/users_and_accounts.rb +10 -0
  63. data/spec/shared/users_and_tasks.rb +20 -2
  64. data/spec/spec_helper.rb +64 -11
  65. data/spec/support/helpers.rb +9 -0
  66. data/spec/unit/association/many_to_many_spec.rb +89 -0
  67. data/spec/unit/association/many_to_one_spec.rb +81 -0
  68. data/spec/unit/association/name_spec.rb +68 -0
  69. data/spec/unit/association/one_to_many_spec.rb +62 -0
  70. data/spec/unit/association/one_to_one_spec.rb +62 -0
  71. data/spec/unit/association/one_to_one_through_spec.rb +69 -0
  72. data/spec/unit/association_errors_spec.rb +2 -4
  73. data/spec/unit/gateway_spec.rb +12 -3
  74. data/spec/unit/migration_tasks_spec.rb +3 -3
  75. data/spec/unit/migrator_spec.rb +2 -4
  76. data/spec/unit/{combined_associations_spec.rb → plugin/assoc_macros/combined_associations_spec.rb} +13 -19
  77. data/spec/unit/{many_to_many_spec.rb → plugin/assoc_macros/many_to_many_spec.rb} +9 -15
  78. data/spec/unit/{many_to_one_spec.rb → plugin/assoc_macros/many_to_one_spec.rb} +9 -14
  79. data/spec/unit/plugin/assoc_macros/one_to_many_spec.rb +78 -0
  80. data/spec/unit/plugin/base_view_spec.rb +11 -11
  81. data/spec/unit/plugin/pagination_spec.rb +62 -62
  82. data/spec/unit/relation_spec.rb +218 -146
  83. data/spec/unit/schema_spec.rb +15 -14
  84. data/spec/unit/types_spec.rb +40 -0
  85. metadata +105 -21
  86. data/.rubocop.yml +0 -74
  87. data/.rubocop_todo.yml +0 -21
  88. data/spec/unit/one_to_many_spec.rb +0 -83
@@ -0,0 +1,40 @@
1
+ require 'rom/sql/types'
2
+ require 'rom/sql/types/pg'
3
+
4
+ RSpec.describe ROM::SQL::Types do
5
+ describe ROM::SQL::Types::Serial do
6
+ it 'accepts ints > 0' do
7
+ expect(ROM::SQL::Types::Serial[1]).to be(1)
8
+ end
9
+
10
+ it 'raises when input is <= 0' do
11
+ expect { ROM::SQL::Types::Serial[0] }.to raise_error(Dry::Types::ConstraintError)
12
+ end
13
+ end
14
+
15
+ describe ROM::SQL::Types::PG::JSON do
16
+ it 'coerces to pg json hash' do
17
+ input = { foo: 'bar' }
18
+
19
+ expect(ROM::SQL::Types::PG::JSON[input]).to eql(Sequel.pg_json(input))
20
+ end
21
+
22
+ it 'coerces to pg json array' do
23
+ input = [1, 2, 3]
24
+ output = ROM::SQL::Types::PG::JSON[input]
25
+
26
+ expect(output).to be_instance_of(Sequel::Postgres::JSONArray)
27
+ expect(output.to_a).to eql(input)
28
+ end
29
+ end
30
+
31
+ describe ROM::SQL::Types::PG::Bytea do
32
+ it 'coerses strings to Sequel::SQL::Blob' do
33
+ input = 'sutin'
34
+ output = described_class[input]
35
+
36
+ expect(output).to be_instance_of(Sequel::SQL::Blob)
37
+ expect(output).to eql('sutin')
38
+ end
39
+ end
40
+ end
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: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-06 00:00:00.000000000 Z
11
+ date: 2016-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.18'
19
+ version: '4.25'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.18'
26
+ version: '4.25'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dry-equalizer
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,20 +38,48 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-types
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rom
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 1.0.0
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rom-support
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
48
76
  type: :runtime
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
80
  - - "~>"
53
81
  - !ruby/object:Gem::Version
54
- version: 1.0.0
82
+ version: '2.0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: bundler
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -89,8 +117,6 @@ extra_rdoc_files: []
89
117
  files:
90
118
  - ".gitignore"
91
119
  - ".rspec"
92
- - ".rubocop.yml"
93
- - ".rubocop_todo.yml"
94
120
  - ".travis.yml"
95
121
  - CHANGELOG.md
96
122
  - Gemfile
@@ -98,15 +124,24 @@ files:
98
124
  - LICENSE.txt
99
125
  - README.md
100
126
  - Rakefile
127
+ - circle.yml
101
128
  - lib/rom-sql.rb
102
129
  - lib/rom/plugins/relation/sql/auto_combine.rb
103
130
  - lib/rom/plugins/relation/sql/auto_wrap.rb
104
131
  - lib/rom/plugins/relation/sql/base_view.rb
105
132
  - lib/rom/sql.rb
133
+ - lib/rom/sql/association.rb
134
+ - lib/rom/sql/association/many_to_many.rb
135
+ - lib/rom/sql/association/many_to_one.rb
136
+ - lib/rom/sql/association/name.rb
137
+ - lib/rom/sql/association/one_to_many.rb
138
+ - lib/rom/sql/association/one_to_one.rb
139
+ - lib/rom/sql/association/one_to_one_through.rb
106
140
  - lib/rom/sql/commands.rb
107
141
  - lib/rom/sql/commands/create.rb
108
142
  - lib/rom/sql/commands/delete.rb
109
143
  - lib/rom/sql/commands/error_wrapper.rb
144
+ - lib/rom/sql/commands/postgres.rb
110
145
  - lib/rom/sql/commands/transaction.rb
111
146
  - lib/rom/sql/commands/update.rb
112
147
  - lib/rom/sql/commands_ext/postgres.rb
@@ -122,43 +157,71 @@ files:
122
157
  - lib/rom/sql/plugin/associates.rb
123
158
  - lib/rom/sql/plugin/pagination.rb
124
159
  - lib/rom/sql/plugins.rb
160
+ - lib/rom/sql/qualified_attribute.rb
125
161
  - lib/rom/sql/rake_task.rb
126
162
  - lib/rom/sql/relation.rb
127
163
  - lib/rom/sql/relation/reading.rb
128
164
  - lib/rom/sql/relation/writing.rb
165
+ - lib/rom/sql/schema.rb
166
+ - lib/rom/sql/schema/associations_dsl.rb
167
+ - lib/rom/sql/schema/dsl.rb
168
+ - lib/rom/sql/schema/inferrer.rb
129
169
  - lib/rom/sql/spec/support.rb
130
170
  - lib/rom/sql/support/active_support_notifications.rb
131
171
  - lib/rom/sql/support/rails_log_subscriber.rb
132
172
  - lib/rom/sql/tasks/migration_tasks.rake
173
+ - lib/rom/sql/types.rb
174
+ - lib/rom/sql/types/pg.rb
133
175
  - lib/rom/sql/version.rb
134
176
  - log/.gitkeep
135
177
  - rom-sql.gemspec
136
178
  - spec/fixtures/migrations/20150403090603_create_carrots.rb
179
+ - spec/integration/association/many_to_many_spec.rb
180
+ - spec/integration/association/many_to_one_spec.rb
181
+ - spec/integration/association/one_to_many_spec.rb
182
+ - spec/integration/association/one_to_one_spec.rb
183
+ - spec/integration/association/one_to_one_through_spec.rb
137
184
  - spec/integration/combine_spec.rb
138
185
  - spec/integration/commands/create_spec.rb
139
186
  - spec/integration/commands/delete_spec.rb
140
187
  - spec/integration/commands/update_spec.rb
188
+ - spec/integration/commands/upsert_spec.rb
141
189
  - spec/integration/gateway_spec.rb
142
190
  - spec/integration/migration_spec.rb
191
+ - spec/integration/plugins/associates_spec.rb
192
+ - spec/integration/plugins/auto_wrap_spec.rb
143
193
  - spec/integration/read_spec.rb
194
+ - spec/integration/relation_schema_spec.rb
195
+ - spec/integration/schema_inference_spec.rb
196
+ - spec/integration/setup_spec.rb
197
+ - spec/integration/support/active_support_notifications_spec.rb
198
+ - spec/integration/support/rails_log_subscriber_spec.rb
144
199
  - spec/shared/database_setup.rb
200
+ - spec/shared/relations.rb
201
+ - spec/shared/users_and_accounts.rb
145
202
  - spec/shared/users_and_tasks.rb
146
203
  - spec/spec_helper.rb
147
- - spec/support/active_support_notifications_spec.rb
148
- - spec/support/rails_log_subscriber_spec.rb
204
+ - spec/support/helpers.rb
205
+ - spec/unit/association/many_to_many_spec.rb
206
+ - spec/unit/association/many_to_one_spec.rb
207
+ - spec/unit/association/name_spec.rb
208
+ - spec/unit/association/one_to_many_spec.rb
209
+ - spec/unit/association/one_to_one_spec.rb
210
+ - spec/unit/association/one_to_one_through_spec.rb
149
211
  - spec/unit/association_errors_spec.rb
150
- - spec/unit/combined_associations_spec.rb
151
212
  - spec/unit/gateway_spec.rb
152
213
  - spec/unit/logger_spec.rb
153
- - spec/unit/many_to_many_spec.rb
154
- - spec/unit/many_to_one_spec.rb
155
214
  - spec/unit/migration_tasks_spec.rb
156
215
  - spec/unit/migrator_spec.rb
157
- - spec/unit/one_to_many_spec.rb
216
+ - spec/unit/plugin/assoc_macros/combined_associations_spec.rb
217
+ - spec/unit/plugin/assoc_macros/many_to_many_spec.rb
218
+ - spec/unit/plugin/assoc_macros/many_to_one_spec.rb
219
+ - spec/unit/plugin/assoc_macros/one_to_many_spec.rb
158
220
  - spec/unit/plugin/base_view_spec.rb
159
221
  - spec/unit/plugin/pagination_spec.rb
160
222
  - spec/unit/relation_spec.rb
161
223
  - spec/unit/schema_spec.rb
224
+ - spec/unit/types_spec.rb
162
225
  homepage: http://rom-rb.org
163
226
  licenses:
164
227
  - MIT
@@ -179,34 +242,55 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
242
  version: '0'
180
243
  requirements: []
181
244
  rubyforge_project:
182
- rubygems_version: 2.4.5.1
245
+ rubygems_version: 2.5.1
183
246
  signing_key:
184
247
  specification_version: 4
185
248
  summary: SQL databases support for ROM
186
249
  test_files:
187
250
  - spec/fixtures/migrations/20150403090603_create_carrots.rb
251
+ - spec/integration/association/many_to_many_spec.rb
252
+ - spec/integration/association/many_to_one_spec.rb
253
+ - spec/integration/association/one_to_many_spec.rb
254
+ - spec/integration/association/one_to_one_spec.rb
255
+ - spec/integration/association/one_to_one_through_spec.rb
188
256
  - spec/integration/combine_spec.rb
189
257
  - spec/integration/commands/create_spec.rb
190
258
  - spec/integration/commands/delete_spec.rb
191
259
  - spec/integration/commands/update_spec.rb
260
+ - spec/integration/commands/upsert_spec.rb
192
261
  - spec/integration/gateway_spec.rb
193
262
  - spec/integration/migration_spec.rb
263
+ - spec/integration/plugins/associates_spec.rb
264
+ - spec/integration/plugins/auto_wrap_spec.rb
194
265
  - spec/integration/read_spec.rb
266
+ - spec/integration/relation_schema_spec.rb
267
+ - spec/integration/schema_inference_spec.rb
268
+ - spec/integration/setup_spec.rb
269
+ - spec/integration/support/active_support_notifications_spec.rb
270
+ - spec/integration/support/rails_log_subscriber_spec.rb
195
271
  - spec/shared/database_setup.rb
272
+ - spec/shared/relations.rb
273
+ - spec/shared/users_and_accounts.rb
196
274
  - spec/shared/users_and_tasks.rb
197
275
  - spec/spec_helper.rb
198
- - spec/support/active_support_notifications_spec.rb
199
- - spec/support/rails_log_subscriber_spec.rb
276
+ - spec/support/helpers.rb
277
+ - spec/unit/association/many_to_many_spec.rb
278
+ - spec/unit/association/many_to_one_spec.rb
279
+ - spec/unit/association/name_spec.rb
280
+ - spec/unit/association/one_to_many_spec.rb
281
+ - spec/unit/association/one_to_one_spec.rb
282
+ - spec/unit/association/one_to_one_through_spec.rb
200
283
  - spec/unit/association_errors_spec.rb
201
- - spec/unit/combined_associations_spec.rb
202
284
  - spec/unit/gateway_spec.rb
203
285
  - spec/unit/logger_spec.rb
204
- - spec/unit/many_to_many_spec.rb
205
- - spec/unit/many_to_one_spec.rb
206
286
  - spec/unit/migration_tasks_spec.rb
207
287
  - spec/unit/migrator_spec.rb
208
- - spec/unit/one_to_many_spec.rb
288
+ - spec/unit/plugin/assoc_macros/combined_associations_spec.rb
289
+ - spec/unit/plugin/assoc_macros/many_to_many_spec.rb
290
+ - spec/unit/plugin/assoc_macros/many_to_one_spec.rb
291
+ - spec/unit/plugin/assoc_macros/one_to_many_spec.rb
209
292
  - spec/unit/plugin/base_view_spec.rb
210
293
  - spec/unit/plugin/pagination_spec.rb
211
294
  - spec/unit/relation_spec.rb
212
295
  - spec/unit/schema_spec.rb
296
+ - spec/unit/types_spec.rb
data/.rubocop.yml DELETED
@@ -1,74 +0,0 @@
1
- # Generated by `rubocop --auto-gen-config`
2
- inherit_from: .rubocop_todo.yml
3
-
4
- # Exclude temporary files
5
- AllCops:
6
- Exclude:
7
- - tmp/**/*
8
-
9
- # It’s quite readable when we know what we are doing
10
- Lint/AssignmentInCondition:
11
- Enabled: false
12
-
13
- # No need to handle LoadError in Rakefile
14
- Lint/HandleExceptions:
15
- Exclude:
16
- - Rakefile
17
-
18
- # gemspec is a special snowflake
19
- Metrics/LineLength:
20
- Exclude:
21
- - rom.gemspec
22
-
23
- # The enforced style doesn’t match Vim’s defaults
24
- Style/AlignParameters:
25
- Enabled: false
26
-
27
- # UTF-8 is perfectly fine in comments
28
- Style/AsciiComments:
29
- Enabled: false
30
-
31
- # Allow using braces for value-returning blocks
32
- Style/BlockDelimiters:
33
- Enabled: false
34
-
35
- # Documentation checked by Inch CI
36
- Style/Documentation:
37
- Enabled: false
38
-
39
- # Early returns have their vices
40
- Style/GuardClause:
41
- Enabled: false
42
-
43
- # Need to be skipped for >-> usage
44
- Style/Lambda:
45
- Enabled: false
46
-
47
- # Multiline block chains are ok
48
- Style/MultilineBlockChain:
49
- Enabled: false
50
-
51
- # Result::Success and Result::Failure use > for callbacks
52
- Style/OpMethod:
53
- Exclude:
54
- - lib/rom/command_registry.rb
55
-
56
- # Don’t introduce semantic fail/raise distinction
57
- Style/SignalException:
58
- EnforcedStyle: only_raise
59
-
60
- # Need to be skipped for >-> usage
61
- Style/SpaceAroundOperators:
62
- Enabled: false
63
-
64
- # Accept both single and double quotes
65
- Style/StringLiterals:
66
- Enabled: false
67
-
68
- # Allow def self.foo; @foo; end
69
- Style/TrivialAccessors:
70
- Enabled: false
71
-
72
- # Allow rom-sql
73
- Style/FileName:
74
- Enabled: false
data/.rubocop_todo.yml DELETED
@@ -1,21 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2015-09-26 17:45:40 +0200 using RuboCop version 0.34.2.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 4
10
- Metrics/AbcSize:
11
- Max: 23
12
-
13
- # Offense count: 17
14
- # Configuration parameters: AllowURI, URISchemes.
15
- Metrics/LineLength:
16
- Max: 118
17
-
18
- # Offense count: 5
19
- # Configuration parameters: CountComments.
20
- Metrics/MethodLength:
21
- Max: 17
@@ -1,83 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Defining one-to-many association' do
4
- include_context 'users and tasks'
5
-
6
- before do
7
- conn[:users].insert id: 2, name: 'Jane'
8
- conn[:tasks].insert id: 2, user_id: 2, title: 'Task one'
9
-
10
- configuration.mappers do
11
- define(:users)
12
-
13
- define(:with_tasks, parent: :users) do
14
- group tasks: [:tasks_id, :title]
15
- end
16
- end
17
-
18
- configuration.relation(:tasks) { use :assoc_macros }
19
- end
20
-
21
- it 'extends relation with association methods' do
22
- configuration.relation(:users) do
23
- use :assoc_macros
24
-
25
- one_to_many :tasks, key: :user_id, on: { title: 'Finish ROM' }
26
-
27
- def by_name(name)
28
- where(name: name)
29
- end
30
-
31
- def with_tasks
32
- association_left_join(:tasks, select: [:id, :title])
33
- end
34
-
35
- def all
36
- select(:id, :name)
37
- end
38
- end
39
-
40
- users = container.relations.users
41
-
42
- expect(users.with_tasks.by_name("Piotr").to_a).to eql(
43
- [{ id: 1, name: 'Piotr', tasks_id: 1, title: 'Finish ROM' }]
44
- )
45
-
46
- result = container.relation(:users).map_with(:with_tasks)
47
- .all.with_tasks.by_name("Piotr").to_a
48
-
49
- expect(result).to eql(
50
- [{ id: 1, name: 'Piotr', tasks: [{ tasks_id: 1, title: 'Finish ROM' }] }]
51
- )
52
- end
53
-
54
- it 'allows setting :conditions' do
55
- configuration.relation(:users) do
56
- use :assoc_macros
57
-
58
- one_to_many :piotrs_tasks, relation: :tasks, key: :user_id,
59
- conditions: { name: 'Piotr' }
60
-
61
- def with_piotrs_tasks
62
- association_left_join(:piotrs_tasks, select: [:id, :title])
63
- end
64
-
65
- def all
66
- select(:id, :name)
67
- end
68
- end
69
-
70
- users = container.relations.users
71
-
72
- expect(users.with_piotrs_tasks.to_a).to eql(
73
- [{ id: 1, name: 'Piotr', tasks_id: 1, title: 'Finish ROM' }]
74
- )
75
-
76
- result = container.relation(:users).map_with(:with_tasks)
77
- .all.with_piotrs_tasks.to_a
78
-
79
- expect(result).to eql(
80
- [{ id: 1, name: 'Piotr', tasks: [{ tasks_id: 1, title: 'Finish ROM' }] }]
81
- )
82
- end
83
- end